I am using a GPS mouse/receiver connected via USB (creates virtual COM port) to determine the computer time drift. GPS mouse sends a PPS event in form of a NMEA message I would like to have a precise timestamp of each message received so that I can calculate the difference between GPS time and computer time.
What is the best way to get a time stamp as soon as the message is received. I tried both with polling the serial port and data received event. Right now my code looks like this:
while ( serialPort.IsOpen())
{
if (serialPort.BytesToRead != 0)
{ GetSystemTimePreciseAsFileTime(out filetime);
DateTime collected = DateTime.Now;
time.Add(collected.Ticks.ToString());
time2.Add(filetime.ToString());
serialPort.DiscardOutBuffer();
serialPort.DiscardInBuffer()
}
else {
}
}`
I have tried with DateTime.Now.Ticks with Stopwatch but the Noise of the difference is arround 20ms. I have seen papers where 1ms accuracy/precision was achieved. Does anyone have an idea what am I doing wrong?