-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathphysical_channel_collection.py
More file actions
233 lines (181 loc) · 8.96 KB
/
physical_channel_collection.py
File metadata and controls
233 lines (181 loc) · 8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from collections.abc import Sequence
from nidaqmx.error_codes import DAQmxErrors
from nidaqmx.errors import DaqError
from nidaqmx.system.physical_channel import (
PhysicalChannel,
_PhysicalChannelAlternateConstructor,
)
from nidaqmx.utils import flatten_channel_string, unflatten_channel_string
class PhysicalChannelCollection(Sequence):
"""Contains the collection of physical channels for a DAQmx device.
This class defines methods that implements a container object.
"""
def __init__(self, device_name, interpreter):
"""Do not construct this object directly; instead, construct a nidaqmx.system.Device and use the appropriate property, such as device.ai_physical_channels.""" # noqa: W505 - doc line too long (166 > 100 characters) (auto-generated noqa)
self._name = device_name
self._interpreter = interpreter
def __contains__( # noqa: D105 - Missing docstring in magic method (auto-generated noqa)
self, item
):
channel_names = self.channel_names
if isinstance(item, str):
items = unflatten_channel_string(item)
return all([i in channel_names for i in items])
elif isinstance(item, PhysicalChannel):
return item._name in channel_names
return False
def __eq__(self, other): # noqa: D105 - Missing docstring in magic method (auto-generated noqa)
if isinstance(other, self.__class__):
return self._name == other._name
return False
def __getitem__(self, index):
"""Indexes a subset of physical channels on this physical channel collection.
Args:
index: The value of the index. The following index types
are supported:
- str: Name of the physical channel, without the
device name prefix, e.g. 'ai0'. You also can
specify a string that contains a list or range of
names to this input. If you have a list of names,
use the DAQmx Flatten Channel String function to
convert the list to a string.
- int: Index/position of the physical channel in the
collection.
- slice: Range of the indexes/positions of physical
channels in the collection.
Returns:
nidaqmx.system.physical_channel.PhysicalChannel:
Indicates the subset of physical channels indexed.
"""
if isinstance(index, int):
return _PhysicalChannelAlternateConstructor(
self.channel_names[index], self._interpreter
)
elif isinstance(index, slice):
return [
_PhysicalChannelAlternateConstructor(channel, self._interpreter)
for channel in self.channel_names[index]
]
elif isinstance(index, str):
requested_channels = unflatten_channel_string(index)
# Ensure the channel names are fully qualified. If the channel is invalid, the user will get errors from the # noqa: W505 - doc line too long (120 > 100 characters) (auto-generated noqa)
# channel objects on use.
channels_to_use = []
for channel in requested_channels:
if channel.startswith(f"{self._name}/"):
channels_to_use.append(channel)
else:
channels_to_use.append(f"{self._name}/{channel}")
if len(channels_to_use) == 1:
return _PhysicalChannelAlternateConstructor(channels_to_use[0], self._interpreter)
return [
_PhysicalChannelAlternateConstructor(channel, self._interpreter)
for channel in channels_to_use
]
else:
raise DaqError(
f'Invalid index type "{type(index)}" used to access collection.',
DAQmxErrors.UNKNOWN,
)
def __iter__(self): # noqa: D105 - Missing docstring in magic method (auto-generated noqa)
for channel_name in self.channel_names:
yield _PhysicalChannelAlternateConstructor(channel_name, self._interpreter)
def __len__(self): # noqa: D105 - Missing docstring in magic method (auto-generated noqa)
return len(self.channel_names)
def __ne__(self, other): # noqa: D105 - Missing docstring in magic method (auto-generated noqa)
return not self.__eq__(other)
def __reversed__(self): # noqa: D105 - Missing docstring in magic method (auto-generated noqa)
channel_names = self.channel_names
channel_names.reverse()
for channel_name in channel_names:
yield _PhysicalChannelAlternateConstructor(channel_name, self._interpreter)
@property
def all(self):
"""nidaqmx.system.physical_channel.PhysicalChannel: Specifies a physical channel object that represents the entire list of physical channels on this channel collection.""" # noqa: W505 - doc line too long (179 > 100 characters) (auto-generated noqa)
return _PhysicalChannelAlternateConstructor(
flatten_channel_string(self.channel_names), self._interpreter
)
@property
def channel_names(self):
"""List[str]: Specifies the entire list of physical channels in this collection."""
raise NotImplementedError()
class AIPhysicalChannelCollection(PhysicalChannelCollection):
"""Contains the collection of analog input physical channels for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x231E)
return unflatten_channel_string(val)
class AOPhysicalChannelCollection(PhysicalChannelCollection):
"""Contains the collection of analog output physical channels for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x231F)
return unflatten_channel_string(val)
class CIPhysicalChannelCollection(PhysicalChannelCollection):
"""Contains the collection of counter input physical channels for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x2324)
return unflatten_channel_string(val)
class COPhysicalChannelCollection(PhysicalChannelCollection):
"""Contains the collection of counter output physical channels for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x2325)
return unflatten_channel_string(val)
class DILinesCollection(PhysicalChannelCollection):
"""Contains the collection of digital input lines for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x2320)
return unflatten_channel_string(val)
class DOLinesCollection(PhysicalChannelCollection):
"""Contains the collection of digital output lines for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x2322)
return unflatten_channel_string(val)
class DIPortsCollection(PhysicalChannelCollection):
"""Contains the collection of digital input ports for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x2321)
return unflatten_channel_string(val)
class DOPortsCollection(PhysicalChannelCollection):
"""Contains the collection of digital output ports for a DAQmx device.
This class defines methods that implements a container object.
"""
@property
def channel_names( # noqa: D102 - Missing docstring in public method (auto-generated noqa)
self,
):
val = self._interpreter.get_device_attribute_string(self._name, 0x2323)
return unflatten_channel_string(val)