Results 1 to 7 of 7
Hi,
I'm planning to use an RS422 to USB converter to fetch bytes arriving over an RS422 port from an instrument. Each data set or sample contain 37 bytes including ...
- 07-24-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 7
Reading Bytes from RS485 stream
Hi,
I'm planning to use an RS422 to USB converter to fetch bytes arriving over an RS422 port from an instrument. Each data set or sample contain 37 bytes including a one byte checksum at the end. The data sample begins with a few sycronization bytes denoting the beginning of the sample.
I do not know when I will start recieving the datastream so I would like to listen to the port and first detect the synchronization bytes and then store all of the 37 bytes of the sample. Then I would like to validate the sample by checking it against the checksum. Then I would like to strip the sample of the bytes of the unessesary bytes and keep those that I want to process.
I'm wondering if there is an efficient and simple way to do this in C?
I've worked with RS232 datastreams, but that was at a low datarate. This RS422 stream will be streaming at 115200 baud. I do not need to catch every sample that comes over the stream, but I would like to make sure that I capture a complete sample each loop through my program so that the checksum checks out.
Initially, it is fine to not get all the 37 byte samples coming over the data stream, but as an improvement, I would like to figure out a way to not miss a sample. This is so that I can apply some filtering to the data coming over.
Thank you,
windell
- 07-24-2008 #2There's no reason why not. What you've described is fairly simple.I'm wondering if there is an efficient and simple way to do this in C?
Unless.
Unless I'm missing a complication. Is your program also doing I/O to other devices as they permit? Is your program also trying to do other computations? Are there other programs contending for the CPU so yours could get starved?
If not, just code it as you've described it. Come back here with specific questions as you go.
It would make your program simpler just to catch all the data and not miss any. Again, unless I'm not seeing some complication here.Initially, it is fine to not get all the 37 byte samples coming over the data stream, but as an improvement, I would like to figure out a way to not miss a sample.--
Bill
Old age and treachery will overcome youth and skill.
- 07-24-2008 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 7
Thanks for the reply, wje_lf.
There is a chance that my code will go as part of a larger loop so I might miss some of the data streaming.
Also, even if I'm only running my program as part of a forever while loop I'm not certain if my loop will come around fast enough as it has to process the sample it just recieved...and the next sample comes immediately after.
The stream is arriving at a steady rate so it doesn't wait on the program.
I was actually looking for some code example. I know how to read ASCII characters from a serial port, but I don't know how to read bytes. I'm sure its pretty simple, but I haven't had any experience with yet.
- 07-24-2008 #4
If you already know how to read ASCII characters from a serial port, you know how to read bytes. It's the same thing, unless your reading of ASCII characters involved setting the number of data bits per byte to 7. Set it to 8 in the usual way, no parity (probably), and you're set. Just refactor your old code.
Be prepared, then, for buffer overflow errors. I've had no experience with those, but you'll learn some new stuff along the way. :)I'm not certain if my loop will come around fast enough
Your own experience with reading ASCII characters from a serial port should be sufficient. But if you want other sample code, download this. I wrote this application to communicate with a modem, but you can ignore the parts you don't need. It's insanely well documented if I say so myself. :)I was actually looking for some code example.
I will leave that source code there for at least two weeks.--
Bill
Old age and treachery will overcome youth and skill.
- 07-26-2008 #5Just Joined!
- Join Date
- Jul 2008
- Posts
- 7
This might be a dumb question, but how to I know when the byte starts with all the zeros and ones coming over the line? I do not know of any delimiters that are with the stream seperating the bytes.
- 07-27-2008 #6
I don't remember the details from my college days 40 years ago, but there are framing bits (start bits and stop bits) which help make this work. It's transparent to the programmer.
--
Bill
Old age and treachery will overcome youth and skill.
- 07-30-2008 #7Just Joined!
- Join Date
- Jul 2008
- Posts
- 7
thank you very much wje_lf. I just remembered that. Thanks for your patience!


Reply With Quote