Solved

read binary data stream through com port, create file

Posted on 2006-07-23
6
498 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

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

16 Experts available now in Live!

Get 1:1 Help Now