2
2
3
3
from ctypes import byref , c_ulong
4
4
import numpy as np
5
+ import logging
6
+
7
+ logger = logging .getLogger (__name__ )
5
8
6
9
7
10
class DAQmxSim :
@@ -14,12 +17,6 @@ def close(self):
14
17
def ping (self ):
15
18
return True
16
19
17
- def string_to_bytes (string , name ):
18
- if isinstance (string , str ):
19
- string = bytes (string , encoding = "ascii" )
20
- elif not isinstance (string , bytes ):
21
- raise ValueError ("{} must be of either str or bytes type" .format (name ))
22
- return string
23
20
24
21
class DAQmx :
25
22
"""NI PXI6733 DAQ interface."""
@@ -38,13 +35,15 @@ def __init__(self, channels, clock):
38
35
39
36
import PyDAQmx as daq
40
37
41
- self .channels = string_to_bytes ( channels , "channels" )
42
- self .clock = string_to_bytes ( clock , "clock" )
38
+ self .channels = channels . encode ( )
39
+ self .clock = clock . encode ( )
43
40
self .task = None
44
41
self .daq = daq
45
42
46
43
def done_callback_py (self , taskhandle , status , callback_data ):
Has conversations. Original line has conversations. 47
- if taskhandle == self .task :
44
+ if taskhandle != self .task :
45
+ logger .warning ("done callback called with unexpected task" )
46
+ else :
48
47
self .clear_pending_task ()
49
48
50
49
def ping (self ):
@@ -60,7 +59,7 @@ def load_sample_values(self, sampling_freq, values):
60
59
61
60
This loads sample values into the PXI 6733 device.
62
61
The device will output samples at each clock rising edge.
Has a conversation. Original line has a conversation. 63
- The first sample is output at the first clock rising edge.
62
+ The device waits for a clock rising edge to output the first sample .
64
63
65
64
When using several channels simultaneously, you must concatenate the
66
65
values for the different channels in the ``values`` array.
@@ -92,7 +91,7 @@ def load_sample_values(self, sampling_freq, values):
92
91
channel_number = self .daq .int32 ()
93
92
t .GetTaskNumChans (byref (channel_number ))
94
93
nb_values = len (values )
95
- if nb_values % channel_number .value > 0 :
94
+ if nb_values % channel_number .value :
96
95
self .daq .DAQmxClearTask (t .taskHandle )
97
96
raise ValueError ("The size of the values array must be a multiple "
98
97
"of the number of channels ({})"