Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

calling DAQmxStartTask on a DI channel unexpectedly clears my digital IO ports

i have IO ports on my test hardware, and i need to (1) read the current state of the IO pins, then (2) write new values to the pins based on current values

(1) to read a port, i have a function that does this:

    DAQmxCreateTask(...);
    DAQmxCreateDIChan(...);
    DAQmxStartTask(...);
    DAQmxReadDigitalU32(...);
    DAQmxStopTask(...);
    DAQmxClearTask(...);

(2) to write a port, another function does this:

    DAQmxCreateTask(...);
    DAQmxCreateDOChan(...);
    DAQmxStartTask(...);
    DAQmxWriteDigitalU32(...);
    DAQmxStopTask(...);
    DAQmxClearTask(...);

both of these functions work, individually.  

they also work when i call my write function after having called the read function, *the first time*

but on subsequent tries (within a program loop), when i go to re-read the IO port, "DAQmxStartTask()" clears the digital port so all lines are 0 (zeros).   Hence, the DAQmxReadDigitalU32() reads all zeros, and my program fails to work as expected.

why is this happening and what can i do to fix it?

thanks

0 Kudos
Message 1 of 3
(3,197 Views)
oops.  they're not bidirectional.

so, um... never mind.


0 Kudos
Message 2 of 3
(3,189 Views)
Hi RJohnson-

What type of hardware are you using?  If (and currently only if) you are using an E Series board it is possible to read line states AND update their values at the same time.  You can simply create input and output tasks as you are currently doing, but you have to set the Digital Input:Tristate property to FALSE for the input task to prevent the situation you're running into now.  You can do this using DAQmxSetDITristate(TaskHandle taskHandle, const char channel[], bool32 data);  before starting the input task.

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 3 of 3
(3,182 Views)