LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Hoiw to define Digital out lines in NI M Series?

I need some help with a simple job…. (I've never worked with DAQ, so, it might be a too simple question…)

I'm using the card NI6250

I'm using in my program 8 bits of P0 and 2 bits of P1 (other pins of P1 are not used)

I want to define all these lines for output.

I want to be able to control each line individually. 

I realize these are the command I need to use.


        DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
        DAQmxErrChk (DAQmxCreateDOChan(taskHandle,chan,"",DAQmx_Val_ChanForAllLines));
        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NUL((

 

1.    Is startTask/Stop task necessary?
2.    How I define 'chan'? (Dev1/po:Dev1/p1 ?)
3.    What will be 'data' if I want to set Port1 line 1 to 1?
4.    What will be 'data' if I want to set Port0 bits 0-7 in one call but not changing any other bits?

 

 

Thanks


 

0 Kudos
Message 1 of 4
(3,316 Views)

Hey Rafi,

 

First, this is a pretty good document for explaining daqmx, and it gives examples for each stage of the process:

http://zone.ni.com/devzone/cda/tut/p/id/2835

 

All of the answers you asked for can be found in the c function help, installed with DAQmx to Start/Programs/National Instruments/NI DAQ/Text Based Code Support/DAQmx C Reference Help

1) If you are writing, you need to start the task. If you are reading in a while loop, you need to start the task (otherwise it will autostart and autostop multiple times, making your code slow). (clarification can be found by looking at the start task function in the help)

2) Chan can be devZ/portX, devZ/portX/lineY, devZ/portX:W, devZ/portX/lineY:S. This is clarified in the help for DAQmxCreateDOChan

3/4)  This is complicated, but the help should explain it. Since you are using lines to write, you would send an array of size X (X number of lines). For that array of U8s, 0 is false, 1 is true. If you want to write to an entire port, you can write the u8 equivalent using writedigitalu8

 

I would strongly recommend taking a look at that help, as it has most everything you need to know about each function--admittedly, it sometimes takes some digging into the links within each help page, but the information is very detailed.

 

Good luck

 

0 Kudos
Message 2 of 4
(3,296 Views)

Hi D. Smith and thanks for your answer,

 

I've done some reading and went through examples, but I'm still confused when it comes to use more than one task.

 

In my application, I want to define one task as Digital output of Dev0:p0 (8 bits)  and another task for Dev0/port1:Line0:Line1

 

Shall I do it as follow:

 

DAQmxErrChk (DAQmxCreateTask("",&taskHandle_1)); 

DAQmxErrChk (DAQmxCreateDOChan(taskHandle_1,"Dev0/port0","",DAQmx_Val_ChanForAllLines));

DAQmxErrChk (DAQmxCreateTask("",&taskHandle_2)); 

DAQmxErrChk (DAQmxCreateDOChan(taskHandle_2,"Dev0/port1/LInes0:Line1","",DAQmx_Val_ChanForAllLines));

 

        //---Defining 1st virtual channel------

        DAQmxErrChk (DAQmxStartTask(taskHandle_2));
        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle_1,1,1,10.0,DAQmx_Val_GroupByChannel,data_1,NULL,NULL));  //data_1[8)

 

        //---Defining 2nd virtual channel-----

        DAQmxErrChk (DAQmxStartTask(taskHandle_2));
        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle_1,1,1,10.0,DAQmx_Val_GroupByChannel,data_2,NULL,NULL)); //data_2[2]

 

        //---1st data to write (assuming data_1, data_2 is loaded with the approperiate data)

        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle_1,1,1,10.0,DAQmx_Val_GroupByChannel,data_1,NULL,NULL));  //data_1[8)

        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle_2,1,1,10.0,DAQmx_Val_GroupByChannel,data_2,NULL,NULL)); //data_2[2]

 

        //---2nd data to write (assuming data_1, data_2 is loaded with different data)

        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle_1,1,1,10.0,DAQmx_Val_GroupByChannel,data_1,NULL,NULL));  //data_1[8)

        DAQmxErrChk (DAQmxWriteDigitalLines(taskHandle_2,1,1,10.0,DAQmx_Val_GroupByChannel,data_2,NULL,NULL)); //data_2[2]

 

        DAQmxStopTask(taskHandle_1);

        DAQmxStopTask(taskHandle_2);

 

        DAQmxClearTask(taskHandle_1);
        DAQmxClearTask(taskHandle_2);

 

Please remark or suggest different approach.

 

Thanks

RK

0 Kudos
Message 3 of 4
(3,280 Views)

Hey Rafi,

 

I think that you've got it set up as it should be. I've spoken with a few colleagues and everything seems to be in order except that you have dev0/port1/lines. Is there a reason these items need to be separate tasks? IE, can you not just write a full byte to each port, setting up ports 0 and 1 in the same task? Still, your code looks pretty good. The only suggestion I have would be to take a look at the simultaneous analog/digital example located at Examples\DAQmx ANSI C\Synchronization\Multi-Function

 

Good luck, and let me know if you have any questions once you test that out.

 

Thanks

0 Kudos
Message 4 of 4
(3,253 Views)