Re: Reading Serial Port
- From: clinisbut <clinisbut@xxxxxxxxx>
- Date: Thu, 31 Jan 2008 23:26:32 -0800 (PST)
Your high CPU usage is probably due to your request to ReadFile to
read only one byte and return. That is very inefficient and wasteful if the
characters are arriving every millisecond!
In this test I set up frames of 16 bytes length only for testing
purposes, but in final version each frame will have different lengths
(16 will be the maximum). That's beacuse I grab a byte each time (the
first byte will say me how many bytes).
If your timeouts are too short, then ReadFile will complete successfully in a short periodWith timeout do you mean the timeout of the WFMO?
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)
DWORD result = WaitForMultipleObjects( 2, hArray, FALSE,
INFINITE ); //<---- This
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.
.
- Follow-Ups:
- Re: Reading Serial Port
- From: Joseph M . Newcomer
- Re: Reading Serial Port
- From: Scott McPhillips [MVP]
- Re: Reading Serial Port
- Prev by Date: Re: CoCreateInstance() returns E_OUTOFMEMORY
- Next by Date: overlapped serial coms
- Previous by thread: Making a CListBox have horizontal ScrollBars???
- Next by thread: Re: Reading Serial Port
- Index(es):
Relevant Pages
|