Solved

Reading Binary Data from Serial Port

Posted on 2003-11-24
6
433 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
Comment Utility
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
Comment Utility
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
Comment Utility
thinking
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:Steve-Howes
Comment Utility
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
Comment Utility
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
Comment Utility
Sounds like fun whatever you're doing!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now