02-17-2016 02:30 PM
First of all, do not worry, see this project as a nice opportunity to learn more about LabVIEW. Always the best thing is the "learning by doing" 😉 I will use your text, and I try to answer each of your questions with red coloured text.
@Michael.Koppelgaard wrote: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.
Ok, clear, I also thought it was only a mistypo.
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?Even if some times using many local variables will not effect your code, but can make you "addicted" to this wrong approach, and you will abouse local variables in cases too later, when they will DO create race conditions. Use the wires to send data between nodes whenever it is possible. An example when it is ok to use local variables: if you want to update a control value, like at reinitialization states... Have a look at the CLD preparation E-kit docs (these are some help docs before taking LabVIEW CLD exam):
http://www.ni.com/gate/gb/GB_EKITCLDEXMPRP/US
See this pdf: http://ftp.ni.com/evaluation/certification/cld/cld_exam_prep_guide_english.pdf
Page 6 for example, very useful tips for "best practices"...
About "Voltage - Continuous Input.vi" :
- The pins in the 6212 is connected RSE. I will discuss with my hardware man to change to difference. This part was his decision. I trust he knows what he is doing, but I will check it with him. But isn’t difference mostly used in case of low voltage? I’m having voltage between 0 and 5 V. Show the following page to your collegue: http://www.ni.com/white-paper/3394/en/ Hopefully this will clarify the situation.
- The "Dev1/ai0:5" is the 5 pressure transducers connected to the soil sample and the 1 connected to the vacuum box. Should I have split the cannels up in "Dev1/ai0:4" and "Dev1/ai5"? No, it is ok then, I forgot about the 6th sensor.
- Could you make an example? I’m aware about stopping the loop after 1 sec. What do you want me to do? You can setup a finite sample number DAQ, and get rid off the 1D Waveform DAQmx Read, use the 2D Double approach. In this way you get a 2D array (think of it as a 'matrix') where the rows are the channels, and the columns are the Samples.
- Have a look at the snippet. Am I far from what you mean? See previous sentence.
Main:
Edit:
I have a look at Queued state machine and state machine. I remove all locals. It might be you do not need a Queued state machine, but a simple state machine with an Event structure in the "Idle" state, where you capture the user interactions. Search for different State Machine examples.Edit2:
“But anyway, the DAQ subVI should be inside the State Machine loop...”Inside state Machine and in an Action Engine? You have different options here. You have to keep in mind, that you will launch dynamically 2 clones of the StateMachine VI. Therefore you need to ensure both StateMachine will be able to use the USB hardware when they request it. This applies for the Analog inputs (2 x 6), and for the Digital outputs as well. Do not forget you also need to get data from the two balances via RS232. You could even have the AI DAQ (12 channels) task running in the MAIN VI: using Dynamic User Events, you could broadcast the data to both dynamically launched StateMachine VIs... You create another "ActionEngine" subVI to operate on the several digital outputs using another DAQmx Task, and you can fire this DIO subVI from the two clones of the StateMachine VIs...
If you describe me exactly the channels and configurations for AI and DO tasks, I can make you the two ActionEngines (subVIs), as early as I get some time...
Edit3:
I only showed half the set up. I have 2 soil samples, 2 “pump1”, 2 “pump2”, 2 balances etc.
Clear now 🙂
About the State Machine: try not to code at once all the required functions. The following approach usually better:
- Take a pencil and paper, and draw a flow-chart with all the required measurement steps (states) plus the transitions (user indicated transition, transition depending on a condition based on DAQ, etc...).
- As second step, only create the "skeleton" of the state machine. You will need also a timing function, so keep this in mind when you think of the states...Repeat myself, have a look at the many State Machine examples...
Good luck! 🙂
02-17-2016 02:34 PM - edited 02-17-2016 02:58 PM
@JÞB wrote: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.
I agree 🙂 Two executables could be created, for the two experimental setups and USB devices...And the two application would run nicely and independently on the same PC...
EDIT: Also think about the scaleability of the project: what do you do, if your bosses tell you, you need to operate a 3rd experimental rig? Then the current approach will not work, not enough channels there...If you used a separate USB DAQ device for each experiment, then you only need to buy a 3rd USB device, and you are good to go...
By the way, now I understand why your colleague decided to use RSE configuration for the AI channels and not Differential (which is "safer", see the above documentation) one: the USB-6212 has only 8 differential AI channels, but 16 if you connect them as RSE... Actually If i was you, and if there is still budget to spend, I would buy a second USB-6212, and after that I would also use 6 differential AI inputs per device (in case you cannot sell the single USB-6212 to buy two USB-6003)
02-18-2016 03:25 AM
Thank you very much guys – your answers really helped me a lot!!
I think I will consider buying an extra 6212 as suggested by Jeff. The coding will be much easier for me.
As you say Blokk the 6212 have to be ready to use for both stateMachines whenever its needed.
I’ll return later.
02-18-2016 03:58 AM
I think I will buy 2 NI USB-6210, since I need 3 maybe 4 digetal input for 2-3 valves and 1 pump.
The sampling rate is lower 250 kS/s , instead of 400, but I guess the will be okay.
Am I right?
02-18-2016 04:03 AM - edited 02-18-2016 04:06 AM
@Michael.Koppelgaard wrote:I think I will buy 2 NI USB-6210, since I need 3 maybe 4 digetal input for 2-3 valves and 1 pump.
The sampling rate is lower 250 kS/s , instead of 400, but I guess the will be okay.
Am I right?
It should be ok, but it also depends on your sensors. I think in your experiment the pressure does not change too fast, I beleive a 1 or maximum 10 Hz sampling rate is totally OK. I guess you wanted to write digital OUTPUT, not input. You need 4 digital outputs.
edit: by the way, do you have additional electronics to interface the digital outputs to the valves? Usual solenoid valves require certain power, so you are not going to be able to power a valve purely with your digital outputs, you need a relay circuit with power supply, or similar thing...
02-18-2016 04:17 AM
Of course -digital output.
Edit : should be okay
02-18-2016 09:51 AM
Have a look this lvlib example in the project. Now i have to leave, i can give more explanation how to use it tomorrow the 4 public VIs.
02-18-2016 10:36 AM
GREAT THANKS
Unfortunately I got LW14. Can’t open it. Can you convert ?
02-18-2016 11:01 AM
02-18-2016 12:35 PM
FINE - FINE - VERY FINE - I'm grateful