LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Digital IO / DAQx: How to write to a single line?

Hello,
 
life was so easy with traditional DAQ...
 
I'm trying to control single lines of DIO cards with DAQmx und CVI 8.0.1 , - the equivalent in traditional DAQ would be "DIG_Out_Line"
 
What I do:
- I create a task
- I add one channel for each digital line
 
DAQmxCreateTask (tsk_MAIN_OUTPUT_A, &tMainOutputA);
DAQmxCreateDOChan (tMainOutputA, "Dev1/port0/line0", "Line0",DAQmx_Val_ChanPerLine);
...
...
DAQmxCreateDOChan (tMainOutputA, "Dev1/port0/line7", "Line7",DAQmx_Val_ChanPerLine);
 
 
When I look into the "WriteFunction" collection, I find all kind of functions that write to tasks, but none which writes to channels...
The examples which comes with CVI only writes to a port, - 8 bit at a time, - which is what I want to avoid...
 
What am I missing?
 
Thanks a lot!
Greg
0 Kudos
Message 1 of 9
(5,397 Views)
For each task you can bind as many or as few DIO lines to the task as you like.  If you want you can create a task for each individual DIO line.  If you want to create the tasks programatically (not in measurement and automation explorer) I find that keeping the task handles in an array, and sometimes using an enumeration to allow the naming of the array index works pretty well.  Of course there are other ways to manage multiple handles and what ever way you feel most comfortable with should work fine.  It does take a little getting used too, but once you make the transition to DAQmx and get used to the task based management of resources, it is pretty strait forward.

Message Edited by mvr on 08-09-2006 01:40 PM

0 Kudos
Message 2 of 9
(5,389 Views)
Hello mvr
 
Let me see if I get you right:
 
To control lines individually, I have to assign a task per line, not a channel per line? Is this correct?
 
Thanks for your help!
Greg
 
0 Kudos
Message 3 of 9
(5,381 Views)
Creating an individual task for each channel you want to address as a single entity will work. The parameter for line grouping can be set to DAQmx_Val_ChanPerLine, and oddly enough I think ChanForAllLines also works when using a task for each line on a port (ChanForAllLines is required when a task spans multiple ports).
 
So you end up calling both
DAQmxCreateTask () and DAQmxCreateDOChan() for each task you create.  You can leave the tasks active for the entire time your application is active, but make sure you close the tasks before exiting the application.  Again an easy process if you just step through each task handle in an array.
 

Message Edited by mvr on 08-09-2006 02:23 PM

0 Kudos
Message 4 of 9
(5,380 Views)
Thanks for your help mvr, the application works perfect now!

Best Regards,
Greg
 
0 Kudos
Message 5 of 9
(5,350 Views)
Hi i'm new to DAQ programming and converting the existing code. Original code is using traditional drivers and  which is in VB . Converting to C# using mx drivers.
 
I need to read and write to a single line. The example( ReadDigChannel) gives how to write to a port. I tried to change the code to get it working for single line instead of a port but gives me an error saying that i need to specify all line in the port.
 
The daq device is 6120. Any help would be greatly appreciated.
 
As i'm beginner i didn't quite understand the solution that is written in this thread can someone please give me an example how to do it in c#.
 
Thank you very much.
 
 
0 Kudos
Message 6 of 9
(4,763 Views)
Hi i'm new to DAQ programming and converting the existing code. Original code is using traditional drivers and  which is in VB . Converting to C# using mx drivers.
 
I need to read and write to a single line. The example( ReadDigChannel) gives how to write to a port. I tried to change the code to get it working for single line instead of a port but gives me an error saying that i need to specify all line in the port.
 
The daq device is 6120. Any help would be greatly appreciated.
 
As i'm beginner i didn't quite understand the solution that is written in this thread can someone please give me an example how to do it in c#.
 
Thank you very much.
 
 
0 Kudos
Message 7 of 9
(4,763 Views)

Hi Aish,

Can you please post a screenshot of your error, along with attaching the code you are using? I believe what is being seen is a discrepancy between the number of channels in your task, the fillmode for the task (DAQmx_Val_GroupByChannel or DAQmx_Val_GroupByScanNumber), and the possibly the array that is being used to capture the data.

I also see you are interested in reading and writing – In order to read and write, this will require either different channels need to be used for the read and write, or if you want to use the same channels, separate tasks will need to be used (I.E. – create a task for DI, read, clear the task, create a DO task, write, clear the task).

David L.
Systems Engineering
National Instruments
0 Kudos
Message 8 of 9
(4,732 Views)
Hi David,
 
                Thank you very much i did get it working now.  I used " ReadSingleSampleSingleLine " method to read the line in the task. I used different lines to read and write. As you said I'll clear after the write task, then read and clear to use the same lines.
0 Kudos
Message 9 of 9
(4,719 Views)