QInstrument 2.4.0__tar.gz → 3.0.0__tar.gz

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 (125) hide show
  1. {qinstrument-2.4.0 → qinstrument-3.0.0}/PKG-INFO +1 -1
  2. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrument.egg-info/PKG-INFO +1 -1
  3. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrument.egg-info/SOURCES.txt +5 -8
  4. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/Proscan/instrument.py +33 -9
  5. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/DS345/instrument.py +5 -4
  6. qinstrument-3.0.0/instruments/StanfordResearch/SR830/__init__.py +10 -0
  7. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR830/instrument.py +25 -5
  8. qinstrument-3.0.0/instruments/StanfordResearch/SR844/__init__.py +10 -0
  9. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR844/instrument.py +25 -5
  10. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/Configure.py +10 -5
  11. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QAbstractInstrument.py +89 -149
  12. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QFakeInstrument.py +13 -18
  13. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QInstrumentTree.py +149 -60
  14. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QInstrumentWidget.py +119 -79
  15. qinstrument-3.0.0/lib/QPollingMixin.py +97 -0
  16. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QReconcileDialog.py +4 -2
  17. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QSerialInstrument.py +127 -59
  18. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/QSerialInterface.py +27 -97
  19. {qinstrument-2.4.0 → qinstrument-3.0.0}/lib/__init__.py +1 -0
  20. qinstrument-3.0.0/lib/lazy.py +124 -0
  21. {qinstrument-2.4.0 → qinstrument-3.0.0}/pyproject.toml +1 -1
  22. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_Configure.py +16 -0
  23. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QAbstractInstrument.py +0 -43
  24. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QFakeInstrument.py +0 -4
  25. qinstrument-3.0.0/tests/test_QInstrumentTree.py +347 -0
  26. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QInstrumentWidget.py +67 -2
  27. qinstrument-3.0.0/tests/test_QPollingMixin.py +132 -0
  28. qinstrument-3.0.0/tests/test_QReconcileDialog.py +85 -0
  29. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QSR830.py +39 -0
  30. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QSR844.py +39 -0
  31. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QSerialInstrument.py +35 -0
  32. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QSerialInterface.py +1 -83
  33. qinstrument-2.4.0/instruments/StanfordResearch/SR830/__init__.py +0 -6
  34. qinstrument-2.4.0/instruments/StanfordResearch/SR830/worker.py +0 -38
  35. qinstrument-2.4.0/instruments/StanfordResearch/SR844/__init__.py +0 -6
  36. qinstrument-2.4.0/instruments/StanfordResearch/SR844/worker.py +0 -38
  37. qinstrument-2.4.0/lib/QInstrumentWorker.py +0 -119
  38. qinstrument-2.4.0/lib/lazy.py +0 -52
  39. qinstrument-2.4.0/tests/test_QInstrumentWorker.py +0 -164
  40. qinstrument-2.4.0/tests/test_QSR830Worker.py +0 -107
  41. {qinstrument-2.4.0 → qinstrument-3.0.0}/LICENSE.md +0 -0
  42. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrument.egg-info/dependency_links.txt +0 -0
  43. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrument.egg-info/entry_points.txt +0 -0
  44. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrument.egg-info/requires.txt +0 -0
  45. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrument.egg-info/top_level.txt +0 -0
  46. {qinstrument-2.4.0 → qinstrument-3.0.0}/QInstrumentRack.py +0 -0
  47. {qinstrument-2.4.0 → qinstrument-3.0.0}/README.md +0 -0
  48. {qinstrument-2.4.0 → qinstrument-3.0.0}/__init__.py +0 -0
  49. {qinstrument-2.4.0 → qinstrument-3.0.0}/__main__.py +0 -0
  50. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/IPGLaser/IPGLaserWidget.ui +0 -0
  51. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/IPGLaser/__init__.py +0 -0
  52. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/IPGLaser/fake.py +0 -0
  53. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/IPGLaser/instrument.py +0 -0
  54. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/IPGLaser/tree.py +0 -0
  55. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/IPGLaser/widget.py +0 -0
  56. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/IPGPhotonics/__init__.py +0 -0
  57. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus/OpusWidget.ui +0 -0
  58. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus/__init__.py +0 -0
  59. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus/fake.py +0 -0
  60. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus/instrument.py +0 -0
  61. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus/tree.py +0 -0
  62. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus/widget.py +0 -0
  63. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus1064/__init__.py +0 -0
  64. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus1064/fake.py +0 -0
  65. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus1064/instrument.py +0 -0
  66. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus1064/tree.py +0 -0
  67. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus1064/widget.py +0 -0
  68. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus532/__init__.py +0 -0
  69. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus532/fake.py +0 -0
  70. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus532/instrument.py +0 -0
  71. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus532/tree.py +0 -0
  72. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus532/widget.py +0 -0
  73. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus660/__init__.py +0 -0
  74. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus660/fake.py +0 -0
  75. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus660/instrument.py +0 -0
  76. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus660/tree.py +0 -0
  77. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/Opus660/widget.py +0 -0
  78. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Novanta/__init__.py +0 -0
  79. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/PDUS210/PDUS210Widget.ui +0 -0
  80. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/PDUS210/__init__.py +0 -0
  81. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/PDUS210/fake.py +0 -0
  82. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/PDUS210/instrument.py +0 -0
  83. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/PDUS210/tree.py +0 -0
  84. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/PDUS210/widget.py +0 -0
  85. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PiezoDrive/__init__.py +0 -0
  86. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/Proscan/ProscanWidget.ui +0 -0
  87. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/Proscan/__init__.py +0 -0
  88. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/Proscan/fake.py +0 -0
  89. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/Proscan/tree.py +0 -0
  90. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/Proscan/widget.py +0 -0
  91. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/PriorScientific/__init__.py +0 -0
  92. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/DS345/DS345Widget.ui +0 -0
  93. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/DS345/__init__.py +0 -0
  94. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/DS345/fake.py +0 -0
  95. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/DS345/tree.py +0 -0
  96. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/DS345/widget.py +0 -0
  97. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR830/SR830Widget.ui +0 -0
  98. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR830/fake.py +0 -0
  99. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR830/tree.py +0 -0
  100. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR830/widget.py +0 -0
  101. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR844/SR844Widget.ui +0 -0
  102. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR844/fake.py +0 -0
  103. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR844/tree.py +0 -0
  104. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/SR844/widget.py +0 -0
  105. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/StanfordResearch/__init__.py +0 -0
  106. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Tektronix/TDS1000/__init__.py +0 -0
  107. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Tektronix/TDS1000/instrument.py +0 -0
  108. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/Tektronix/__init__.py +0 -0
  109. {qinstrument-2.4.0 → qinstrument-3.0.0}/instruments/__init__.py +0 -0
  110. {qinstrument-2.4.0 → qinstrument-3.0.0}/setup.cfg +0 -0
  111. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QDS345.py +0 -0
  112. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QIPGLaser.py +0 -0
  113. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QInstrumentRack.py +0 -0
  114. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QLedWidget.py +0 -0
  115. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QOpus.py +0 -0
  116. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QPDUS210.py +0 -0
  117. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QProscan.py +0 -0
  118. {qinstrument-2.4.0 → qinstrument-3.0.0}/tests/test_QRotaryEncoderSpinBox.py +0 -0
  119. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/QJoystick.py +0 -0
  120. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/QJoystickPad.py +0 -0
  121. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/QLedWidget.py +0 -0
  122. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/QRotaryEncoder.py +0 -0
  123. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/QRotaryEncoderSpinBox.py +0 -0
  124. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/QRotaryEncoderSpinBox.ui +0 -0
  125. {qinstrument-2.4.0 → qinstrument-3.0.0}/widgets/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QInstrument
3
- Version: 2.4.0
3
+ Version: 3.0.0
4
4
  Summary: Qt-based framework for controlling scientific instruments over serial ports
5
5
  Author-email: "David G. Grier" <david.grier@nyu.edu>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QInstrument
3
- Version: 2.4.0
3
+ Version: 3.0.0
4
4
  Summary: Qt-based framework for controlling scientific instruments over serial ports
5
5
  Author-email: "David G. Grier" <david.grier@nyu.edu>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -64,14 +64,12 @@ pyproject.toml
64
64
  ./instruments/StanfordResearch/SR830/instrument.py
65
65
  ./instruments/StanfordResearch/SR830/tree.py
66
66
  ./instruments/StanfordResearch/SR830/widget.py
67
- ./instruments/StanfordResearch/SR830/worker.py
68
67
  ./instruments/StanfordResearch/SR844/SR844Widget.ui
69
68
  ./instruments/StanfordResearch/SR844/__init__.py
70
69
  ./instruments/StanfordResearch/SR844/fake.py
71
70
  ./instruments/StanfordResearch/SR844/instrument.py
72
71
  ./instruments/StanfordResearch/SR844/tree.py
73
72
  ./instruments/StanfordResearch/SR844/widget.py
74
- ./instruments/StanfordResearch/SR844/worker.py
75
73
  ./instruments/Tektronix/__init__.py
76
74
  ./instruments/Tektronix/TDS1000/__init__.py
77
75
  ./instruments/Tektronix/TDS1000/instrument.py
@@ -80,7 +78,7 @@ pyproject.toml
80
78
  ./lib/QFakeInstrument.py
81
79
  ./lib/QInstrumentTree.py
82
80
  ./lib/QInstrumentWidget.py
83
- ./lib/QInstrumentWorker.py
81
+ ./lib/QPollingMixin.py
84
82
  ./lib/QReconcileDialog.py
85
83
  ./lib/QSerialInstrument.py
86
84
  ./lib/QSerialInterface.py
@@ -156,14 +154,12 @@ instruments/StanfordResearch/SR830/fake.py
156
154
  instruments/StanfordResearch/SR830/instrument.py
157
155
  instruments/StanfordResearch/SR830/tree.py
158
156
  instruments/StanfordResearch/SR830/widget.py
159
- instruments/StanfordResearch/SR830/worker.py
160
157
  instruments/StanfordResearch/SR844/SR844Widget.ui
161
158
  instruments/StanfordResearch/SR844/__init__.py
162
159
  instruments/StanfordResearch/SR844/fake.py
163
160
  instruments/StanfordResearch/SR844/instrument.py
164
161
  instruments/StanfordResearch/SR844/tree.py
165
162
  instruments/StanfordResearch/SR844/widget.py
166
- instruments/StanfordResearch/SR844/worker.py
167
163
  instruments/Tektronix/__init__.py
168
164
  instruments/Tektronix/TDS1000/__init__.py
169
165
  instruments/Tektronix/TDS1000/instrument.py
@@ -172,7 +168,7 @@ lib/QAbstractInstrument.py
172
168
  lib/QFakeInstrument.py
173
169
  lib/QInstrumentTree.py
174
170
  lib/QInstrumentWidget.py
175
- lib/QInstrumentWorker.py
171
+ lib/QPollingMixin.py
176
172
  lib/QReconcileDialog.py
177
173
  lib/QSerialInstrument.py
178
174
  lib/QSerialInterface.py
@@ -184,15 +180,16 @@ tests/test_QDS345.py
184
180
  tests/test_QFakeInstrument.py
185
181
  tests/test_QIPGLaser.py
186
182
  tests/test_QInstrumentRack.py
183
+ tests/test_QInstrumentTree.py
187
184
  tests/test_QInstrumentWidget.py
188
- tests/test_QInstrumentWorker.py
189
185
  tests/test_QLedWidget.py
190
186
  tests/test_QOpus.py
191
187
  tests/test_QPDUS210.py
188
+ tests/test_QPollingMixin.py
192
189
  tests/test_QProscan.py
190
+ tests/test_QReconcileDialog.py
193
191
  tests/test_QRotaryEncoderSpinBox.py
194
192
  tests/test_QSR830.py
195
- tests/test_QSR830Worker.py
196
193
  tests/test_QSR844.py
197
194
  tests/test_QSerialInstrument.py
198
195
  tests/test_QSerialInterface.py
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import logging
4
4
  from qtpy import QtCore
5
+ from QInstrument.lib.QAbstractInstrument import QAbstractInstrument
5
6
  from QInstrument.lib.QSerialInstrument import QSerialInstrument
6
7
 
7
8
 
@@ -210,6 +211,20 @@ class QProscan(QSerialInstrument):
210
211
 
211
212
  positionChanged = QtCore.Signal(object)
212
213
 
214
+ _VOLATILE: frozenset[str] = frozenset({'speed', 'zspeed'})
215
+ '''Properties excluded from save/restore.
216
+
217
+ ``speed`` and ``zspeed`` reflect the stage's live motion limits.
218
+ Silently writing a stale saved value on reconnect could cause
219
+ unexpected or unsafe stage behaviour, so they are excluded from
220
+ :attr:`settings`.
221
+
222
+ To exclude additional properties in a subclass, redefine
223
+ ``_VOLATILE`` as a superset::
224
+
225
+ _VOLATILE = QProscan._VOLATILE | frozenset({'stepsize'})
226
+ '''
227
+
213
228
  comm = dict(baudRate=QSerialInstrument.BaudRate.Baud9600,
214
229
  dataBits=QSerialInstrument.DataBits.Data8,
215
230
  stopBits=QSerialInstrument.StopBits.OneStop,
@@ -217,22 +232,31 @@ class QProscan(QSerialInstrument):
217
232
  flowControl=QSerialInstrument.FlowControl.NoFlowControl,
218
233
  eol='\r')
219
234
 
235
+ @property
236
+ def settings(self) -> QAbstractInstrument.Settings:
237
+ return {k: v for k, v in super().settings.items()
238
+ if k not in self._VOLATILE}
239
+
240
+ @settings.setter
241
+ def settings(self, s: QAbstractInstrument.Settings) -> None:
242
+ QAbstractInstrument.settings.fset(
243
+ self, {k: v for k, v in s.items()
244
+ if k not in self._VOLATILE})
245
+
220
246
  def _registerProperties(self) -> None:
221
247
  self._flip: bool = False
222
248
  self._mirror: bool = False
223
- for name, cmd, persist in (
224
- ('speed', 'SMS', False),
225
- ('acceleration', 'SAS', True),
226
- ('scurve', 'SCS', True),
227
- ('zspeed', 'SMZ', False),
228
- ('zacceleration', 'SAZ', True),
229
- ('zscurve', 'SCZ', True)):
249
+ for name, cmd in (('speed', 'SMS'),
250
+ ('acceleration', 'SAS'),
251
+ ('scurve', 'SCS'),
252
+ ('zspeed', 'SMZ'),
253
+ ('zacceleration', 'SAZ'),
254
+ ('zscurve', 'SCZ')):
230
255
  self.registerProperty(
231
256
  name,
232
257
  getter=lambda c=cmd: self.getValue(c, int),
233
258
  setter=lambda v, c=cmd: self.expect(f'{c},{int(v)}', '0'),
234
- ptype=int,
235
- persist=persist)
259
+ ptype=int)
236
260
  self.registerProperty(
237
261
  'stepsize',
238
262
  getter=lambda: float(self.handshake('X').split(',')[0]),
@@ -108,8 +108,9 @@ class QDS345(QSerialInstrument):
108
108
  def _registerProperties(self) -> None:
109
109
  '''Register all instrument properties via ``registerProperty()``.
110
110
 
111
- Called once from ``__init__``. Subclasses that extend the property
112
- set should call ``super()._registerProperties()`` first.
111
+ Called automatically by ``QAbstractInstrument.__init__``. Subclasses
112
+ that extend the property set should call
113
+ ``super()._registerProperties()`` first.
113
114
  '''
114
115
  self._muted: bool = False
115
116
  self._saved_amplitude: float
@@ -144,8 +145,8 @@ class QDS345(QSerialInstrument):
144
145
  def _registerMethods(self) -> None:
145
146
  '''Register all instrument methods via ``registerMethod()``.
146
147
 
147
- Called once from ``__init__``. Subclasses that add methods should
148
- call ``super()._registerMethods()`` first.
148
+ Called automatically by ``QAbstractInstrument.__init__``. Subclasses
149
+ that add methods should call ``super()._registerMethods()`` first.
149
150
  '''
150
151
  self.registerMethod('reset', self.reset)
151
152
  self.registerMethod('trigger', self.trigger)
@@ -0,0 +1,10 @@
1
+ from QInstrument.lib.lazy import make_getattr
2
+
3
+ _lazy = {
4
+ 'QSR830': 'instrument',
5
+ 'QFakeSR830': 'fake',
6
+ 'QSR830Widget': 'widget',
7
+ }
8
+
9
+ __getattr__ = make_getattr(_lazy, __name__)
10
+ __all__ = list(_lazy)
@@ -1,11 +1,13 @@
1
1
  import logging
2
+ from qtpy import QtCore
3
+ from QInstrument.lib.QPollingMixin import QPollingMixin
2
4
  from QInstrument.lib.QSerialInstrument import QSerialInstrument
3
5
 
4
6
 
5
7
  logger = logging.getLogger(__name__)
6
8
 
7
9
 
8
- class QSR830(QSerialInstrument):
10
+ class QSR830(QPollingMixin, QSerialInstrument):
9
11
  '''SRS SR830 Lock-in Amplifier
10
12
 
11
13
  Properties
@@ -106,8 +108,9 @@ class QSR830(QSerialInstrument):
106
108
  def _registerProperties(self) -> None:
107
109
  '''Register all instrument properties via ``registerProperty()``.
108
110
 
109
- Called once from ``__init__``. Subclasses that extend the property
110
- set should call ``super()._registerProperties()`` first.
111
+ Called automatically by ``QAbstractInstrument.__init__``. Subclasses
112
+ that extend the property set should call
113
+ ``super()._registerProperties()`` first.
111
114
  '''
112
115
  # Reference and Phase
113
116
  self._register('amplitude', 'SLVL', float)
@@ -140,8 +143,8 @@ class QSR830(QSerialInstrument):
140
143
  def _registerMethods(self) -> None:
141
144
  '''Register all instrument methods via ``registerMethod()``.
142
145
 
143
- Called once from ``__init__``. Subclasses that add methods should
144
- call ``super()._registerMethods()`` first.
146
+ Called automatically by ``QAbstractInstrument.__init__``. Subclasses
147
+ that add methods should call ``super()._registerMethods()`` first.
145
148
  '''
146
149
  self.registerMethod('reset', self.reset)
147
150
  self.registerMethod('auto_gain', self.auto_gain)
@@ -184,6 +187,23 @@ class QSR830(QSerialInstrument):
184
187
  '''
185
188
  return 'SR830' in self.handshake('*IDN?')
186
189
 
190
+ def _poll(self) -> None:
191
+ '''Poll frequency, R, and theta simultaneously and emit results.
192
+
193
+ Overrides :meth:`QPollingMixin._poll` to use the ``SNAP?9,3,4``
194
+ batch command instead of three sequential queries, keeping the
195
+ captured values time-coherent.
196
+ '''
197
+ if not getattr(self, '_polling', False):
198
+ return
199
+ frequency, r, theta = self.report()
200
+ self.propertyValue.emit('frequency', frequency)
201
+ self.propertyValue.emit('r', r)
202
+ self.propertyValue.emit('theta', theta)
203
+ if getattr(self, '_polling', False):
204
+ QtCore.QTimer.singleShot(
205
+ self.POLL_INTERVAL, self._poll)
206
+
187
207
  def report(self) -> list[float]:
188
208
  '''Return the current frequency, magnitude, and phase.
189
209
 
@@ -0,0 +1,10 @@
1
+ from QInstrument.lib.lazy import make_getattr
2
+
3
+ _lazy = {
4
+ 'QSR844': 'instrument',
5
+ 'QFakeSR844': 'fake',
6
+ 'QSR844Widget': 'widget',
7
+ }
8
+
9
+ __getattr__ = make_getattr(_lazy, __name__)
10
+ __all__ = list(_lazy)
@@ -1,11 +1,13 @@
1
1
  import logging
2
+ from qtpy import QtCore
3
+ from QInstrument.lib.QPollingMixin import QPollingMixin
2
4
  from QInstrument.lib.QSerialInstrument import QSerialInstrument
3
5
 
4
6
 
5
7
  logger = logging.getLogger(__name__)
6
8
 
7
9
 
8
- class QSR844(QSerialInstrument):
10
+ class QSR844(QPollingMixin, QSerialInstrument):
9
11
  '''SRS SR844 RF Lock-in Amplifier
10
12
 
11
13
  Properties
@@ -93,8 +95,9 @@ class QSR844(QSerialInstrument):
93
95
  def _registerProperties(self) -> None:
94
96
  '''Register all instrument properties via ``registerProperty()``.
95
97
 
96
- Called once from ``__init__``. Subclasses that extend the property
97
- set should call ``super()._registerProperties()`` first.
98
+ Called automatically by ``QAbstractInstrument.__init__``. Subclasses
99
+ that extend the property set should call
100
+ ``super()._registerProperties()`` first.
98
101
  '''
99
102
  # Reference and Phase
100
103
  self._register('frequency', 'FREQ', float)
@@ -128,8 +131,8 @@ class QSR844(QSerialInstrument):
128
131
  def _registerMethods(self) -> None:
129
132
  '''Register all instrument methods via ``registerMethod()``.
130
133
 
131
- Called once from ``__init__``. Subclasses that add methods should
132
- call ``super()._registerMethods()`` first.
134
+ Called automatically by ``QAbstractInstrument.__init__``. Subclasses
135
+ that add methods should call ``super()._registerMethods()`` first.
133
136
  '''
134
137
  self.registerMethod('reset', self.reset)
135
138
  self.registerMethod('auto_gain', self.auto_gain)
@@ -172,6 +175,23 @@ class QSR844(QSerialInstrument):
172
175
  '''
173
176
  return 'SR844' in self.handshake('*IDN?')
174
177
 
178
+ def _poll(self) -> None:
179
+ '''Poll frequency, R, and theta simultaneously and emit results.
180
+
181
+ Overrides :meth:`QPollingMixin._poll` to use the ``SNAP?9,3,4``
182
+ batch command instead of three sequential queries, keeping the
183
+ captured values time-coherent.
184
+ '''
185
+ if not getattr(self, '_polling', False):
186
+ return
187
+ frequency, r, theta = self.report()
188
+ self.propertyValue.emit('frequency', frequency)
189
+ self.propertyValue.emit('r', r)
190
+ self.propertyValue.emit('theta', theta)
191
+ if getattr(self, '_polling', False):
192
+ QtCore.QTimer.singleShot(
193
+ self.POLL_INTERVAL, self._poll)
194
+
175
195
  def report(self) -> list[float]:
176
196
  '''Return the current frequency, magnitude, and phase simultaneously.
177
197
 
@@ -98,19 +98,24 @@ class Configure(QtCore.QObject):
98
98
  '''
99
99
  return str(self.configdir / (obj.__class__.__name__ + '.json'))
100
100
 
101
- def save(self, obj: object) -> None:
101
+ def save(self, obj: object,
102
+ settings: dict | None = None) -> None:
102
103
  '''Save *obj*'s settings to its JSON configuration file.
103
104
 
104
105
  Reads ``obj.settings`` (a dict) and serializes it to
105
- :meth:`configname`. Does nothing when ``obj.settings`` is empty.
106
+ :meth:`configname`. Does nothing when the settings dict is empty.
107
+ An explicit *settings* dict may be supplied to avoid reading from
108
+ *obj* directly — useful when *obj* lives in a worker thread.
106
109
 
107
110
  Parameters
108
111
  ----------
109
112
  obj : object
110
- Object with a ``settings`` property returning a
111
- ``dict[str, bool | int | float | str]``.
113
+ Object whose class name determines the configuration filename.
114
+ settings : dict or None, optional
115
+ Settings to save. When ``None`` (default), reads
116
+ ``obj.settings``.
112
117
  '''
113
- settings = obj.settings
118
+ settings = obj.settings if settings is None else settings
114
119
  if not settings:
115
120
  return
116
121
  filename = self.configname(obj)
@@ -9,18 +9,16 @@ _AUTO = object() # sentinel: auto-generate getter/setter from _name convention
9
9
 
10
10
 
11
11
  class QAbstractInstrument(QtCore.QObject):
12
- '''Abstract base class defining the computer-instrument interface.
12
+ '''Abstract base class for scientific instruments.
13
13
 
14
- Provides a transport-agnostic property and method registration
15
- system for controlling scientific instruments. Concrete
16
- instrument classes inherit from this (via a transport-specific
17
- subclass such as :class:`QSerialInstrument`) and must supply
18
- ``transmit()`` and ``receive()`` methods.
14
+ Models instrument state as named properties registered via
15
+ :meth:`registerProperty` and accessed through the thread-safe
16
+ :meth:`get` and :meth:`set` slots. Methods are registered via
17
+ :meth:`registerMethod` and invoked by name via :meth:`execute`.
19
18
 
20
- Properties are registered with :meth:`registerProperty` and
21
- accessed by name via :meth:`get` and :meth:`set`. Methods are
22
- registered with :meth:`registerMethod` and invoked by name via
23
- :meth:`execute`. Both slots are thread-safe.
19
+ This class has no concept of hardware communication. A concrete
20
+ transport subclass (e.g. :class:`QSerialInstrument`) provides the
21
+ I/O layer and higher-level communication helpers.
24
22
 
25
23
  Signals
26
24
  -------
@@ -39,91 +37,31 @@ class QAbstractInstrument(QtCore.QObject):
39
37
  self.mutex = QtCore.QMutex()
40
38
  self._properties = {}
41
39
  self._methods = {}
40
+ self._registerProperties()
41
+ self._registerMethods()
42
+
43
+ def __repr__(self) -> str:
44
+ return f'{self.__class__.__name__}()'
42
45
 
43
46
  def _registerProperties(self) -> None:
44
47
  '''Register instrument properties.
45
48
 
46
- No-op base implementation. Concrete instruments override this
47
- to call :meth:`registerProperty` for each of their properties.
48
- Subclasses that extend the property set should call
49
- ``super()._registerProperties()`` first.
49
+ Called automatically by :meth:`__init__`. No-op base
50
+ implementation; concrete instruments override this to call
51
+ :meth:`registerProperty` for each of their properties.
52
+ Subclasses that extend the property set of a parent instrument
53
+ should call ``super()._registerProperties()`` first.
50
54
  '''
51
55
 
52
56
  def _registerMethods(self) -> None:
53
57
  '''Register instrument methods.
54
58
 
55
- No-op base implementation. Concrete instruments override this
56
- to call :meth:`registerMethod` for each of their methods.
57
- Subclasses that extend the method set should call
58
- ``super()._registerMethods()`` first.
59
- '''
60
-
61
- def __repr__(self) -> str:
62
- return f'{self.__class__.__name__}()'
63
-
64
- def handshake(self, data: str, **kwargs) -> str:
65
- '''Transmit a command and return the instrument's response.
66
-
67
- Delegates to ``transmit()`` and ``receive()``, which must be
68
- provided by the concrete instrument class.
69
-
70
- Parameters
71
- ----------
72
- data : str
73
- Command string to send to the instrument.
74
- **kwargs :
75
- Passed through to ``receive()``.
76
-
77
- Returns
78
- -------
79
- str
80
- Response string from the instrument.
81
- '''
82
- self.transmit(data)
83
- return self.receive(**kwargs).strip()
84
-
85
- def getValue(self, query: str, dtype: type = float) -> PropertyValue | None:
86
- '''Query the instrument and return a typed value.
87
-
88
- Parameters
89
- ----------
90
- query : str
91
- Command string that elicits a single-value response.
92
- dtype : type, optional
93
- Converts the response string to the desired type.
94
- Default: ``float``.
95
-
96
- Returns
97
- -------
98
- PropertyValue or None
99
- Value converted by *dtype*, or ``None`` if conversion fails.
100
- '''
101
- response = self.handshake(query)
102
- try:
103
- value = dtype(response)
104
- except ValueError:
105
- value = None
106
- return value
107
-
108
- def expect(self, query: str, response: str, **kwargs) -> bool:
109
- '''Return True if the instrument's response
110
- contains the expected string.
111
-
112
- Parameters
113
- ----------
114
- query : str
115
- Command string to send to the instrument.
116
- response : str
117
- Substring expected in the instrument's reply.
118
- **kwargs :
119
- Passed through to ``receive()``.
120
-
121
- Returns
122
- -------
123
- bool
124
- ``True`` if *response* appears in the instrument's reply.
59
+ Called automatically by :meth:`__init__`. No-op base
60
+ implementation; concrete instruments override this to call
61
+ :meth:`registerMethod` for each of their methods.
62
+ Subclasses that extend the method set of a parent instrument
63
+ should call ``super()._registerMethods()`` first.
125
64
  '''
126
- return response in self.handshake(query, **kwargs)
127
65
 
128
66
  def registerProperty(self,
129
67
  name: str,
@@ -167,6 +105,22 @@ class QAbstractInstrument(QtCore.QObject):
167
105
  self._properties[name] = dict(
168
106
  getter=getter, setter=setter, ptype=ptype, **meta)
169
107
 
108
+ def registerMethod(self,
109
+ name: str,
110
+ method: Callable[[], None]) -> None:
111
+ '''Register a named zero-argument callable.
112
+
113
+ Registered methods can be invoked by name via :meth:`execute`.
114
+
115
+ Parameters
116
+ ----------
117
+ name : str
118
+ Method name used with :meth:`execute`.
119
+ method : callable
120
+ Zero-argument callable to invoke.
121
+ '''
122
+ self._methods[name] = method
123
+
170
124
  @property
171
125
  def properties(self) -> list[str]:
172
126
  '''Names of all registered instrument properties.'''
@@ -174,23 +128,31 @@ class QAbstractInstrument(QtCore.QObject):
174
128
 
175
129
  @property
176
130
  def settings(self) -> Settings:
177
- '''Current values of all writable, persistent registered properties.
131
+ '''Current values of all writable registered properties.
178
132
 
179
133
  Getting this property calls every qualifying getter, which may
180
134
  issue instrument queries. A property qualifies when its setter
181
- is not ``None`` (writable) and its ``persist`` metadata flag is
182
- ``True`` (default).
135
+ is not ``None`` (writable).
183
136
 
184
137
  Setting it calls each registered setter for keys present in the
185
- supplied dict, skipping unknown keys, read-only properties, and
186
- properties whose ``persist`` flag is ``False``.
138
+ supplied dict, skipping unknown keys and read-only properties.
139
+ Unlike :meth:`set`, the setter does not emit
140
+ :attr:`propertyValue` for each key; call
141
+ :meth:`_syncProperties` after a bulk restore if the UI must
142
+ reflect the new values.
143
+
144
+ Subclasses that need to exclude specific properties from
145
+ save/restore (e.g. motion-speed parameters that must not be
146
+ silently overwritten on reconnect) should override both the
147
+ getter and setter to filter those names. See
148
+ :class:`QProscan` for an example.
187
149
  '''
188
150
  with QtCore.QMutexLocker(self.mutex):
189
151
  props = list(self._properties.items())
190
152
  return {
191
153
  name: info['getter']()
192
154
  for name, info in props
193
- if info['setter'] is not None and info.get('persist', True)
155
+ if info['setter'] is not None
194
156
  }
195
157
 
196
158
  @settings.setter
@@ -198,12 +160,45 @@ class QAbstractInstrument(QtCore.QObject):
198
160
  with QtCore.QMutexLocker(self.mutex):
199
161
  calls = [(self._properties[k]['setter'], v)
200
162
  for k, v in settings.items()
201
- if k in self._properties
202
- and self._properties[k].get('persist', True)]
163
+ if k in self._properties]
203
164
  for setter, value in calls:
204
165
  if setter is not None:
205
166
  setter(value)
206
167
 
168
+ @property
169
+ def methods(self) -> list[str]:
170
+ '''Names of all registered instrument methods.'''
171
+ return list(self._methods.keys())
172
+
173
+ @QtCore.Slot(str)
174
+ def get(self, key: str) -> PropertyValue | None:
175
+ '''Return the current value of a registered property.
176
+
177
+ Thread-safe Qt slot. The registry lock is released before
178
+ calling the getter, so the getter may safely call other
179
+ instrument methods without deadlocking. Emits
180
+ :attr:`propertyValue` with the name and value. Logs an error
181
+ and returns ``None`` if the key is not registered.
182
+
183
+ Parameters
184
+ ----------
185
+ key : str
186
+ Registered property name.
187
+
188
+ Returns
189
+ -------
190
+ PropertyValue or None
191
+ Current value, or ``None`` if *key* is unknown.
192
+ '''
193
+ with QtCore.QMutexLocker(self.mutex):
194
+ if key not in self._properties:
195
+ logger.error(f'Unknown property: {key}')
196
+ return None
197
+ getter = self._properties[key]['getter']
198
+ value = getter()
199
+ self.propertyValue.emit(key, value)
200
+ return value
201
+
207
202
  @QtCore.Slot(str, object)
208
203
  def set(self, key: str, value: PropertyValue) -> None:
209
204
  '''Set a registered property to the given value.
@@ -259,62 +254,6 @@ class QAbstractInstrument(QtCore.QObject):
259
254
  info['readonly'] = info.pop('setter', None) is None
260
255
  return info
261
256
 
262
- @QtCore.Slot(str)
263
- def get(self, key: str) -> PropertyValue | None:
264
- '''Return the current value of a registered property.
265
-
266
- Thread-safe Qt slot. The registry lock is released before
267
- calling the getter, so the getter may safely call other
268
- instrument methods without deadlocking. Emits
269
- :attr:`propertyValue` with the name and value. Logs an error
270
- and returns ``None`` if the key is not registered.
271
-
272
- Parameters
273
- ----------
274
- key : str
275
- Registered property name.
276
-
277
- Returns
278
- -------
279
- PropertyValue or None
280
- Current value, or ``None`` if *key* is unknown.
281
- '''
282
- with QtCore.QMutexLocker(self.mutex):
283
- if key not in self._properties:
284
- logger.error(f'Unknown property: {key}')
285
- return None
286
- getter = self._properties[key]['getter']
287
- value = getter()
288
- self.propertyValue.emit(key, value)
289
- return value
290
-
291
- def busy(self) -> bool:
292
- '''Return True if the instrument is busy.
293
-
294
- Returns ``False`` by default. Subclasses should override this
295
- if the instrument exposes a queryable busy/ready state.
296
- '''
297
- return False
298
-
299
- def registerMethod(self, name: str, method: Callable[[], None]) -> None:
300
- '''Register a named zero-argument callable.
301
-
302
- Registered methods can be invoked by name via :meth:`execute`.
303
-
304
- Parameters
305
- ----------
306
- name : str
307
- Method name used with :meth:`execute`.
308
- method : callable
309
- Zero-argument callable to invoke.
310
- '''
311
- self._methods[name] = method
312
-
313
- @property
314
- def methods(self) -> list[str]:
315
- '''Names of all registered instrument methods.'''
316
- return list(self._methods.keys())
317
-
318
257
  @QtCore.Slot(str)
319
258
  def execute(self, key: str) -> None:
320
259
  '''Call a registered method by name.
@@ -334,4 +273,5 @@ class QAbstractInstrument(QtCore.QObject):
334
273
  method = self._methods[key]
335
274
  method()
336
275
 
276
+
337
277
  __all__ = ['QAbstractInstrument']