意外と設定項目が多かったのでメモ.あとで追記する.
import nidaqmx
from nidaqmx.constants import AcquisitionType, Edge
# Check NI device terminals
# using USB-6001
device = nidaqmx.system.device.Device("Dev3")
for tr in device.terminals:
print(tr)
# Wait Trigger to PFI/0
with nidaqmx.Task() as ditask:
ditask.ai_channels.add_ai_voltage_chan("/Dev3/ai1")
ditask.timing.cfg_samp_clk_timing(100, u'', Edge.RISING , AcquisitionType.FINITE)
ditask.triggers.start_trigger.cfg_dig_edge_start_trig("/Dev3/PFI0", Edge.RISING)
ditask.in_stream.timeout = 200
k=0
ditask.read(1, 120) # sample, timeout [s];
print(k)
Digital In/Out の例.
import nidaqmx
from nidaqmx.constants import (LineGrouping)
from nidaqmx.errors import DaqError
import time
import sys
# Mainly coded for NI USB-6001
class DAQ_task:
def __init__(self, devID="Dev0", taskType="di",
port="port0", lineCh="line4:7"):
self.task = nidaqmx.Task()
if (taskType=='di'):
self.task.di_channels.add_di_chan(
"/" + devID + "/" + port + "/" + lineCh,
line_grouping=LineGrouping.CHAN_PER_LINE
)
elif (taskType=='do'):
self.task.do_channels.add_do_chan(
"/" + devID + "/" + port + "/" + lineCh,
line_grouping=LineGrouping.CHAN_PER_LINE
)
else:
print("Unknown Task type: " + taskType)
def startAll(self):
self.task.start()
def stop(self):
self.task.stop()
self.task.close()
def writeDO(self, tflist):
self.task.write(tflist)
def readDI(self):
return self.task.read()
def demoDIO(self):
for i in range(5):
self.writeDO([True,False,True,False])
print(self.readDI())
time.sleep(.05)
self.writeDO([False,True,False,True])
print(self.readDI())
self.writeDO([False,False,False,False])
'''