diff --git a/src/pymodaq_plugins_daqmx/__init__.py b/src/pymodaq_plugins_daqmx/__init__.py index 62ada89..5a55878 100644 --- a/src/pymodaq_plugins_daqmx/__init__.py +++ b/src/pymodaq_plugins_daqmx/__init__.py @@ -1,5 +1,11 @@ from pathlib import Path -from pymodaq.utils.logger import set_logger # to be imported by other modules. +from pymodaq_utils.logger import set_logger # to be imported by other modules. +from pymodaq_utils.utils import get_version, PackageNotFoundError + +try: + __version__ = get_version(__package__) +except PackageNotFoundError: + __version__ = '0.0.0dev' from .utils import Config config = Config() diff --git a/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Move.py b/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Move.py index c4720be..db72c3c 100644 --- a/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Move.py +++ b/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Move.py @@ -17,7 +17,7 @@ class DAQ_NIDAQmx_Actuator(DAQ_Move_base, DAQ_NIDAQmx_base): *params* dictionnary =============== ============== """ - _controller_units = 'Volts' + _controller_units = 'V' is_multiaxes = False # set to True if this plugin is controlled for a multiaxis controller (with a unique communication link) stage_names = [] # "list of strings of the multiaxes @@ -163,6 +163,12 @@ def move_Home(self): ## TODO: Reimplement in your daq_move with NIDAQmx library raise NotImplementedError + def close(self): + """Terminate the communication protocol: close the current task of the controller""" + controller = getattr(self, 'controller', None) + if controller is not None: + controller.close() + def stop_motion(self): """ Call the specific move_done function (depending on the hardware). diff --git a/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Viewer.py b/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Viewer.py index 6818f9e..1d885f7 100644 --- a/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Viewer.py +++ b/src/pymodaq_plugins_daqmx/hardware/national_instruments/NIDAQmx_Viewer.py @@ -59,7 +59,7 @@ class DAQ_NIDAQmx_Viewer(DAQ_Viewer_base, DAQ_NIDAQmx_base): param_devices = NIDAQmx.get_NIDAQ_devices().device_names params = viewer_params + [ {'title': 'Devices :', 'name': 'devices', 'type': 'list', 'limits': param_devices, - 'value': param_devices[0] + 'value': param_devices[0] if param_devices else '' }, ] + DAQ_NIDAQmx_base.params diff --git a/src/pymodaq_plugins_daqmx/hardware/national_instruments/daqmxni.py b/src/pymodaq_plugins_daqmx/hardware/national_instruments/daqmxni.py index 944f7e0..7280499 100644 --- a/src/pymodaq_plugins_daqmx/hardware/national_instruments/daqmxni.py +++ b/src/pymodaq_plugins_daqmx/hardware/national_instruments/daqmxni.py @@ -8,13 +8,31 @@ from nidaqmx.system import System as niSystem from nidaqmx.system.device import Device as niDevice from nidaqmx import Task as niTask -from nidaqmx.errors import DaqError, DAQmxErrors +from nidaqmx.errors import DaqError, DAQmxErrors, DaqNotFoundError from pymodaq_plugins_daqmx import config logger = set_logger(get_module_name(__file__)) +class _NoDevices: + """Stands for the collection of devices when the NI-DAQmx driver is not installed: no device at all. + + The modules of the plugin build their settings when they are imported, which then must not fail on a computer + without the driver (for instance a continuous integration runner). + """ + device_names = [] + + def __iter__(self): + return iter(()) + + def __len__(self): + return 0 + + def __contains__(self, item): + return False + + class ClockSettingsBase: def __init__(self, Nsamples=1000, repetition=False): @@ -202,6 +220,9 @@ def get_NIDAQ_devices(cls): if devices == ['']: devices = [] return devices + except DaqNotFoundError: # the NI-DAQmx driver is not installed + logger.warning('The NI-DAQmx driver is not installed: no NI device can be listed') + return _NoDevices() except DaqError as e: return e.error_code