Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

control everything from daq

Hi, I need to interface my setup with the computer. The setup is:

Read voltage from pressure transducer
Read voltage from flow meter
Read data from serial port

Based on these readings, I want to be able to manual control:

Pump that takes 7 digital inputs
Solenoid valves that take digital inputs.

I'm using the DAQ M PCI-6221 card, with Labview professional. What is the best way to implement this? I want the inputs to be continually being updated, and I want to have buttons on the interface that allow the pump speed,direction,etc to be controlled and buttons that control whether the solenoid valves are opened or closed.

The voltage readings are easily obtained using DAQmx. However, I'm not exactly sure how to update the serial reading continually. Would I just use a while loop with frames inside?

The next part I'm having difficulty with is being able to control the pump. I'm relatively new to Labview, so I'm wondering is there some way of doing an interrupt? Basically I want the pump to be updated as soon as I push a pump control button on my panel (or will it just have to use frames and wait until the next iteration of the loop? which i guess isn't a big deal if the DAQ card runs at several hundred kHz).

But yeah, just wondering if anyone has any suggestions for the best way to do this.

Thanks a lot!!

Sunny
0 Kudos
Message 1 of 10
(3,284 Views)
For reading serial data continuously, a while loop is perfect. If the serial instrument does not require a command to return a reading, the minimum you would need in the loop is a VISA Read. If the byte count expected is a constant, just wire that number to the VISA Read. If it varies, you would use the function VISA Bytes at Serial Port to determine how many bytes are available. There is no need for a sequence structure (what I think you're calling frames). In fact, you should try to avoid sequence structures. Usually, there's no need. Outside the while loop is the VISA Open and Initialize Serial Port. When the while loop finishes, then you do a VISA Close.

For your control, what you want to use is the event structure. There are several shipping examples of this. Basically, whenever a button is clicked, an event is fired. Inside the event you would have your code to write to the digital line.
Message 2 of 10
(3,279 Views)
Great, thank you for you advice. I will try the event structures. As for the serial read, the part I'm confused about is getting the program to read in voltage values from my DAQ card as well as the serial port. What I'm thinking is, have a VISA Configure Serial Port to initialize the serial port, and also have my DAQmx vi's to initialize the voltage input channels, and wire both of these to a while loop and inside the while loop I will read the serial port and the input channels.

I'm confused since neither the VISA Configure Serial Port nor the DAQmx Create channel vi's are connected outside of the while loop, so which will labview execute first? Or will they be executed simultaneously? And in the loop, can I just have a set of vi's to read the serial port and a set of vi's to read the DAQmx channels without bothering to attach either of these? (Ie: will it execute all of the serial vi's and DAQmx vi's together, and wait until they are both complete before going to the next iteration of the loop?) This is why I thought I may need to use a sequence structure, so in the while loop first I would read in the serial port value and in the next sequence I would read in the DAQmx channel values.

I hope this makes sense! 😄

Thanks again,

Sunny
0 Kudos
Message 3 of 10
(3,275 Views)
When there is no data flow connecting functions, LabVIEW will execute those functions in parallel (in most cases anyway). When you want to do things sequentially, the best way to enforce this is with the error in/error out connections. I've attached a picture that shows a couple simple methods of both.
Message 4 of 10
(3,269 Views)
Hi, thanks for your help!

I've gotten started on my VI. I'm wondering if you can have a look at it and tell me if what I'm trying is reasonable. Basically, if the motor on button is pressed I need to send a digital pulse to a certain pin on the controller and the motor will be activated. To stop the motor, I need to send a digital pulse to a different pin on the controller. So, I use 2 different Digital Outs to do this.

Also, the DAQmx write VI requires that I specify a high and low time... Isn't the low time redundant? Won't the output from that digital channel always be low until I write to it?

Thanks so much for all the help!
0 Kudos
Message 5 of 10
(3,264 Views)
You should put your serial and analog acquisition in a separate while loop than the event structure. You could also put it inside the timeout event. With a small timeout value, the serial and daq will run until you fire the motor on/off event. Yoy will get a brief interuption of your acquisition at that point. If you don't want the interuption, use a separate while loop. You event structure should also have an value change event for the stop button. Put the stop button inside the event and wire it out to the while loop termination terminal.

You have rise time and fall time because you have selected a counter output task and not a digital channel. The way I would do it with two channels is to use a single create channel and specify both in the lines input instead of two different ones like you have. Then with the digital write, one pattern would be a 01 and the other pattern would be 10.

Also, the Start Task for your digital output should be outside the while loop just like the analog acquisition start task.
Message 6 of 10
(3,258 Views)
Allright, I will make the changes you suggest.

Thank you so much for your help!!! It is greatly appreciated!! You've saved me countless hours!

Thanks again!

Sunny
0 Kudos
Message 7 of 10
(3,249 Views)
Hi,

I have a couple questions about my latest iteration.

First, I don't think I can use the Boolean Digital Outputs as you suggested, because I need to just produce a digital pulse. I don't want the line to remain high. So I'm using the counter pulse generation DAQmx and I will specify the appropriate digital lines that I want pulsed.

First Question: Can I run the Counter Pulse Generation VI's in parallel with the Analog Output DAQmx VI as I have it now?

Second Question: In the Event Structure, when the 'Motor START/STOP' button is pushed I need to send a pulse to start the motor. But I need to know which direction to go, so I have a case structure whose selector value is wired to the 'Forward/Reverse' button which is in a different event structure. Is it ok to have the selector value in a different event structure?

Third Question: For the Counter Pulse Gen. I put the DAQmx Task Start VI's in the event structures. I did this in the hopes that every time that event happens, the DAQmx Task Start will cause a digital pulse to be sent. Is this correct?

Thanks again!!!
0 Kudos
Message 8 of 10
(3,242 Views)
Forgot to attact the file...
0 Kudos
Message 9 of 10
(3,241 Views)
What will actually start pulse is a DAQmx Write. The start task will not do this. You need to replace the start tasks with writes. Putting the direction control in it's own event is fine but you're going to have a problem with the feedback node. In some of the events, you have nothing wired to it so it will use the default (False). It's possible that you can execute one event and the actual value of the control read in another event will not be correct.
Message 10 of 10
(3,231 Views)