LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute a series command automatically

Solved!
Go to solution

Hi, 

 

I am very new on Labiew. I made a vi as attached to drive a syringe pump and rotary valve, and it worked fine. what it does is to send command each time I click 'pump' or 'valve' button.

 

But now, I want to run a series of commands automatically, for instance, command #1 to pump, #2 to valve, #3 to pump, #4 to pump, etc. total number of commands will be around 10. I wonder what is the best ways to realize it.

 

Thanks a lot

0 Kudos
Message 1 of 24
(4,442 Views)
Solution
Accepted by topic author flylark1977

Make a cluster (a typedef) that for instance contains info on time and type of command (I supposed you would want to time the different commands)

Make an array of these "command clusters" (or a queue, read up on QMH) and feed it to a state machine that issues the commands at the right time.

If you are new to any of these concepts, read up on the free documentation before you start:

https://www.ni.com/getting-started/labview-basics/

 

By the way, you do not need the outer while loop. Instead, make the stop button a case in your event structure and wire the stop terminal to be true only in the stop button case.

 

0 Kudos
Message 2 of 24
(4,426 Views)
Solution
Accepted by topic author flylark1977

You can do several things:

 

1. Make all the code in the "Pump" event case into a SubVI. Do the same for all the code in the "Valve" event case. This can be done quickly by highlighting all the code and selecting from the menu Edit>>Create SubVI. If the connector pane has been set up to your liking, in a new VI, you can now string together these SubVIs, but still have a VI with an interactive UI as before.

 

2. Use the functions in the Events pallette to create user events. User events allow you to programmatically trigger (without UI intervention) cases within the event structure. With this in mind, the same event case could be configured for a UI event and a user event. Equipped with the user event refnum, you can then "fire" off the event by calling the Generate User Event function. Consult the LabVIEW documentation for information on user events in the event structure.

 

3. Follow the Queued State Machine design pattern as suggested by peterhult, which is probably the preferred method by seasoned LabVIEW folks.

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
0 Kudos
Message 3 of 24
(4,342 Views)

Thank you very much for you reply.

 I was able to build a state machine and queue the command, but am currently having trouble to excute the command at right time. Basically I could easily miss a command.

 

I wonder if I could get help from you on this regard.

Thanks!

0 Kudos
Message 4 of 24
(4,336 Views)

In your Queued State Machine, in addition to enqueuing the state to execute, you can also include the time to wait before moving on to the next state.

 

This can be done by changing the data type of your queue to a cluster that includes a numeric that represents the wait time. When you enqueue, bundle the state's name and time. On dequeue, unbundle.

 

If your code is written in a sequential manner rather than in parallel loops, you can use wires through shift registers to pass the wait time between states.

 

Alternatively, you can create a state machine case that is dedicated only to wait. Between enqueues of commands, enqueue this "Wait" state and its delay value.

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
0 Kudos
Message 5 of 24
(4,329 Views)

Thank you very much for your reply.

I am trying to figure out the first method.

When you say string together the subVIs do you mean use a flat sequence to lay out all the command?

Thanks.

 

0 Kudos
Message 6 of 24
(4,316 Views)

I usually do something like this.

 

Delay.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 24
(4,306 Views)

It's always a good idea to post the latest version of your VI with every new question you have so we can make suggestions.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 24
(4,304 Views)

Hi flylark1977,

 

Using a flat sequence structure is frowned upon nowadays.

 

You'll want to have an error-in and error-out cluster on the front panels of your SubVIs, so that the error cluster flows from one VI to the next. This enforces the dataflow execution sequence of the code in addition to picking up any errors that occur along the way. These error clusters usually are on the bottom left and bottom right of the connector pane.

 

Look at the way NI's functions are built for guidance. The File I/O functions and example code is a good starting place.

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
0 Kudos
Message 9 of 24
(4,300 Views)

Here is my latest version using state machine. I could not get the timing right...

basically, the next command started before the previous command finish, or  several command was simply skiped...

0 Kudos
Message 10 of 24
(4,280 Views)