How to precisely send out a command via serial every second?


Recommended Posts

Use the wait() function in your loop. Normally you really want to use delay(), but this is the one case for which wait() is designed:

while (1)

device.mydevice.write("VW,101" + chr(13)



Very important: make sure the timeout on your device is set smaller than the default of 1000 milliseconds. Otherwise, if you disconnect the device, the loop will slowly backlog as it will take slightly longer than 1000 milliseconds to loop (1000ms + however much time it takes to execute the other 3 statements).

The precision will depend on a number of things, but mostly on what else your system is doing. For best results do not run any other software than DAQFactory, especially anything that might access the disk a bunch. Turn off anti-virus and make sure automatic updates is turned off. You might want to go through your running processes and make sure all but the minimum is running. MsConfig is handy for this (go to Start-Run -> msconfig) It also helps if you are running a multiprocessor or dual core system.

You can get more precision by making sure the priority on the sequence is set to 5 and all other sequences are set to a lower value. You should also trigger any channels from sequences (using read()) instead of using the Timing parameter and set those sequences to priority 4. These steps will make your one sequence the top priority in DAQFactory.

Next, if you don't need display, you could run DAQFactory in Acquire Mode (File - Switch to acquire mode). This eliminates the user interface and bumps DAQFactory up into what windows calls the Real Time priority class. Its not really real-time, but it does put DAQFactory above all user level applications and almost all system functions, except maybe disk access.

Finally, there is a registry parameter that sets what is called the maximum spin time. This is the maximum amount of time DAQFactory will spin in a loop waiting for a particular time to occur rather than sleep (which takes no CPU time, but can create larger latencies). Larger values require more CPU time, but result in more precise timing. The default is 2 milliseconds, the maximum is 20. You have to restart DAQFactory for changes to take affect. The parameter is under HKEY_CURRENT_USER\Software\DAQFactory\DAQFactory\Settings. Note that since its under HKEY_CURRENT_USER, it will revert to 2 for a different windows login.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.