forked from M-Labs/artiq
1
0
Fork 0

pxi6733: cleanup

This commit is contained in:
Yann Sionneau 2015-06-08 11:54:39 +02:00
parent c251601204
commit d66117ed99
1 changed files with 10 additions and 11 deletions

View File

@ -2,6 +2,9 @@
from ctypes import byref, c_ulong from ctypes import byref, c_ulong
import numpy as np import numpy as np
import logging
logger = logging.getLogger(__name__)
class DAQmxSim: class DAQmxSim:
@ -14,12 +17,6 @@ class DAQmxSim:
def ping(self): def ping(self):
return True return True
def string_to_bytes(string, name):
if isinstance(string, str):
string = bytes(string, encoding="ascii")
elif not isinstance(string, bytes):
raise ValueError("{} must be of either str or bytes type".format(name))
return string
class DAQmx: class DAQmx:
"""NI PXI6733 DAQ interface.""" """NI PXI6733 DAQ interface."""
@ -38,13 +35,15 @@ class DAQmx:
import PyDAQmx as daq import PyDAQmx as daq
self.channels = string_to_bytes(channels, "channels") self.channels = channels.encode()
self.clock = string_to_bytes(clock, "clock") self.clock = clock.encode()
self.task = None self.task = None
self.daq = daq self.daq = daq
def done_callback_py(self, taskhandle, status, callback_data): def done_callback_py(self, taskhandle, status, callback_data):
if taskhandle == self.task: if taskhandle != self.task:
logger.warning("done callback called with unexpected task")
else:
self.clear_pending_task() self.clear_pending_task()
def ping(self): def ping(self):
@ -60,7 +59,7 @@ class DAQmx:
This loads sample values into the PXI 6733 device. This loads sample values into the PXI 6733 device.
The device will output samples at each clock rising edge. The device will output samples at each clock rising edge.
The first sample is output at the first clock rising edge. The device waits for a clock rising edge to output the first sample.
When using several channels simultaneously, you must concatenate the When using several channels simultaneously, you must concatenate the
values for the different channels in the ``values`` array. values for the different channels in the ``values`` array.
@ -92,7 +91,7 @@ class DAQmx:
channel_number = self.daq.int32() channel_number = self.daq.int32()
t.GetTaskNumChans(byref(channel_number)) t.GetTaskNumChans(byref(channel_number))
nb_values = len(values) nb_values = len(values)
if nb_values % channel_number.value > 0: if nb_values % channel_number.value:
self.daq.DAQmxClearTask(t.taskHandle) self.daq.DAQmxClearTask(t.taskHandle)
raise ValueError("The size of the values array must be a multiple " raise ValueError("The size of the values array must be a multiple "
"of the number of channels ({})" "of the number of channels ({})"