MCPcopy Create free account
hub / github.com/LabPy/lantz / AmplitudeScannerShutter

Class AmplitudeScannerShutter

examples/backend_frontend/myapps.py:97–148  ·  view source on GitHub ↗

A complex application that requires a function generator, an oscilloscope and a shutter. We could subclass AmplitudeScanner, but we have chosen to embed it instead.

Source from the content-addressed store, hash-verified

95
96
97class AmplitudeScannerShutter(Backend):
98 """A complex application that requires a function generator, an
99 oscilloscope and a shutter.
100
101 We could subclass AmplitudeScanner, but we have chosen to embed it instead.
102 """
103
104 # Enumerate drivers required by the backend marking them with InstrumentSlot
105 osci = InstrumentSlot
106 fungen = InstrumentSlot
107 shutter = InstrumentSlot
108
109 # Embedded apps (Notice we embed the backend, not the Frontend)
110 scanner = AmplitudeScanner
111
112 # This signal will be emited when new data is available.
113 new_data = QtCore.Signal(object, object)
114
115 def scan_amplitude(self, amplitudes):
116 """Open the shutter an then for each amplitude:
117 - scan the amplitude of the function generator.
118 - sleeps .3 seconds.
119 - measures the trace of the oscilloscope.
120 - yields amplitude, data for each amplitude.
121
122 Finally, close the shutter.
123
124 :param amplitudes: iterable of amplitudes.
125 """
126 self.shutter.opened = True
127
128 # We use the embedded app to perform the actual operation.
129 # Notice that we have not explicitly instantiated the AmplitudeScanner
130 # nor provided the instruments. Lantz has done this in the back
131 # connecting InstrumentsSlots by name.
132 # i.e. self.osci is self.scanner.osci
133 for amplitude, data in self.scanner.scan_amplitude(amplitudes):
134 self.new_data.emit(amplitude, data)
135 yield amplitude, data
136
137 self.shutter.opened = False
138
139 def _scan_amplitude(self, amplitudes):
140 """Because scan_amplitude is a generator, this helper functions is used
141 to iterate over all the items.
142 """
143 return list(self.scan_amplitude(amplitudes))
144
145 def default_scan(self):
146 """A linear scan from 1 to 19 Volts.
147 """
148 return list(self.scan_amplitude(Q_(list(range(1, 20)), 'volt')))
149
150
151class AmplitudeScannerShutterUi(Frontend):

Callers 2

example3-cli2.pyFile · 0.90
example4-gui2.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected