Re: Reading Serial Port
"clinisbut" <clinisbut@gmail.com> wrote in message
news:8eb60069-1f6d-47e9-977c-e7c5c3c1635e@v29g2000hsf.googlegroups.com...
If your timeouts are too short, then ReadFile will complete successfully
in a short period
of time, and return 0 bytes read, so the event will essentially become
signalled after
virtually no delay, and your CPU will quickly spike to 100% (in the RS485
case, I had the
timeouts wrong, and the reader thread went into an infinite high-priority
loop,
effectively disabling the entire machine; I changed the timeouts and it
worked quite fine
after that)
With timeout do you mean the timeout of the WFMO?
DWORD result = WaitForMultipleObjects( 2, hArray, FALSE,
INFINITE ); //<---- This
No. The timeout on a serial port refers to the setting of SetCommTimeouts.
It is used to tell ReadFile to return if no new data arrives within the read
timeout period.
Will incrementing the bytes per read cause to receive a frame (with
length>bytes_per_read) in two pieces? (Not receive the second part
until a second FRAME arrives) I can't deal with this behaviour.
Assuming that you use SetCommTimeouts so ReadFile will always return
promptly then you really have no control over the number of bytes returned.
It depends on the timing of the data source. You _must_ deal with this
behavior. If you get only part of what you consider a "frame" then save it
and assemble the frame later, when the rest has arrived. It's a simple
buffering algorithm.
--
Scott McPhillips [VC++ MVP]