01-19-2015 03:20 AM
Hi, I am trying to implement a system which measures voltage and current for a varying source voltage at varying temperature. The program acquires 5 pairs of voltage and current data. The issue here is that the source voltage is varied by manually changing the value of the variable resistor. What I would like to do is somehow pause the program automatically once the loop (for acquiring 5 V and I data pairs) has completed. Then, after the user manually changes the value of the variable resistor (and enters the new value through a front panel indicator), the user should be able to resume the program through a front panel button like in this example: https://decibel.ni.com/content/docs/DOC-10792
Is it possible to implement this in LabView?
In summary: I would like to implement a system in which the program would pause automatically after a condition has been fulfilled, and can be resumed through a front panel button.
Thank you in advance for any help and suggestions. I hope I made my query clear. I'm not sure whether attaching the program would help but I included it just in case 🙂
Solved! Go to Solution.
01-19-2015 03:49 AM
Yes, of course you can do this in LabVIEW - LabVIEW is a programming language so you can do just about anything!
I suggest you look into state machines and the event structure - do your data acquisition in the state machine and when the data acquisition has finished, go into an 'idle' state and use the event structure to detect when the button has been pressed and then start the data acquisition again.
I had a look at your VI and it is very messy and hard to follow - I suggest you have a look at some LabVIEW tutorials to help you restructure your program. Things like having lots of backwards wires and while loops inside while loops are generally considered ill-advised. If you learn about the state machine it will help you to restructure your program and it will be easier for you to do what you want.
01-19-2015 09:50 PM
Hi Sam,
Thanks for your prompt reply. Good to know that it's actually possible. I'm still new to LabView and have tried following several tutorials (only up to while and for loops sadly :p) but I'll try to read up more on state machines and event structure.
Now that you mention it, I do have plenty of while loops running inside while loops. I'm at loss though as to how else I can achieve what I'm trying to do with my program but I'll try to read up some more. 🙂
01-19-2015 10:12 PM
Sam put you on the right track. You certainly don't need while loops inside of while loops.
You can accomplish what you want to do with a while loop, a case structure, and an event structure. The while loop is the outer most structure. Inside that, you have the case structure controlling the state you're in. Inside one state, you have an event structure. The event structure will want to have an event for the stop button and the start button as well as a timeout. You'll want to iterate through your measurements using a state, or states depending on duration of your measurement.
It should be relatively easy to pick up.
01-20-2015 01:45 AM
01-20-2015 09:30 PM
Thank you all for your reply! Looking forward to your blog post on Monday, Mike, but I'm going to try coming up with something--to the extent of my capability anyway.
I tried out some tutorials on state machines and I'm beginning to grasp the concept. I still find it somewhat difficult to comprehend event structures. 😕 Pardon the very basic question, but I need to confirm some things.
- Suppose that I have an Idle, Run (for data acquisition) and Quit state. If I wanted the program to go to the Idle state (where the user will have to press a button to commence measurement) once the while loop in the Run state has finished, to accomplish this by the event structure, would the Event I'm looking for be 'Value Change'? And would the value would be the Boolean value linked to the Stop If True in the while loop?
- I also read up a bit more on Sequence Structures and apparently using them isn't particularly good coding practice? (In the case of my program, I used them to ensure that it is only after the temperature has reached the established setpoint that temperature measurement is conducted). I think it would be possible though to substitute the Sequence Structure with a Case Structure instead. Would this be better?
Best,
Amanda
01-20-2015 09:48 PM
@amndk wrote:
I think it would be possible though to substitute the Sequence Structure with a Case Structure instead. Would this be better?
http://www.ni.com/newsletter/51735/en/
Sequence structures have their uses but the article above highlights some ways that they are misused. The link below should give you more ideas on when to use them and when case structures may be a better idea.
http://zone.ni.com/reference/en-XX/help/371361L-01/lvhowto/avoid_overusing_sequence_structures/
If you run into trouble post what you have so we can help you out.
01-20-2015 11:30 PM
01-28-2015 02:54 AM
Hi all! I've overhauled my program after learning how to create state machines in LabVIEW. I think I've managed to make it able to pause program execution by staying in the Initialize state if Pause After Measurement is set to True, only resuming measurement once the user has pressed the front panel button to Acquire Data. Attached is the code for the program.
Thanks to you all for leading me to the right direction (I hope) 🙂
I have other questions though for some other functions I want to implement in the program (which are not very relevant to the original topic title). Would it be better to start a new topic or continue the discussion here?
01-28-2015 06:00 AM