Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Using two AI channels at once in ANSI C

Solved!
Go to solution

Does anyone have an example in ANSI C of collecting data from 2 different transducers at the same time? The examples I have seen are for one AI only. I need to gather the data as two separate streams. The data from AI0 should not be mixed with the data from AI1. Do I start two separate tasks? If so, is there an example available?

0 Kudos
Message 1 of 10
(4,908 Views)

Are you going to be collecting data on two channels of the same device or are you going to be collecting data from two seperate devices?  Also, if you are using one device, are you familiar with channel expansion?  

-Joe
0 Kudos
Message 2 of 10
(4,882 Views)

I want to use two channels on one device. Using two devices may be a later option. Right now, I can easily access one channel with:

DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev5/ai0","AnalogInput0",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

 

As soon as I change this to:

DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev5/ai0:1","AnalogInput0",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

 

I get a channel definition error. I need to record the data from two channels at once as part of a regulator pressure response test.

 

Thanks!

Tim

0 Kudos
Message 3 of 10
(4,861 Views)

Tim,

 

you tell us the DAQmxCreateAIVoltageChan is creating an error with that parameters?

Which device are you using as Dev5?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 10
(4,838 Views)

USB-6008. All works fine with a single channel, but trying to use two has me stumped. Unfortunately, all of the examples just show using one channel and not multiples or multiple devices.

 

My frustration level has hit the ceiling!

0 Kudos
Message 5 of 10
(4,836 Views)

If you run a MAX testpanel, is using that channel string working?

 

You didn't answer if the create channel is generating the error. I somehow assume that it is more something like e.g. timing which could create an issue.....

 

Norbert

 

EDIT: It would be useful if you post a screenshot of the error and some code snippet.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 10
(4,829 Views)

Yes, the channels are working. It never gets to the point where timing is an issue.

I have used a single channel to gather data and display it on a graph while logging to a TDMS file and that works great. However, trying to expand to a second channel has not worked at all. Just changing the following line make the program choke:
     DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev5/ai0","AnalogInput0",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

to:   DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev5/ai0:1","AnalogInput0",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

 

I need to know how the program should be structured. I assumed that someone at NI at sometime had actually performed this operation and that the solution would be readily available. If I knew the proper functions to call and the proper syntax, then I would be ready to tackle any timing issues that might arise.

 

  1. DAQmxCreateTask ("", 0x6DE8C768)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:31.954       Call Duration 00:00:00.422

Status: 0 (0x0)

 

  1. DAQmxCreateAIVoltageChan (0x6DE8C768, "Dev5/ai0,Dev5/ai1", "AnalogInput0", "DAQmx_Val_Cfg_Default", -10, 10, DAQmx_Val_Volts, NULL)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.376       Call Duration 00:00:00.547

Status: 0 (0x0)

 

  1. DAQmxCfgDigEdgeStartTrig (0x6DE8C768, "/Dev5/PFI0", DAQmx_Val_Falling)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.923       Call Duration 00:00:00.015

Status: 0 (0x0)

 

  1. DAQmxCreateTask ("", 0x6DE8C840)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.938      Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxCreateAOVoltageChan (0x6DE8C840, "Dev5/ao1", "", 0, 5, DAQmx_Val_Volts, "")

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.938       Call Duration 00:00:00.016

Status: 0 (0x0)

 

  1. DAQmxCfgSampClkTiming (0x6DE8C768, "", 1000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2000)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.954       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxConfigureLogging (0x6DE8C768, "E:\NITinkering\...trigger003.tdms", DAQmx_Val_LogAndRead, "GroupName", DAQmx_Val_OpenOrCreate)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.954       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxRegisterEveryNSamplesEvent (0x6DE8C768, "DAQmx_Val_Acquired_Into_Buffer", 2000, 0, 0x00403898, NULL)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:32.954       Call Duration 00:00:00.047

Status: 0 (0x0)

 

  1. DAQmxRegisterDoneEvent (0x6DE8C768, 0, 0x0040397C, NULL)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.001       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxStartTask (0x6DE8C768)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.001       Call Duration 00:00:00.265

Status: 0 (0x0)

 

  1. DAQmxStartTask (0x6DE8C840)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.266       Call Duration 00:00:00.016

Status: 0 (0x0)

 

  1. DAQmxCreateTask ("", 0x6DE8C918)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.282       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxCreateDOChan (0x6DE8C918, "Dev5/port0/line0:7", "", "DAQmx_Val_ChanForAllLines")

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.282       Call Duration 00:00:00.016

Status: 0 (0x0)

 

  1. DAQmxStartTask (0x6DE8C918)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.298       Call Duration 00:00:00.046

Status: 0 (0x0)

 

  1. DAQmxWriteDigitalLines (0x6DE8C918, 1, True, 10, "DAQmx_Val_GroupByChannel", {0x01}, NULL, NULL)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:33.344       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxWriteDigitalLines (0x6DE8C918, 1, True, 10, "DAQmx_Val_GroupByChannel", {0x00}, NULL, NULL)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:49.157       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxWriteDigitalLines (0x6DE8C918, 1, True, 10, "DAQmx_Val_GroupByChannel", {0x00}, NULL, NULL)

Process ID: 0x00000278         Thread ID: 0x00001094

Start Time: 11:42:49.157       Call Duration 00:00:00.000

Status: 0 (0x0)

 

> 18. DAQmxReadAnalogF64 (0x6DE8C768, 1000, 10, "DAQmx_Val_GroupByScanNumber", {0,0,...}, 1000, 0, NULL)

> Process ID: 0x00000278         Thread ID: 0x0000069C

> Start Time: 11:42:51.157       Call Duration 00:00:00.125

> Status: -200229 (0xFFFCF1DB)

 

  1. DAQmxGetExtendedErrorInfo ("Buffer is too s...s Code: -200229", 2048)

Process ID: 0x00000278         Thread ID: 0x0000069C

Start Time: 11:42:51.282       Call Duration 00:00:00.000

Status: 0 (0x0)

 

  1. DAQmxStopTask (0x6DE8C768)

Process ID: 0x00000278       Thread ID: 0x0000069C

Start Time: 11:42:51.282       Call Duration 00:00:00.032

Status: 0 (0x0)

 

  1. DAQmxClearTask (0x6DE8C768)

Process ID: 0x00000278         Thread ID: 0x0000069C

Start Time: 11:42:51.314       Call Duration 00:00:00.000

Status: 0 (0x0)

 

 

Thanks again for your assistance.

0 Kudos
Message 7 of 10
(4,826 Views)

From your log i see that you run into an error when reading the analog data.

 

Error -200229 occurred at an unidentified location

Possible reason(s):

Buffer is too small to fit read data.

 

 

There is a parameter for the read function to define the size of the buffer (or you pre-allocated it). If you acquire two instead of one channel using the same data rate, the amount of data will be double. So you require a double sized buffer to fetch all data.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 10
(4,824 Views)

I increased the buffer size to 10000 and the error still occurs.

Thanks,

Tim

0 Kudos
Message 9 of 10
(4,821 Views)
Solution
Accepted by topic author Sparkman2

I solved the problem by using NISpy and changing parameters to see what effect they had on the program. I was trying to read two channels with 1000 data points each. I thought my buffer size was the problem, but it was in the call to:
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle, 1000, 10.0,DAQmx_Val_GroupByChannel,data, 2000, &read,NULL));

I did not realize the significance of the parameter arraySizeInSamps and had left it at 1000 when I added the additional channel.

0 Kudos
Message 10 of 10
(4,816 Views)