LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger DAQ via main Vi

Solved!
Go to solution

Hi everyone,

 

Currently I am trying to start and stop data acquisition via a main vi. 

 

I did it according to: http://digital.ni.com/public.nsf/allkb/A882E27D1D7A949386256E0D0066B91A

 

If I exchange the Control Reference and use a simple button in my subvi it works the way I want.

 

But if I use the mainVi it does not work. Can someone tell my why it doesn't work?

 

SInce I am fairly new to LabView I've got no idea. 

 

Thank you very much!

 

 

 

Both VIs are attached.

 

Edit: Since the DAQ currently gets build into a rack, I am working with simulated signals.

Download All
0 Kudos
Message 1 of 10
(3,439 Views)

You need to spend several hours, maybe days, getting yourself much more familiar with LabVIEW.  An excellent list can be found at the end of http://forums.ni.com/t5/Feedback-on-NI-Discussion-Forums/Unofficial-Forum-Rules-and-Guidelines/m-p/3...  What would you think if someone posted on a Java Forum "I'm new to Java -- how do I build a Web Front End to my SQL Database so customers can shop at my site?".  Fortunately, LabVIEW is a little easier to learn (IMHO), but you still need to expend some effort ...

 

Bob Schor

 

0 Kudos
Message 2 of 10
(3,415 Views)

Hello Bob Schor

 

I really would love to spend a lot more time to get familiar with LabView.

 

But I am currently writing my master thesis in a company and on the 4th September my programs have to be ready for testing. So from now on I just have two and a half weeks to do what I need to. 

I also would have loved to start a few months earlier but thanks to internal problems  I got LabView at the end of July and could not start earlier. 

I am already reading a lot of tutorials and manuals but I still encounter some problems I just can't resolve and I really thought that's what forums are made for...

 

Please help me get it working. 

 

 Edit: Oh and I am not totally unfamiliar with programming in general: I am already quite experienced in VBA, Java, PHP and mySQL. I just have to get used to LabView and I am really hoping that you can help me.

0 Kudos
Message 3 of 10
(3,411 Views)

Hi everyone

 

I would be really grateful if someone would try to help me.

I am definitely willing to learn, what I have to. But since my time is unfortunately limited it would be wonderful, if you could at least the specific topic I have to learn more about so I can solve the problem on my own.

 

Thank you very much.

0 Kudos
Message 4 of 10
(3,347 Views)

Some VIs or controls are missing but that is not important.

 

Problems:

 

1.) You immediately go into the Wait state, no timeout is needed.(After the timeout you go back to the wait state)

2.) To get out of the wait state the VALUE of the boolean must change.

3.) To get in the ACQUIRE state it needs to go from False - to - True. Unlikely to happen when the program starts from its initial state.

4.) Easy Fix - Add two booleans a start and stop. Use the value change for each, on for Acquire on for Stop.

 

Cheers,

mcduff

 

EDIT : Make sure you change the True/False constant for each case for the while loop, I did not change that

 

test.png

0 Kudos
Message 5 of 10
(3,339 Views)

Hi mcduff

 

Thanks a lot for your help. I changed it according to your suggestions.

 

 

And it sure makes sense, that the data acquisition can't start the way I did it - impossible to even miss this Smiley Embarassed

 

With your snippet I am able to start the acquisition, but it does not stop. Is it possible, that it never goes back to the state "wait"  after starting? 

 

Thank you very much and kind regards 🙂

 

EDIT: I just tried it and I goes back to the state wait.  So why doesn't it stop? Also if I directly go into the waiting mode it does not start. So I think it does not register the events? 

0 Kudos
Message 6 of 10
(3,313 Views)
Solution
Accepted by topic author lotusbluete

You are building a State Machine, but are doing it in an overly-complicated way.  An especially simple way, particularly for someone not so experienced in LabVIEW, is to build a Queued State Machine using the Producer/Consumer Design Pattern to handle Front Panel Controls (like Start and Stop).

 

Open LabVIEW.  Go to the File menu, choose New ... (the one with three dots), and open From Template, Frameworks, Design Patterns, Producer/Consumer Design Pattern (Events).  This will show you how, when the user pushes Start, you can put the Acquire State on the Queue.

 

The Consumer loop on the bottom becomes a Queued State Machine.  It waits to dequeue a State, and when it does, it uses a Case Statement to execute the code for that State (just as you do in your Acquire State).

 

Now you need to think about what States you need for your State Machine.  Particularly for an Acquisition Task, you should have (as a minimum) Initialize (the hardware), Acquire (a data point), optionally Process (the data point), and Stop (and clean up after yourself).  You will probably have at least two controls, Start (begin Acquiring) and Stop (finish and clean up).

 

The Producer Task is only concerned with handling the Start and Stop buttons, which cause it to put the Acquire and Stop States on the State Machine's Queue.  As long as no button is being pushed, this loop takes no time to execute, so you can otherwise ignore it.

 

The Consumer Loop does all the work.  How do we get started?  Specifically, how do we get "Initialize" onto the State Queue?  Simple -- just enqueue it before entering the Consumer Loop (i.e. outside the While loop).  This will put it first on the Queue, and you'll Initialize and wait for someone to push Start or Stop.

 

So how do we take the second point?  [We take the first when Start is pushed].  Again, simple -- when do you want to take the second point?  Do you want to wait between points?  Fine, make a Wait State, and in the Consumer's Acquire State, enqueue Wait.  The Wait state has your delay, and it, in turn, enqueues "Acquire".  Do you want to process each point?  Every other point?  Something else?  Fine, figure out where you want to do this and enqueue the Process State (remember to enqueue what comes after Process, perhaps Wait).

 

Your code uses Dynamic Events, which is a "more advanced" topic than the simple Event Structure, which should be all you would need.  Note that if you do need to "export" some of the processing to a sub-VI, it almost always makes the most sense to keep the code involving the Front Panel (like the Event loop) in the Main VI, and to pass a Queue Reference (if you are using a Queued State Machine in your sub-VI) to the sub-VI.

 

Hope this is helpful to you.

 

Bob Schor

 

P.S. -- you note you have familiarity with VBA, Java, and other languages.  Would you consider doing a major project with one of these languages if you "first got it in July, with the project due in September"?  As I am sure you already know, learning proficiency in any language takes time and benefits a lot from on-going guidance (which means "a mentor").  We'll try to be your Missing Mentor.

 

Message 7 of 10
(3,302 Views)

I realize, after I posted my rather long previous post, that you might read it and think "Oh, no, he wants me to start all over, rather than trying to fix the one-or-two things that are wrong with my existing code".

 

And you would be correct!  I am suggesting that you "start over", but I'm trying to give you a much more simplified (and verified) pattern that you should be able to quickly adapt to your current situation.  But more important, having a well-designed framework will make it much easier for you to add features (such as processing the data) and will make it much easier to find bugs (like "Why does my code not Start?" or "Why does my code not Stop?" or "Why does my code not run at the Rate I want?".

 

Bob Schor

0 Kudos
Message 8 of 10
(3,283 Views)

Hi Bob

 

I already try getting the Queued State Machine to work in parallel to the other option. 

But if the queued state machine is the easier solution I will work with this one. Since starting/stopping the acquisition is not the only task my program has to perform I thought it would be better for the clarity to work with several subvis that I execute according to task to be performed. The tasks to be performed are determined via a tcp/ip command.

 

 

And no I don't care if I have to start again - it doesn't matter to me how much effort I have to invest, if it is working in the end. 

 

 

Thank you and regards

 

 

PS: Regarding the infinite stupidity of the time frame you got a pm. 

 

0 Kudos
Message 9 of 10
(3,276 Views)

As Bob said it may be best to rewrite. (I like the JKI State Machine)

 

Go to Help Menu, Find Examples, then search for State Machine Fundamentals.

 

I cannot test your VI because it it missing parts.

 

I just tried it and I goes back to the state wait.  So why doesn't it stop? Also if I directly go into the waiting mode it does not start. So I think it does not register the events?

 

You are registered for the wrong event. You have value change, you need to register for Dynmaic Events, Value Change. See attachment.

 

Good Luck.

 

Cheers,

mcduff

 

 

 

0 Kudos
Message 10 of 10
(3,237 Views)