LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

plotting analog inputs from 2 different channels of the same task on different charts

Hello, I have two analog sensors. I need to acquire the analog input of these two sensors simultaneously and plot the live data on two separate graphs. I am fairly new to labview, so any help would be great. I tried creating charts of two separate channel constants within Daqmx, but only one channel is updated. I try creating a single task with the two separate channels, but I don't know how to plot the different channels on different charts. I can only get both channels plotted on the same chart. I have been getting the error message that the operation couldn't be carried out because the resource is reserved. Can someone please provide a short and simple example of a multi-channel analog input data acquisition using DaQmx driver and plotting the separate channels on separate charts? Thank you. I appreciate the help.

0 Kudos
Message 1 of 9
(1,025 Views)

It would be very helpful to know:

  • What DAQ device you are using (model number)
  • What channels are connected to signals (e.g. Analog Inputs 0 and 3).
  • How you have set up the DAQ device.  Include gain settings, sampling rate, whether Finite Samples or Continuous, number of points being sampled, anything else that you think of.
  • What version of LabVIEW you are using (year, whether 32-bit or 64-bit).
  • If you want us to help you with your code, you must show us your code.

The best way to show us your code is to attach the relevant VIs.  If you are using LabVIEW 2022 or 2023, many of the more experienced LabVIEW developers are running older versions (like LabVIEW 2019 or 2021), so you should "Save for Previous Version" your VI (or VIs).

 

Please don't show us "pictures" of your code -- we cannot inspect the wiring, edit the code, or run the code.

 

Bob Schor

0 Kudos
Message 2 of 9
(1,005 Views)

Hello, I am using the cDAQ-9174

2023 Q1 64 bit
cDAQ-9174 with Analog input NI-9205, and analog output NI-9263. My analog input for my +signal of LVDT sensor is connected to AI0 of the NI-9205 and the -signal is connected to channel AI8. For my load cell sensor, I have the +signal connected to channel AI1 of the NI-9205.I also have my analog output to my LVDT connected to the NI-9263 on channel AO0 and I have the -signal connected to COM. I have taken readings in DAQ-express and the sensors respond to respective changes. I want to take continuous samples. I have it setup for rate: 1000 samples/sec. I can attach my current code for the VI below. Thank you.

0 Kudos
Message 3 of 9
(963 Views)

I guess you didn't read all of my suggestions.

Missing LabVIEW Version.png

 

Maybe some other first-time LabVIEW users who are using LabVIEW 2023 will help you.  As you can see, I'm running (as I mentioned) LabVIEW 2019, which cannot open any VI saved with a more recent version of LabVIEW (this is a Feature, not a Bug).

 

Bob Schor 

 

 

0 Kudos
Message 4 of 9
(954 Views)

Hi Bob, sorry about that. I believe this attached folder should be saved as version 19.0. Thank you. I appreciate the help. 

0 Kudos
Message 5 of 9
(942 Views)

Thanks for the code.  I have a number of suggestions.

 

  • Before trying to acquire data from "2 different channels of the same task on different charts", write some code to acquire data from one channel on a chart.
  • When you acquire analog data, think about timing.  The really accurate clock is the one in your DAQ device, not the one in your PC.  You are acquiring data at 1 kHz, and are acquiring it one point at a time.  You then send this (one) point to a Chart for plotting.  Think about the timing -- to avoid "missing data", you need the loop to run at 1 kHz, so you have to call the plotting routine 1000 times a second to display 1 point each time.  A much simpler thing to do is to sample 100 (or even 1000) points at a time, say 100 points.  This takes 0.1 second, after which the DAQ Read will present you with an array of 100 points.  More important, you now have 0.1 seconds to get those 100 points plotted, which takes much less time than plotting 1 point 100 times, so the plotting can "keep up" with the acquisition!
  • How to do this with two (independent) Analog channels?  How about having two While Loops, each with its own 1 Channel N Sample DAQ Read and its own Chart.
  • How do you synchronize them?  I suspect you've already done a pretty good "first attempt" by putting them inside an encompassing While Loop.  [I actually am uncertain how good an idea this is -- I'd try doing a test routine, maybe with a common signal and looking for differences in the acquired signals].  The idea is that neither of the inner loops can start until the outer While starts (you'd make it a "Do Once" loop by writing "True" to its Stop Control -- it's only there for synchronization).  You'll let LabVIEW "do its best" to obey the Third Law of Data Flow that says that two "things" (While Loops) that don't have a data dependency relationship with each other don't have a "sequential order" of execution, i.e. the system tries to run them concurrently (which is just what you want).

Bob Schor

0 Kudos
Message 6 of 9
(935 Views)

Hi Bob, 

Thanks for the detailed response. I went ahead and did a simple test of plotting one channel on one chart. This works, but when I try and plot a 2nd graph in a 2nd while loop like you mention, I get the error "this resource is reserved". I am calling 2 global channels, so this could be my issue. Do you have any recommendations to create one task and then specify for the code to read one of the specific channels? 

0 Kudos
Message 7 of 9
(923 Views)

I figured the issue out. Thank you!

0 Kudos
Message 8 of 9
(910 Views)

Please share the solution (by posting one or more VIs -- we'll struggle with being able to read it if we're still using LabVIEW 2019 ...).  We've tried to help you (but might not have totally understood the problem), so why don't you "return the favor" and help others (and get to mark your "Solution" as the Solution)?  You seem to have figured out something that we didn't quite "get" ...

 

Bob Schor

0 Kudos
Message 9 of 9
(897 Views)