Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting

5.16 Avoiding being hanged

Scroll Prev Top Next More

It is really easy to write an infinite loop in DAQFactory:

 

while(1)

  Input.read()

endwhile

On a first look, this sequence seems fine.  It will continuously read the Input channel.  The problem is that the sequence does not release the CPU for other tasks.  Instead as soon as Input channel is read, the sequence loops and reads it again.  This would be better:

 

while(1)

  Input.read()

  delay(0.1)

endwhile

Now we have a delay statement and the sequence will release the CPU for 0.1 seconds every time it reads Input.  This will also cause Input to be read 10 times a second rather than as fast as electronically possible.  The worse part about the first example without the delay() statement is that, when run, it may hang DAQFactory and possibly your computer as it uses all the CPU time.  

As such, you should always make sure you have some sort of delay() inside your loops.  There are, of course, exceptions, such as when you want to loop through an array for data processing.