Solved

read binary data stream through com port, create file

Posted on 2006-07-23
6
497 Views
Last Modified: 2008-03-06
I am new to working with binary data in vb.net and need to write code that will open a com port (com5) and read binary data from a sensor device. The binary data stream has characters "cs" and "end" that signify the start and end of the stream, respectively. A new data stream will begin every 5 minutes. I want to save the binary data inbetween the "cs" and the "end" characters to a file on the computer, let's say in "c:\sensor\binary" with a ".000" extension. I need to remove the "cs" and "end" from the resulting binary file.

I have seen several posts about serial/com ports, but nothing about reading the data in the stream (esp. data between certain characters) to a file and I wasn't sure about a replace function for binary data, either. I think I just need a kick in the right direction about how to approach the problem. Any help is appreciated.
0
Comment
Question by:dobbinjp
  • 2
6 Comments
 
LVL 9

Expert Comment

by:jrscherer
ID: 17165170
Hi
few questions:
has the data a constant length between the "cs" and "end"?
How do you recognize the "cs" and "end" info. Is this a unique binary pattern, not existing in the data?
Is the data a real binary pattern, as opposed to a stream of ASCII characters containing encoded data?
What is the expected data rate in bytes per second?

What vb.net version are you using?

The answer to these questions is important to understand the concept and to suggest the best solution.
Jack.net



0
 

Author Comment

by:dobbinjp
ID: 17168146
I figured I was leaving something out, here are the answers:

1. the data will not be a constant length between "cs" and "end" It is a pretty large stream (about 100kb worth of data every 5 minutes)
2. yes, "cs" and "end" are not found anywhere else in the data so it should be a unique binary pattern
3. the data does not look like 1's and 0's when I open it in Notepad, rather it looks like hieroglyphics (úLh q£T5TUD   ýÛþ¿E+ gÿÊÿ©ÿ   ? –ÿ    žÿñÿ   ­ÿéÿ    ÿØÿ  6), so I assume the answer is really a stream of ascii characters with the encoded data...I am a DB guy so not very used to working with binary data.
4. the expected data rate is 9600 8-none-1
5. I am using .NET framework 2.0, Visual Studio 2005

Thanks again!
0
 
LVL 9

Accepted Solution

by:
jrscherer earned 500 total points
ID: 17181892
Hi dobbinjp

I was looking into my own programs, but I found that I had always ASCII streams with CRLF as line terminator.

First I thought that the new my.Computer.Ports  in 2005 could do the job. But it is really string oriented and does not supply a byte stream or anything which could be converted into it.

You can get a byte stream using the WIN32 API
A good starting point is the sample:  101 VB.NET Samples\Framework - Using the COM Port
This is a 2003 sample set, but it still is working on 2005.

You can find it here http://www.microsoft.com/downloads/details.aspx?familyid=08e3d5f8-033d-420b-a3b1-3074505c03f3&displaylang=en

You will need to do some modifications in Rs232.vb to get a stream instead a string, but it seems to be doable.
Jack.net
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

18 Experts available now in Live!

Get 1:1 Help Now