Solved

Reading Binary Data from Serial Port

Posted on 2003-11-24
6
434 Views
Last Modified: 2006-11-17
I need to read binary data from a serial port. The data is in the format of 23 single byte values. After the values are read I need to combine pairs of byte values (high  and low) to get a 16 bit value.

I have read text values from the serial port before but have no experience in binary data. How do I ....

1) read binary data into a variable?
2) convert high and low single byte values into one 16 bit value?

Some simple code examples would be appreciated.
0
Comment
Question by:allsopp
6 Comments
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 500 total points
ID: 9811990
Here is a starting point for you:


Once you have loaded your data into a string from the COM port, you can use the Mid function to extract a single byte at a time.

Therefore to get the third of the 23 bytes out of your string (called sWholeString in this example), use:

sHigh = Mid(sWholeString,3,1)

That is a string. Then you can use Asc(sByte) to get the Ascii value.

iHigh = Asc(sHigh)

Then if your low byte is in the next byte, use this to get your 16 bit value:

sLow = Mid(sWholeString,4,1)

iLow = Asc(sLow)

iTotal = sHigh * 256 + iLow



Try it out and if it works and you want more detail let me know.
0
 

Author Comment

by:allsopp
ID: 9812014
Thanks. The actual equipment I need to talk to is arriving sometime this week. I'll try it out and respond then.
0
 
LVL 1

Expert Comment

by:MsLim
ID: 9834609
thinking
0
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.

 

Expert Comment

by:Steve-Howes
ID: 9845173
the parallel port is much easier to manipulate in vb, if you get dlportio from DriverLINX you can just use a function to return a value for the port,, but if the equiptment you are using will only support the serial port then it will be quite a bit harder to do
0
 

Author Comment

by:allsopp
ID: 9896579
The equipment is a radio tx/rx unit with a receiver that outputs to RS485 serial.
The code example you provided worked perfectly first time so the points are yours
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9896934
Sounds like fun whatever you're doing!
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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

867 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

15 Experts available now in Live!

Get 1:1 Help Now