Daniel Jackson Peacock
Sandia National Laboratories
Best Regards,
Chirs Matthews
National Instruments
For anyone who might be in a simular position, I'll explain how I
solved this. The code that I had that was constantly refreshing first
sent a request over the serial port and then read a responce which was
always X bytes long. What I did was install a callback that is called
every time that X bytes are received.
In this callback all I do is set a flag variable (x_bytes_read) to
one. Then in my function that does the constant updateing I put the
following
//send request
x_bytes_read = 0;
ti = Timer();
while (!x_bytes_read && Timer()-ti < COM_TIMEOUT){
ProcessSystemEvents();
}
if (!x_bytes_read) {
// we timed out return error
}
// read responce
This way, when I'm in the refreshing code I wait for the callback to
be called before proceding, so I know that the data is already there.
And if the callback is called when I am using the comport for
something else it is harmless (and my main loop garentees that all
events are processed before the refresh code is run again, so I know
that the callback was one that was issued after I sent the request not
left over from some other communication). Hope this will help someone
else in the future.
Cheers
D. Jackson Peacock
up a callback for the code that is constantly refreshing.
// send request
in = GetInQLen (COM_PORT);
while (in < size){
Delay ((size-in)*8/(double)COM_RATE);
in = GetInQLen (COM_PORT);
}
// read responce
For some reason this was far less effecient (2x-3x slower depending on
the sleep policy) than the previous solution I posted. I have not
noticed any signs that the callback has significant overhead while
running. The most overhead I noticed was installing the callback,
which is why I chose to run it constantly instead of installing it
just before each wait, and disabling it afterwards. I agree that what
you say appears to be a fine way of solving the problem, it just
unfortunately did not turn out that way for some reason.
Thank you for your post.
jackson