Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

DO using python on DAQ (pyDAQ)

Hi guys, I'm new to pyDAQ and I'm just trying to send out a Digital waveform through my python code.

There is sooo much documentation that every time I get close to a solution, I get lost...

I try to run the following:

 

from PyDAQmx import *
import numpy
from PyDAQmx.DAQmxConstants import DAQmx_Val_ChanForAllLines, DAQmx_Val_GroupByChannel 

# Declaration of variable passed by reference
taskHandle = TaskHandle(0)

try:
    # DAQmx Configure Code
    DAQmxCreateTask("",byref(taskHandle))
    DAQmxCreateDOChan(taskHandle,"KeyDAQ/port0/line0:7","", DAQmx_Val_ChanForAllLines) 
    
    DAQmxCfgSampClkTiming(taskHandle, '/KeyDAQ/PFI4 ',10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000)
    
    data = [0,1]
    arr = numpy.array(data, dtype=numpy.uint8)
    DAQmxWriteDigitalU8(taskHandle, 100, True, 500, DAQmx_Val_GroupByChannel, 
                    arr, None, None)  
    
    # DAQmx Start Code
    DAQmxStartTask(taskHandle)
    
    print "Generating digital output continuously. Press Enter to interrupt\n"


except DAQError as err:
    print "DAQmx Error: %s"%err
finally:
    if taskHandle:
        # DAQmx Stop Code
        DAQmxStopTask(taskHandle)
        DAQmxClearTask(taskHandle)

and I get 

 

DAQmx Error: Specified operation cannot be performed while the task is running.
Task Name: _unnamedTask<0>

Status Code: -200479
 in function DAQmxStartTask

I know I probably don't have the right direction, so could someone point me what I should look for ?

0 Kudos
Message 1 of 2
(4,107 Views)

Hi Sdemmer,

 

There is a KB article on  the same error code. The error can be caused by calling the DAQmx write or read function before DAQmx start task, which is what we have here.

 

I am not an expert in python or pyDAQ, but I believe pyDAQ is simply a wrapper for the regular DAQmx dll. The error code in pyDAQ should match DAQmx error code as well.

 

Ren H.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 2
(4,089 Views)