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
Solved

MsComm control Pass byte data to output

Posted on 1997-11-09
4
593 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

856 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