Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading Binary Data from Serial Port

Posted on 2003-11-24
6
Medium Priority
?
443 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
[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
6 Comments
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 2000 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
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!

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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

604 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