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.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

ANSI C examples of mixed operations? (ie, AI and DI, AI and DO, AI/DI/DO)

The examples that come with NIDaq MX Base are nice but appear to be fairly basic, and most of the more complex examples online appear to be for LabView.

 

I'm using a USB-6215 in C on OS X, and will need to do multiple things at once, so the included examples aren't that useful. Are there any good C-based examples that go well beyond what the bundled examples do?

 

(Another type of C example that would be useful would be some examples of using DAQmxBaseExportSignal to reroute clocks in some useful way.)

 

Thanks,

 

Jon

 

PS: I find searching for C-based material to be a little bit difficult on the site, often turning up LabView material instead. It'd be nice if under "NI Developer Zone :: Examples :: Software" there were a section for "mx Base" or "ANSI C/C++". Something similar for the discussion forums would also be nice. Each one would help avoid using a text search for the topic. There might not be much traffic, but that's an argument for them, because it shows how such posts would be lost among all the other material.

 

Message Edited by JonHendry on 10-21-2009 11:21 PM
Systems Manager / Programmer
Maunsell Lab
Dept. of Neurobiology
Harvard Medical School
0 Kudos
Message 1 of 10
(4,080 Views)

Hello Jon,

 

Unfortunately there aren't too many DAQmx Base C examples, but the DAQmx C programming structure is almost identical to DAQmx Base and there are some synchronization/multi-function examples for that.  Is there anything in particular that you were trying to code?  Maybe I can help you get started.

 

Regards,

0 Kudos
Message 2 of 10
(4,058 Views)

Hi Brandon,

 

Thanks for responding.

 

Basically, I have a Mac, a C++/Objective-C application, and a USB-6215. I need to get the 6215 doing asynchronous digital out, asynchronous digital in, and also analog in. All concurrently (or effectively concurrently). It's going to be reading in eye positions (2 analog signals), responding to lever presses (digital in), and occasionally triggering a solenoid (digital out).

 

It appears that the application would have to set up a digital input task, a digital output task, and an analog input task, and run them all at the same time, but it's not clear if that's possible, or how I would do that. 

 

Any help you can provide would be much appreciated. 

 

Thanks! 

Systems Manager / Programmer
Maunsell Lab
Dept. of Neurobiology
Harvard Medical School
0 Kudos
Message 3 of 10
(4,041 Views)

Oh, almost forgot: I also need to be able to obtain some sort of timestamp equivalent for events that are observed, such as the lever presses on the digital in. I understand something workable should be possible with a counter, but I'm not sure how to do that, let alone how to do so in mx base, let alone when the device is doing other things at the same time.

 

Unfortunately, I'm a total hardware virgin, and the people in the lab who have experience with NI DAQs worked with different APIs. This lab has been using ITC products for a while, but we're trying to move to NI.

 

Thanks,

 

Jon 

Message Edited by JonHendry on 10-26-2009 02:45 PM
Systems Manager / Programmer
Maunsell Lab
Dept. of Neurobiology
Harvard Medical School
0 Kudos
Message 4 of 10
(4,014 Views)

Hello Jon,

 

So if I understand correctly, you would like to trigger two analog inputs based off of a digital input, and then have these analog inputs trigger a digital output.  Is this correct?  One thing your DAQ card doesn't support is analog triggering, so I'm not sure if you will be able to do the second part.  As far as triggering on the digital input, you can use the DAQmxBaseCfgDigEdgeStartTrig function to select the rising or falling edge of a PFI line to start acquisition.  Refer to the DAQmx Base C Function Reference help for more information on how to use this function.

 

Regards,

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

Hi Brandon,

 

Actually I want to do simultaneous AI and DI, and occasionally do an application-triggered DO. Sorry if I wasn't clear.

 

I found a NIDAQ mx example, "M Series Correlated Digital Input with Analog Input Sample Clock in ANSI C", 4673.zip, which looks helpful, if the differences aren't too great between mx and mx base.

 

Systems Manager / Programmer
Maunsell Lab
Dept. of Neurobiology
Harvard Medical School
0 Kudos
Message 6 of 10
(3,997 Views)

Hello Jon,

 

One fundamental difference between DAQmx and DAQmx Base that make cause a problem is that DAQmx Base is not threadsafe.  As a result, you shouldn't call multiple DAQmx Base functions at the same time, otherwise unexpected behavior can occur.  Simultaneously running an AI and DI task will work, but you'll need to read the data from the card sequentially to avoid conflicts.

 

Regards,

 

Seth B.
Principal Test Engineer | National Instruments
Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 7 of 10
(3,980 Views)

Thanks Seth.

 

I'm not sure we'll be able to use our NI gear, as there doesn't seem to be any way for us to set sampling rate on the DI. At least, DAQmxBaseCfgSampClkTiming doesn't appear to work for digital channels.

 

DAQmxBase Error -200452: Specified property is not supported by the device or is not applicable to the task.

  

It'd be nice if the limitations were clearly documented someplace where a potential customer might find it before ordering.

Systems Manager / Programmer
Maunsell Lab
Dept. of Neurobiology
Harvard Medical School
0 Kudos
Message 8 of 10
(3,971 Views)
Sorry about the prior message. Cranky and frustrated. 😕
Systems Manager / Programmer
Maunsell Lab
Dept. of Neurobiology
Harvard Medical School
0 Kudos
Message 9 of 10
(3,968 Views)

Hi Jon,

Although not in the most obvious location, this information is available before purchase in the readme on driver download page [1].

Under the M Series section, it says

 

-Correlated DIO (PCI/PCIe/PXI only)
    -speed is limited to about 100kHz (system dependent) because DMA is not supported for DIO

 

Which shows why you're getting that error for your USB device.

Further down, the readme says

 

NI-DAQmx Base is not multi-thread safe. In LabVIEW, use the error cluster to force execution order. In C, use only one thread to make API calls; especially for task/channel creation and deletion.

 

Which explains why there are no asynchronous API calls or examples for DAQmx Base.

[1] DAQmx Base 3.3 for OS X
http://joule.ni.com/nidu/cds/view/p/id/1341/lang/en

Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 10 of 10
(3,965 Views)