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: 

Digital write multi sample single line

Hello,

 

I am using a PCI-6289 DAQ card and programming in C#. I am attempting to write analog/digital data arrays using one task per channel. However, I noticed something odd about the DigitalSingleChannelWriter. From the function list, I noticed the WriteSingleSampleSingleLine function which simply writes in the Boolean value. However, I couldn't find a function to write an array of Boolean values (ie, WriteMultiSampleSingleLine). The closest match (WriteMultiSamplePort) doesn't seem to quite do what I want it to, since I only want to write to a single line. How would I go about doing this? Is it possible to write to a single line rather than the entire port?

 

Another quick question. Does this premise even work? I'm not sure I exactly understand the scope of a task. Can I assign different analog channels on the same board to different tasks, or do I have to group them in a single task?

 

Thanks,

WormholeX

0 Kudos
Message 1 of 5
(4,956 Views)

A followup for my second question. I read other threads on how to synchronize analog and digital output by setting the analog task to use whatever as its start trigger, and set the digital to use "/Dev1/ao/StartTrigger". However, this refers to the start trigger for which analog channel? Do all the analog output channels on Dev1 share the same start trigger?

 

I am interested in this is because my eventual goal is to program "a01" and "a02" on separate tasks, setting "a01"'s trigger to the 20 Mhz timebase, and setting "a02" to use "a01"'s start trigger (ie, "/Dev1/ao1/StartTrigger", if such is possible). Then I would hit a02Task.Start() before ao1's, and synchronize them that way. Is there a better way to do this?

 

Thanks,

WormholeX

 

PS: The reason I want these on separate tasks is that I generate the double[]'s for each channel separately. However, the C# AnalogMultiChannelWriter class has the WriteMultiSample function (equivalent to N channel, N sample) take in a multidimensional double[,] array. Copying the single arrays into the multidimensional array is inefficient.

0 Kudos
Message 2 of 5
(4,869 Views)

If you want both ao channels to be clocked, they'll both need to be in the same task and then you'll need to do the work of figuring out how to sync the 2D array of timed values for the 2 channels.  Your board doesn't support the  ability to independently clock 2 different ao tasks.  (Note that it is possible to clock 1 ao channel while performing on-demand software-timed ao updates on another channel.)

 

As to the digital stuff, I know DAQmx provides for the ability to generate multiple samples out of a single digital line.  However, I've only done it via LabVIEW and can't offer any help about the C# syntax.  Just saying, there should be a way.

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 5
(4,854 Views)

Thank you for your response. Using the same clock is ok. However, I was worried that if I use the 20 MHz timebase as a master trigger, I could get into a situation where i hit ao1Task.Start() and the clock starts before I hit ao2Task.Start(), thus the channels are not synchronized. I was wondering if the following procedure would work for actually doing it on different tasks. Same clock is ok, I just need the channels to be synchronized.

 

1) Define a master trigger, say "Dev1/PFI0".

2) Physically wire a spare digital line, say "Dev1/port0/line15" into PFI0.

3) Create tasks for each ao channel.

4) Take a single task and configure the sample clock/trigger to PFI0. This should apply to all ao channels?

5) Write data to ao tasks.

6) Start ao tasks

7) Write and start a digital pulse to "Dev1/port0/line15".

 

Would this work? Perhaps this is just such a silly thing to do and I should just suck it up and use a single task for all the AO.

 

Also for the digital, could you send me some LabVIEW code? I should be able to convert it to C# syntax.

 

Thanks,

WormholeX

0 Kudos
Message 4 of 5
(4,841 Views)

Hi, first I'd like to point you to some resources that will probably help you in the future.  If you go Start>Programs>National Instruments>NI-DAQ>Text Based Support, we have a few things that will help you.  The first is the 'NI DAQmx C Reference Help'.  This contains all of the commands, plus other help topics.  Additionally we offer a plethora of different sample codes that cover different scenarios, and all of this is linked from that folder location.  It also sounds like you benefit greatly by giving our Using NI-DAQmx in Text Based Programming Environments tutorial a look.
Using the DAQmx help and the samples listed above, I affirmed that the functions you will want to use to write multiple values are the following:


DAQmxWriteAnalogF64
DAQmxWriteDigitalU32(or U16 or U8)


Regarding the tasks, you can eitherchoose to write to a single each line, or a task for an entire port.  Keep in mind that all similar tasks on a device will have to acquire at the same rate. You can choose to write either single channel with single samples, up to writing multiple channels with multiple samples, its up to you.
Regarding Synchronization, I believe you would benefit from checking out our Synchronization Basics tutorial.

 
For the example you gave, you would be using the analog output starting as your trigger to start something else, in this case the digital output.  Since, you can only have one clock rate per type of task, the rate from that isn't dependent on which port you're on.  To answer your question, yes they would share the same start trigger.


You will not need to do anything to synchronize the timing and start between your similar tasks, including your AO tasks.  You will need to use synchronization if you want to sync up your digital and analog tasks, however.


I would recommend giving the help I recommended, and other help a look soon to learn more about programming with DAQmx. 

Paul Davidson
National Instruments
Product Owner - ni.com Chat
0 Kudos
Message 5 of 5
(4,839 Views)