LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
christian.karcher

Timeout terminal for while loops

Status: Duplicate

Hi,

 

one of my main errors while programming were infinite loops due to instruments that responded not as expected or numerical criteria that could not be fulfilled.

I got rid of these problems (with instrument I/O in particular) by introducing timeouts into my while loops, i.e. just counting the milliseconds and exit upon timeout.

Hence my idea is to integrate an optional timeout into while loops to simplify this procedure.

 

while loop timeout terminal

 

- Christian

7 Comments
altenbach
Knight of NI

A lot of IO operations have a settable timeout and generate an error on timeout, so you could use that to decide to continue looping.

 

I don't quite understand how your idea would fit into typical code? Can you give a more specific example? How does your current solution look like?

 

Many things are not clear to me. What if there is blocking code (event structure, long calculations, wait, etc.)? Should they get aborted if a loop timeout occurs or should the loop only terminate if all code of the current iteration has finished AND a timeout has occurred?

Should the timeout reset with every loop iteration or do you want a global timeout that starts at iteration zero and keeps going, independent of the number of iterations?

 

Sorry, so many questions!

christian.karcher
Member

lots of questions are always good, much better than none 🙂

 

  • A lot of IO operations have a settable timeout and generate an error on timeout, so you could use that to decide to continue looping. I don't quite understand how your idea would fit into typical code? Can you give a more specific example? How does your current solution look like?

That is correct. Whenever an instrument does not answer at all, this error can be catched quite nicely. But if the instrument is responding in an unexpected way and you are waiting for a specific answer, this  answer will never appear although the instruments continues to talk.

Examples: a camera which is stuck in the aquisition process continues to tell you that it is busy while you are waiting for an idle message. The only way to check if the camera is stuck is to count the time and compare it to the set up exposure time.

 

  • What if there is blocking code (event structure, long calculations, wait, etc.)? Should they get aborted if a loop timeout occurs or should the loop only terminate if all code of the current iteration has finished AND a timeout has occurred?

The latter.

 

  • Should the timeout reset with every loop iteration or do you want a global timeout that starts at iteration zero and keeps going, independent of the number of iterations?

Again, the latter. This timeout should only serve to prevent accidental endless loops. I see your point though, the only example I could really think of which is not connected to not-fail-proof programming is a freak-hardware failure (which happens). Maybe for these special cases one does not need new terminals + context menu entry. It was just an idea, which came to my mind when thinking of endless loops.

 

 

 

Zafer.Depe
Active Participant
christian.karcher
Member

I did a search on "while timeout" before posting this, unfortunatly not for "time out".

Zafer.Depe
Active Participant

This idea seems useful but people somehow doesn't meet long analyze durations or it is not such a matter.

 

I have found "How Do I Stop a Running VI Programmatically?". It aborts execution of the VI. So you should make a SubVI that is the critical part of the code inside the "while loop" and add a parallel "Execution Time Tracker Loop" to stop the VI if necessary.

 

I prefer "While Loop with Time Out Option" if possible.

christian.karcher
Member

This method is a little too violent for me Smiley Very Happy

Whenever I consider a loop critical, I add my "internal timeout counter" (which is a little bulky):

pitastic timeout loop.png

 

MaryH
Member
Status changed to: Duplicate