Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquire N scans on multiple channels using daqmx and Visual Basic .NET

I need to read N scans from several channels on an M-Series board and average those N scans. If I have physical channels called "Dry Bulb Temp" and "Wet Bulb Temp," how would I tell the reader to read from all of these channels, N number of times, as fast as possible?

I have the following code from a sample project:

Private myTask As Task 'Main Task which is Assigned when the Start Button is Clicked
Dim reader As AnalogMultiChannelReader
Private totalSamples As Int32 'Global Container for the number samples to be acquired
Private acquiredSamplesCount As Int32 = 0 'Iteration variable which hold the current sample being acquired

Private dataColumn As DataColumn() 'Channels of Data
Private dataTable As DataTable = New DataTable 'Table to Display Data

'Add any initialization after the InitializeComponent() call
physicalChannelComboBox.Items.AddRange(DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External))
If (physicalChannelComboBox.Items.Count > 0) Then
physicalChannelComboBox.SelectedIndex = 0
End If

totalSamples = Convert.ToInt32(numberOfSamplesNumeric.Value)
acquiredSamplesCount = 0
Try
'Create a new task
myTask = New Task("aiTask")
'Create a virtual channel
myTask.AIChannels.CreateVoltageChannel(physicalChannelComboBox.Text, "", _
CType(-1, AITerminalConfiguration), Convert.ToDouble(minimumValueNumeric.Value), _
Convert.ToDouble(maximumValueNumeric.Value), AIVoltageUnits.Volts)
'Verify the Task
myTask.Control(TaskAction.Verify)

reader = New AnalogMultiChannelReader(myTask.Stream)

Catch exception As DaqException
'Dispose the Task and Disable the Timer
myTask.Dispose()
MessageBox.Show(exception.Message)
End Try
0 Kudos
Message 1 of 15
(6,430 Views)
Hi Joe,

To read from multiple channels, you can enter in the "Physical Channel" combo box, the channels seperated by commas, or if you're reading from physical channels, the string "DevX/aiY:Z", where X is the device number, and X and Y are the first and last channel you want to scan (e.g. To read from ai0 to ai4 from your device 1, enter "Dev1/ai0:4"). From the names of your channels, I'm assuming they're global channels created in MAX? You can still read from multiple channels by seperating them with commas.

If you want to read N scans, you can configure your task to do finite acquisition, and specify N as the SamplesPerChan:

//Example
myTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChan)

Hope this helps,
Lesley Y.
0 Kudos
Message 2 of 15
(6,412 Views)
Can someone please correct the following code. This is what I think is involved for analog voltate acquisition from start to finish.. What is the sample rate to make it read as past as possible? What if I need to read DevX/aiY:Z fro two different devices? "Dev1/ai0::7, Dev2/ai0:7, Dev2/ai0:3" ???

Try
myTask = New Task("aiTask") 'Create Task
myTask.AIChannels.CreateVoltageChannel("DevX/aiY:Z", "", _
CType(-1, AITerminalConfiguration), 0, 5, AIVoltageUnits.Volts) 'Add Channels to Task
myTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising,
SampleQuantityMode.FiniteSamples, samplesPerChan) 'Set timing, speed and N
myTask.Control(TaskAction.Verify) 'Verify Task
reader = New AnalogMultiChannelReader(myTask.Stream) 'Create reader
Dim data() As Double = reader.ReadMultiSample(1000) 'Read 1000 samples per channel
Catch exception As DaqException
myTask.Dispose()
MessageBox.Show(exception.Message)
End Try

Thanks!
0 Kudos
Message 3 of 15
(6,406 Views)

Hi Joe,

You can control the sampling rate by changing the parameter "sampleRate" from "myTask.Timing.ConfigureSampleClock("", sampleRate, SampleClockActiveEdge.Rising,...)" to the desired rate. The maximum sampling rate of the device can be found in the device specifications (I've attached a link to the E Series Help..check the NI site if it's a different device). You cannot read from multiple devices from the same task. Hence you will have to configure a new task to acquire from the second device.

E Series Help (User Manual)

Thanks,
Lesley

0 Kudos
Message 4 of 15
(6,389 Views)
Hi Lesley
>>You cannot read from multiple devices from the same task.
I take it that to run two cards I would need two run two tasks.
I will be using the RISI bus two put a 1/r trigger on the bus two start a trigger Acquisition (I seem two remember that I can not put a signal from an PFI pin strait on the bus).
Perhaps I will use both triggered inputs.
But how do I synchronize both cards two start at the same time from the same trigger if they are different tasks?

Thanks
Colin
0 Kudos
Message 5 of 15
(6,256 Views)
Hi Colin,

You can use two tasks in the same program to control the two devices. For each task (device), you can route the desired signal to the appropriate RTSI line using the "Route Signal" VI. You will then be able to access this signal from the RTSI line of the other task. You can access differnet synchronization examples in LabVIEW's Example Finder (try keywords: RTSI or synchronization OR browse under Hardware Input and Output >> DAQmx >> Synchronization)

Thanks,
Lesley
0 Kudos
Message 6 of 15
(6,235 Views)
Hi Lesley

I have done this in the past with Borland but am now using MX for the first time using M-Studio, not Labview.
I had a problem before with the old daq driver, putting a triggered input onto the RTSI line (could not be done) so I used a triggered countered timer and put the output of that onto the RTSI line.
I don't no if things have change.
The problem was that I could not root the trigger input (PFI 0) directly to the RTSI Line.
I would prefer that when a card was triggered, that it produced a trigger pulse for the other card as that is the only way I see synchronization properly.
That way you would start the second card first and make it wait for the first card.
Using the same trigger does not guarantee that they both start on the same trigger if there is a system delay between starting both tasks.
As I have not used MX before may be missing something.

Thanks

Colin
0 Kudos
Message 7 of 15
(6,229 Views)
Colin,

The easiest way to do this is to route the analog input sample clock of the master card to that of another card. For instance, if Dev2 is the "slave" card with task "myTask", try:

myTask.Timing.ConfigureSampleClock("Dev1/ai/SampleClock", sampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, samplesPerChan)

Be sure to set up the task for Dev1 before issuing this command. Also, start "myTask" before the task for Dev1 so that it will not miss the beginning clock pulses of the ai sample clock if the trigger comes early. The DAQmx driver should automatically handle the routing of this clock. Just be sure that your RTSI cable is configured in MAX.

Regards,
Ryan V.
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 8 of 15
(6,209 Views)
Hi Ryan

I will try that but it still leaves me with the problem of the trigger but if the sample clock only starts after DEV1 is started then that might do the trick.

I did not no about setting up the RTSI in MAX. (Thanks, I will look into that one)

At the moment I am playing with one of the MAX sample that uses call-back so there is no start command.
I am looking for a sample that uses software control using the Task Start command.

I am finding the help file a bit skimpy with many useful functions that don't seem to work with my card.
The old NIDAQ book used to list what cards different commands worked with.
One that I was interested in was the autozero function but again the help just list the function.
Give me a good reference book any day.
As I say I am only just getting into the MX way of doing things.

The software that I am doing is simply to capture 12 cylinder (Engine test rig) pressures and find peak pressure.
Needed for rig shut down if out of range.

This needs auto-zero and a small amount of averaging aroud the peak.
Simple
Thanks again Ryan
Colin
0 Kudos
Message 9 of 15
(6,204 Views)
Colin,

You are correct. The sample clock on our DAQ cards is only started after the start trigger is encountered. I'll see if I can find an example for you.

Ryan V.
Ryan Verret
Product Marketing Engineer
Signal Generators
National Instruments
0 Kudos
Message 10 of 15
(6,185 Views)