views:

40

answers:

1

I need to measure the time between character events on a serial port, preferably under Windows 7.
I have read in various places, statements like "Windows will not provide greater resolution than 10ms", but I have not been able to find out what that really means.
Is the problem that the OS will not deliver the events with greater accuracy, or is it that the timing functions (for measuring) used to be that "poor"? (I'm thinking GetTickCount)

If the latter, then I guess I should be able to use something like QueryPerformanceCounter for good-enough measuring, but if the events aren't delivered with similar accuracy, that obviously won't help.

+1  A: 

I think the 10 ms time is due to the task switching. Even if your timing application is the only user task running, there are still a bunch of system tasks that might get switched in.

On top of that, I'm guessing that the time between receiving a character on the port and receiving a DataReceived event (or whatever software notification you want) is highly variable. The UART chip may not interrupt the CPU until it feels like it (usually when its FIFO is full or some timeout expires), then the kernel may decide to take some time before sending that interrupt information on to your application. So even though you can use a high resolution timer in your software, you would probably be at the mercy of hardware/kernel level variability.

mtrw
Task switching sounds obvious, now that you say it. Regarding the UART, I would have expected buffer limits etc. to be configurable, but maybe I'm a bit optimistic. Sounds like I need to do more research anyway.
Niklas
@Niklas - You can set the read buffer size: here's the .NET way: http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.readbuffersize.aspx. Of course, who knows if this really works, or if you can pass a number like 1. Also, I stumbled upon this VERY detailed discussion of the event handling layers in the .NET SerialPort class: http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/e36193cd-a708-42b3-86b7-adff82b19e5e/. Even if you're not using .NET you might find it interesting.
mtrw