LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loops, timers and errors


GerdW wrote:

Hi Tzench,

 

you should always check errors in loops to avoid endless iterations...

And I would advise to use shift registers with error wires!


 

Gerd,

 

Are you sure about this?  I generally don't use shift registers on error wires.  Suppose I am repeatedly reading a VISA in a while loop but I get a timeout error,  perhaps a cable was accidentally unplugged.  I want to try the read again on the next iteration.  But the timeout error would be sent into the next iteration and would keep the VISA read from trying to read the port again.

0 Kudos
Message 11 of 35
(1,213 Views)

There are few points about the code.

 

1. When the first loop doesnt get data it will be struck in the loop for ever which will stop your timer from ticking, the other operation scheduled for 250ms will not happen.

2. If the first loop ends with error and gets out of the loop, yes the second loop also will get the error as you said.  But if first while loop successfully gets gets the data what is the probability that second loop will not generate and get struck within it.

3.If you are not interested with error handling at least make a timeout exit as shows in the picture which will force the loop to exit after specified time has elapsed. 

With regards,
JK
(Certified LabVIEW Developer)
Give Kudos for Good Answers, and Mark it a solution if your problem is solved.
Message 12 of 35
(1,200 Views)

GerdW wrote:

Hi Tzench,

 

you should always check errors in loops to avoid endless iterations...

And I would advise to use shift registers with error wires!


Should the error wire be connected to a shift register? What would be the purpose of that?

0 Kudos
Message 13 of 35
(1,179 Views)

2. If the first loop ends with error and gets out of the loop, yes the second loop also will get the error as you said.  But if first while loop successfully gets gets the data what is the probability that second loop will not generate and get struck within it.

But if there is an error in first loop, there is no mechanism that will automaticaly skip the second loop is there? Therefore, there should be some kind of check if the first loop worked before starting the second. I could put the second loop in a case structure connected to the status boolean - there is hardly any point in trying to read again if it didn't work the first time.

0 Kudos
Message 14 of 35
(1,176 Views)

Hi TZench,

 

without a shift register you would always use the state of error that enters the loop, changes of error state in the loop will be forgotten by next iteration...

 

I think it's a bad idea to forget changes of error state... It will definitely be better to incorporate some error checks in your code.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 15 of 35
(1,174 Views)
Message Edited by Baji on 04-03-2009 02:28 PM
Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
0 Kudos
Message 16 of 35
(1,173 Views)
Message Edited by Ravens Fan on 04-03-2009 10:58 AM
0 Kudos
Message 17 of 35
(1,145 Views)

That's weird, when I went to edit the previous post to insert the picture, it didn't give me the original text.  And every time I pasted it back in (luckily I has a sense something was going to go wrong and I saved it to a text file before it got lost), it never actually submitted the text I pasted.  I still think these forums have major problems with the editor that just didn't exist with the old editor months ago.Smiley Mad

Ravens Fan wrote:

Message Edited by Ravens Fan on 04-03-2009 11:02 AM
0 Kudos
Message 18 of 35
(1,141 Views)

IT DID IT AGAIN!Smiley MadSmiley Mad  I'll try again by completely logging out of the forums and closing IE and coming back in.

 

--------------------------------------------------------------------------------
Ravens Fan wrote:

Here is the mechanism to skip the second loop in the event of an error in the first loop.

 

Gerd,

I disagree that you would want to put a shift register on the error wire of a while loop.

Suppose you have a while loop where you continually write to a serial port then read from it.  You've put in timeouts so that the loop doesn't get stuck waiting for bytes that might never come such as someone kicked a cable.  They discover it and plug it back in.  Wouldn't you want the loop to continue to try writing and reading again?  I would.  But if you carry your timeout error into the next iteration of the loop, the VISA write and read will be skipped.

 

In general, if you have errors at the end of a while loop, you should plan for them and handle them accordingly, whether it is to stop the loop, clear certain errors, flash a warning on the front panel, (rarely use pop up dialogs as they would stop the program, or give continuous popups each time you hit OK).  Perhaps if you have a sort of state machine and you want to carry the error into the next iteration that executes an error case, handles the error, and clears it in that following iteration, then you would want a shift register.  But I would never wrap just a VISA read as shown in the OP's code with just a shift register without handling the error in some special way.

Message Edited by Ravens Fan on 04-03-2009 11:06 AM
0 Kudos
Message 19 of 35
(1,137 Views)

About delay:

I have used the tick count since I need to synchronize two different events with different period time. Introducing some form of delay, and still keeping the tick count seems absurd, whouldn't I risk missing some event? should I not remove the tick count instead, and use some other timing device?

0 Kudos
Message 20 of 35
(1,096 Views)