Skip to content

Commit

Permalink
make errors and warnings ints (#150)
Browse files Browse the repository at this point in the history
* make errors and warnings ints

* clean up error code

* contributing
  • Loading branch information
zhindes authored Feb 15, 2022
1 parent ffe817b commit 2a3e0c3
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
* [64: nidaqmx-python and pynidaqmx projects use the same package name](https://github.com/ni/nidaqmx-python/issues/64)
* [65: ci_count_edges.py REQUIRES A START COMMAND](https://github.com/ni/nidaqmx-python/issues/65)
* [100: How to clear task and create a new task with same name?](https://github.com/ni/nidaqmx-python/issues/100)
* [101: Use IntEnum instead of Enum](https://github.com/ni/nidaqmx-python/issues/101)
* [102: handle types and daqmx versions](https://github.com/ni/nidaqmx-python/issues/102)
* [117: Error in example](https://github.com/ni/nidaqmx-python/issues/117)
* [131: task.write for COUNTER_OUTPUT - UsageTypeCO.PULSE_FREQUENCY has frequency and duty cycle reversed](https://github.com/ni/nidaqmx-python/issues/131)
Expand Down
4 changes: 2 additions & 2 deletions nidaqmx/_task_modules/channel_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def __getitem__(self, index):
else:
raise DaqError(
'Invalid index type "{0}" used to access channels.'
.format(type(index)), DAQmxErrors.UNKNOWN.value)
.format(type(index)), DAQmxErrors.UNKNOWN)

if channel_names:
return Channel._factory(self._handle, channel_names)
else:
raise DaqError(
'You cannot specify an empty index when indexing channels.\n'
'Index used: {0}'.format(index), DAQmxErrors.UNKNOWN.value)
'Index used: {0}'.format(index), DAQmxErrors.UNKNOWN)

def __hash__(self):
return hash(self._handle.value)
Expand Down
6 changes: 3 additions & 3 deletions nidaqmx/error_codes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Do not edit this file; it was automatically generated.

from enum import Enum
from enum import IntEnum

__all__ = ['DAQmxErrors', 'DAQmxWarnings']


class DAQmxErrors(Enum):
class DAQmxErrors(IntEnum):
MULTI_TASK_CFG_SAMP_RATE_NOT_SUPPORTED_WITH_PROP_SET = -209886
MULTI_TASK_CFG_SAMP_RATE_CONFLICTING_PROP = -209885
NO_COMMON_SAMP_RATE_FOUND_NO_REPEAT_SAMPS = -209884
Expand Down Expand Up @@ -1746,7 +1746,7 @@ class DAQmxErrors(Enum):
UNKNOWN = -1


class DAQmxWarnings(Enum):
class DAQmxWarnings(IntEnum):
UNKNOWN = -1
TIMESTAMP_COUNTER_ROLLED_OVER = 200003
INPUT_TERMINATION_OVERLOADED = 200004
Expand Down
10 changes: 5 additions & 5 deletions nidaqmx/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, message, error_code, task_name=''):

super(DaqError, self).__init__(message)

self._error_code = error_code
self._error_code = int(error_code)

try:
self._error_type = DAQmxErrors(self._error_code)
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, message, error_code):
super(DaqWarning, self).__init__(
'\nWarning {0} occurred.\n\n{1}'.format(error_code, message))

self._error_code = error_code
self._error_code = int(error_code)

try:
self._error_type = DAQmxWarnings(self._error_code)
Expand Down Expand Up @@ -138,9 +138,9 @@ def check_for_error(error_code):

def is_string_buffer_too_small(error_code):
return (
error_code == DAQmxErrors.BUFFER_TOO_SMALL_FOR_STRING.value or
error_code == DAQmxWarnings.CAPI_STRING_TRUNCATED_TO_FIT_BUFFER.value)
error_code == DAQmxErrors.BUFFER_TOO_SMALL_FOR_STRING or
error_code == DAQmxWarnings.CAPI_STRING_TRUNCATED_TO_FIT_BUFFER)


def is_array_buffer_too_small(error_code):
return error_code == DAQmxErrors.WRITE_BUFFER_TOO_SMALL.value
return error_code == DAQmxErrors.WRITE_BUFFER_TOO_SMALL
4 changes: 2 additions & 2 deletions nidaqmx/stream_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _verify_array(self, data, number_of_samples_per_channel,
'Shape of NumPy Array provided: {0}\n'
'Shape of NumPy Array required: {1}'
.format(data.shape, array_shape),
DAQmxErrors.UNKNOWN.value, task_name=self._task.name)
DAQmxErrors.UNKNOWN, task_name=self._task.name)

def _verify_array_digital_lines(
self, data, is_many_chan, is_many_line):
Expand Down Expand Up @@ -138,7 +138,7 @@ def _verify_array_digital_lines(
'Shape of NumPy Array provided: {0}\n'
'Shape of NumPy Array required: {1}'
.format(data.shape, array_shape),
DAQmxErrors.UNKNOWN.value, task_name=self._task.name)
DAQmxErrors.UNKNOWN, task_name=self._task.name)


class AnalogSingleChannelReader(ChannelReaderBase):
Expand Down
2 changes: 1 addition & 1 deletion nidaqmx/stream_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _raise_error_if_invalid_write_dimensions(
'No. of dimensions of NumPy Array provided: {0}\n'
'No. of dimensions of NumPy Array required: {1}'
.format(num_dimensions_in_data, num_dimensions_expected),
DAQmxErrors.UNKNOWN.value, task_name=self._task.name)
DAQmxErrors.UNKNOWN, task_name=self._task.name)


class AnalogSingleChannelWriter(ChannelWriterBase):
Expand Down
2 changes: 1 addition & 1 deletion nidaqmx/system/_collections/device_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __getitem__(self, index):
else:
raise DaqError(
'Invalid index type "{0}" used to access collection.'
.format(type(index)), DAQmxErrors.UNKNOWN.value)
.format(type(index)), DAQmxErrors.UNKNOWN)

def __iter__(self):
for device_name in self.device_names:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __getitem__(self, index):
else:
raise DaqError(
'Invalid index type "{0}" used to access collection.'
.format(type(index)), DAQmxErrors.UNKNOWN.value)
.format(type(index)), DAQmxErrors.UNKNOWN)

def __iter__(self):
for channel_name in self.global_channel_names:
Expand Down
2 changes: 1 addition & 1 deletion nidaqmx/system/_collections/persisted_scale_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __getitem__(self, index):
else:
raise DaqError(
'Invalid index type "{0}" used to access collection.'
.format(type(index)), DAQmxErrors.UNKNOWN.value)
.format(type(index)), DAQmxErrors.UNKNOWN)

def __iter__(self):
for scale_name in self.scale_names:
Expand Down
2 changes: 1 addition & 1 deletion nidaqmx/system/_collections/persisted_task_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __getitem__(self, index):
else:
raise DaqError(
'Invalid index type "{0}" used to access collection.'
.format(type(index)), DAQmxErrors.UNKNOWN.value)
.format(type(index)), DAQmxErrors.UNKNOWN)

def __iter__(self):
for task_name in self.task_names:
Expand Down
2 changes: 1 addition & 1 deletion nidaqmx/system/_collections/physical_channel_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __getitem__(self, index):
else:
raise DaqError(
'Invalid index type "{0}" used to access collection.'
.format(type(index)), DAQmxErrors.UNKNOWN.value)
.format(type(index)), DAQmxErrors.UNKNOWN)

def __iter__(self):
for channel_name in self.channel_names:
Expand Down
12 changes: 6 additions & 6 deletions nidaqmx/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def read(self, number_of_samples_per_channel=NUM_SAMPLES_UNSET,
raise DaqError(
'Read failed, because there are no channels in this task from '
'which data can be read.',
DAQmxErrors.READ_NO_INPUT_CHANS_IN_TASK.value,
DAQmxErrors.READ_NO_INPUT_CHANS_IN_TASK,
task_name=self.name)

if (read_chan_type == ChannelType.COUNTER_INPUT and
Expand Down Expand Up @@ -1078,7 +1078,7 @@ def _raise_invalid_num_lines_error(
'Number of Lines Per Channel in Task: {0}\n'
'Number of Lines Per Channel in Data: {1}'
.format(num_lines_expected, num_lines_in_data),
DAQmxErrors.NUM_LINES_MISMATCH_IN_READ_OR_WRITE.value,
DAQmxErrors.NUM_LINES_MISMATCH_IN_READ_OR_WRITE,
task_name=self.name)

def _raise_invalid_write_num_chans_error(
Expand All @@ -1093,7 +1093,7 @@ def _raise_invalid_write_num_chans_error(
'Number of Channels in Task: {0}\n'
'Number of Channels in Data: {1}'
.format(number_of_channels, number_of_channels_in_data),
DAQmxErrors.WRITE_NUM_CHANS_MISMATCH.value, task_name=self.name)
DAQmxErrors.WRITE_NUM_CHANS_MISMATCH, task_name=self.name)

def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0):
"""
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0):
'boolean samples when there is one digital line per '
'channel in a task.\n\n'
'Requested sample type: {0}'.format(type(element)),
DAQmxErrors.UNKNOWN.value, task_name=self.name)
DAQmxErrors.UNKNOWN, task_name=self.name)

data = numpy.asarray(data, dtype=bool)
return _write_digital_lines(
Expand All @@ -1253,7 +1253,7 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0):
'unsigned 32-bit integer samples when there are '
'multiple digital lines per channel in a task.\n\n'
'Requested sample type: {0}'.format(type(element)),
DAQmxErrors.UNKNOWN.value, task_name=self.name)
DAQmxErrors.UNKNOWN, task_name=self.name)

data = numpy.asarray(data, dtype=numpy.uint32)
return _write_digital_u_32(
Expand Down Expand Up @@ -1312,5 +1312,5 @@ def write(self, data, auto_start=AUTO_START_UNSET, timeout=10.0):
raise DaqError(
'Write failed, because there are no output channels in this '
'task to which data can be written.',
DAQmxErrors.WRITE_NO_OUTPUT_CHANS_IN_TASK.value,
DAQmxErrors.WRITE_NO_OUTPUT_CHANS_IN_TASK,
task_name=self.name)
2 changes: 1 addition & 1 deletion nidaqmx/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def test_task_duplicate(self):
# doesn't seem to be working. Regardless it will print a warning that contributors
# should see if it regresses.
del(u)
assert dupe_exception.value.error_code == DAQmxErrors.DUPLICATE_TASK.value
assert dupe_exception.value.error_code == DAQmxErrors.DUPLICATE_TASK

0 comments on commit 2a3e0c3

Please sign in to comment.