Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

ChannelsToRead and Physical/Virtual Channel name

If I create a channel and specify a virtual channel name, as in the following:

taskAnalogIn.AIChannels.CreateVoltageChannel("Dev1/ai" + daqChannel.ToString(), "Power Meter", AITerminalConfiguration.Rse, Convert.ToDouble(0.0), Convert.ToDouble(10.0),    AIVoltageUnits.Volts);

do I always have to refer to this channel by it's virtual name?
I tried to call ChannelsToRead and specified the physical channel name, but I got an exception when I tried to verify the task that indicated that the channel I specified didn't exist.



0 Kudos
Message 1 of 15
(5,018 Views)

Hi DRT-

Yes, you must use the vitual channel name when using the ChannelsToRead method.  I have modified the "ContAcqVoltageSamples_IntClk" C# shipping example to illustrate the use of the ChannelsToRead setting to return data from a single channel of a multi-channel input task.  Please let me know if you have any additional questions.

Thanks-

 

Tom W
National Instruments
0 Kudos
Message 2 of 15
(5,005 Views)
Tom,
Thanks for the response. So, OK, I need to use the Virtual Channel name when setting ChannelsToRead. But tell me, what exactly does setting ChannelsToRead do? The reason I ask is this:
I thought that I could set up multiple channels in a task, and the create multiple data readers, each one reading one or more channels, by setting ChannelsToRead to the channel(s) I wanted my data reader to read. This doesn't appear to be the case. It looks like there is no way to read individual channels, and I have to read all my channels and then update various data variables with the values read from each channel. Is this the case? Note that in my particular case, I have one channel that I have to continuously read from, and other channels that I want to read from a timer or in response to some user input.


0 Kudos
Message 3 of 15
(4,994 Views)

Hi DRT-

The effect of reading from a subset of the total number of channels in the task is that the other data points are thrown away.  If you want to pull individual channel data for use in different portions of your program, the best suggestion would be to run your acquisition in one thread that is accessible globally from your other threads and just access those points once they have already been pulled from the PC buffer and into your application memory.

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 4 of 15
(4,987 Views)
Thanks for the quick response. I am still confused about how I can determine what data came from which daq channel.
In what order does the channel data come in from the multidimensional array that is returned from a ReadMultiSample call?
I suppose it is in the same order in which I added the channels to the task, yes?  So I have to keep track of this order and
access the correct "column" of the data array to read the data for the channel I want? If so, what is the purpose of having data readers, and of allowing me to name the channels. Shouldn't I be able to call a function like GetDataForChannel(virtualChannelName), or have data readers that read just the subset of channels that I assign to them?
0 Kudos
Message 5 of 15
(4,980 Views)

Hi DRT-

You specify the arrangement of channel data in the overall read array with the order in which you add the channels to the task.  From the NI-DAQmx .NET Framework Help(Start>>Programs>>National Instruments>>NI-DAQ) for AnalogMultiChannelReader.ReadMultiSample Method:

Return Value

A 2D array of floating-point samples from the task. Each element in the first dimension of the array corresponds to a channel in the task. Each element in the second dimension of the array corresponds to a sample from each of the channels. The order of the channels in the array corresponds to the order in which you add the channels to the task or to the order of the channels you specify in ChannelsToRead.

So, you can override the arrangement of the data in the array by setting ChannelsToRead to a different order.  You name channels so that you can set per-channel properties at a more granual level than the task-level properties you set for timing, etc. 

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 6 of 15
(4,974 Views)
Thanks for clearing that up. One last question, I promise.
Once I add a channel to a task, how do I remove it?
(OK, two last questions)
If I set the Stream's ChannelsToRead property to only the channels I want to read, does the daq card actually stop reading from the excluded channels, or is it that once I add a channel to a task, that channel is always sampled, until I stop and dispose of the task?
0 Kudos
Message 7 of 15
(4,969 Views)

Hi DRT-

There isn't a built-in mechanism to remove channels from a task- you will just have to destroy the task and recreate it with only the channels you want to look at.  When you set the ChannelsToRead property, the card is still physically sampling from all channels but only the channels of interest are actually returned to your application.  This gives you the ability to pare down the sheer amount of data you will be reading into your application from your PC buffer on a multi-channel acquisition when only a subset of the channels are of interest.

Let us know if you run into anything else-

Tom W
National Instruments
0 Kudos
Message 8 of 15
(4,963 Views)
OK, I attempted to dispose of the task, rebuild the task, add additional channels, and then restart the task.
Everything seemed to be OK until I tried to access the AIChannel VirtualName property in my asynchronous callback. My application stopped responding.

Attached is a modification of an example provided by NI that shows the issue.
Click the start button - The text box that shows the channel virtual name is filled in and the grid starts being updated.
Click the stop button. This disposes of the task, rebuilds it, adds a channel, and then restarts the task.
When the task is restarted, no more response.

What am I doing wrong?
0 Kudos
Message 9 of 15
(4,953 Views)

Hi DRT-

I am seeing the same behavior as you on my end and we're currently investigating its cause.  I'll let you know as soon as we can sort it out- thanks for your patience!

Tom W
National Instruments
0 Kudos
Message 10 of 15
(4,903 Views)