Quantcast
Channel: Digital I/O topics
Viewing all articles
Browse latest Browse all 2177

DO using python on DAQ (pyDAQ)

$
0
0

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 ?


Viewing all articles
Browse latest Browse all 2177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>