Solved

MsComm control Pass byte data to output

Posted on 1997-11-09
4
613 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

687 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