J
Jamie Risk
I'm trying to implement a protocol that has a concept of a GAP
timer in the serial stream; if two properly framed characters
are spaced in time by so many milliseconds or longer, there is
an error.
So far I'm looking at using the SerialPort.DataReceived event.
It's nice because I can suck in bytes filter it through a state
machine to see if packets are properly framed than raise an
event. The problem as I understand it, the DataReceived event
is minimally guaranteed to fire every time it gets
ReceivedBytesThreshold.
This doesn't help me, if I set the threshold to one (1), on the
odd occasion my event handler may be dealing with two or more
characters in the buffer. All this to write that the
DataReceived event isn't a perfect solution for implementing a
GAP timer.
I'm not comfortable with the idea of using the
SerialPort.ReadTimeout mechanism for two reasons:
1. I'm not sure it times what I want it too (could
someone fill me - see the post script?)
2. The DataReceived event mechanism looks like it would work
more nicely with threading. (As opposed to continually
calling SerialPort.ReadByte and relying on the timeouts.
I'm really, _really_ new at this .Net/C# stuff, design help
would be appreciated.
- Jamie
p.s. Does the ReadTimeout mechanism start counting during some
point to the call of ReadByte/Char/Existing/Line/To?
timer in the serial stream; if two properly framed characters
are spaced in time by so many milliseconds or longer, there is
an error.
So far I'm looking at using the SerialPort.DataReceived event.
It's nice because I can suck in bytes filter it through a state
machine to see if packets are properly framed than raise an
event. The problem as I understand it, the DataReceived event
is minimally guaranteed to fire every time it gets
ReceivedBytesThreshold.
This doesn't help me, if I set the threshold to one (1), on the
odd occasion my event handler may be dealing with two or more
characters in the buffer. All this to write that the
DataReceived event isn't a perfect solution for implementing a
GAP timer.
I'm not comfortable with the idea of using the
SerialPort.ReadTimeout mechanism for two reasons:
1. I'm not sure it times what I want it too (could
someone fill me - see the post script?)
2. The DataReceived event mechanism looks like it would work
more nicely with threading. (As opposed to continually
calling SerialPort.ReadByte and relying on the timeouts.
I'm really, _really_ new at this .Net/C# stuff, design help
would be appreciated.
- Jamie
p.s. Does the ReadTimeout mechanism start counting during some
point to the call of ReadByte/Char/Existing/Line/To?