From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of DaqTasks required??

Solved!
Go to solution

I am developing a 16 channel data acquistion application using a cDaq9184 with a 9205 module.  So far, I have one DaqTask set up in my .NET project along with one DaqComponent on the form for setting up the first AI channel.  Each channel will have its own Waveform Graph on the form (form has a tab control for each WFG).  I need to be able to log data from each of the channels selected by the user.  All channels selected, their data will be logged to a single TDMS file.  My question lies in the number of tasks that I require.  For this application, should I use a single task with all the channels included in it or should I set up an individual task for each individual channel.  If using individual tasks for each channel, is it going to be difficult or a pain to log all channels data to the single TDMS file? 

 

Thank you

0 Kudos
Message 1 of 11
(4,954 Views)
You don't have a choice. You must use single task. Otherwise, you will get an error. There is only a single convert clock.
0 Kudos
Message 2 of 11
(4,949 Views)

Okay, so if I use only one task for my 16 channels (DaqTask1 auto generates code and configures all 16 channels in the following sub.  This is in the DaqTask1.vb and not the DaqTask1.User.vb

 

Public Overridable Sub Configure()

AIChannels.CreateVoltageChannel("cDAQ9184-1A2B748Mod1/ai0", "Voltage_0", AITerminalConfiguration.Differential, 0, 400, "MyScale")

AIChannels.CreateVoltageChannel("cDAQ9184-1A2B748Mod1/ai1", "Voltage_1", AITerminalConfiguration.Differential, 0, 400, "MyScale")

''

''

etc..for the remaining channels

End Sub

 

How do I configure the WFG so that it only plots one wafeform plot (ai0) and not all 16 channels?  I need to set up 15 more WFG's the same with each channel plotted to its own WFG.  Obviously, I can omit all lines of code other than the first line in the above configuration sub so that only ai0 plots on the WFG but I'm pretty sure that's not the answer, since I would be ommiting all the other channels from the task.  Opening up the WFG on my form and editing the plots isn't it either since it only shows one plot, yet when I run the program all 16 channels are plotted on the WFG.  I'm hazy on what's going on here and what I need to do to remedy. 

 

Thank you

0 Kudos
Message 3 of 11
(4,927 Views)
Hi DM@Means,

I have a few questions:

-Is your project a Windows Forms project or a WPF project?
-How do you currently send the data to your graph (which graph methods, if any, are you using?)
Daniel Dorroh
National Instruments
0 Kudos
Message 4 of 11
(4,923 Views)

It is a Windows Forms Application.  Technically, when I created the project, I selected "NI Windows Forms Application" under Measurement Studio templates. 

 

The graph is getting its data from the auto generated code when I selected the option to auto generate a UI (wafeform Graph) and Measurement Studio auto generates the code for it.  See attached - the code that is added to my Main Windows form.  MS creates the task code (DaqTask1.vb) also but I have not altered that or the code generated in the Main Form (attached jpg). 

0 Kudos
Message 5 of 11
(4,918 Views)

It appears to be reading all channels from the DaqTaskComponent1 when the switch on the UI is high. 

 

If Switch1.Value Then

DaqTask1Component1.StartRead()

Else

DaqTask1Component1.StopRead()

End If

 

I'm trying to modify that code so to only read one channel (ai0), but I can't seem to find the solution.  Is there a way/method to modify this exhisting code so that when the StartRead() method is called, it is called for a specific channel in the task and not all of them?

0 Kudos
Message 6 of 11
(4,911 Views)

As a possible work around to my problem, would it be possible to create a single task with DaqTaskComponent for each individual channel for the purpose of simply reading each plot to its own WFG?  Then add yet another task to the project for reading and writing all channels to the TDMS file? 

0 Kudos
Message 7 of 11
(4,908 Views)
Solution
Accepted by topic author busarider29

Hi DM@Means,

 

To solve your multiple waveform graph problem, you will need to modify the DaqTaskComponent1_DataReady event handler. Please see the following pseudo-code which would represent the modification you might make:

 

System.Threading.Monitor.Enter(DaqTask1Component1)
Dim acquiredData() As NationalInstruments.AnalogWaveform(Of Double) = e.GetData
 
'Plot the 0th waveform on WaveformGraph1
WaveformGraph1.PlotWaveform(acquiredData(0))
'Plot the 1st waveform on WaveformGraph2
WaveformGraph2.PlotWaveform(acquiredData(1))
'... 
'Plot the (n-1)th waveform on WaveformGraphn
'WavformGraphn.PlotWaveform(acquiredData(n-1))
System.Threading.Monitor.Exit(DaqTask1Component1)

 

This way, when you're data are ready, you can just plot them on the graphs you have prepared on your UI.

Daniel Dorroh
National Instruments
0 Kudos
Message 8 of 11
(4,898 Views)

Thank you.  It appears that its working like I want now.  I modified the code to just read the first channel (0) and it is working.  I have yet to try it with additional WFG's and their channels but it looks like this will work. 

 

Thanks again.

0 Kudos
Message 9 of 11
(4,886 Views)

I have accepted the solution posted, however I have run into a problem and before I start another thread, I will post to this one first.  I tried reading multiple channels to separate WFGs and it appears to be working.  However......I can only run one of the WFG's at a time and not multiple at the same time or I get a Daq error ("The Specified Resource is Reserved"). My online search reveals that it doesn't like that the program is reading from the same task before it's been released? 

 

I dropped another DaqComponent onto my form (DaqTask1Component2) and pointed it to the same task since that is where the channels are that I want to read from.  So I have two DaqComponents referencing the same task but they can't reference the task at the same time. 

 

I copied the code generated by MS for my other DaqComponent and just changed the names accordingly to all objects.  This is the code generated in the MainForm.  (See attached). 

 

Is there a work around for this issue or am I dead in the water?  I really need to be able to run any of my WFG's at any time, and simulaneously.  Am I going to have to create individual tasks for each channel and DaqComponents?

 

Thank you 

0 Kudos
Message 10 of 11
(4,878 Views)