?
Solved

MsComm control Pass byte data to output

Posted on 1997-11-09
4
Medium Priority
?
643 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 600 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

800 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