|
2 | 2 |
|
3 | 3 | import threading |
4 | 4 | import warnings |
| 5 | +from collections.abc import Iterable |
5 | 6 | from enum import Enum |
6 | 7 |
|
7 | 8 | import numpy |
@@ -1240,6 +1241,7 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0): |
1240 | 1241 | sample for multiple channels. |
1241 | 1242 | - List of lists/2D numpy.ndarray: Multiple samples for multiple |
1242 | 1243 | channels. |
| 1244 | + - AnalogWaveform: Waveform data for a single analog output channel. |
1243 | 1245 |
|
1244 | 1246 | The data type of the samples passed in must be appropriate for |
1245 | 1247 | the channel type of the task. |
@@ -1316,6 +1318,14 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0): |
1316 | 1318 | number_of_samples_per_channel = len(data) |
1317 | 1319 | element = data[0] |
1318 | 1320 |
|
| 1321 | + elif isinstance(data, AnalogWaveform): |
| 1322 | + WAVEFORM_SUPPORT.raise_if_disabled() |
| 1323 | + if number_of_channels != 1: |
| 1324 | + self._raise_invalid_write_num_chans_error( |
| 1325 | + number_of_channels, 1) |
| 1326 | + number_of_samples_per_channel = data.sample_count |
| 1327 | + element = data.raw_data[0] |
| 1328 | + |
1319 | 1329 | else: |
1320 | 1330 | number_of_samples_per_channel = 1 |
1321 | 1331 | element = data |
@@ -1356,10 +1366,14 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0): |
1356 | 1366 | auto_start = True |
1357 | 1367 |
|
1358 | 1368 | if write_chan_type == ChannelType.ANALOG_OUTPUT: |
1359 | | - data = numpy.asarray(data, dtype=numpy.float64) |
1360 | | - return self._interpreter.write_analog_f64( |
1361 | | - self._handle, number_of_samples_per_channel, auto_start, |
1362 | | - timeout, FillMode.GROUP_BY_CHANNEL.value, data) |
| 1369 | + if isinstance(data, AnalogWaveform): |
| 1370 | + return self._interpreter.write_analog_waveform( |
| 1371 | + self._handle, data, auto_start, timeout) |
| 1372 | + else: |
| 1373 | + data = numpy.asarray(data, dtype=numpy.float64) |
| 1374 | + return self._interpreter.write_analog_f64( |
| 1375 | + self._handle, number_of_samples_per_channel, auto_start, |
| 1376 | + timeout, FillMode.GROUP_BY_CHANNEL.value, data) |
1363 | 1377 |
|
1364 | 1378 | elif write_chan_type == ChannelType.DIGITAL_OUTPUT: |
1365 | 1379 | if self.out_stream.do_num_booleans_per_chan == 1: |
@@ -1396,6 +1410,11 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0): |
1396 | 1410 |
|
1397 | 1411 | if number_of_samples_per_channel == 1: |
1398 | 1412 | data = [data] |
| 1413 | + elif not isinstance(data, Iterable): |
| 1414 | + raise DaqError( |
| 1415 | + 'Write failed, because the provided data type is not supported ' |
| 1416 | + 'for counter output channels.', |
| 1417 | + DAQmxErrors.UNKNOWN, task_name=self.name) |
1399 | 1418 |
|
1400 | 1419 | if output_type == UsageTypeCO.PULSE_FREQUENCY: |
1401 | 1420 | if not all(isinstance(sample, CtrFreq) for sample in data): |
|
0 commit comments