Answer the question
In order to leave comments, you need to log in
Execution of a section of code in real time, time tracking?
Here's a snippet of code:
t1 = timeGetTime();
Device.sendRequest( Command1 );
R1 = Device.readResponse();
Device.sendRequest( Command2 );
R2 = Device.readResponse();
t2 = timeGetTime();
cout << t2-t1 << " ms" << endl;
Answer the question
In order to leave comments, you need to log in
is Windows 7 a real time system? :)
set a higher priority - yes - it will help a little, but it won't get rid of the context switch.
if RT is important, then it is better to look towards RTOS, try Linux with an RT patch, etc.
Regarding timers in Windows, there is a good introductory article by Jan Wassenberg "Timing Pitfalls and Solutions"
github.com/0ad/0ad/raw/master/docs/timing_pitfalls.pdf
Windows has more accurate methods for measuring time, e.g. QueryPerformanceCounter. To find out if your process has been preempted, you can look up the value of some context switch counter.
Regarding the timer - have you already read stackoverflow.com/questions/1825720/c-high-precision-time-measurement-in-windows ?
This is the first link on Google for "windows high resolution timer".
As for the priorities, everything is written correctly, they write the same thing here.
Found by Google for "windows change process priority c++".
On a multi-core processor, the maximum priority will allow the process/thread to get _almost_ realtime.
If it still turns out to be insufficient, then it remains to either switch to a full-fledged (?) RT OS, or take a WDK and write your own driver :)
As already mentioned above: Windows is not Real Time. Second: a serial port, at least in XP / 2K - a tricky thing and the time may depend on the implementation of Device.readResponse. And the most, after all, the main question: what do you measure? Real time from receiving a parcel to the end of the transmission (from the point of view of the device) or the time from transmission to reception on Windows? If the first - LED and oscilloscope. If the second is sadness.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question