06-02-2009 08:58 AM
I am using CIV 9.0. I can set the 'SetComTime' for a ComRdByte to less than 1.0 mS, and the status returns 0 (no failure). However, if the device is not ready, or the timeout is exceeded, the 'timeout' will NOT return, ever.
Through trial and experiment, I determined that the low end of the SetComTime is 1.0 mS. Is this true? If not, what is the method to decrease the timeout lower than 1.0 ms?
Running at 115,200, there is less than 90uS for each byte when requesting 10 bytes. I should be able to set the timeout to 90uS.
Thanks in advance.
06-03-2009 03:19 AM
Gromit,
Could you post more details about what are you trying to do ?
Regards
06-03-2009 10:11 AM
the Windows API defines the comm timeouts in milliseconds, with zero signifying the timeouts are not used.
i can bet the behavior you see is in direct relation with those facts, and that you cannot achieve a timeout better than 1ms.
06-04-2009 01:32 PM
You should consider also the time required for the device to process your command.
Is it able to process your command, prepare an answer and transmit it within 1 ms?
Just remember that, if the device cannot respond within 1ms, your RS-232 function will return an error.
06-05-2009 08:06 AM
Thanks for all the replies.
I am trying to acquire serial data from an external device, connected via USB to an RS232 converter. The s/w uses ComRdByte to read a byte-@-a-time. The SetComTime seems to only go down to 1mS per ComRdByte.
I was hoping to set it much lower in order to use it as a message timeout (~90uS / byte). Setting to 1mS works, but if the read takes longer that 90uS, I cannot tell from the timeout.
Thanks.
Gromit
06-05-2009 08:46 AM
Gromit,
To be sure that I understand what are you trying to do, you want to detect that a byte has been missed during a transmision ?
If this is the case, using timeout is not the way to do it, because timeout function is supposed to detect that a character or a number of characters are not recieved in a rather long timeframe - in the range of seconds. And it's not only a matter of detecting this situation, but also taking an action, that can also take some aditional time, that cannot be predicted with sufficient precision, compared with the short timeframes that are you talking about (90us).
I guess that your approach would be more suitable for an application running under a real time OS or for an embedded application, than Windows.
Regards
06-05-2009 12:16 PM
with such short times between each byte, reading the data one byte at a time is not a good idea.
you certainly know that Windows is a multitasking OS, which means that many processes are running in parallel on the computer. since you have less processors than you have processes running, the system is cheating by executing small amount of each process regularly, which gives the impression of parallel execution. each execution frame is in the order of the millisecond, which means that your process may sometimes not be running for some millisecond. it is for the same reason that timers on windows are limited to a 5ms resolutions (now, really we can have a better resolution by using some specialized calls). so, you cannot guarantee that a byte you read did really come less than a ms after the previous byte. (sometimes, windows decides to swap a lot of stuff from the pagefile, locking the system for only half a second, but that's 500 characters that should have been read by the time windows schedules your process again).
you should also take into account the input buffer on the serial port: once the comm port is open and configured, every bytes coming in are stored into a buffer under the hood, and using ComRdByte reads from the buffer. the timeout comes into play only when the buffer is empty. this way, you can also not guarantee that a byte you read did really come less than a ms after the previous byte.
you should really consider reworking your reading process to read strings of multiple bytes at once: it will be much easier to program, less prone to timeout errors, and way more robust.
06-05-2009 12:23 PM
Thank you everyone.. it has become clear that I cannot use this method for such low response times. It was not a problem on earlier projects when the response time was 100 mS.
Thanks again for all your input, it is duely noted.
Gromit