04-01-2011 11:18 PM
Hi folks,
i'm using Labview to control a camera and a motor, both of which need some initialization before I can use them. Currently I check does condition manually but it is getting time consuming and unproductive. I wish that part of my code run first and before any other code in my VI. I'm a bit clueless of how can this be done and my gutfeeling is that is shouldn't be that hard.
I've tried using boolean to start my loop once the code is run but this is not effective when I more than one initialisation sequence to run. Labview run them in parallel...
Can somebody help?
Thanks in advance.
Solved! Go to Solution.
04-01-2011 11:35 PM
Hi,
I am not sure what exactly your are trying to say. May be sharing your code will give a bit more idea. Well if you just want to run a part of the code before running the rest, you can use a SEQUENCE STRUCTURE ( though this is not advised is all cases). Using error clusters for controlling data flow is a good practice. Getting a good idea of the data flow programming from here will help you. Take a look at the example vi which i have attached.. may be it will help you.
Regards,
Nitz..
(Kudos are always welcome)
04-02-2011 12:36 AM - edited 04-02-2011 12:37 AM
All you need to do is create a data dependency. It's all in the dataflow!
Can you give a bit more details on what your initialization code needs to do? Most likely it outputs an error at the end, so if if you wire that error to the edge of the main code loop, it will need to wait until the initialization has finished.
A better option would be to create a proper state machine, where one of the states is the initialization code. Trigger it as the first state. This method has the advantage that you can reinitialize again at a later time if needed, without the need for a program restart.
Never trap code in a sequence structure as above, it is very inflexible. For example it is not possible to skip one state or change the order at run time.
04-02-2011 12:53 AM
Hi AltenBach,
Thanks for mentioning the drawbacks of Sequence structure. I would be glad if you could tell me the ideal situations where sequence structures can be used. The usage of sequence structures has been confusing for me from day 1 of my labview.
Regards,
Nitz
04-02-2011 09:22 AM
Sequence structures are rarely needed if you use the dataflow paradigm on which LabVIEW is based. Stacked sequence structures obscure code, require left to right wiring to pass data among frames, and generally create more problems than they solve.
A single frame sequence structure can be used to enforce an order of execution on two nodes which have no data dependency. The common example of this is placing a Wait function between two VIs such as VISA Write and Read. Since the Wait does not have error in and error out terminals, wiring the error through a sequence structure with the Wait inside forces the wait to occur after the Write and before the Read.
A three frame flat sequence is used as a timing test structure. The first and third frames contain a Tick Count function and the middle frame contains the code to be timed. If the code being timed is likely to take less than a few milliseconds, it is usually repeated in a For loop to accumulate enough time to be measurable by this technique. This is only used to check various algorithms or programming techniques for speed and does not appear in the final code.
For most other purposes a sequence structure can usually be replaced by a state machine or other architecture which inherently uses dataflow and is much more flexible.
Lynn
04-03-2011 02:10 PM
HI Altenbach
Your call about state machine seems to be the answer I'm looking for. I never used state machine so couldn't think about it by myseif.
Beside what NI says about stage machine in labview, do you have any reference that could be useful?
Regards,
04-04-2011 08:17 PM
Hi mijac,
Here is a host of examples using state machines, just pick the one that looks like the most interesting.