Solved

MsComm control Pass byte data to output

Posted on 1997-11-09
4
559 Views
Last Modified: 2006-11-17
My question comes from the MsComm control.

I am trying to write a test program to control a microcontoler that I have programed.  The Microcontroler has  12 commands that it receivers from and rs232 interface programed into the chip.  What I am trying to do is to build an operations interface for the microcontroler.  What I am trying to do.

When I click on a button I want to send out a byte string.
Say command 1, I want to send eight bits that are "00000001".  I am trying to use this code

Private Sub Command1_Click()
Dim Buffer As Variant
Dim Channel1 As Byte
Channel1 = 1
Buffer = Channel1
MSComm1.CommPort = 3
MSComm1.PortOpen = True

MSComm1.Output = Channel1

Now the VB Books on line tells me that the type BYTE is

"Byte variables are stored as single, unsigned, 8-bit (1-byte) numbers ranging in value from 0–255"

Well this is what I want to output
But when I use my code I get an error saying type mismatch.

The Vb books online say this

To send binary data, you must pass a Variant which contains a byte array to the Output property.


What am I doing wrong.

0
Comment
Question by:jaalex
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:alamo
ID: 1440326
I don't know why the documentation claims you need to use a byte array for binary data, except that a binary array is slightly easier to work with than a string. Passing it through a variant probably should convert it to a string for the MSComm control, but I experience the same results as your do.

The MSComm control needs a string, so give it a string - who cares if the data is binary:

Dim strBuffer As String
strBuffer = Chr$(1)
MSComm1.CommPort = 3
MSComm1.PortOpen = True
MSComm1.Output = strBuffer

For binary data don't forget to set Handshaking to None or RTS/CTS, and NullDiscard to False. Good luck!
0
 

Author Comment

by:jaalex
ID: 1440327
Ok so I can pass a string.    But using the chr$ function will I get the byte information.

The micro will only understand  

Start bit + eight data bits + stop

The commands can only be

Start + "00000000" + stop
Start + "00000001" + stop

Anyway you get the picture.  

I read in the doc that if I do

Dim buffer as String

buffer = Chr(67)  

I will return an A value.   Is this the same as a Chr$

If you feel you need more points I will add them
0
 
LVL 6

Accepted Solution

by:
alamo earned 150 total points
ID: 1440328
Yes, Chr and Chr$ are basically the same, VB is trying to get away from $ to denote strings but I use it out of habit. Actually, I just looked the the help and they have changed Chr so it deals "properly" with double-byte character sets; ChrB is guaranteed to return just 1 character, used for the sort of thing you need.

So 'Start + "00000000" + stop' would be ChrB(0), 'Start + "00000001" + stop' would be ChrB(1).

(Actually, Chr(65) is "A", not Chr(67), which is "C").

Let me know how it works... the points are fine. By the way, you can leave a comment without rejecting the answer if you need more information or clarification; when you leave a comment I get an email notifying me so I can check.
0
 

Author Comment

by:jaalex
ID: 1440329
OK cool  I will check it out.

Thanks for the info
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 50
add text to end of existing text in file 16 69
to transfer string from C lanaguage to VBA 4 56
vbModal 12 31
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now