View previous topic :: View next topic |
Author |
Message |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
RS232 Rx Frame Question |
Posted: Mon Aug 09, 2010 12:27 pm |
|
|
Hi,
I need to get a variable length frame from RS232, I use int_rda and I need to know which is the best way for detect that the end of frame.
The frame have this format |ETX|CMD|LEN|DATA|CRC|ETX|
I wait for your comments,
Thanks & Regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 09, 2010 12:45 pm |
|
|
Where does this protocol come from ? What device ?
Are you certain that it begins with "ETX" ? It would be a lot easier if it
began with "STX" (Start of Text). It would be more logical, too. |
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Mon Aug 09, 2010 12:50 pm |
|
|
PCM programmer wrote: | Where does this protocol come from ? What device ?
Are you certain that it begins with "ETX" ? It would be a lot easier if it
began with "STX" (Start of Text). It would be more logical, too. |
This frame come in from PC, I have a error, sorry, the frame start with STX.
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Aug 09, 2010 6:40 pm |
|
|
Quote: |
I need to know which is the best way for detect that the end of frame
|
By the way, ETX is used specifically to detect an end of frame in strings of variable length.
regards. |
|
|
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Mon Aug 09, 2010 7:56 pm |
|
|
Humberto wrote: | Quote: |
I need to know which is the best way for detect that the end of frame
|
By the way, ETX is used specifically to detect an end of frame in strings of variable length.
regards. |
PCM Programmer
Thank for your time!, I dont want that you write the code for me, my question is for know how to implement this other people.
Humberto, you are wrong, in the binary frame the char 0x03 can exist into the frame, is not possible detect the end of frame seeking the char 0x03.
thanks, |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Aug 10, 2010 10:38 am |
|
|
You defined you protocol in this way
Quote: |
The frame have this format |ETX|CMD|LEN|DATA|CRC|ETX|
|
FYI, LEN=Packet length
Hence, you know in advance in what position you are going to expect ETX.
If it's a continous stream you might have to get more tricky based upon known commands sequences and lengths etc.
There is not any conflict handling data streams in this way, I have made hundreds of systems and they are still
running since years.
Humberto |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Tue Aug 10, 2010 3:06 pm |
|
|
How about this? Both you and Humberto are correct
Quote: | Humberto, you are wrong, in the binary frame the char 0x03 can exist into the frame, is not possible detect the end of frame seeking the char 0x03. |
If you are referring to binary numbers, then you are correct; 0x03 could be one of the sequence of numbers on the frame.
Quote: | ETX is used specifically to detect an end of frame in strings of variable length |
For strings (which is what Humberto is referring to) this is true. A normal character will not be 0x03, lookup the ascii chart and noticed 0x03 is defined as ETX.
The frame structure you are looking at really only makes sense for strings (or characters), not for straight binary numbers. Not saying you could not use it for such, but to use it for binary numbers then STX and ETX would not have much meaning. It really all depends on how you define the frames.
In either case, you would probably use buffering (as previously suggested). |
|
|
|