Advice on handeling protocol transfer via COM Port requested 
Author Message
 Advice on handeling protocol transfer via COM Port requested

I am writing a program that communicates to an external device via the COM
Port.  The device does not support hardware handshaking but does support
ACK/NAK handshaking.

Data is received and sent  using the following packet format:

[ASCII DLE character]  [1 byte packet ID]  [1 byte data size]  [0 to 255
databytes] [1 byte checksum]  [ASCII DLE character]  [ASCII ETX character]

If there is a DLE character needed in the size, data or checksum then an
additional DLE is added as an escape character.

Right now I am sending a command to the device and then waiting a period of
time for a complete packet to return.  Since the length of the packet can be
variable I have to wait as long as it takes the longest packet to come back
from the device,  This is not very efficient.  Any tips on how to handle
this problem?  Any sample code out there?



Sat, 19 Apr 2003 12:53:31 GMT  
 Advice on handeling protocol transfer via COM Port requested

Quote:

> I am writing a program that communicates to an external device via the COM
> Port.  The device does not support hardware handshaking but does support
> ACK/NAK handshaking.

> Data is received and sent  using the following packet format:

> [ASCII DLE character]  [1 byte packet ID]  [1 byte data size]  [0 to 255
> databytes] [1 byte checksum]  [ASCII DLE character]  [ASCII ETX character]

> If there is a DLE character needed in the size, data or checksum then an
> additional DLE is added as an escape character.

> Right now I am sending a command to the device and then waiting a period of
> time for a complete packet to return.  Since the length of the packet can be
> variable I have to wait as long as it takes the longest packet to come back
> from the device,  This is not very efficient.  Any tips on how to handle
> this problem?  Any sample code out there?

SetCommTimeouts is just what you need.  You can set it to return when a couple
of character times have elapsed with no input, so it detects the end of message
by the silence that follows.

--
Scott McPhillips [VC++ MVP]



Sat, 19 Apr 2003 13:29:44 GMT  
 Advice on handeling protocol transfer via COM Port requested
Thanks Scott,

So I would set ReadIntervalTimeout and ReadFile would wait this period
of time for two characters (my [ASCII DLE character] andd [1 byte
packet ID])  ?   Is that right?



Quote:


> > I am writing a program that communicates to an external device via
the COM
> > Port.  The device does not support hardware handshaking but does
support
> > ACK/NAK handshaking.

> > Data is received and sent  using the following packet format:

> > [ASCII DLE character]  [1 byte packet ID]  [1 byte data size]  [0
to 255
> > databytes] [1 byte checksum]  [ASCII DLE character]  [ASCII ETX
character]

> > If there is a DLE character needed in the size, data or checksum
then an
> > additional DLE is added as an escape character.

> > Right now I am sending a command to the device and then waiting a
period of
> > time for a complete packet to return.  Since the length of the
packet can be
> > variable I have to wait as long as it takes the longest packet to
come back
> > from the device,  This is not very efficient.  Any tips on how to
handle
> > this problem?  Any sample code out there?

> SetCommTimeouts is just what you need.  You can set it to return when
a couple
> of character times have elapsed with no input, so it detects the end
of message
> by the silence that follows.

> --
> Scott McPhillips [VC++ MVP]

Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 19 Apr 2003 21:29:23 GMT  
 Advice on handeling protocol transfer via COM Port requested

Quote:

> Thanks Scott,

> So I would set ReadIntervalTimeout and ReadFile would wait this period
> of time for two characters (my [ASCII DLE character] andd [1 byte
> packet ID])  ?   Is that right?

No.  First, the function is SetCommTimeout.  Its sets the time ReadFile waits
while there is no input.  In other words, every received character resets the
timer.  If no character is received for the set interval then ReadFile returns.
So if you set an appropriate interval it will return after the end of a received
message, independent of the message length.  Think of it as an inactivity
detector, not a character detector.

--
Scott McPhillips [VC++ MVP]



Sun, 20 Apr 2003 10:41:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Transfer file via serial port

2. Need COM advice on 16 server/ 32 client with large data transfers

3. DCB Block -- Controlling device via RS-232 COM Port

4. Com Port Communication Via a Win32 DLL

5. HTTP protocol file transfer written in C

6. File transfer protocols and data compression source code/algorithm

7. File transfer protocols and data compression source code/algorithms sought

8. Excecption Handeling in COM - > going accross boundaries

9. C source for transfer protocols

10. What is the RTP(Real-Time Transfer Protocol)?

11. transferring long's via 8-bit fifo

12. Bytes transferred via Eternet-card

 

 
Powered by phpBB® Forum Software