Repository navigation
Initial commit for OmniControl 200 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7c86042
6f28b99
4a3223e
d67bbe2
ebae78e
17a7552
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| from pymodaq_utils.utils import get_version, PackageNotFoundError | ||
| from pathlib import Path | ||
| from pymodaq.utils.logger import set_logger # to be imported by other modules. | ||
|
|
||
| from .utils import Config | ||
| config = Config() | ||
| from pymodaq_utils.utils import get_version, PackageNotFoundError | ||
| from pymodaq_utils.logger import set_logger, get_module_name | ||
|
|
||
| config = Config() | ||
| try: | ||
| __version__ = get_version(__package__) | ||
| except PackageNotFoundError: | ||
| __version__ = '0.0.0dev' | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import numpy as np | ||
|
|
||
| from pymodaq_utils.utils import ThreadCommand | ||
| from pymodaq_data.data import DataToExport | ||
| from pymodaq_gui.parameter import Parameter | ||
|
|
||
| from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main | ||
| from pymodaq.utils.data import DataFromPlugins | ||
|
|
||
| from pymodaq_plugins_pfeiffer.hardware.omnicontrol import Omnicontrol | ||
| from serial.tools import list_ports | ||
|
|
||
| def get_com_ports() -> list[str]: | ||
| """Détecte les ports COM connectés et les renvoie sous forme de liste de strings.""" | ||
| return [port.device for port in list_ports.comports()] | ||
|
|
||
| class DAQ_0DViewer_Pfeiffer_Omnicontrol(DAQ_Viewer_base): | ||
| """ Instrument plugin class for a OD viewer. | ||
| * Plugin for OmniControl 200 controller. | ||
| * Developed and tested only with a PKR 251 pressure gauge connected. | ||
| * Developed on PyMoDAQ 5.2 | ||
| * May require a virtual COM port driver: https://ftdichip.com/drivers/ | ||
|
|
||
| """ | ||
| params = comon_parameters+[ | ||
| {'title': 'COM port :', 'name': 'com_port', 'type': 'list', 'limits': get_com_ports()}, | ||
| {'title': 'Channel 1', 'name': 'ch_1', 'type': 'bool', 'value':True}, | ||
| {'title': 'Channel 2', 'name': 'ch_2', 'type': 'bool', 'value':True}, | ||
| ] | ||
|
|
||
| def _active_channels(self): | ||
| """Names of the currently checked channel booleans, in tree order.""" | ||
| return [ch.name() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should group your channels in a dedicated group in the settings |
||
| for ch in self.settings.children() | ||
| if ch.name().startswith('ch_') and ch.value()] | ||
|
|
||
|
|
||
| def ini_attributes(self): | ||
| self.controller: Omnicontrol = None | ||
| self.port=None | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't nee an extra variable to store the COM port, it is already stored in the settings! |
||
| pass | ||
|
|
||
| def ini_detector(self, controller=None): | ||
| """Detector communication initialization""" | ||
| self.settings.child('com_port').setLimits(get_com_ports()) | ||
| if self.is_master: | ||
| self.port=self.settings.child('com_port').value() | ||
| self.port="COM9" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hardcoded here?????????????, use the config if you want to store a default value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and place the default value in the "value" key of the com_port parameter |
||
| self.controller = Omnicontrol(self.port) | ||
| initialized = True | ||
| else: | ||
| self.controller = controller | ||
| initialized = True | ||
|
|
||
| self.pressure_data=[np.array([0]) for ch in self._active_channels()] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use np.atleast_1d to make sure you always have at least a numpy array |
||
| label=[] | ||
| for ch in self._active_channels(): | ||
| if ch == 'ch_1': | ||
| label.append('Channel 1') | ||
| elif ch == 'ch_2': | ||
| label.append('Channel 2') | ||
| self.dte_signal_temp.emit(DataToExport(name='OmniControl', | ||
| data=[DataFromPlugins(name='Pressure', | ||
| data=self.pressure_data, | ||
| dim='Data0D', | ||
| labels=label)])) | ||
| # labels = ['Channel 1', 'Channel 2'])])) | ||
|
|
||
| info = self.controller.read_name() # lève PfeifferError si pas de réponse | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments in english |
||
| return info, initialized | ||
|
|
||
| def close(self): | ||
| """Terminate the communication protocol""" | ||
| if self.is_master and self.controller is not None: | ||
| self.controller.close() | ||
| self.controller = None | ||
|
|
||
| def grab_data(self, Naverage=1, **kwargs): | ||
| """Start a grab from the detector | ||
|
|
||
| Parameters | ||
| ---------- | ||
| Naverage: int | ||
| Number of hardware averaging (if hardware averaging is possible, self.hardware_averaging should be set to | ||
| True in class preamble and you should code this implementation) | ||
| kwargs: dict | ||
| others optionals arguments | ||
| """ | ||
| pressure_data=[] | ||
| try: | ||
| for ch in self._active_channels(): | ||
| if ch == 'ch_1': | ||
| pressure_data.append(np.array([self.controller.read_pressure(122)])) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 122 and 132 ?? You should assign a variable name to store those at the top of your script: CHANNEL1 = 122 |
||
| elif ch == 'ch_2': | ||
| pressure_data.append(np.array([self.controller.read_pressure(132)])) | ||
| except Exception as e: | ||
| self.emit_status(ThreadCommand('Update_Status', [str(e), 'log'])) | ||
| return | ||
|
|
||
| label=[] | ||
| for ch in self._active_channels(): | ||
| if ch == 'ch_1': | ||
| label.append('Channel 1') | ||
| elif ch == 'ch_2': | ||
| label.append('Channel 2') | ||
|
|
||
| self.dte_signal.emit(DataToExport( | ||
| name='OmniControl', | ||
| data=[DataFromPlugins(name='Pressure', | ||
| data=pressure_data, | ||
| dim='Data0D', | ||
| labels=label)])) | ||
|
|
||
| def stop(self): | ||
| """Stop the current grab hardware wise if necessary""" | ||
| return '' | ||
|
|
||
| def commit_settings(self, param: Parameter): | ||
| """Apply the consequences of a change of value in the detector settings | ||
|
|
||
| Parameters | ||
| ---------- | ||
| param: Parameter | ||
| A given parameter (within detector_settings) whose value has been changed by the user | ||
| """ | ||
| ## TODO for your custom plugin | ||
| if param.name() == "com_port": | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could remove this if you just use the com port value stored in the settings |
||
| self.port=self.settings.child('com_port').value() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main(__file__) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,4 @@ | |
| Created the 01/06/2023 | ||
|
|
||
| @author: Sebastien Weber | ||
| """ | ||
| """ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use only english to make it usable by everyone