LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to synchronise two VI


@Naama2110 wrote:

Bob, thank you very much for your response. I don't have anyone I can consult because nobody works with labview, but I will try to learn it from youtube.


Well, you are attempting to do "not-so-elementary things" using LabVIEW, so it really helps to have a local "guru" for support.  But the Forum is filled with such gurus, and we'll try to suggest things you might consider.

 

Here is one way to do what you originally described, namely have two VIs run alternately until some condition has been met.  I'm going to show you, using simple "Demo" VIs, one way  to do this.  I'll describe it in words rather than "do it for you", as you seem eager to learn, and it will "stick" much better if you do it yourself.

 

  1. Create Main.vi, which will be the State Machine that runs two sub-VIs, "First" and "Second", alternately until you push a "Quit" button.  The Front Panel of Main should have a Quit button and a large sub-Panel (found on the Containers Palette) that takes up most of your PC's screen.  Sub-Panels are a mechanism by which you can run sub-VIs as though they were the Top-Level VI, giving you access to their Front Panels and controls.
  2. Put an Enum on the Front Panel and right-click "Edit" it so it has two entries, "First" and "Second".  We'll come back to Main in a few steps, but now let's create the VIs First and Second.
  3. Create First.  Open its Block Diagram, put down a For Loop, put a Delay of 1000 msec (i.e. a 1-second Wait) inside, wire an indicator "Loop" to the index, and wire a constant 10 to the Loop count. 
  4. Add Error In and Error Out, wired to the lower left and right corners, and wire the Error Line through the While Loop.  From the Block Diagram, right-click Error In and choose "Hide Control" (you don't need to see it on the Front Panel).  Do the same with Error Out.  You now have a sub-VI whose Front Panel consists of a Loop counter that counts from 0 to 9 at 1 Hz, then the VI exits.
  5. If you know how to do this, create a VI Icon that says "First".
  6. Create Second.  Do the same as you did for First, except use a While Loop, add a Stop Indicator, and change the Delay to 500.  This will now count at 2 Hz until you push the Stop button.  Make sure that the Front Panels of First and Second are small enough to fit into the Sub-Panel you made in Main.
  7. Now let's return to Main and make our State Machine that runs First and Second  (if I had two more VIs, I would describe Main as "One VI to Rule them All, and with LabVIEW, Bind Them").  Its Block Diagram should show the Quit Control and a Sub-Panel Method node saying "Insert VI".
  8. Start the State Machine by creating a While Loop surrounding a Case Statement.
  9. Right-click the Enum and select "Change to Constant".  [A better thing to do would be to right-click it and choose "Create TypeDef", as almost all Enums and almost all Clusters that you create should be associated with a TypeDef that becomes part of your code, giving you a single place to define or modify them, but for this Demo, I'm taking a short-cut].  Note that it now can be set to "First" or to "Second".
  10. Put a Shift Register on the While Loop, wire the Enum (showing "First") to the Shift Register from outside the loop, the Shift Register to the Case Selector.  The Case Selector should now show "Second".  Copy the Enum into this Case and wire it to the right Shift Register.
  11. Now drag the Sub Panel "Insert VI" Method and the Quit Control into this "Second" Case.
  12. Insert the Second VI into this case (right-click, choose "Select VI ...", find Second.vi).  Wire Error Out from the Sub Panel Method to Error In of Second, Error Out of Second to a new Shift Register on the outer While Loop, and wire the new left Error Shift Register to Error In of the Insert VI Method.
  13. From the Application Control Palette, drop a Static VI Reference.  Right-click it, Browse for Path to Second VI.  Wire this to the VI Ref input of the Insert VI Method.
  14. Now here's a useful trick when working with Case Statements and Enums.  Look at the other Case(s) -- it should say "First, Default", and be empty.  Right-click the upper edge of the Case structure and choose the following:
    • Remove Empty Cases.  This gets rid of everything except "Second".
    • Now right-click the upper edge and choose "Duplicate Case".  You'll populate the First Case, but with "Second" information.
    • Right-click the Static VI Reference and browse for First.
    • Replace the instance of Second (sitting on the Error Wire after the Insert VI Method) with First.
    • Change the "next State" Enum to Second.
    • Now go back to the "Second" Case, drag the Quit Control into it, and wire it to the Stop Indicator.  Change the Tunnel to "Use Default if Unwired".
  15. You should now have finished Main, First, and Second.  Check that the Run Arrows in all three VIs show No Errors -- if any are "broken", find and fix the errors.  Now run Main -- it should flip between the 1Hz, count-to-10 (0..9) First Case and the 2Hz count-until-stop Second Case, repeating until you push Quit.

I said, above, I wasn't going to post the code, but given the amount of "new" stuff here, I'll at least post a picture of Main's Block Diagram, as a number of "new things" are introduced here.  I hope, with the description above and the picture, you'll be able to make this little demo -- I urge you to do so (i.e. "start simple, then make it more complex") before trying to replace First and Second with your own VIs.  I generated this using LabVIEW 2016, but it should look the same when you do it in LabVIEW 2015.

Main Pix.pngMain, LabVIEW 2016

Best wishes for a Happy, Healthy, Fun-with-LabVIEW 2018.

 

Bob Schor

 

Message 11 of 13
(156 Views)

Hi Bob,

 

I like literally don't have the words to thank you, I am new in Labview and as you said I am attempting to do  "not-so-elementary things". So thanks a lot. I have tried to follow the steps but I got stuck in the middle...

I am having trouble to manipulate the loops. For example in both of my programs I have a while loop (which creates the problem) and in step 3 you told me to had a for loop, but then I need to press on the stop button 10 times dunning the program ran. With your logic I wrote something else (see the attached block diagram/VI), but then adding the error in and out didn't go well. 

I also have a while loop in my "connect to Motor" VI so I don't understand where to add the while loop that you have mentioned in step 6. 

 

thanks in advanced and happy new year,

Naama.

0 Kudos
Message 12 of 13
(140 Views)

Naama,

 

     The purpose of my earlier post was to give you an "exercise" to do that would teach you how to use sub-Panels, which I think would be a good method to solve your ultimate problem.  I'm sorry I wasn't sufficiently clear.  Rather than trying to have a one-to-one discussion with you that may be similarly "slightly off-topic", I'll send you a Private Message explaining my point.

 

     Other readers of this Post will probably have other methods to suggest to you.  I'm sure that this New Year will bring you insights and ultimately a Good Solution to the task you are undertaking.

 

     With best wishes for a Happy and Healthy 2018,

 

Bob Schor

 

0 Kudos
Message 13 of 13
(135 Views)