Solved

Reading Binary Data from Serial Port

Posted on 2003-11-24
6
437 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 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

735 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