by cncdrive » Tue Sep 13, 2016 12:07 am
Yes, the wait time is 1/25Hz at the end of each loop. There is a fixed wait time (Thread.Sleep) at the end of the thread loop.
It is just a simple Thread running in the UCCNC.exe and calling the plugin dll once in every loop.
You could create your own same kind of Threads in the plugin and then if you want you can code it in a way to measure time at the end of the loop and then skip only when the time expired and that way you can have a loop which always runs at e.g. 25Hz except if your code execution requires more time than the 1/25Hz.
To skip if your code executes for more than the loop target time may be possible or may be not, depending on your code.
If all single lines of your code requires less than 1/25Hz then you can place time check codes and skip if the expired time is already greater or you could make a sequence of execution of the lines etc., but if it is an acceptable solution to skip in the middle of the job again depends on what your code is doing, what it's job is.
Ofcourse the 25Hz in this case was just an example you can code your own Thread loop to any frequency/time interval you want with the constraint of minimum 1msec time, because Thread.Sleep has that resolution.
Also please keep in mind that Windows is not a realtime system, so very short time intervals may be not very precise ... you can make it more precise with highering the Thread priority,
but take care to not set it too high at least not in the development process, because if you do you may need to reset your computer in case your Thread locks up for any reasons/mistakes in the development process and sucks up all of your CPU time.