microeye 2.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. microEye/__init__.py +47 -0
  2. microEye/_version.py +2 -0
  3. microEye/analysis/__init__.py +1 -0
  4. microEye/analysis/checklist_dialog.py +143 -0
  5. microEye/analysis/cmosMaps.py +228 -0
  6. microEye/analysis/filters/__init__.py +9 -0
  7. microEye/analysis/filters/base.py +21 -0
  8. microEye/analysis/filters/spatial.py +338 -0
  9. microEye/analysis/filters/temporal.py +76 -0
  10. microEye/analysis/fitting/__init__.py +0 -0
  11. microEye/analysis/fitting/fit.py +680 -0
  12. microEye/analysis/fitting/nena.py +375 -0
  13. microEye/analysis/fitting/phasor_fit.py +90 -0
  14. microEye/analysis/fitting/processing.py +317 -0
  15. microEye/analysis/fitting/psf/__init__.py +6 -0
  16. microEye/analysis/fitting/psf/extract.py +1129 -0
  17. microEye/analysis/fitting/psf/rubost_mean.py +150 -0
  18. microEye/analysis/fitting/psf/spline.py +167 -0
  19. microEye/analysis/fitting/psf/stats/__init__.py +12 -0
  20. microEye/analysis/fitting/psf/stats/core.py +295 -0
  21. microEye/analysis/fitting/psf/stats/curve_fit.py +708 -0
  22. microEye/analysis/fitting/psf/stats/io.py +104 -0
  23. microEye/analysis/fitting/psf/stats/slope_fit.py +171 -0
  24. microEye/analysis/fitting/psf/temp.py +147 -0
  25. microEye/analysis/fitting/psf/test.py +47 -0
  26. microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUfunctions.py +657 -0
  27. microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUmleFit_LM.py +1336 -0
  28. microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUsplineLib.py +270 -0
  29. microEye/analysis/fitting/pyfit3Dcspline/CPU/__init__.py +1 -0
  30. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUfunctions.py +609 -0
  31. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_EMCCD.py +1396 -0
  32. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_sCMOS.py +1426 -0
  33. microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUsplineLib.py +231 -0
  34. microEye/analysis/fitting/pyfit3Dcspline/GPU/__init__.py +2 -0
  35. microEye/analysis/fitting/pyfit3Dcspline/__init__.py +10 -0
  36. microEye/analysis/fitting/pyfit3Dcspline/constants.py +27 -0
  37. microEye/analysis/fitting/pyfit3Dcspline/mainfunctions.py +903 -0
  38. microEye/analysis/fitting/results.py +917 -0
  39. microEye/analysis/fitting/results_stats.py +251 -0
  40. microEye/analysis/fitting/tardis.py +209 -0
  41. microEye/analysis/multi_viewer.py +568 -0
  42. microEye/analysis/processing/__init__.py +1 -0
  43. microEye/analysis/processing/frc.py +120 -0
  44. microEye/analysis/rendering/__init__.py +3 -0
  45. microEye/analysis/rendering/base.py +452 -0
  46. microEye/analysis/rendering/cloud.py +215 -0
  47. microEye/analysis/rendering/core.py +47 -0
  48. microEye/analysis/rendering/volumetric.py +198 -0
  49. microEye/analysis/tools/__init__.py +0 -0
  50. microEye/analysis/tools/kymograms.py +1079 -0
  51. microEye/analysis/tools/roi_selectors.py +556 -0
  52. microEye/analysis/utils/__init__.py +3 -0
  53. microEye/analysis/utils/coordinates.py +18 -0
  54. microEye/analysis/utils/images.py +68 -0
  55. microEye/analysis/utils/windows.py +19 -0
  56. microEye/analysis/viewer/__init__.py +3 -0
  57. microEye/analysis/viewer/image_options_widget.py +615 -0
  58. microEye/analysis/viewer/images.py +1225 -0
  59. microEye/analysis/viewer/layers_widget.py +415 -0
  60. microEye/analysis/viewer/localizations.py +1304 -0
  61. microEye/analysis/viewer/psf.py +1003 -0
  62. microEye/analysis/viewer/volume.py +456 -0
  63. microEye/hardware/__init__.py +3 -0
  64. microEye/hardware/cams/__init__.py +29 -0
  65. microEye/hardware/cams/camera_calibration.py +99 -0
  66. microEye/hardware/cams/camera_list.py +528 -0
  67. microEye/hardware/cams/camera_options.py +694 -0
  68. microEye/hardware/cams/camera_panel.py +941 -0
  69. microEye/hardware/cams/dummy/__init__.py +1 -0
  70. microEye/hardware/cams/dummy/dummy_panel.py +759 -0
  71. microEye/hardware/cams/jobs.py +497 -0
  72. microEye/hardware/cams/line_profiler.py +99 -0
  73. microEye/hardware/cams/linescan/IR_Cam.py +474 -0
  74. microEye/hardware/cams/linescan/__init__.py +1 -0
  75. microEye/hardware/cams/micam.py +524 -0
  76. microEye/hardware/cams/pco/__init__.py +58 -0
  77. microEye/hardware/cams/pco/enums.py +382 -0
  78. microEye/hardware/cams/pco/pco_cam.py +761 -0
  79. microEye/hardware/cams/pco/pco_panel.py +477 -0
  80. microEye/hardware/cams/shortcuts.py +312 -0
  81. microEye/hardware/cams/thorlabs/__init__.py +1 -0
  82. microEye/hardware/cams/thorlabs/thorlabs.py +1508 -0
  83. microEye/hardware/cams/thorlabs/thorlabs_panel.py +850 -0
  84. microEye/hardware/cams/ueye/__init__.py +1 -0
  85. microEye/hardware/cams/ueye/ueye_camera.py +1023 -0
  86. microEye/hardware/cams/ueye/ueye_panel.py +861 -0
  87. microEye/hardware/cams/vimba/__init__.py +1 -0
  88. microEye/hardware/cams/vimba/vimba_cam.py +1000 -0
  89. microEye/hardware/cams/vimba/vimba_panel.py +813 -0
  90. microEye/hardware/device.py +60 -0
  91. microEye/hardware/lasers/__init__.py +13 -0
  92. microEye/hardware/lasers/io_matchbox.py +791 -0
  93. microEye/hardware/lasers/io_params.py +85 -0
  94. microEye/hardware/lasers/io_single_laser.py +742 -0
  95. microEye/hardware/lasers/laser_relay.py +594 -0
  96. microEye/hardware/mieye/__init__.py +1 -0
  97. microEye/hardware/mieye/acquisition_manager.py +467 -0
  98. microEye/hardware/mieye/devices_manager.py +533 -0
  99. microEye/hardware/mieye/miEye.py +659 -0
  100. microEye/hardware/misc/__init__.py +0 -0
  101. microEye/hardware/misc/acquisition_view.py +71 -0
  102. microEye/hardware/misc/reglo.py +761 -0
  103. microEye/hardware/misc/temp.py +188 -0
  104. microEye/hardware/port_config.py +59 -0
  105. microEye/hardware/protocols/__init__.py +2 -0
  106. microEye/hardware/protocols/actions.py +402 -0
  107. microEye/hardware/protocols/actions_items.py +703 -0
  108. microEye/hardware/protocols/designer.py +244 -0
  109. microEye/hardware/protocols/scene_manager.py +191 -0
  110. microEye/hardware/protocols/serialization.py +97 -0
  111. microEye/hardware/pycromanager/__init__.py +16 -0
  112. microEye/hardware/pycromanager/core.py +1433 -0
  113. microEye/hardware/pycromanager/devices.py +461 -0
  114. microEye/hardware/pycromanager/enums.py +107 -0
  115. microEye/hardware/pycromanager/headless.py +153 -0
  116. microEye/hardware/pycromanager/utils.py +34 -0
  117. microEye/hardware/pycromanager/widgets/__init__.py +5 -0
  118. microEye/hardware/pycromanager/widgets/bridges.py +407 -0
  119. microEye/hardware/pycromanager/widgets/headless_manager.py +258 -0
  120. microEye/hardware/pycromanager/widgets/headless_options.py +224 -0
  121. microEye/hardware/pycromanager/widgets/pycro_panel.py +455 -0
  122. microEye/hardware/stages/__init__.py +18 -0
  123. microEye/hardware/stages/elliptec/__init__.py +5 -0
  124. microEye/hardware/stages/elliptec/baseDevice.py +314 -0
  125. microEye/hardware/stages/elliptec/device.py +384 -0
  126. microEye/hardware/stages/elliptec/deviceID.py +212 -0
  127. microEye/hardware/stages/elliptec/devicePort.py +379 -0
  128. microEye/hardware/stages/elliptec/deviceStatus.py +65 -0
  129. microEye/hardware/stages/elliptec/devicesView.py +706 -0
  130. microEye/hardware/stages/elliptec/ellDevices.py +134 -0
  131. microEye/hardware/stages/elliptec/messageUpdater.py +34 -0
  132. microEye/hardware/stages/elliptec/motorInfo.py +153 -0
  133. microEye/hardware/stages/elliptec/stage.py +62 -0
  134. microEye/hardware/stages/elliptec/test.py +139 -0
  135. microEye/hardware/stages/kinesis/__init__.py +1 -0
  136. microEye/hardware/stages/kinesis/kdc101/__init__.py +1 -0
  137. microEye/hardware/stages/kinesis/kdc101/enums.py +1002 -0
  138. microEye/hardware/stages/kinesis/kdc101/factory.py +171 -0
  139. microEye/hardware/stages/kinesis/kdc101/kdc101.py +718 -0
  140. microEye/hardware/stages/kinesis/kinesis.py +776 -0
  141. microEye/hardware/stages/piezo_concept.py +607 -0
  142. microEye/hardware/stages/stabilizer.py +785 -0
  143. microEye/hardware/stages/stage.py +89 -0
  144. microEye/hardware/widgets/__init__.py +10 -0
  145. microEye/hardware/widgets/controller.py +246 -0
  146. microEye/hardware/widgets/devices.py +133 -0
  147. microEye/hardware/widgets/focusWidget.py +264 -0
  148. microEye/hardware/widgets/qlist_slider.py +113 -0
  149. microEye/hardware/widgets/scan_acquisition.py +424 -0
  150. microEye/icons/1024.png +0 -0
  151. microEye/icons/128.png +0 -0
  152. microEye/icons/16.png +0 -0
  153. microEye/icons/24.png +0 -0
  154. microEye/icons/256.png +0 -0
  155. microEye/icons/32.png +0 -0
  156. microEye/icons/48.png +0 -0
  157. microEye/icons/512.png +0 -0
  158. microEye/icons/64.png +0 -0
  159. microEye/icons/__init__.py +0 -0
  160. microEye/icons/close.svg +88 -0
  161. microEye/icons/mieye.png +0 -0
  162. microEye/icons/min.svg +83 -0
  163. microEye/icons/viewer.png +0 -0
  164. microEye/launcher.py +42 -0
  165. microEye/qt.py +181 -0
  166. microEye/utils/__init__.py +2 -0
  167. microEye/utils/enum_encoder.py +10 -0
  168. microEye/utils/expandable_groupbox.py +93 -0
  169. microEye/utils/gui_helper.py +457 -0
  170. microEye/utils/hid/__init__.py +8 -0
  171. microEye/utils/hid/controller.py +153 -0
  172. microEye/utils/hid/device.py +63 -0
  173. microEye/utils/hid/enums.py +140 -0
  174. microEye/utils/hid/utils.py +58 -0
  175. microEye/utils/labelled_slider.py +134 -0
  176. microEye/utils/metadata.py +599 -0
  177. microEye/utils/metadata_tree.py +718 -0
  178. microEye/utils/micro_launcher.py +245 -0
  179. microEye/utils/parameter_tree.py +325 -0
  180. microEye/utils/pyscripting.py +444 -0
  181. microEye/utils/retry_exec.py +35 -0
  182. microEye/utils/start_gui.py +112 -0
  183. microEye/utils/thread_worker.py +115 -0
  184. microEye/utils/uImage.py +1512 -0
  185. microeye-2.3.2.dist-info/METADATA +401 -0
  186. microeye-2.3.2.dist-info/RECORD +190 -0
  187. microeye-2.3.2.dist-info/WHEEL +5 -0
  188. microeye-2.3.2.dist-info/entry_points.txt +2 -0
  189. microeye-2.3.2.dist-info/licenses/LICENSE +674 -0
  190. microeye-2.3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,594 @@
1
+ import os
2
+ import sys
3
+ from enum import Enum
4
+ from typing import Optional
5
+
6
+ from pyqtgraph.parametertree import Parameter
7
+
8
+ from microEye.qt import QtCore, QtSerialPort, QtWidgets, Signal
9
+ from microEye.utils import StartGUI, Tree
10
+
11
+
12
+ class LaserRelay:
13
+ def __init__(self) -> None:
14
+ """
15
+ Initialize a new LaserRelay instance.
16
+
17
+ Sets up the serial port with a baud rate of 115200 and a port of 'COM6'.
18
+ Also initializes the last sent configuration, the current laser relay state,
19
+ and the ALEX flag.
20
+ """
21
+ self.__port = QtSerialPort.QSerialPort()
22
+ self.__port.setBaudRate(115200)
23
+ self.__port.setPortName('COM6')
24
+
25
+ self.__last = ''
26
+ self.laserRelay_curr = ''
27
+ self.__alex = False
28
+
29
+ @property
30
+ def lastCommand(self):
31
+ return self.__last
32
+
33
+ def isOpen(self) -> bool:
34
+ '''
35
+ Check if the serial port is open.
36
+
37
+ Returns
38
+ -------
39
+ bool
40
+ True if the serial port is open, False otherwise.
41
+ '''
42
+ return self.__port.isOpen()
43
+
44
+ def isALEX(self) -> bool:
45
+ '''
46
+ Check if the ALEX flag is set.
47
+
48
+ Returns
49
+ -------
50
+ bool
51
+ True if the ALEX flag is set, False otherwise.
52
+ '''
53
+ return self.__alex
54
+
55
+ def setALEX(self, value: bool):
56
+ '''
57
+ Set the ALEX flag.
58
+
59
+ Parameters
60
+ ----------
61
+ value : bool
62
+ The new value for the ALEX flag.
63
+
64
+ Raises
65
+ ------
66
+ TypeError
67
+ If the value is not a boolean.
68
+ '''
69
+ if not isinstance(value, bool):
70
+ raise TypeError('ALEX value should be boolean.')
71
+
72
+ self.__alex = value
73
+
74
+ def open(self):
75
+ '''
76
+ Open the serial port.
77
+
78
+ If the serial port is not already open,
79
+ this method will open it in read-write mode.
80
+ '''
81
+ if not self.isOpen():
82
+ self.__port.open(QtCore.QIODevice.OpenModeFlag.ReadWrite)
83
+
84
+ def close(self):
85
+ '''
86
+ Close the serial port.
87
+
88
+ If the serial port is already open, this method will close it.
89
+ '''
90
+ if self.isOpen():
91
+ self.__port.close()
92
+
93
+ def portName(self):
94
+ '''
95
+ Get the name of the serial port.
96
+
97
+ Returns
98
+ -------
99
+ str
100
+ The name of the serial port.
101
+ '''
102
+ return self.__port.portName()
103
+
104
+ def baudRate(self):
105
+ '''
106
+ Get the baud rate of the serial port.
107
+
108
+ Returns
109
+ -------
110
+ int
111
+ The baud rate of the serial port.
112
+ '''
113
+ return self.__port.baudRate()
114
+
115
+ def setBaudRate(self, value: int):
116
+ '''
117
+ Set the baud rate of the serial port.
118
+
119
+ Parameters
120
+ ----------
121
+ value : int
122
+ The new baud rate for the serial port.
123
+
124
+ Raises
125
+ ------
126
+ ValueError
127
+ If the value is not a valid baud rate.
128
+ '''
129
+ if not self.isOpen():
130
+ self.__port.setBaudRate(value)
131
+
132
+ def setPortName(self, value: str):
133
+ '''
134
+ Set the port of the serial port.
135
+
136
+ Parameters
137
+ ----------
138
+ value : str
139
+ The new port for the serial port.
140
+
141
+ Raises
142
+ ------
143
+ ValueError
144
+ If the value is not a valid port.
145
+ '''
146
+ if not self.isOpen():
147
+ self.__port.setPortName(value)
148
+
149
+ def sendConfig(self, config: str = None):
150
+ '''
151
+ Send the RelayBox configuration command.
152
+
153
+ Parameters
154
+ ----------
155
+ config : str, optional
156
+ The configuration to send. If None, the current configuration will be sent.
157
+
158
+ Raises
159
+ ------
160
+ Exception
161
+ If there is an error sending the configuration.
162
+ '''
163
+ try:
164
+ if not self.isOpen():
165
+ raise ConnectionError('Device is not open.')
166
+
167
+ if config is None:
168
+ config = ('ALEXON' if self.isALEX() else 'ALEXOFF') + '\r'
169
+
170
+ self.__port.write(config.encode('utf-8'))
171
+ self.__last = config
172
+ print(str(self.__port.readAll(), encoding='utf-8'))
173
+ except Exception as e:
174
+ print('Failed Laser Relay Send Config: ' + str(e))
175
+
176
+
177
+ class RelayParams(Enum):
178
+ '''
179
+ Enum class defining Laser Relay parameters.
180
+ '''
181
+
182
+ MODEL = 'Model'
183
+ ALEX = 'ALEX'
184
+ SEND_COMMAND = 'Send Command'
185
+
186
+ SERIAL_PORT = 'Serial Port'
187
+ PORT = 'Serial Port.Port'
188
+ BAUDRATE = 'Serial Port.Baudrate'
189
+ SET_PORT = 'Serial Port.Set Config'
190
+ OPEN = 'Serial Port.Connect'
191
+ CLOSE = 'Serial Port.Disconnect'
192
+ PORT_STATE = 'Serial Port.State'
193
+
194
+ REMOVE = 'Remove Device'
195
+
196
+ def __str__(self):
197
+ '''
198
+ Return the last part of the enum value (Param name).
199
+ '''
200
+ return self.value.split('.')[-1]
201
+
202
+ def get_path(self):
203
+ '''
204
+ Return the full parameter path.
205
+ '''
206
+ return self.value.split('.')
207
+
208
+
209
+ class LaserRelayView(Tree):
210
+ PARAMS = RelayParams
211
+ sendCommandActivated = Signal()
212
+ removed = Signal(object)
213
+
214
+ def __init__(
215
+ self, parent: Optional['QtWidgets.QWidget'] = None, relay: LaserRelay = None
216
+ ):
217
+ self.__laserRelay = relay if relay else LaserRelay()
218
+
219
+ super().__init__(parent=parent)
220
+
221
+ def create_parameters(self):
222
+ '''
223
+ Create the parameter tree structure.
224
+ '''
225
+ params = [
226
+ {
227
+ 'name': str(RelayParams.MODEL),
228
+ 'type': 'str',
229
+ 'value': 'Laser Relay Box',
230
+ 'readonly': True,
231
+ },
232
+ {'name': str(RelayParams.ALEX), 'type': 'bool', 'value': False},
233
+ {'name': str(RelayParams.SEND_COMMAND), 'type': 'action'},
234
+ {
235
+ 'name': str(RelayParams.SERIAL_PORT),
236
+ 'type': 'group',
237
+ 'expanded': False,
238
+ 'children': [
239
+ {
240
+ 'name': str(RelayParams.PORT),
241
+ 'type': 'list',
242
+ 'limits': [
243
+ info.portName()
244
+ for info in QtSerialPort.QSerialPortInfo.availablePorts()
245
+ ],
246
+ },
247
+ {
248
+ 'name': str(RelayParams.BAUDRATE),
249
+ 'type': 'list',
250
+ 'value': 115200,
251
+ 'limits': [
252
+ baudrate
253
+ for baudrate in \
254
+ QtSerialPort.QSerialPortInfo.standardBaudRates()
255
+ ],
256
+ },
257
+ {'name': str(RelayParams.SET_PORT), 'type': 'action'},
258
+ {'name': str(RelayParams.OPEN), 'type': 'action'},
259
+ {'name': str(RelayParams.CLOSE), 'type': 'action'},
260
+ {
261
+ 'name': str(RelayParams.PORT_STATE),
262
+ 'type': 'str',
263
+ 'value': 'closed',
264
+ 'readonly': True,
265
+ },
266
+ ],
267
+ },
268
+ ]
269
+
270
+ self.param_tree = Parameter.create(name='', type='group', children=params)
271
+ self.param_tree.sigTreeStateChanged.connect(self.change)
272
+ self.header().setSectionResizeMode(
273
+ QtWidgets.QHeaderView.ResizeMode.ResizeToContents
274
+ )
275
+
276
+ self.get_param(RelayParams.CLOSE).sigActivated.connect(self.__laserRelay.close)
277
+ self.get_param(RelayParams.SEND_COMMAND).sigActivated.connect(
278
+ lambda: self.sendCommandActivated.emit()
279
+ )
280
+
281
+ def remove_widget(self):
282
+ '''
283
+ Remove the widget from its parent.
284
+
285
+ This method removes the view from its parent widget if
286
+ the laser relay is not open.
287
+ '''
288
+ if self.parent() and not self.__laserRelay.isOpen():
289
+ self.parent().layout().removeWidget(self)
290
+ self.removed.emit(self)
291
+ self.deleteLater()
292
+ else:
293
+ print(f'Disconnect Laser Relay before removing!')
294
+
295
+ def StartGUI():
296
+ '''Initializes a new :class:`QApplication` and :class:`LaserRelay`.
297
+
298
+ Use
299
+ -------
300
+ app, window = LaserRelay.StartGUI()
301
+
302
+ app.exec()
303
+
304
+ Returns
305
+ -------
306
+ tuple (:class:`QApplication`, :class:`LaserRelay`)
307
+ Returns a tuple with QApp and LaserRelay main window.
308
+ '''
309
+ return StartGUI(LaserRelay)
310
+
311
+
312
+ class LaserRelayController:
313
+ def __init__(self, relay: LaserRelay = None, view: LaserRelayView = None):
314
+ '''
315
+ Initialize the LaserRelayController class.
316
+
317
+ This class controls the interaction between the LaserRelay
318
+ and the LaserRelayView widget.
319
+
320
+ Parameters
321
+ ----------
322
+ relay: LaserRelay
323
+ The laser relay to be controlled.
324
+ Default is a new LaserRelay instance.
325
+ view: LaserRelayView
326
+ The GUI/view for the laser relay.
327
+ Default is a new LaserRelayView instance with the relay as an argument.
328
+ '''
329
+ self.__relay = relay if relay else LaserRelay()
330
+ self.__view = view if view else LaserRelayView(relay=self.__relay)
331
+
332
+ self.__view.get_param(RelayParams.SET_PORT).sigActivated.connect(
333
+ self.set_config
334
+ )
335
+ self.__view.get_param(RelayParams.OPEN).sigActivated.connect(self.connect)
336
+
337
+ @property
338
+ def sendCommandActivated(self):
339
+ '''
340
+ PyQt signal emitted when the "Send Command" action is
341
+ activated in the parameter tree.
342
+ '''
343
+ return self.__view.sendCommandActivated
344
+
345
+ @property
346
+ def lastCommand(self):
347
+ '''
348
+ The last command sent by the LaserRelay instance.
349
+
350
+ Returns
351
+ -------
352
+ str
353
+ The last command sent by the LaserRelay instance.
354
+ '''
355
+ return self.__relay.lastCommand
356
+
357
+ @property
358
+ def view(self):
359
+ '''
360
+ The GUI/view for the laser relay.
361
+
362
+ Returns
363
+ -------
364
+ :class:`LaserRelayView`
365
+ The GUI/view for the laser relay.
366
+ '''
367
+ return self.__view
368
+
369
+ def portName(self):
370
+ '''
371
+ Get the name of the serial port.
372
+
373
+ Returns
374
+ -------
375
+ str
376
+ The name of the serial port.
377
+ '''
378
+ return self.__relay.portName()
379
+
380
+ def setPortName(self, value: str):
381
+ '''
382
+ Set the name of the serial port.
383
+
384
+ Parameters
385
+ ----------
386
+ value : str
387
+ The name of the serial port.
388
+ '''
389
+ self.__relay.setPortName(value)
390
+ self.__view.set_param_value(RelayParams.PORT, value)
391
+
392
+ def baudRate(self):
393
+ '''
394
+ Get the baud rate of the serial port.
395
+
396
+ Returns
397
+ -------
398
+ int
399
+ The baud rate of the serial port.
400
+ '''
401
+ return self.__relay.baudRate()
402
+
403
+ def setBaudRate(self, value: int):
404
+ '''
405
+ Set the baud rate of the serial port.
406
+
407
+ Parameters
408
+ ----------
409
+ value : int
410
+ The baud rate of the serial port.
411
+ '''
412
+ self.__relay.setBaudRate(value)
413
+ self.__view.set_param_value(RelayParams.BAUDRATE, value)
414
+
415
+ def isOpen(self):
416
+ '''
417
+ Check if the laser relay is open.
418
+
419
+ Returns
420
+ -------
421
+ bool
422
+ True if the laser relay is open, False otherwise.
423
+ '''
424
+ return self.__relay.isOpen()
425
+
426
+ def set_config(self):
427
+ '''Sets the serial port configuration.
428
+
429
+ This method sets the serial port configuration based on the current
430
+ settings in the parameter tree.
431
+ '''
432
+ if not self.__relay.isOpen():
433
+ self.__relay.setPortName(self.__view.get_param_value(RelayParams.PORT))
434
+ self.__relay.setBaudRate(self.__view.get_param_value(RelayParams.BAUDRATE))
435
+
436
+ def connect(self):
437
+ '''
438
+ Connect to the laser relay.
439
+
440
+ This method opens the serial port and sets the port state to "open" in the
441
+ parameter tree.
442
+ '''
443
+ self.__relay.open()
444
+
445
+ self.__view.set_param_value(RelayParams.PORT_STATE, 'open')
446
+
447
+ def disconnect(self):
448
+ '''
449
+ Disconnect from the laser relay.
450
+ '''
451
+ self.__relay.close()
452
+
453
+ self.__view.set_param_value(RelayParams.PORT_STATE, 'closed')
454
+
455
+ def isALEX(self) -> bool:
456
+ '''
457
+ Check if the ALEX flag is set.
458
+
459
+ Returns
460
+ -------
461
+ bool
462
+ True if the ALEX flag is set, False otherwise.
463
+ '''
464
+ return self.__relay.isALEX()
465
+
466
+ def sendCommand(self, config: str):
467
+ '''
468
+ Send a configuration command to the laser relay.
469
+
470
+ Parameters
471
+ ----------
472
+ config : str
473
+ The configuration command to send to the laser relay.
474
+ '''
475
+ self.__relay.sendConfig(config)
476
+
477
+ def updatePortState(self):
478
+ '''
479
+ Update the port state in the parameter tree.
480
+
481
+ This method updates the port state in the parameter
482
+ tree to reflect the current state of the laser relay.
483
+ '''
484
+ color = '#004CB6' if self.isOpen() else 'black'
485
+
486
+ self.__view.set_param_value(
487
+ RelayParams.PORT_STATE, 'open' if self.isOpen() else 'closed'
488
+ )
489
+
490
+ next(self.__view.get_param(RelayParams.OPEN).items.keys()).button.setStyleSheet(
491
+ f'background-color: {color}'
492
+ )
493
+
494
+ def updateHighlight(self, config: str):
495
+ '''
496
+ Update the highlight style of the "Send Command" action.
497
+
498
+ This method updates the highlight style of the "Send Command" action
499
+ in the parameter tree based on whether the given configuration matches
500
+ the last command sent.
501
+
502
+ Parameters
503
+ ----------
504
+ config : str
505
+ The configuration to compare with the last command sent.
506
+ '''
507
+ style = ''
508
+ if config is not None:
509
+ if config == self.lastCommand:
510
+ style = 'background-color: #004CB6'
511
+ else:
512
+ style = 'background-color: black'
513
+
514
+ next(
515
+ self.__view.get_param(RelayParams.SEND_COMMAND).items.keys()
516
+ ).button.setStyleSheet(style)
517
+
518
+ def refreshPorts(self):
519
+ """
520
+ Refreshes the available serial ports list in the GUI.
521
+
522
+ This method updates the list of available serial ports in the GUI by fetching
523
+ the current list of available ports and setting it as the options for the
524
+ 'Serial Port' parameter in the parameter tree.
525
+ """
526
+ if not self.isOpen():
527
+ self.__view.get_param(RelayParams.PORT).setLimits(
528
+ [
529
+ info.portName()
530
+ for info in QtSerialPort.QSerialPortInfo.availablePorts()
531
+ ]
532
+ )
533
+
534
+ def getCommand(self, config: str):
535
+ '''
536
+ Get the full configuration command to send to the laser relay.
537
+
538
+ This method returns the full configuration command to send to the laser relay,
539
+ including the ALEXON/ALEXOFF command based on the current ALEX flag.
540
+
541
+ Parameters
542
+ ----------
543
+ config : str
544
+ The configuration command to send to the laser relay,
545
+ excluding the ALEXON/ALEXOFF command.
546
+
547
+ Returns
548
+ -------
549
+ str
550
+ The full configuration command to send to the laser relay,
551
+ including the ALEXON/ALEXOFF command.
552
+ '''
553
+ return config + ('ALEXON' if self.isALEX() else 'ALEXOFF') + '\r'
554
+
555
+ def get_config(self) -> dict:
556
+ '''
557
+ Get the current configuration of the laser relay.
558
+
559
+ Returns
560
+ -------
561
+ dict
562
+ The current configuration of the laser relay.
563
+ '''
564
+ return {
565
+ 'port': self.__relay.portName(),
566
+ 'baudrate': self.__relay.baudRate(),
567
+ 'alex': self.isALEX(),
568
+ }
569
+
570
+ def load_config(self, config: dict):
571
+ '''
572
+ Load the configuration from a dictionary.
573
+
574
+ Parameters
575
+ ----------
576
+ config : dict
577
+ The configuration dictionary to load.
578
+ '''
579
+ if not isinstance(config, dict):
580
+ raise TypeError("Config must be a dictionary.")
581
+
582
+ port = config.get('port')
583
+ baudrate = config.get('baudrate')
584
+ alex = config.get('alex')
585
+
586
+ if port:
587
+ self.setPortName(port)
588
+ if baudrate:
589
+ self.setBaudRate(baudrate)
590
+ if alex:
591
+ self.__relay.setALEX(alex)
592
+
593
+ def __str__(self):
594
+ return 'Laser Relay Controller'
@@ -0,0 +1 @@
1
+ from microEye.hardware.mieye.miEye import miEye_module