06-05-2023 09:30 AM
Hello everyone,
I am currently attempting to use a NI USB-6001, together with LabView 2023, to generate analog signals as part of an experiment.
In terms of drivers, I'm not sure what my situation looks like, but I've been using NI MAX to create the analog and digital input and output tasks to use the USB-6001 with.
I have already written a .vi that produces a continuous sine wave signal for the experiment, but I am also interested in being able to send signals of arbitrary nature to the experiment; that is to say; generate analog outputs from the USB-6001 that are not merely a single sine wave, DC voltage, or what have you, but rather I would like to read in data from a text file, then output that data via the USB-6001's analog output, and then have the USB-6001 cease outputting the signal as soon as it has reached the end of the data.
I've attached the .vi I'm currently using to attempt to do this, as well as a text file that contains the data I wish to output. For clarity, the text file is formatted as a comma-delimited array, with the first column being the desired voltage to write, the second column being the time in seconds, and the third column being the sampling frequency (really, the third column only needs to be a single value, but I didn't bother making it as such). If you import that text file into the spreadsheet program of your choice and plot the first column as Y and the second column as X, you'll see a sine wave that goes for about 4 seconds, but in its first two seconds, ramps up from zero amplitude to 300 mV of amplitude; because this signal is not periodic (the sine wave is, but its change in amplitude is not), I think this is the best way to do it.
So as the .vi runs, it reads the first column (data) and third column (sampling frequency), then opens an analog output (voltage) task on the USB-6001, generates a waveform from the data and the sampling frequency, and then writes that waveform to the analog output.
In practice, however, that doesn't happen. Usually, no output appears to happen at all; an analog input task I have watching the USB-6001's analog outputs for troubleshooting does not report any change. The one time I was able to get an output, I put the "write analog waveform" function inside a while loop with a stop button to break the loop. When I did this, the signal outputted precisely as I desired...except it repeated, with the analog output continuing to write the full duration of the data over and over until I stop it. I only want to write the data from the text file once, then have the .vi stop itself. So for example, with the text file I provided, in an ideal case, the USB-6001 would write all four seconds of the data and then stop the .vi, writing nothing else.
I'm sure there's a simpler solution than forcing the while loop to stop itself when the elapsed run time reaches the duration of the input data (though I am not even certain how to do that), but I don't know what it is.
In short, I would like to read data from a text file, make a waveform out of it, and then write that waveform to the USB-6001's analog output just once before the .vi stops, rather than either a) doing nothing at all, or b) writing the waveform over and over, defeating the purpose of the .vi.
Thanks.
06-05-2023 09:45 AM
I'm not sure if this would work with 6001, I found this example, but you can search on the examples to see if other examples would work.
06-05-2023 12:20 PM
As an update, I think I have found the solution I was looking for. I placed a "DAQmx Wait" block after the "DAQmx Write" block and before the "DAQmx Stop" block; this gives DAQmx Write the time it needs to actually write all the samples in the signal, before it gets stopped. I set the timeout value of DAQmx Wait to the final value of the time signal, so that it waits no longer than it must. Implementing this change writes all of the data in the .txt file just once, and then the .vi stops.
I'm attaching the updated .vi with that wait included. Hopefully this can help someone else in the future.