09-16-2013 11:12 AM
Thank you for your help. I just recently purchased a new USB-6212 BNC DAQ Device. I have past experience with VB 6.0 and legacy NI-DAQ. I am now learing Visual Studios 2012 VB.Net 4.5 and your new NI-DAQ mx. I have studied your: Using NI-DAQmx in Text Based Programming Environments http://www.ni.com/white-paper/5409/en#toc4. I am also looking at your sample VB.net 4.5 text based programs samples: C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.5\Analog In. I have written a small VB program following your examples and I can see data from one AI channel at a time. I post this data to a VB Chart. It works. However, my experiment needs to record multiple channels, for example, AI0, AI1, AI2, AI3... and post those to different ChartArea of my chart named LIFChart. So my question is, how do I write the texted to get more than one channel?
Here is my short code:
Imports NationalInstruments.DAQmx
Public Class LIFGraphForm
Private myTask AsTask
Private data AsDouble()
Private myAnalogReader AsAnalogMultiChannelReader
Public i AsInteger = 0
PublicSubNew()
InitializeComponent()
EndSub
Private Sub Button1_Click(sender AsObject, e AsEventArgs) Handles Button1.Click
data = myAnalogReader.ReadSingleSample()
currentVoltage.Text = data(1).ToString
LIFChart.Series(0).Points.AddXY(i + 20, data(1)
i = i + 1
EndSub
PrivateSub LIFGraphForm_Load(sender AsObject, e AsEventArgs) HandlesMyBase.Load
myTask = NewTask()
myTask.AIChannels.CreateVoltageChannel("Dev1/ai0, Dev1/ai1", "", CType(-1, AITerminalConfiguration), -10, 10, AIVoltageUnits.Volts)
myTask.Control(TaskAction.Verify)
myAnalogReader =NewAnalogMultiChannelReader(myTask.Stream)
EndSub End Class
My question is with the line myTask.AIChannels.CreateVoltageChannel("Dev1/ai0, Dev1/ai1", "", CType(-1, AITerminalConfiguration), -10, 10, AIVoltageUnits.Volts)
I have tried to follow your formum posting http://forums.ni.com/t5/Measurement-Studio-for-NET/Acquire-Thermocouple-Measurement-and-Current-Inpu...
**forum posting section **
2) You can call myTask.AIChannels.CreateXYZChannel() multiple times. You can also specify multiple physical channel names per call, such as "Dev1/ai0:7" or "Dev1/ai0,Dev1/ai3".3) Here's how the help explains the return value of AnalogMultiChannelReader.ReadMultiSample():
"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." If you configure the task the way you described, then X[0,0] is the 1st TC sample, X[1,0] is the 1st current sample, X[0,42] is the 43rd TC sample, X[1,99] is the 100th current sample, etc.
**End forum posting Section**
Question: How do I write the my.task.AIChannels.... line to collect multiple channels of data at on point in time "instanly" when I click the button "Button1_Click" and how will I get the data from my "Data" variable:
data = myAnalogReader.ReadSingleSample(). Will it be like: ChannelAI0Data = Data(0), ChannelAI1Data = Data(1), ChannelAI2Data = Data(2),.. Thank you very much for your help. I will look forward to your response. Sincerely, Tony
09-17-2013 05:25 PM
Hi Tony,
The information you gathered is correct and seems to effectively be correlated into your code.
Were you able to apply those steps? Did you encounter any trouble?
Also a good place for reference would be to look at DAQmx examples: http://digital.ni.com/public.nsf/allkb/E3BAF6FC4017960B8625755A00525D37
09-17-2013 10:18 PM
Hi MJ,
Thank you for your email. Yes my code works but only for one channel at a time, example AI0. I need to collect data from mutlitple channels at once and store that data using variables. Can you give me a suggestion on where I need to change my code to get multiple channel data? Your link that you provided is not working. Can you resend the link again? Thank you. I will look forward to your help. Tony
09-18-2013 06:35 PM - edited 09-18-2013 06:37 PM
Hi Tony,
I am a little less familiar with the particulars of coding syntax in .net but I may be able to help narrow down where the issue may be.
The link send previously is: http://digital.ni.com/public.nsf/allkb/E3BAF6FC4017960B8625755A00525D37
The above link will show you how to locate DAQmx examples. You can try the example that acquires multiple channels to use as coding reference. If the provided code does not work, it is possible that you may have a hardware or driver issue.
Could you try acquiring multiple analog inputs using NI-MAX. Are you able to? Are the values as you expected? Please follow the below link to do so: http://digital.ni.com/public.nsf/allkb/F28C6BD62B0ED68F86257A6B00733E0E
Also please keep in mind that you can not collect all channels completely simultaneously. Since each channel is multiplexed you cannot truly collect all data at once. However, depending on your application this may have no negative impact at all.