Hello,
For an application I am writing I am time stamping each byte as it comes in.
I am using the following code to read in the byte and record it as it comes
in. I then find the difference between the times at which the bytes came and
build a new array of time differences. The only thing is that sometimes I get
negative values within this differential time array which doesnâ??t make much
sense to me. Other times Iâ??ll get almost all negative values with a few
positive ones.
The only reasons I can think of is that the performance counter loops around
and the occasional negative value is the result of this. But, does that
explain the times when I get a majority of negative values with a few
positives? If I replace the ReadFile with a sleep(10) I get times that make
sense.
Hereâ??s a stripped down version of my code:
LARGE_INTEGER times[1000];
LARGE_INTEGER time;
if (WaitCommEvent(m_hIRPort, &commEvent, NULL)) {
while (numRead && bufNdx < 1000) {
ReadFile(m_hIRPort, buffer + bufNdx, 1, &numRead, NULL);
QueryPerformanceCounter(&time);
times[bufNdx] = time;
bufNdx++;
}
}
__int64 adjTimes[1000];
for (int ndx = 1; ndx < bufNdx; ndx++)
adjTimes[ndx] = 1000000 * (times[ndx].QuadPart - times[ndx-1].QuadPart)
/ freq.QuadPart;
Kyle