03-16-2014 02:42 PM
When I teach "Introduction to LabVIEW", I have a lab called "Building a Virtual Instrument" whose task is to build a Touch Sensor using an NI USB 6009, which has an A/D converter that we run at 1 KHz. We generally start using MAX to explore sampling and "looking at" data (which gives a nice feel for single samples, Finite Samples, and Continuous Samples, as well as the appearance of their plots). Sometimes we take a detour through the DAQ Assistant (which creates a very simple "Sample and Display" routine, not unlike MAX), but if they're good students, I go straight to showing them the 3 or 4 DAQmx functions they'll need to use. A wonderful NI White Paper on this subject is here: http://zone.ni.com/devzone/cda/tut/p/id/2835.
If you are using non-NI hardware, you can still benefit from the NI Examples. Just try to make your code "emulate" what DAQmx does. You want to write a few sub-VIs (and, please, do write sub-VIs -- you do not want your entire program to be on a single enormous block diagram, as it is very hard to see, very hard to debug, very hard to understand, and very hard to maintain).
The first VI should be a "Configure" VI. Here you will establish communication (USB?) with your device, setting Baud rates, etc. as needed. Then comes "Start", where you put the device-specific code to get it to start doing whatever it needs to do. Follow this with "Read Data". Here you have choices -- you can return a single data point (and wait within the sub-VI until you have that point "in hand") or an array of points (with similar "waits" to be sure you actually have data). Before trying to plot it, you can simply wire it to an indicator and see if you have numbers that make sense. Note that you will probably want to put the Read Data VI inside a While loop, with a Stop button to stop the loop. Be sure, however, to put your "display" (or indicator) inside the While loop so that it gets updated for every data point. Finally, you'll want a Stop Device VI to send the final series of commands to the Device to turn it off.
In DAQmx, when you configure a Device, you generate an I/O Channel that you pass along, into and out of, the DAQmx VIs. If you are writing your own code for a non-NI device, such as a USB device, then you will probably generate a VISA channel as part of Configure. Copy the DAQmx functionality and wire VISA In and VISA Out on the upper left and upper right connector terminals (you'll find that it is a good practice to, as often as possible, choose the 4-2-2-4 Connector Pattern when you create your VI -- this is the default pattern in current versions of LabVIEW). Within your own Device VIs, use these connectors to maintain the communication path to your device (once you open the device with a VISA Open, you shouldn't close it until you do the Stop Device VI). Be sure that you don't "break" this wire as it flows from Configure to Stop Device.
When you have data coming out that looks reasonable in an indicator, then it is a simple step to replace the numeric indicator with either a Graph or a Chart, and have the plots that you want.