02-16-2016 02:08 PM
I’m building an instrument which is measuring on to soil samples.
Each soil sample is controlled by 1 state machine. Both state machine are using data from an NI USB-6212
The state machine is both going to send data to NI USB-6212 (opening and closing valves) and receive data from NI USB-6212 (pressure transducers).
The 2 state machines are not going to run parallel.
I been advised to use and attached vi’s.
Where to put the communication to the NI USB-6212?
Solved! Go to Solution.
02-16-2016 02:45 PM
The 2 state machines are not going to run parallel.
You start the two subVIs in my example, so the two state machines will actually do run in parallel! Maybe you mean that, you need only to make valve opening operation, etc, at once only using one state machine? So at a time, your user will only interact with one of the two Front Panels of the the 2 subVIs (and the other state machine will "sleep" in Idle mode?)?
You have different options here. Depends on your actual requirement. Could you specify a measurement scenario in details, so we can give better advice?
Right now just pure guessing, so I give one possible option which might be or not as you want.
What is the data acquisiton frequency, and how many analog input channels you need? And I guess you will use the two analog output channels to control the valves? Or the digital outputs?
I would just create an Action Engine (AE) which has four actions:
Just to make it simple, only Initialize and Close the HW resources at the very beginning and end of the MAIN VI (so you do not need to reinit between state machine operations, but this depends on your actual needs).
When you have an actual State Machine running, you place the AE in the required case, so in the subVI. Actually it would be even safe to run the two State machines (2 subVI clones) in really parallel, since the AE eliminates race condition. But this can cause slight time delays, depending on your DAQ rate, number of samples, etc...
Here is a nice tutorial how to wrap up an AE, so you can even hide the reference wires inside:
http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/td-p/503801
If you specify your requirements more in details, I can guide you further...
Good luck!
02-17-2016 12:20 AM
The 2 state machines are not going to run parallel.
Just some new thoughts. If you never wanna run the two state machines in parallel, why you need the two clones of your State Machine subVI at all???
If you want to operate only one State Machine at a time, just create a single MAIN VI, and you just do not need the complexity of dynamic VI calls, etc...
Your state machine should have an "Initialize" and a "Close resources" state. When you want to do a new measurement, you just specify the COM ports (DEV number, Valve port, etc...) via a pop-up dialog window or in the main FP itself, and you initialize your hardware. You do your measurement, save data to file, and in the end you release your HW resources.
Your whole project would be much simpler... I would just use in this case a producer/consumer design pattern with a single state machine...
02-17-2016 01:07 AM
And I'll chime in--- (I do that from time to time)
Let us (Re-)define an Action Engine. An AE that holds access to a specific piece of hardware is, in my lexicon, a "Resource Module"
The trick is defining the "Resource"
With the 6212- you get 1 AO Task and 1 AI task. SO you need a RM for each and a method of getting or setting data into each. That AI is simple- put the data out of the loop that controls the data rate on a Notifier!
With the output you may need a SR that contains the current state and an input that changes the state of one or, more line(s)
02-17-2016 06:59 AM
Thank you for your answers so far.
To be more specific I have 2 soil samples in which the tension (humidity) is going to be controlled. This is done by adding water from top of the soil sample with pump 1 and suck water out from the bottom into a vacuum container. The humidity is logged by using 5 pressure transducers, which is connected to the sample through so called tension meters.
I have planned to use 2 state machines – 1 for each sample.
The state machines are going to through several steps, and through all steps the vacuum in the plate under the sample have to be controlled and also the speed of the pump 1 have to be controlled and changed from time to time.
The analyze will take around 12 – 24 timer depending of the soil type. Therefore I have to have the two samples running at the same time, but not in necessary in same speed. By that I mean, that one step in the state machine can be repeated several times for the one sample but not for the other sample.
What I have to control for each of the 2 soil samples
I attached the main program as it is now. I am aware, I have to make changes.
Right now the reading of the 5 pressure transducer, are done by a loop, where I open and close the connection to NI6212 for each reading. In the program the 5 pressure transducers are called tension meters (T1-T5).
The init values is so far stored in a cluster called Settling.
As I understand you I have to collect all communication with NI6212 in an Action Engine and only open connection in the start of the program an close in the end ?
02-17-2016 08:32 AM - edited 02-17-2016 08:43 AM
"Log data from the 5 transducers, using digital output from NI6212, 1 time each 1 minute."
I guess you wanted to write "using analog inputs" of the NI-6212? You cannot measure analog signal using digital outputs of a DAQ card...
The "Pressure.vi" is totally wrong. Get rid of the Sequence structure! Do NOT use the local variables! Are you aware you can just connect the wires to the other functions directly? I cannot comment on your regression calculations, since I do not know exactly what you want to calculate and how, but it also looks strange...
Comments on the "Voltage - Continuous Input.vi" :
About the MAIN.vi:
EDIT: but I wanna say, you are not far, but you need to refine/restructure some parts...
Edit2: there are also timing problems, like inside your Main.Vi, in the "Get data from tensiometers weights" Case structure, you use a "Wait" function with 1 second. But you have already the Pressure.vi inside this Case, which execution will take 1 second! It means that, this case structure will iterate at every 2 seconds only! Remove the Wait function from this case. But anyway, the DAQ subVI should be inside the State Machine loop...
EDIT3:
And the project is still not enough clear to me:
"Therefore I have to have the two samples running at the same time, but not in necessary in same speed. By that I mean, that one step in the state machine can be repeated several times for the one sample but not for the other sample."
So if you have two soil samples, and you wanna do measurements on them, you need every HW elements doubled, yes? So you need 2 x 5 pressure sensors, valves doubled, etc? Correct?
02-17-2016 09:53 AM
I can see I have a LOT to learn
And I also forgot to put out the scetch of the setup. I will return later.
02-17-2016 09:57 AM
If these are all your HW elements in your experiment, how do you want to measure TWO soil samples at the same time???
"Therefore I have to have the two samples running at the same time, but not in necessary in same speed. By that I mean, that one step in the state machine can be repeated several times for the one sample but not for the other sample."
02-17-2016 01:52 PM
First: thanks for taking the time to read my unreadable code !
Comments to your comments starting from the top:
You are right about “using analog inputs". Of course I want to use analog inputs to read signas form pressure transducers.
Pressure.vi:
I know it is not popular with local variable, but will it course any errors in this case – any race condition? The reason for using them, is that I found it more readable. But if it’s wrong I will get read of local variables. When is it legal to use local variables?
About "Voltage - Continuous Input.vi" :
Main:
Edit:
I have a look at Queued state machine and state machine. I remove all locals.
Edit2:
“But anyway, the DAQ subVI should be inside the State Machine loop...”
Inside state Machine and in an Action Engine?
Edit3:
I only showed half the set up. I have 2 soil samples, 2 “pump1”, 2 “pump2”, 2 balances etc.
02-17-2016 02:29 PM
A Quick thought:
you seam to have 2 identicle sets of hardware that have very little overlap except at the DAQ device. Why not buy two cheaper DAQs and simplify the whole problem of "Where to put the code?" A pair of 6003's would even be a cost savings over the single 6212 and easier to implement and maintain.