LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loops, timers and errors

I have made a subVI containing a loop which is supposed to syncronize some activities with a clock (Tick count). The SubVI also has in and outlets for errors. The error wire passes through two different case strucures inside the while loop.

 

As I run the program the clock seems to get stuck almost imediatly, but the loop keeps doing more and more iterations. Could this be a data flow problem, that the error wire sends the program of in the wrong direction when it's supposed to tick up the clock?

0 Kudos
Message 1 of 35
(3,381 Views)

Seeing the block diagram the error cluster is routed into the case structure and should not affect the millisecond timer function.  If the VI is struct within the VISA functions the timer will stop but are you sure that the VI is still running without hanging up in the subVI's.  can you post the code so that we can probe into it.

 

Note:

1. As good programming practice introduce a delay in the while loop to avoid 100% CPU usage

2.Use appropriate data types to avoid coercion dots in the code that will make the code memory efficient.

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

Do you see a potential abuse of data types?

0 Kudos
Message 3 of 35
(3,345 Views)
 
Download All
0 Kudos
Message 4 of 35
(3,342 Views)

When the basic programming practices are followed without flaw the code will run without error and in your case i can see that very clearly.  You have violated the programming law by not handling the errors within your loop. 

 

When the visa read returns error the get string.vi gets struck in the while loop indefinitely since you have not handled the error case.

 

The programming practices and suggestions might be simple but  following it you can avoid errors and debugging cycles.  A developer might not anticipate many problems by not following these but in a bigger setup these will reflect and the performance of the code gets affected.

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

Hi Tzench,

    I seen some of your posts, I think ur new to LabVIEW. For best programming practices go through LabVIEW basics manuals.Here i attached some usefull information for you regarding the while loop and error handling.

1) Ya as JK told your while loop got stucked in the getstrings vi without proper error handling.

2) your Vis consuming maximum CPU usage because of absence of delays inside the loops.

 

http://zone.ni.com/reference/en-XX/help/371361B-01/lvconcepts/error_checking_and_error_handling/

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.
Message 6 of 35
(3,329 Views)
This loop sits in a main program which consists of a series of loops. The error wire makes these loops know in which order they are supposed to be executed. As far as I knew this was a well established way of programming in LabVIEW. If every loop should contain an error handler, how could I still upkeep the order of events?
0 Kudos
Message 7 of 35
(3,326 Views)

As you said:The error wire makes these loops know in which order they are supposed to be executed. As far as I knew this was a well established way of programming in LabVIEW

But you have not strictly follwed the well established way of programming  Smiley Tongue.Find your mistakes in the attaached screen shots.Smiley Very Happy

 

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.
Download All
Message 8 of 35
(3,313 Views)
Is the second loop in GetString in some manner safe from errors, or should it also have a status check? As far as I can tell, if you run into an error in the first loop, the second will crash from the same reason, since they are quite similiar.
0 Kudos
Message 9 of 35
(3,299 Views)

Hi Tzench,

 

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

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

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 35
(3,281 Views)