コード例 #1
0
class MoglabsXRF_RFClient(QtWidgets.QGroupBox):
    name = None
    DeviceProxy = None
    updateID = np.random.randint(0, 2**31 - 1)
    amplitudeDisplayUnits = [(0, 'dBm')]
    amplitudeDigits = None
    frequencyDisplayUnits = [(-6, 'uHz'), (-3, 'mHz'), (0, 'Hz'), (3, 'kHz'),
                             (6, 'MHz'), (9, 'GHz')]
    frequencyDigits = None
    fmgainDisplayUnits = [(6, 'MHz/V')]
    fmgainDigits = None
    amgainDisplayUnits = [(0, '%')]
    amgainDigits = None

    spinboxWidth = 100

    def __init__(self, reactor, cxn=None):
        QtWidgets.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)
        self.connectLabrad()

    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name,
                             host=os.getenv('LABRADHOST'),
                             password='')
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)
        # self.fm_dev1 = self.device.fm_dev1

    def populateGUI(self):
        self.nameLabel = ClickableLabel('<b>' + self.name + '</b>')

        self.channelLabel1 = ClickableLabel('<b>' + 'CH 1' + '</b>')
        self.stateButton1 = QtWidgets.QPushButton()
        self.stateButton1.setCheckable(True)

        self.frequencyLabel1 = ClickableLabel('Frequency: ')
        self.frequencyBox1 = SuperSpinBox(self.device._frequency_range,
                                          self.frequencyDisplayUnits,
                                          self.frequencyDigits)
        self.frequencyBox1.setFixedWidth(self.spinboxWidth)

        self.amplitudeLabel1 = ClickableLabel('Amplitude: ')
        self.amplitudeBox1 = SuperSpinBox(self.device._amplitude_range,
                                          self.amplitudeDisplayUnits,
                                          self.amplitudeDigits)
        self.amplitudeBox1.setFixedWidth(self.spinboxWidth)

        #############

        self.channelLabel2 = ClickableLabel('<b>' + 'CH 2' + '</b>')
        self.stateButton2 = QtWidgets.QPushButton()
        self.stateButton2.setCheckable(True)

        self.frequencyLabel2 = ClickableLabel('Frequency: ')
        self.frequencyBox2 = SuperSpinBox(self.device._frequency_range,
                                          self.frequencyDisplayUnits,
                                          self.frequencyDigits)
        self.frequencyBox2.setFixedWidth(self.spinboxWidth)

        self.amplitudeLabel2 = ClickableLabel('Amplitude: ')
        self.amplitudeBox2 = SuperSpinBox(self.device._amplitude_range,
                                          self.amplitudeDisplayUnits,
                                          self.amplitudeDigits)
        self.amplitudeBox2.setFixedWidth(self.spinboxWidth)

        ##############

        self.layout = QtWidgets.QGridLayout()
        self.layout.addWidget(self.nameLabel, 0, 0, 1, 2,
                              QtCore.Qt.AlignHCenter)

        self.layout.addWidget(self.channelLabel1, 1, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.stateButton1, 1, 1)
        self.layout.addWidget(self.frequencyLabel1, 2, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.frequencyBox1, 2, 1)
        self.layout.addWidget(self.amplitudeLabel1, 3, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.amplitudeBox1, 3, 1)

        self.layout.addWidget(self.channelLabel2, 4, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.stateButton2, 4, 1)
        self.layout.addWidget(self.frequencyLabel2, 5, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.frequencyBox2, 5, 1)
        self.layout.addWidget(self.amplitudeLabel2, 6, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.amplitudeBox2, 6, 1)

        self.setLayout(self.layout)

        self.setWindowTitle(self.name)
        self.setFixedSize(120 + self.spinboxWidth, 250)

        self.connectSignals()
        self.reactor.callInThread(self.getAll)

    def getAll(self):
        self.getRFState1()
        self.getFrequency1()
        self.getAmplitude1()

        self.getRFState2()
        self.getFrequency2()
        self.getAmplitude2()

    def getRFState1(self):
        rf_state1 = self.device.rf_state1
        self.reactor.callFromThread(self.displayRFState1, rf_state1)

    def displayRFState1(self, rf_state1):
        if rf_state1:
            self.stateButton1.setChecked(1)
            self.stateButton1.setText('RF ON')
        else:
            self.stateButton1.setChecked(0)
            self.stateButton1.setText('RF OFF')

    def getFrequency1(self):
        frequency1 = self.device.frequency1
        self.reactor.callFromThread(self.displayFrequency1, frequency1)

    def displayFrequency1(self, frequency1):
        self.frequencyBox1.display(frequency1)

    def getAmplitude1(self):
        amplitude1 = self.device.amplitude1
        self.reactor.callFromThread(self.displayAmplitude1, amplitude1)

    def displayAmplitude1(self, amplitude1):
        self.amplitudeBox1.display(amplitude1)

    def getRFState2(self):
        rf_state2 = self.device.rf_state2
        self.reactor.callFromThread(self.displayRFState2, rf_state2)

    def displayRFState2(self, rf_state2):
        if rf_state2:
            self.stateButton2.setChecked(1)
            self.stateButton2.setText('RF ON')
        else:
            self.stateButton2.setChecked(0)
            self.stateButton2.setText('RF OFF')

    def getFrequency2(self):
        frequency2 = self.device.frequency2
        self.reactor.callFromThread(self.displayFrequency2, frequency2)

    def displayFrequency2(self, frequency2):
        self.frequencyBox2.display(frequency2)

    def getAmplitude2(self):
        amplitude2 = self.device.amplitude2
        self.reactor.callFromThread(self.displayAmplitude2, amplitude2)

    def displayAmplitude2(self, amplitude2):
        self.amplitudeBox2.display(amplitude2)

    def connectSignals(self):
        self.nameLabel.clicked.connect(self.onNameLabelClick)

        self.frequencyLabel1.clicked.connect(self.onFrequencyLabelClick1)
        self.amplitudeLabel1.clicked.connect(self.onAmplitudeLabelClick1)

        self.stateButton1.released.connect(self.onNewRFState1)
        self.frequencyBox1.returnPressed.connect(self.onNewFrequency1)
        self.amplitudeBox1.returnPressed.connect(self.onNewAmplitude1)

        self.frequencyLabel2.clicked.connect(self.onFrequencyLabelClick2)
        self.amplitudeLabel2.clicked.connect(self.onAmplitudeLabelClick2)

        self.stateButton2.released.connect(self.onNewRFState2)
        self.frequencyBox2.returnPressed.connect(self.onNewFrequency2)
        self.amplitudeBox2.returnPressed.connect(self.onNewAmplitude2)

    def onNameLabelClick(self):
        self.reactor.callInThread(self.getAll)

    def onFrequencyLabelClick1(self):
        self.reactor.callInThread(self.getFrequency1)

    def onAmplitudeLabelClick1(self):
        self.reactor.callInThread(self.getAmplitude1)

    def onNewRFState1(self):
        rf_state1 = self.stateButton1.isChecked()
        self.reactor.callInThread(self.setRFState1, rf_state1)

    def setRFState1(self, rf_state1):
        self.device.rf_state1 = rf_state1
        self.reactor.callFromThread(self.displayRFState1, rf_state1)

    def onNewFrequency1(self):
        frequency1 = self.frequencyBox1.value()
        self.reactor.callInThread(self.setFrequency1, frequency1)

    def setFrequency1(self, frequency1):
        self.device.frequency1 = frequency1
        self.reactor.callFromThread(self.displayFrequency1, frequency1)

    def onNewAmplitude1(self):
        amplitude1 = self.amplitudeBox1.value()
        self.reactor.callInThread(self.setAmplitude1, amplitude1)

    def setAmplitude1(self, amplitude1):
        self.device.amplitude1 = amplitude1
        self.reactor.callFromThread(self.displayAmplitude1, amplitude1)

    ######################

    def onFrequencyLabelClick2(self):
        self.reactor.callInThread(self.getFrequency2)

    def onAmplitudeLabelClick2(self):
        self.reactor.callInThread(self.getAmplitude2)

    def onNewRFState2(self):
        rf_state2 = self.stateButton2.isChecked()
        self.reactor.callInThread(self.setRFState2, rf_state2)

    def setRFState2(self, rf_state2):
        self.device.rf_state2 = rf_state2
        self.reactor.callFromThread(self.displayRFState2, rf_state2)

    def onNewFrequency2(self):
        frequency2 = self.frequencyBox2.value()
        self.reactor.callInThread(self.setFrequency2, frequency2)

    def setFrequency2(self, frequency2):
        self.device.frequency2 = frequency2
        self.reactor.callFromThread(self.displayFrequency2, frequency2)

    def onNewAmplitude2(self):
        amplitude2 = self.amplitudeBox2.value()
        self.reactor.callInThread(self.setAmplitude2, amplitude2)

    def setAmplitude2(self, amplitude2):
        self.device.amplitude2 = amplitude2
        self.reactor.callFromThread(self.displayAmplitude2, amplitude2)

    @inlineCallbacks
    def connectLabrad(self):
        from labrad.wrappers import connectAsync
        self.cxn = yield connectAsync(name=self.name,
                                      host=os.getenv('LABRADHOST'),
                                      password='')
        yield self.cxn.update.signal__signal(self.updateID)
        yield self.cxn.update.addListener(listener=self.receiveUpdate,
                                          source=None,
                                          ID=self.updateID)
        yield self.cxn.update.register(self.name)

    def receiveUpdate(self, c, updateJson):
        # to be updated
        update = json.loads(updateJson)

        state1 = update.get('state1')
        if state1 is not None:
            self.displayState1(state1)
        frequency1 = update.get('frequency1')
        if frequency1 is not None:
            self.displayFrequency1(frequency1)
        amplitude1 = update.get('amplitude1')
        if amplitude1 is not None:
            self.displayAmplitude1(amplitude1)

        state2 = update.get('state2')
        if state2 is not None:
            self.displayState2(state2)
        frequency2 = update.get('frequency2')
        if frequency2 is not None:
            self.displayFrequency2(frequency2)
        amplitude2 = update.get('amplitude2')
        if amplitude2 is not None:
            self.displayAmplitude2(amplitude2)

    def closeEvent(self, x):
        self.reactor.stop()
コード例 #2
0
class RFClient(QtGui.QGroupBox):
    name = None
    DeviceProxy = None
    updateID = np.random.randint(0, 2**31 - 1)
    amplitudeDisplayUnits = [(0, 'dBm')]
    amplitudeDigits = None
    frequencyDisplayUnits = [(-6, 'uHz'), (-3, 'mHz'), (0, 'Hz'), (3, 'kHz'), 
                             (6, 'MHz'), (9, 'GHz')]
    frequencyDigits = None
    spinboxWidth = 100
    
    def __init__(self, reactor, cxn=None):
        QtGui.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)
        self.connectLabrad()
    
    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name)
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)

    def populateGUI(self):
        self.nameLabel = ClickableLabel('<b>' + self.name + '</b>')
        self.stateButton = QtGui.QPushButton()
        self.stateButton.setCheckable(True)
        
        self.frequencyLabel = ClickableLabel('Frequency: ')
        self.frequencyBox = SuperSpinBox(self.device._frequency_range, 
                                          self.frequencyDisplayUnits, 
                                          self.frequencyDigits)
        self.frequencyBox.setFixedWidth(self.spinboxWidth)
        
        self.amplitudeLabel = ClickableLabel('Amplitude: ')
        self.amplitudeBox = SuperSpinBox(self.device._amplitude_range, 
                                          self.amplitudeDisplayUnits, 
                                          self.amplitudeDigits)
        self.amplitudeBox.setFixedWidth(self.spinboxWidth)
        
        self.layout = QtGui.QGridLayout() 
        self.layout.addWidget(self.nameLabel, 0, 0, 1, 1, 
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.stateButton, 0, 1)
        self.layout.addWidget(self.frequencyLabel, 1, 0, 1, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.frequencyBox, 1, 1)
        self.layout.addWidget(self.amplitudeLabel, 2, 0, 1, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.amplitudeBox, 2, 1)
        self.setLayout(self.layout)

        self.setWindowTitle(self.name)
        self.setFixedSize(110 + self.spinboxWidth, 100)
        
        self.connectSignals()
        self.reactor.callInThread(self.getAll)

    def getAll(self):
        self.getState()
        self.getFrequency()
        self.getAmplitude()

    def getState(self):
        state = self.device.state
        self.reactor.callFromThread(self.displayState, state)

    def displayState(self, state):
        if state:
            self.stateButton.setChecked(1)
            self.stateButton.setText('On')
        else:
            self.stateButton.setChecked(0)
            self.stateButton.setText('Off')

    def getFrequency(self):
        frequency = self.device.frequency
        self.reactor.callFromThread(self.displayFrequency, frequency)

    def displayFrequency(self, frequency):
        self.frequencyBox.display(frequency)
    
    def getAmplitude(self):
        amplitude = self.device.amplitude
        self.reactor.callFromThread(self.displayAmplitude, amplitude)

    def displayAmplitude(self, amplitude):
        self.amplitudeBox.display(amplitude)

    def connectSignals(self):
        self.nameLabel.clicked.connect(self.onNameLabelClick)
        self.frequencyLabel.clicked.connect(self.onFrequencyLabelClick)
        self.amplitudeLabel.clicked.connect(self.onAmplitudeLabelClick)
        
        self.stateButton.released.connect(self.onNewState)
        self.frequencyBox.returnPressed.connect(self.onNewFrequency)
        self.amplitudeBox.returnPressed.connect(self.onNewAmplitude)
    
    def onNameLabelClick(self):
        self.reactor.callInThread(self.getAll)
    
    def onFrequencyLabelClick(self):
        self.reactor.callInThread(self.getFrequency)
    
    def onAmplitudeLabelClick(self):
        self.reactor.callInThread(self.getAmplitude)
    
    def onNewState(self):
        state = self.stateButton.isChecked()
        self.reactor.callInThread(self.setState, state)
    
    def setState(self, state):
        self.device.state = state
        self.reactor.callFromThread(self.displayState, state)
        
    def onNewFrequency(self):
        frequency = self.frequencyBox.value()
        self.reactor.callInThread(self.setFrequency, frequency)

    def setFrequency(self, frequency):
        self.device.frequency = frequency
        self.reactor.callFromThread(self.displayFrequency, frequency)
    
    def onNewAmplitude(self):
        amplitude = self.amplitudeBox.value()
        self.reactor.callInThread(self.setAmplitude, amplitude)

    def setAmplitude(self, amplitude):
        self.device.amplitude = amplitude
        self.reactor.callFromThread(self.displayAmplitude, amplitude)
    
    @inlineCallbacks
    def connectLabrad(self):
        from labrad.wrappers import connectAsync
        self.cxn = yield connectAsync(name=self.name)
        yield self.cxn.update.signal__signal(self.updateID)
        yield self.cxn.update.addListener(listener=self.receiveUpdate, source=None, 
                                          ID=self.updateID)
        yield self.cxn.update.register(self.name)
    
    def receiveUpdate(self, c, updateJson):
        update = json.loads(updateJson)
        state = update.get('state')
        if state is not None:
            self.displayState(state)
        frequency = update.get('frequency')
        if frequency is not None:
            self.displayFrequency(frequency)
        amplitude = update.get('amplitude')
        if amplitude is not None:
            self.displayAmplitude(amplitude)
    
    def closeEvent(self, x):
        self.reactor.stop()
コード例 #3
0
class MSQClient(QtWidgets.QWidget):
    """ Widget for Msquared server control """
    msquared_servername = None
    msquared_devicename = None
    wlm_servername = None

    update_time1 = 2500  # [ms]
    update_time2 = 5000  # [ms]
    lock_update_time = 2500  # [ms]
    is_on_OneShot = False

    frequency_units = ['THz', 'GHz']
    wavelength_units = ['nm', 'um']

    etalon_range = (0, 100)  # Etalon tuner
    etalon_units = [(0, '%')]
    etalon_digits = 2
    etalon_max = 196

    resonator_range = (0, 100)  # Resonator tuner
    resonator_units = [(0, '%')]
    resonator_digits = 4
    resonator_max = 196

    fineresonator_range = (0, 100)  # Resonator Fine tuner
    fineresonator_units = [(0, '%')]
    fineresonator_digits = 2

    PD_range = (0, 100)
    PD_units = [(0, 'V')]
    PD_digits = 4

    xy_range = (0, 100)  # X, Y tuner
    xy_units = [(0, '%')]
    xy_digits = 2

    wl_range = (696, 877)  # Rough wavelength
    wl_units = [(0, 'nm')]
    wl_digits = 1

    spinbox_height = 30
    spinbox_width = 80
    update_id = np.random.randint(0, 2**31 - 1)

    def __init__(self, reactor, cxn, msquared_servername, msquared_devicename,
                 wlm_servername, parent):
        super(MSQClient, self).__init__()
        try:
            self.reactor = reactor
            self.cxn = cxn
            self.msquared_servername = msquared_servername
            self.msquared_devicename = msquared_devicename
            self.wlm_servername = wlm_servername
            self.parent = parent
            self.connect()
        except Exception as e:
            print(e)
            traceback.print_exc()

    @inlineCallbacks
    def connect(self):
        if self.cxn == None:
            self.cxn = connection()
            yield self.cxn.connect()
        self.populate()
        yield self.connectWidgets()

    def populate(self):
        self.nameLabel = ClickableLabel('<b> MSquared Laser Control </b>')

        self.statusLabel = ClickableLabel('<b> MSquared Status: </b>')
        self.statusText = QtWidgets.QLineEdit()
        self.statusText.setReadOnly(True)
        self.statusText.setAlignment(QtCore.Qt.AlignCenter)
        self.statusText.setFixedHeight(40)
        self.statusText.setFont(QtGui.QFont('Arial', 10))

        self.wlmLabel = ClickableLabel('<b> HF Wavemeter: </b>')
        self.wlmText = QtWidgets.QLineEdit()
        self.wlmText.setReadOnly(True)
        self.wlmText.setAlignment(QtCore.Qt.AlignCenter)
        self.wlmText.setFixedHeight(40)
        self.wlmText.setFont(QtGui.QFont('Arial', 10))

        self.lockButton = QtWidgets.QPushButton()
        self.lockButton.setCheckable(True)
        self.lockButton.setFixedHeight(40)
        self.lockButton.setFixedWidth(120)

        self.oneshotButton = QtWidgets.QPushButton()
        self.oneshotButton.setFixedHeight(40)
        self.oneshotButton.setFixedWidth(120)
        self.oneshotButton.setText('One Shot Alignment')

        self.manualButton = QtWidgets.QPushButton()
        self.manualButton.setFixedHeight(40)
        self.manualButton.setFixedWidth(120)
        self.manualButton.setText('Manual Alignment')

        self.EtalonTunerLabel = ClickableLabel('Etalon Tuner: ')
        self.EtalonTunerBox = SuperSpinBox(self.etalon_range,
                                           self.etalon_units,
                                           self.etalon_digits)
        self.EtalonTunerBox.setFixedHeight(self.spinbox_height)
        self.EtalonTunerBox.setFixedWidth(self.spinbox_width)

        self.ResonatorTunerLabel = ClickableLabel('Resonator Tuner: ')
        self.ResonatorTunerBox = SuperSpinBox(self.resonator_range,
                                              self.resonator_units,
                                              self.resonator_digits)
        self.ResonatorTunerBox.setFixedHeight(self.spinbox_height)
        self.ResonatorTunerBox.setFixedWidth(self.spinbox_width)

        self.ResonatorFineTunerLabel = ClickableLabel(
            'Resonator Fine \n Tuner:')
        self.ResonatorFineTunerLabel.setAlignment(QtCore.Qt.AlignRight
                                                  | QtCore.Qt.AlignVCenter)
        self.ResonatorFineTunerBox = SuperSpinBox(self.fineresonator_range,
                                                  self.fineresonator_units,
                                                  self.fineresonator_digits)
        self.ResonatorFineTunerBox.setFixedHeight(self.spinbox_height)
        self.ResonatorFineTunerBox.setFixedWidth(self.spinbox_width)

        self.XLabel = ClickableLabel('X Tuner: ')
        self.XBox = SuperSpinBox(self.xy_range, self.xy_units, self.xy_digits)
        self.XBox.setFixedHeight(self.spinbox_height)
        self.XBox.setFixedWidth(self.spinbox_width)

        self.YLabel = ClickableLabel('Y Tuner: ')
        self.YBox = SuperSpinBox(self.xy_range, self.xy_units, self.xy_digits)
        self.YBox.setFixedHeight(self.spinbox_height)
        self.YBox.setFixedWidth(self.spinbox_width)

        self.wavelengthLabel = ClickableLabel(
            'Preset wavelength: \n (rough tune)')
        self.wavelengthLabel.setAlignment(QtCore.Qt.AlignRight
                                          | QtCore.Qt.AlignVCenter)
        self.wavelengthBox = SuperSpinBox(self.wl_range, self.wl_units,
                                          self.wl_digits)
        self.wavelengthBox.setFixedHeight(self.spinbox_height)
        self.wavelengthBox.setFixedWidth(self.spinbox_width)

        self.EtalonPDLabel = ClickableLabel('Etalon PD DC:')
        self.EtalonPDLabel.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignVCenter)
        self.EtalonPDBox = SuperSpinBox(self.PD_range, self.PD_units,
                                        self.PD_digits)
        self.EtalonPDBox.setFixedHeight(self.spinbox_height)
        self.EtalonPDBox.setFixedWidth(self.spinbox_width)
        self.EtalonPDBox.setReadOnly(True)

        self.OutputPDLabel = ClickableLabel('Output PD:')
        self.OutputPDLabel.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignVCenter)
        self.OutputPDBox = SuperSpinBox(self.PD_range, self.PD_units,
                                        self.PD_digits)
        self.OutputPDBox.setFixedHeight(self.spinbox_height)
        self.OutputPDBox.setFixedWidth(self.spinbox_width)
        self.OutputPDBox.setReadOnly(True)

        self.layout = QtWidgets.QGridLayout()
        self.layout.addWidget(self.nameLabel, 1, 0, 1, 6,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.statusLabel, 2, 0, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.statusText, 2, 1, 2, 5)
        self.layout.addWidget(self.wlmLabel, 4, 0, 2, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.wlmText, 4, 1, 2, 5)
        self.layout.addWidget(self.lockButton, 6, 0, 2, 2,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.oneshotButton, 6, 2, 2, 2,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.manualButton, 6, 4, 2, 2,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.EtalonTunerLabel, 8, 0, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.EtalonTunerBox, 8, 1, 2, 2,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.XLabel, 8, 3, 2, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.XBox, 8, 4, 2, 2, QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.ResonatorTunerLabel, 10, 0, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ResonatorTunerBox, 10, 1, 2, 2,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.YLabel, 10, 3, 2, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.YBox, 10, 4, 2, 2, QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.ResonatorFineTunerLabel, 12, 0, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ResonatorFineTunerBox, 12, 1, 2, 2,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.wavelengthLabel, 12, 3, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.wavelengthBox, 12, 4, 2, 2,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.EtalonPDLabel, 14, 0, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.EtalonPDBox, 14, 1, 2, 2,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.OutputPDLabel, 14, 3, 2, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.OutputPDBox, 14, 4, 2, 2,
                              QtCore.Qt.AlignLeft)

        self.layout.setContentsMargins(5, 5, 5, 5)
        self.layout.setSpacing(5)
        self.setLayout(self.layout)
        self.setFixedSize(450, 450)

    @inlineCallbacks
    def connectWidgets(self):
        self.msquared_server = yield self.cxn.get_server(
            self.msquared_servername)
        yield self.msquared_server.signal__update(self.update_id)
        yield self.msquared_server.addListener(listener=self.receive_update,
                                               source=None,
                                               ID=self.update_id)
        self.wlm_server = yield self.cxn.get_server(self.wlm_servername)
        self.nameLabel.clicked.connect(self.onNameLabelClick)
        self.wlmLabel.clicked.connect(self.getWLM)
        self.lockButton.released.connect(self.onLockButton)
        self.oneshotButton.released.connect(self.onOneShotButton)
        self.manualButton.released.connect(self.onManualButton)
        self.XBox.returnPressed.connect(self.onX)
        self.YBox.returnPressed.connect(self.onY)
        self.wavelengthBox.returnPressed.connect(self.onWavelength)
        self.EtalonPDLabel.clicked.connect(self.getEtalonPD)
        self.OutputPDLabel.clicked.connect(self.getOutputPD)

        self.timer1 = QtCore.QTimer(self)
        self.timer1.timeout.connect(self.timer_task1)
        self.timer1.start(self.update_time1)

        self.timer2 = QtCore.QTimer(self)
        self.timer2.timeout.connect(self.timer_task2)
        self.timer2.start(self.update_time2)

        self.lock_timer = QtCore.QTimer(self)
        self.lock_timer.timeout.connect(self.lock_timer_task)

        self.getAll()

    def receive_update(self, c, signal_json):
        signal = json.loads(signal_json)
        message = signal.get('alignment_x_auto')
        if message is not None:
            value = message[self.msquared_devicename]
            self.displayX(value)
        message = signal.get('alignment_y_auto')
        if message is not None:
            value = message[self.msquared_devicename]
            self.displayY(value)

    def disable_when_wlm_lock(self, state):
        self.lockButton.setDisabled(state)
        self.EtalonTunerBox.setDisabled(state)
        self.wavelengthBox.setDisabled(state)

        resonator_state = not bool(state ^ self.lockButton.isChecked())
        self.ResonatorTunerBox.setDisabled(resonator_state)
        self.ResonatorFineTunerBox.setDisabled(resonator_state)

    def onNameLabelClick(self):
        self.getAll()

    def timer_task1(self):
        if self.lockButton.isChecked():
            self.getLockState()
        if self.parent.LockClient.lockButton.isChecked():
            self.lock_timer.start(self.lock_update_time)
        else:
            self.lock_timer.stop()

    def timer_task2(self):
        if self.is_on_OneShot:
            self.getOneShotState()
            self.getOutputPD()
            self.getEtalonPD()

    def lock_timer_task(self):
        self.getWLM()
        self.getResonatorTuner()
        self.getEtalonPD()
        self.getOutputPD()

    def getAll(self):
        self.getLockState()
        self.getEtalonTuner()
        self.getResonatorTuner()
        self.getX()
        self.getY()
        self.getWavelength()
        self.getWLM()
        self.getEtalonPD()
        self.getOutputPD()

    def onLockButton(self):
        lock_state = self.lockButton.isChecked()
        self.setLockState(lock_state)

    @inlineCallbacks
    def setLockState(self, lock_state):
        if lock_state:
            request_json = json.dumps({self.msquared_devicename: True})
        else:
            request_json = json.dumps({self.msquared_devicename: False})
        yield self.msquared_server.etalon_lock(request_json)
        self.displayLockState(lock_state)

    @inlineCallbacks
    def getLockState(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.etalon_lock(request_json)
        response = json.loads(response_json)
        message = response[self.msquared_devicename]
        if message == True:
            lock_state = True
        elif message == False:
            lock_state = False
        else:
            lock_state = False
            self.statusText.setText(message)
            request_json = json.dumps({self.msquared_devicename: False})
            yield self.msquared_server.etalon_lock(request_json)
        self.displayLockState(lock_state)

    def displayLockState(self, lock_state):
        if lock_state == True:
            self.lockButton.setChecked(1)
            self.lockButton.setText('Remove Etalon Lock')
            self.statusText.setText('Etalon lock ON')
            self.ResonatorTunerBox.setDisabled(False)
            self.ResonatorFineTunerBox.setDisabled(False)
        else:
            self.lockButton.setChecked(0)
            self.lockButton.setText('Apply Etalon Lock')
            self.statusText.setText('Etalon lock OFF')
            self.ResonatorTunerBox.setDisabled(True)
            self.ResonatorFineTunerBox.setDisabled(True)
        self.parent.toggle_lock()

    @inlineCallbacks
    def onOneShotButton(self):
        if not self.is_on_OneShot:
            self.is_on_OneShot = True
            mode = 4  # 4 for One Shot
            request_json = json.dumps({self.msquared_devicename: mode})
            yield self.msquared_server.beam_alignment(request_json)
            self.statusText.setText('One Shot Alignment Started...')
            self.oneshotButton.setDisabled(True)
            self.manualButton.setEnabled(True)
            self.XBox.setDisabled(True)
            self.YBox.setDisabled(True)
        else:
            pass

    @inlineCallbacks
    def getOneShotState(self):
        if self.is_on_OneShot:
            request_json = json.dumps({self.msquared_devicename: None})
            response_json = yield self.msquared_server.beam_alignment(
                request_json)
            status = json.loads(response_json).get(self.msquared_devicename)
            if status == True:
                self.is_on_OneShot = False
                self.statusText.setText('One Shot Alignment Completed')
                self.oneshotButton.setDisabled(False)
                self.XBox.setDisabled(False)
                self.YBox.setDisabled(False)
            else:
                pass
        else:
            pass

    @inlineCallbacks
    def onNewEtalonTuner(self):
        value = self.EtalonTunerBox.value()
        request_json = json.dumps({self.msquared_devicename: value})
        yield self.msquared_server.etalon_tune(request_json)
        self.displayEtalonTuner(value)

    @inlineCallbacks
    def getEtalonTuner(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.etalon_tune(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        value_percentage = value / self.etalon_max * 100
        self.displayEtalonTuner(value_percentage)

    def displayEtalonTuner(self, value):
        self.EtalonTunerBox.display(value)

    @inlineCallbacks
    def onNewResonatorTuner(self):
        value = self.ResonatorTunerBox.value()
        request_json = json.dumps({self.msquared_devicename: value})
        yield self.msquared_server.resonator_tune(request_json)
        self.displayResonatorTuner(value)

    @inlineCallbacks
    def getResonatorTuner(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.resonator_tune(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        value_percentage = value / self.resonator_max * 100
        self.displayResonatorTuner(value_percentage)

    def displayResonatorTuner(self, value):
        self.ResonatorTunerBox.display(value)

    @inlineCallbacks
    def onManualButton(self):
        self.is_on_OneShot = False
        self.oneshotButton.setDisabled(False)
        self.XBox.setDisabled(False)
        self.YBox.setDisabled(False)
        mode = 1  # 1 for Manual
        request_json = json.dumps({self.msquared_devicename: mode})
        yield self.msquared_server.beam_alignment(request_json)

    @inlineCallbacks
    def onX(self):
        value = self.XBox.value()
        request_json = json.dumps({self.msquared_devicename: value})
        yield self.msquared_server.alignment_x(request_json)
        self.displayX(value)

    @inlineCallbacks
    def getX(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.alignment_x(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        self.displayX(value)

    def displayX(self, value):
        self.XBox.display(value)

    @inlineCallbacks
    def onY(self):
        value = self.YBox.value()
        request_json = json.dumps({self.msquared_devicename: value})
        yield self.msquared_server.alignment_y(request_json)
        self.displayY(value)

    @inlineCallbacks
    def getY(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.alignment_y(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        self.displayY(value)

    def displayY(self, value):
        self.YBox.display(value)

    @inlineCallbacks
    def onWavelength(self):
        value = self.wavelengthBox.value()
        request_json = json.dumps({self.msquared_devicename: value})
        yield self.msquared_server.wavelength(request_json)
        self.displayWavelength(value)

    @inlineCallbacks
    def getWavelength(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.wavelength(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        self.displayWavelength(value)

    def displayWavelength(self, value):
        self.wavelengthBox.display(value)

    @inlineCallbacks
    def getWLM(self):
        units = self.parent.PIDClient.unitsBox.currentText()
        channel = self.parent.PIDClient.channelBox.currentText()
        if units in self.frequency_units:
            value = yield self.wlm_server.get_frequency(int(channel))
        elif units in self.wavelength_units:
            value = yield self.wlm_server.get_wavelength(int(channel))
        self.displayWLM(value, units)

    def displayWLM(self, value, units):
        self.wlmText.setText('{} {}'.format(value, units))

    @inlineCallbacks
    def getEtalonPD(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.etalon_pd(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        self.displayEtalonPD(value)

    def displayEtalonPD(self, value):
        self.EtalonPDBox.display(value)

    @inlineCallbacks
    def getOutputPD(self):
        request_json = json.dumps({self.msquared_devicename: None})
        response_json = yield self.msquared_server.output_pd(request_json)
        response = json.loads(response_json)
        value = response.get(self.msquared_devicename)
        self.displayOutputPD(value)

    def displayOutputPD(self, value):
        self.OutputPDBox.display(value)

    def closeEvent(self, x):
        pass
コード例 #4
0
class RedMOTRFClient(QtWidgets.QGroupBox):
    name = None
    DeviceProxy = None
    updateID = np.random.randint(0, 2**31 - 1)
    amplitudeDisplayUnits = [(0, 'dBm')]
    amplitudeDigits = None
    frequencyDisplayUnits = [(-6, 'uHz'), (-3, 'mHz'), (0, 'Hz'), (3, 'kHz'), 
                             (6, 'MHz'), (9, 'GHz')]
    frequencyDigits = None
    fmfreqDisplayUnits = [(-6, 'uHz/V'), (-3, 'mHz/V'), (0, 'Hz/V'), (3, 'kHz/V'), 
                             (6, 'MHz/V'), (9, 'GHz/V')]
    fmfreqDigits = None
    spinboxWidth = 120
    
    def __init__(self, reactor, cxn=None):
        QtWidgets.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)
        self.connectLabrad()
    
    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name, host=os.getenv('LABRADHOST') , password = '')
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)

    def populateGUI(self):
        self.nameLabel = ClickableLabel('<b>' + self.name + '</b>')
        
        self.beatnoteLabel = ClickableLabel('Beatnote Freq: ')
        self.beatnoteBox = SuperSpinBox(self.device._frequency_range, 
                                          self.frequencyDisplayUnits, 
                                          self.frequencyDigits)
        self.beatnoteBox.setFixedWidth(self.spinboxWidth)
        
        self.isotopeLabel = ClickableLabel('Choose isotope: ')
        self.isotopeBox = QtWidgets.QComboBox()
        isotope = 'Sr-88'
        isotope_list = ['Sr-87, F=11/2', 'Sr-87, F=9/2', 'Sr-86', 'Sr-84']
        
        self.isotopeBox.addItem(isotope)
        self.isotopeBox.addItems(isotope_list)
        
        self.transitionfreqLabel = ClickableLabel('1S0-3P1 freq: ')
        self.transitionfreqBox = QtWidgets.QDoubleSpinBox()
        self.transitionfreqBox.setRange(0, 3e9)
        self.transitionfreqBox.setReadOnly(True)
        self.transitionfreqBox.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
        self.transitionfreqBox.setDecimals(2)
        self.transitionfreqBox.setGroupSeparatorShown(True)
        self.transitionfreqBox.setSuffix(' MHz')
        
        self.redafreqLabel = ClickableLabel('Red-A freq: ')
        self.redafreqBox = QtWidgets.QDoubleSpinBox()
        self.redafreqBox.setRange(0, 3e9)
        self.redafreqBox.setReadOnly(True)
        self.redafreqBox.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
        self.redafreqBox.setDecimals(2)
        self.transitionfreqBox.setGroupSeparatorShown(True)
        self.transitionfreqBox.setSuffix(' MHz')
        
        # CH 2
        self.name2Label = ClickableLabel('<b>' + 'CH2' + '</b>')
        self.state2Button = QtWidgets.QPushButton()
        self.state2Button.setCheckable(True)
        
        self.layout = QtWidgets.QGridLayout() 
        self.layout.addWidget(self.nameLabel, 0, 0, 1, 2, 
                              QtCore.Qt.AlignCenter)
        
        self.layout.addWidget(self.beatnoteLabel, 1, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.beatnoteBox, 1, 1)
        
        self.layout.addWidget(self.isotopeLabel, 2, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.isotopeBox, 2, 1)
        
        self.layout.addWidget(self.transitionfreqLabel, 3, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.transitionfreqBox, 3, 1)        

        self.layout.addWidget(self.redafreqLabel, 4, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.redafreqBox, 4, 1)   
        
        self.layout.addWidget(self.name2Label, 5, 0, 1, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.state2Button, 5, 1)
        
        self.setLayout(self.layout)

        self.setWindowTitle(self.name)
        self.setFixedSize(120 + self.spinboxWidth, 170)
        
        self.connectSignals()
        self.reactor.callInThread(self.getAll)
        
    def getAll(self):
        self.getFrequency()
        self.getTransitionFreq()
        self.getRFState2()
    
    def getFrequency(self):
        frequency = self.device.freq1
        self.reactor.callFromThread(self.displayFrequency, frequency)

    def displayFrequency(self, frequency):
        self.beatnoteBox.display(frequency)
        
    def getRFState2(self):
        rf_state2 = self.device.state2
        self.reactor.callFromThread(self.displayRFState2, rf_state2)
    
    def displayRFState2(self, rf_state2):
        if rf_state2:
            self.state2Button.setChecked(1)
            self.state2Button.setText('RF ON')
        else:
            self.state2Button.setChecked(0)
            self.state2Button.setText('RF OFF')
            
    def onNewRFState2(self):
        rf_state2 = self.state2Button.isChecked()
        self.reactor.callInThread(self.setRFState2, rf_state2)
    
    def setRFState2(self, rf_state2):
        self.device.state2 = rf_state2
        self.reactor.callFromThread(self.displayRFState2, rf_state2)
    
    def connectSignals(self):
        self.nameLabel.clicked.connect(self.onNameLabelClick)
        self.beatnoteLabel.clicked.connect(self.onBeatnoteLabelClick)
        
        self.beatnoteBox.returnPressed.connect(self.onNewBeatnote)
        self.isotopeBox.currentIndexChanged.connect(self.onIsotopeBoxChange)
        
        self.name2Label.clicked.connect(self.onNameLabelClick)
        self.state2Button.released.connect(self.onNewRFState2)
    
    def onIsotopeBoxChange(self):
        self.reactor.callInThread(self.getTransitionFreq)
    
    def getTransitionFreq(self):
        index = self.isotopeBox.currentIndex()
        self.reactor.callFromThread(self.displayTransitionFreq, index)
    
    def displayTransitionFreq(self, index):
        sr_88 = 434829121.300
        sr_87_F11_2 = 434827879.860
        sr_87_F9_2 = 434829343.010
        if index == 0:
            self.transitionfreqBox.setValue(sr_88)
        elif index == 1:
            self.transitionfreqBox.setValue(sr_87_F11_2)
        elif index == 2:
            self.transitionfreqBox.setValue(sr_87_F9_2)
    
    def onNameLabelClick(self):
        self.reactor.callInThread(self.getAll)
    
    def onBeatnoteLabelClick(self):
        self.reactor.callInThread(self.getFrequency)

    def onNewBeatnote(self):
        frequency = self.beatnoteBox.value()
        self.reactor.callInThread(self.setBeatnote, frequency)

    def setBeatnote(self, frequency):
        self.device.freq1 = frequency
        self.reactor.callFromThread(self.displayFrequency, frequency)
    
    @inlineCallbacks
    def connectLabrad(self):
        from labrad.wrappers import connectAsync
        self.cxn = yield connectAsync(name=self.name, host=os.getenv('LABRADHOST'), password='')
        yield self.cxn.update.signal__signal(self.updateID)
        yield self.cxn.update.addListener(listener=self.receiveUpdate, source=None, 
                                          ID=self.updateID)
        yield self.cxn.update.register(self.name)
    
    def receiveUpdate(self, c, updateJson):
        update = json.loads(updateJson)
        state2 = update.get('state2')
        if state2 is not None:
            self.displayRFState2(state2)
        frequency = update.get('frequency')
        if frequency is not None:
            self.displayFrequency(frequency)
        amplitude = update.get('amplitude')
        if amplitude is not None:
            self.displayAmplitude(amplitude)
    
    def closeEvent(self, x):
        self.reactor.stop()
コード例 #5
0
class ECDLClient(QtGui.QGroupBox):
    name = None
    DeviceProxy = None

    def __init__(self, reactor):
        QtGui.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)

    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name)
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)
        self.reactor.callFromThread(self.connectSignals)

    def populateGUI(self):
        self.nameLabel = ClickableLabel('<b>' + self.name + '</b>')
        self.stateButton = QtGui.QPushButton()
        self.stateButton.setCheckable(1)

        self.piezoVoltageLabel = ClickableLabel('Piezo Voltage: ')
        self.piezoVoltageBox = SuperSpinBox(self.device._piezo_voltage_range,
                                            self.piezoVoltageDisplayUnits,
                                            self.piezoVoltageDigits)
        self.piezoVoltageBox.setFixedWidth(self.spinboxWidth)
        self.piezoVoltageBox.display(0)

        self.diodeCurrentLabel = ClickableLabel('Diode Current: ')
        self.diodeCurrentBox = SuperSpinBox(self.device._diode_current_range,
                                            self.diodeCurrentDisplayUnits,
                                            self.diodeCurrentDigits)
        self.diodeCurrentBox.setFixedWidth(self.spinboxWidth)
        self.diodeCurrentBox.display(0)

        self.layout = QtGui.QGridLayout()
        self.layout.addWidget(self.nameLabel, 0, 0, 1, 1,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.stateButton, 0, 1)
        self.layout.addWidget(self.piezoVoltageLabel, 1, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.piezoVoltageBox, 1, 1)
        self.layout.addWidget(self.diodeCurrentLabel, 2, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.diodeCurrentBox, 2, 1)
        self.setLayout(self.layout)

        self.setWindowTitle(self.name)
        self.setFixedSize(120 + self.spinboxWidth, 100)

        self.reactor.callInThread(self.getAll)

    def getAll(self):
        self.getState()
        self.getPiezoVoltage()
        self.getDiodeCurrent()

    def getState(self):
        state = self.device.state
        self.reactor.callFromThread(self.displayState, state)

    def displayState(self, state):
        if state:
            self.stateButton.setChecked(1)
            self.stateButton.setText('On')
        else:
            self.stateButton.setChecked(0)
            self.stateButton.setText('Off')

    def getPiezoVoltage(self):
        piezoVoltage = self.device.piezo_voltage
        self.reactor.callFromThread(self.displayPiezoVoltage, piezoVoltage)

    def displayPiezoVoltage(self, piezoVoltage):
        self.piezoVoltageBox.display(piezoVoltage)

    def getDiodeCurrent(self):
        diodeCurrent = self.device.diode_current
        self.reactor.callFromThread(self.displayDiodeCurrent, diodeCurrent)

    def displayDiodeCurrent(self, diodeCurrent):
        self.diodeCurrentBox.display(diodeCurrent)

    def callInThread(self, callable, *args, **kwargs):
        def f():
            return self.reactor.callInThread(callable, *args, **kwargs)

        return f

    def connectSignals(self):
        self.hasNewState = False
        self.hasNewPiezoVoltage = False
        self.hasNewDiodeCurrent = False

        self.stateButton.released.connect(self.onNewState)
        self.piezoVoltageBox.returnPressed.connect(self.onNewPiezoVoltage)
        self.diodeCurrentBox.returnPressed.connect(self.onNewDiodeCurrent)

        self.nameLabel.clicked.connect(self.callInThread(self.getAll))
        self.piezoVoltageLabel.clicked.connect(
            self.callInThread(self.getPiezoVoltage))
        self.diodeCurrentLabel.clicked.connect(
            self.callInThread(self.getDiodeCurrent))

    def onNewState(self):
        state = self.stateButton.isChecked()
        self.reactor.callInThread(self.setState, state)

    def onNewPiezoVoltage(self):
        piezoVoltage = self.piezoVoltageBox.value()
        self.reactor.callInThread(self.setPiezoVoltage, piezoVoltage)

    def onNewDiodeCurrent(self):
        diodeCurrent = self.diodeCurrentBox.value()
        self.reactor.callInThread(self.setDiodeCurrent, diodeCurrent)

    def setState(self, state):
        self.device.state = state
        self.reactor.callFromThread(self.displayState, state)

    def setPiezoVoltage(self, piezoVoltage):
        self.device.piezo_voltage = piezoVoltage
        self.reactor.callFromThread(self.displayPiezoVoltage, piezoVoltage)

    def setDiodeCurrent(self, diodeCurrent):
        self.device.diode_current = diodeCurrent
        self.reactor.callFromThread(self.displayDiodeCurrent, diodeCurrent)

    def closeEvent(self, x):
        self.reactor.stop()
コード例 #6
0
class PIDClient(QtWidgets.QWidget):
    
    wlm_lock_servername = None
    
    units = None
    units_list = ['nm', 'GHz']
    
    channel_list = ['1', '2', '3', '4']
    
    gain_range = (0, 100)
    gain_units = [(0, '')]
    gain_digits = 2
    
    setpoint_range = (0, 1e15)
    setpoint_units = [(0, '')]
    setpoint_digits = 6
    
    offset_range = (0, 100)  # Resonator offset
    offset_units = [(0, '%')]
    offset_digits = 4
    
    spinbox_height = 30
    spinbox_width = 80
    
    config_directory = 'C:\\LabRad\\SrA\\msquared_wlm_lock'
    
    def __init__(self, reactor, cxn, wlm_lock_servername, parent):
        super(PIDClient, self).__init__(None)
        try:
            self.reactor = reactor
            self.cxn = cxn
            self.wlm_lock_servername = wlm_lock_servername
            self.parent = parent
            self.connect()
        except Exception as e:
            print(e)
            traceback.print_exc()            
    
    @inlineCallbacks
    def connect(self):
        if self.cxn == None:
            self.cxn = connection()
            yield self.cxn.connect()
        self.populate()
        yield self.connectWidgets()
    
    def populate(self):
        self.nameLabel =  ClickableLabel('<b> PID Settings </b>')
        
        self.loadButton = QtWidgets.QPushButton()
        self.loadButton.setText('Load Settings')
        self.loadButton.setFixedHeight(40)
        self.loadButton.setFixedWidth(100)
        self.saveButton = QtWidgets.QPushButton()
        self.saveButton.setText('Save Settings')
        self.saveButton.setFixedHeight(40)
        self.saveButton.setFixedWidth(self.spinbox_width*1.5)
        
        self.setpointLabel = ClickableLabel('Set point: ')
        self.setpointBox = SuperSpinBox(self.setpoint_range, self.setpoint_units,
                                        self.setpoint_digits)
        self.setpointBox.setFixedHeight(self.spinbox_height)
        self.setpointBox.setFixedWidth(self.spinbox_width*1.5)
    
        self.offsetLabel = ClickableLabel('Offset: ')
        self.offsetBox = SuperSpinBox(self.offset_range, self.offset_units,
                                        self.offset_digits)
        self.offsetBox.setFixedHeight(self.spinbox_height)
        self.offsetBox.setFixedWidth(self.spinbox_width*1.5)
        
        self.unitsLabel = ClickableLabel('<b> Setpoint Units: </b>')
        self.unitsBox = QtWidgets.QComboBox()
        self.unitsBox.addItems(self.units_list)
        
        self.channelLabel = ClickableLabel('<b> WLM Channel: </b>')
        self.channelBox = QtWidgets.QComboBox()
        self.channelBox.addItems(self.channel_list)
        
        self.OverallGainLabel = ClickableLabel('Overall Gain: ')
        self.OverallGainBox = SuperSpinBox(self.gain_range, self.gain_units,
                                        4)
        self.OverallGainBox.setFixedHeight(self.spinbox_height)
        self.OverallGainBox.setFixedWidth(self.spinbox_width)
        self.PGainLabel = ClickableLabel('P Gain: ')
        self.PGainBox = SuperSpinBox(self.gain_range, self.gain_units,
                                        self.gain_digits)
        self.PGainBox.setFixedHeight(self.spinbox_height)
        self.PGainBox.setFixedWidth(self.spinbox_width)
        self.IGainLabel = ClickableLabel('I Gain: ')
        self.IGainBox = SuperSpinBox(self.gain_range, self.gain_units,
                                        self.gain_digits)
        self.IGainBox.setFixedHeight(self.spinbox_height)
        self.IGainBox.setFixedWidth(self.spinbox_width)
        self.DGainLabel = ClickableLabel('D Gain: ')
        self.DGainBox = SuperSpinBox(self.gain_range, self.gain_units,
                                        self.gain_digits)
        self.DGainBox.setFixedHeight(self.spinbox_height)
        self.DGainBox.setFixedWidth(self.spinbox_width)
        
        
        self.layout = QtWidgets.QGridLayout()
        self.layout.addWidget(self.nameLabel, 1, 0, 3, 1, 
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.loadButton, 1, 1, 3, 2, 
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.saveButton, 1, 3, 3, 2, 
                              QtCore.Qt.AlignHCenter)
        
        self.layout.addWidget(self.setpointLabel, 4, 0, 3, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.setpointBox, 4, 1, 3, 3, 
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.offsetLabel, 7, 0, 3, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.offsetBox, 7, 1, 3, 3, 
                              QtCore.Qt.AlignLeft)
        
        self.layout.addWidget(self.unitsLabel, 4, 3, 2, 2,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.unitsBox, 6, 3, 2, 2,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.channelLabel, 8, 3, 2, 2,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.channelBox, 10, 3, 2, 2,
                              QtCore.Qt.AlignHCenter)
        
        self.layout.addWidget(self.OverallGainLabel, 10, 0, 3, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.OverallGainBox, 10, 1, 3, 1,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.PGainLabel, 13, 0, 3, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.PGainBox, 13, 1, 3, 1,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.IGainLabel, 16, 0, 3, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.IGainBox, 16, 1, 3, 1,
                              QtCore.Qt.AlignLeft)
        self.layout.addWidget(self.DGainLabel, 19, 0, 3, 1, 
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.DGainBox, 19, 1, 3, 1,
                              QtCore.Qt.AlignLeft)
        
        self.layout.setContentsMargins(5, 5, 5, 5)
        self.layout.setSpacing(10)
        self.setLayout(self.layout)
        self.setFixedSize(400, 300)

    # def updateParameters(self, parameter_values):
    #     self.parameter_values = parameter_values
    #     self.displaySequence(self.sequence)
    
    @inlineCallbacks
    def connectWidgets(self):
        self.wlm_lock_server = yield self.cxn.get_server(self.wlm_lock_servername)
        
        self.nameLabel.clicked.connect(self.getAll)
        self.loadButton.clicked.connect(self.browseLoad)
        self.saveButton.clicked.connect(self.browseSave)
        self.setpointBox.returnPressed.connect(self.onNewPIDsetpoint)
        self.offsetBox.returnPressed.connect(self.onNewPIDoffset)
        self.OverallGainBox.returnPressed.connect(self.onNewPIDparams)
        self.PGainBox.returnPressed.connect(self.onNewPIDparams)
        self.IGainBox.returnPressed.connect(self.onNewPIDparams)
        self.DGainBox.returnPressed.connect(self.onNewPIDparams)
        self.unitsBox.currentIndexChanged.connect(self.onUnitsChange)
        self.channelBox.currentIndexChanged.connect(self.onChannelChange)
        
        self.getAll()
    
    def disconnectWidgets(self):
        try:
            self.nameLabel.disconnect()
            self.loadButton.disconnect()
            self.saveButton.disconnect()
            self.setpointBox.disconnect()
            self.offsetBox.disconnect()
            self.OverallGainBox.disconnect()
            self.PGainBox.disconnect()
            self.IGainBox.disconnect()
            self.DGainBox.disconnect()
            self.unitsBox.disconnect()
            self.channelBox.disconnect()
        except:
            pass
    
    def disableAll(self):
        self.loadButton.setDisabled(True)
        self.saveButton.setDisabled(True)
        self.setpointBox.setDisabled(True)
        self.offsetBox.setDisabled(True)
        self.OverallGainBox.setDisabled(True)
        self.PGainBox.setDisabled(True)
        self.IGainBox.setDisabled(True)
        self.DGainBox.setDisabled(True)
        self.unitsBox.setDisabled(True)
        self.channelBox.setDisabled(True)
        self.disconnectWidgets()

    def enableAll(self):
        self.loadButton.setDisabled(False)
        self.saveButton.setDisabled(False)
        self.setpointBox.setDisabled(False)
        self.offsetBox.setDisabled(False)
        self.OverallGainBox.setDisabled(False)
        self.PGainBox.setDisabled(False)
        self.IGainBox.setDisabled(False)
        self.DGainBox.setDisabled(False)
        self.unitsBox.setDisabled(False)
        self.channelBox.setDisabled(False)
        self.connectWidgets()
    
    def getAll(self):
        self.getPID()
        self.getWLM()
    
    def disable_when_wlm_lock(self, state):
        self.unitsBox.setDisabled(state)
        self.channelBox.setDisabled(state)
        self.setpointBox.setDisabled(state)
        self.offsetBox.setDisabled(state)
        self.loadButton.setDisabled(state)
    
    @inlineCallbacks
    def loadSettingsFromServer(self):
        current_settings_json = yield self.wlm_lock_server.load_current_settings()
        current_settings = json.loads(current_settings_json)
        self.displaySettings(current_settings)

    def browseLoad(self):
        # timestr = time.strftime(self.time_format)
        directory = self.config_directory
        if not os.path.exists(directory):
            directory = self.config_directory.split('{}')[0]
        filepath = QtWidgets.QFileDialog().getOpenFileName(directory=directory)[0]  # Added [0]
        if filepath:
            self.loadConfig(filepath)
    
    def loadConfig(self, filepath):
        with open(filepath, 'r') as infile:
            settings = json.load(infile)
        self.displaySettings(settings)       
        
    def browseSave(self):
        directory = self.config_directory
        if not os.path.exists(directory):
            directory = self.config_directory.split('{}')[0]
        filepath = QtWidgets.QFileDialog().getSaveFileName(directory=directory)[0]
        if filepath:
            self.saveConfig(filepath)
    
    @inlineCallbacks
    def saveConfig(self, filepath):
        current_settings_json = yield self.wlm_lock_server.load_current_settings()
        with open(filepath, 'w') as f:
            f.write(current_settings_json)

    def displaySettings(self, settings):
        pid_settings = settings['pid']
        wlm_settings = settings['wlm']
        
        setpoint = pid_settings['setpoint']
        offset = pid_settings['offset']
        overall_gain = pid_settings['overall_gain']
        prop_gain = pid_settings['prop_gain']
        int_gain = pid_settings['int_gain']
        diff_gain = pid_settings['diff_gain']
        
        units = wlm_settings['units']
        channel = wlm_settings['channel']
        
        self.displayPIDsetpoint(setpoint)
        self.displayPIDoffset(offset)
        self.displayPIDparams(overall_gain, prop_gain, int_gain, diff_gain)
        self.displayUnits(units)
        self.displayChannel(channel)    


    def getPID(self):
        self.getPIDsetpoint()
        self.getPIDoffset()
        self.getPIDparams()
    
    @inlineCallbacks
    def getPIDsetpoint(self):
        setpoint = yield self.wlm_lock_server.get_setpoint()
        self.displayPIDsetpoint(setpoint)
        
    @inlineCallbacks
    def getPIDoffset(self):
        offset = yield self.wlm_lock_server.get_offset()
        self.displayPIDoffset(offset)
    
    @inlineCallbacks
    def getPIDparams(self):
        overall_gain = yield self.wlm_lock_server.get_gain()
        prop_gain = yield self.wlm_lock_server.get_prop_gain()
        int_gain = yield self.wlm_lock_server.get_int_gain()
        diff_gain = yield self.wlm_lock_server.get_diff_gain()
        self.displayPIDparams(overall_gain, prop_gain, int_gain, diff_gain)
    
    def displayPIDsetpoint(self, setpoint):
        self.setpointBox.display(setpoint)

    def displayPIDoffset(self, offset):
        self.offsetBox.display(offset)
        
    def displayPIDparams(self, overall_gain, prop_gain, int_gain, diff_gain):
        self.OverallGainBox.display(overall_gain)
        self.PGainBox.display(prop_gain)
        self.IGainBox.display(int_gain)
        self.DGainBox.display(diff_gain)
    
    def onNewPIDsetpoint(self):
        setpoint = self.setpointBox.value()
        self.setPIDsetpoint(setpoint)

    def onNewPIDoffset(self):
        offset = self.offsetBox.value()
        self.setPIDoffset(offset)
    
    def onNewPIDparams(self):
        overall_gain = self.OverallGainBox.value()
        prop_gain = self.PGainBox.value()
        int_gain = self.IGainBox.value()
        diff_gain = self.DGainBox.value()
        self.setPIDparams(overall_gain, prop_gain, int_gain, diff_gain)

    @inlineCallbacks
    def setPIDsetpoint(self, setpoint):
        yield self.wlm_lock_server.set_setpoint(setpoint)
        self.displayPIDsetpoint(setpoint)
        
    @inlineCallbacks
    def setPIDoffset(self, offset):
        yield self.wlm_lock_server.set_offset(offset)
        self.displayPIDoffset(offset)
        
    @inlineCallbacks
    def setPIDparams(self, overall_gain, prop_gain, int_gain, diff_gain):
        yield self.wlm_lock_server.set_gain(overall_gain)
        yield self.wlm_lock_server.set_prop_gain(prop_gain)
        yield self.wlm_lock_server.set_int_gain(int_gain)
        yield self.wlm_lock_server.set_diff_gain(diff_gain)
        self.displayPIDparams(overall_gain, prop_gain, int_gain, diff_gain)
    
    def getWLM(self):
        self.getUnits()
        self.getChannel() 
        
    def onUnitsChange(self):
        value = self.unitsBox.currentText()
        self.setUnits(value)
    
    @inlineCallbacks
    def setUnits(self, value):
        yield self.wlm_lock_server.set_units(value)
    
    @inlineCallbacks
    def getUnits(self):
        units = yield self.wlm_lock_server.get_units()
        self.displayUnits(units)
    
    def displayUnits(self, units):
        index = self.unitsBox.findText(units, QtCore.Qt.MatchFixedString)
        if index >= 0:
            self.unitsBox.setCurrentIndex(index)
    
    def onChannelChange(self):
        value = self.channelBox.currentText()
        self.setChannel(int(value))

    @inlineCallbacks
    def setChannel(self, value):
        yield self.wlm_lock_server.set_channel(value)
        
    @inlineCallbacks
    def getChannel(self):
        channel = yield self.wlm_lock_server.get_channel()
        self.displayChannel(channel)
        
    def displayChannel(self, channel):
        index = self.channelBox.findText(str(channel), QtCore.Qt.MatchFixedString)
        if index >= 0:
            self.channelBox.setCurrentIndex(index)
    
    def closeEvent(self, x):
        # super(WLMLockControllerClient, self).closeEvent(x)
        # self.PIDClient.wlm_lock_server.remove_etalon_lock(10) # TODO: Remove Etalon Lock when exit
        try:
            self.reactor.stop()
            x.accept()
        except:
            pass       
コード例 #7
0
class ECDLClient(QtGui.QGroupBox):
    def __init__(self, reactor, cxn=None):
        QtGui.QDialog.__init__(self)
        self.reactor = reactor
        self.cxn = cxn
        self.connect()

    @inlineCallbacks
    def connect(self):
        if self.cxn is None:
            self.cxn = connection()
            cname = '{} - {} - client'.format(self.servername, self.name)
            yield self.cxn.connect(name=cname)
        yield self.select_device()
        self.populateGUI()
        yield self.connectSignals()
        yield self.requestValues()

    @inlineCallbacks
    def select_device(self):
        server = yield self.cxn.get_server(self.servername)
        request = {self.name: {}}
        yield server.initialize_devices(json.dumps(request))
        request = {self.name: None}
        info_json = yield server.get_device_infos(json.dumps(request))
        info = json.loads(info_json)
        for key, value in info[self.name].items():
            setattr(self, key, value)

    def populateGUI(self):
        self.state_button = QtGui.QPushButton()
        self.state_button.setCheckable(1)

        self.piezo_voltage_box = SuperSpinBox(self.piezo_voltage_range,
                                              self.piezo_voltage_display_units,
                                              self.piezo_voltage_digits)
        self.piezo_voltage_box.setFixedWidth(self.spinbox_width)
        self.piezo_voltage_box.display(0)

        self.diode_current_box = SuperSpinBox(self.diode_current_range,
                                              self.diode_current_display_units,
                                              self.diode_current_digits)
        self.diode_current_box.setFixedWidth(self.spinbox_width)
        self.diode_current_box.display(0)

        self.layout = QtGui.QGridLayout()

        row = 0
        self.layout.addWidget(QtGui.QLabel('<b>' + self.name + '</b>'), 0, 0,
                              1, 1, QtCore.Qt.AlignHCenter)
        if 'state' in self.update_parameters:
            self.layout.addWidget(self.state_button, 0, 1)
        else:
            self.layout.addWidget(QtGui.QLabel('always on'), 0, 0, 1, 1,
                                  QtCore.Qt.AlignHCenter)
        if 'piezo_voltage' in self.update_parameters:
            row += 1
            self.piezo_voltage_label = ParameterLabel('Piezo Voltage: ')
            self.layout.addWidget(self.piezo_voltage_label, row, 0, 1, 1,
                                  QtCore.Qt.AlignRight)
            self.layout.addWidget(self.piezo_voltage_box, row, 1)
        if 'diode_current' in self.update_parameters:
            row += 1
            self.diode_current_label = ParameterLabel('Diode Current: ')
            self.layout.addWidget(self.diode_current_label, row, 0, 1, 1,
                                  QtCore.Qt.AlignRight)
            self.layout.addWidget(self.diode_current_box, row, 1)

        self.setWindowTitle(self.name)
        self.setLayout(self.layout)
        self.setFixedSize(120 + self.spinbox_width, 100)

    @inlineCallbacks
    def connectSignals(self):
        self.hasNewState = False
        self.hasNewPiezoVoltage = False
        self.hasNewDiodeCurrent = False
        server = yield self.cxn.get_server(self.servername)
        yield server.signal__update(self.update_id)
        yield server.addListener(listener=self.receive_update,
                                 source=None,
                                 ID=self.update_id)
        yield self.cxn.add_on_connect(self.servername, self.reinitialize)
        yield self.cxn.add_on_disconnect(self.servername, self.disable)

        self.state_button.released.connect(self.onNewState)
        self.piezo_voltage_box.returnPressed.connect(self.onNewPiezoVoltage)
        self.diode_current_box.returnPressed.connect(self.onNewDiodeCurrent)

        if 'piezo_voltage' in self.update_parameters:
            self.piezo_voltage_label.clicked.connect(self.requestValues)
        if 'diode_current' in self.update_parameters:
            self.diode_current_label.clicked.connect(self.requestValues)

        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.writeValues)
        self.timer.start(self.update_time)

    @inlineCallbacks
    def requestValues(self, c=None):
        server = yield self.cxn.get_server(self.servername)
        request = {self.name: None}
        for parameter in self.update_parameters:
            yield getattr(server, parameter + 's')(json.dumps(request))

    def receive_update(self, c, signal_json):
        signal = json.loads(signal_json)
        for message_type, message in signal.items():
            device_message = message.get(self.name)
            if (message_type == 'states') and (device_message is not None):
                self.free = False
                if device_message:
                    self.state_button.setChecked(1)
                    self.state_button.setText('On')
                else:
                    self.state_button.setChecked(0)
                    self.state_button.setText('Off')
                self.free = True
            if (message_type == 'piezo_voltages') and (device_message
                                                       is not None):
                self.free = False
                self.piezo_voltage_box.display(device_message)
                self.free = True
            if (message_type == 'diode_currents') and (device_message
                                                       is not None):
                self.free = False
                self.diode_current_box.display(device_message)
                self.free = True

    @inlineCallbacks
    def onNewState(self):
        if self.free:
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: None}
            response = yield server.states(json.dumps(request))
            server_state = json.loads(response)[self.name]
            if server_state == self.state:
                request = {self.name: None}
                if self.state:
                    yield server.shutdown(json.dumps(request))
                else:
                    yield server.warmup(json.dumps(request))

    def onNewPiezoVoltage(self):
        if self.free:
            self.hasNewPiezoVoltage = True

    def onNewDiodeCurrent(self):
        if self.free:
            self.hasNewDiodeCurrent = True

    @inlineCallbacks
    def writeValues(self):
        if self.hasNewPiezoVoltage:
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: self.piezo_voltage_box.value()}
            yield server.piezo_voltages(json.dumps(request))
            self.hasNewPiezoVoltage = False
        elif self.hasNewDiodeCurrent:
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: self.diode_current_box.value()}
            yield server.diode_currents(json.dumps(request))
            self.hasNewDiodeCurrent = False

    def reinitialize(self):
        self.setDisabled(False)

    def disable(self):
        self.setDisabled(True)

    def closeEvent(self, x):
        self.reactor.stop()
コード例 #8
0
class DIM3000_RFClient(QtWidgets.QGroupBox):
    name = None
    DeviceProxy = None
    updateID = np.random.randint(0, 2**31 - 1)
    amplitudeDisplayUnits = [(0, 'dBm')]
    amplitudeDigits = None
    frequencyDisplayUnits = [(-6, 'uHz'), (-3, 'mHz'), (0, 'Hz'), (3, 'kHz'),
                             (6, 'MHz'), (9, 'GHz')]
    frequencyDigits = None
    fmfreqDisplayUnits = [(-6, 'uHz/V'), (-3, 'mHz/V'), (0, 'Hz/V'),
                          (3, 'kHz/V'), (6, 'MHz/V'), (9, 'GHz/V')]
    fmfreqDigits = None
    spinboxWidth = 80

    def __init__(self, reactor, cxn=None):
        QtWidgets.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)
        self.connectLabrad()

    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name,
                             host=os.getenv('LABRADHOST'),
                             password='')
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)
        self.fm_dev = self.device.fm_dev

    def populateGUI(self):
        self.nameLabel = ClickableLabel('<b>' + self.name + '</b>')
        self.stateButton = QtWidgets.QPushButton()
        self.stateButton.setCheckable(True)

        self.frequencyLabel = ClickableLabel('Frequency: ')
        self.frequencyBox = SuperSpinBox(self.device._frequency_range,
                                         self.frequencyDisplayUnits,
                                         self.frequencyDigits)
        self.frequencyBox.setFixedWidth(self.spinboxWidth)

        self.amplitudeLabel = ClickableLabel('Amplitude: ')
        self.amplitudeBox = SuperSpinBox(self.device._amplitude_range,
                                         self.amplitudeDisplayUnits,
                                         self.amplitudeDigits)
        self.amplitudeBox.setFixedWidth(self.spinboxWidth)

        self.fmstateButton = QtWidgets.QPushButton()
        self.fmfreqBox = SuperSpinBox(self.device._fmfreq_range,
                                      self.fmfreqDisplayUnits,
                                      self.fmfreqDigits)
        self.fmfreqBox.setFixedWidth(self.spinboxWidth)
        self.fmfreqBox.setReadOnly(True)

        self.fmstateButton.setCheckable(True)
        self.fmdevLabel = ClickableLabel('FM Dev: ')
        self.fmdevBox = QtWidgets.QDoubleSpinBox()
        self.fmdevBox.setKeyboardTracking(False)
        self.fmdevBox.setRange(*self.device._fmdev_range)
        #        self.fmdevBox.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
        self.fmdevBox.setDecimals(0)

        self.layout = QtWidgets.QGridLayout()
        self.layout.addWidget(self.nameLabel, 0, 0, 1, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.stateButton, 0, 1)
        self.layout.addWidget(self.frequencyLabel, 1, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.frequencyBox, 1, 1)
        self.layout.addWidget(self.amplitudeLabel, 2, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.amplitudeBox, 2, 1)

        self.layout.addWidget(self.fmstateButton, 3, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.fmfreqBox, 3, 1)
        self.layout.addWidget(self.fmdevLabel, 4, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.fmdevBox, 4, 1)

        self.setLayout(self.layout)

        self.setWindowTitle(self.name)
        self.setFixedSize(120 + self.spinboxWidth, 180)

        self.connectSignals()
        self.reactor.callInThread(self.getAll)

    def getAll(self):
        self.getRFState()
        self.getFMState()
        self.getFrequency()
        self.getAmplitude()
        self.getFMdev()
        self.getFMfreq()

    def getFMdev(self):
        fm_dev = self.fm_dev
        self.reactor.callFromThread(self.displayFMdev, fm_dev)

    def displayFMdev(self, fm_dev):
        self.fmdevBox.setValue(fm_dev)

    def getFMfreq(self):
        fm_freq = 3200 * 2**int(self.fm_dev)
        self.reactor.callFromThread(self.displayFMfreq, fm_freq)

    def displayFMfreq(self, fm_freq):
        self.fmfreqBox.display(fm_freq)

    def getRFState(self):
        rf_state = self.device.state
        self.reactor.callFromThread(self.displayRFState, rf_state)

    def displayRFState(self, rf_state):
        if rf_state:
            self.stateButton.setChecked(1)
            self.stateButton.setText('RF ON')
        else:
            self.stateButton.setChecked(0)
            self.stateButton.setText('RF OFF')

    def getFMState(self):
        fm_state = self.device.fm
        self.reactor.callFromThread(self.displayFMState, fm_state)

    def displayFMState(self, fm_state):
        if fm_state:
            self.fmstateButton.setChecked(1)
            self.fmstateButton.setText('FM ON')
        else:
            self.fmstateButton.setChecked(0)
            self.fmstateButton.setText('FM OFF')

    def getFrequency(self):
        frequency = self.device.frequency
        self.reactor.callFromThread(self.displayFrequency, frequency)

    def displayFrequency(self, frequency):
        self.frequencyBox.display(frequency)

    def getAmplitude(self):
        amplitude = self.device.amplitude
        self.reactor.callFromThread(self.displayAmplitude, amplitude)

    def displayAmplitude(self, amplitude):
        self.amplitudeBox.display(amplitude)

    def connectSignals(self):
        self.nameLabel.clicked.connect(self.onNameLabelClick)
        self.frequencyLabel.clicked.connect(self.onFrequencyLabelClick)
        self.amplitudeLabel.clicked.connect(self.onAmplitudeLabelClick)

        self.stateButton.released.connect(self.onNewRFState)
        self.fmstateButton.released.connect(self.onNewFMState)

        self.frequencyBox.returnPressed.connect(self.onNewFrequency)
        self.amplitudeBox.returnPressed.connect(self.onNewAmplitude)

        self.fmdevBox.valueChanged.connect(self.onNewFMDev)

    def onNameLabelClick(self):
        self.reactor.callInThread(self.getAll)

    def onFrequencyLabelClick(self):
        self.reactor.callInThread(self.getFrequency)

    def onAmplitudeLabelClick(self):
        self.reactor.callInThread(self.getAmplitude)

    def onNewRFState(self):
        rf_state = self.stateButton.isChecked()
        self.reactor.callInThread(self.setRFState, rf_state)

    def setRFState(self, rf_state):
        self.device.state = rf_state
        self.reactor.callFromThread(self.displayRFState, rf_state)

    def onNewFMState(self):
        fm_state = self.fmstateButton.isChecked()
        self.reactor.callInThread(self.setFMState, fm_state)

    def setFMState(self, fm_state):
        self.device.fm = fm_state
        self.reactor.callFromThread(self.displayFMState, fm_state)

    def onNewFMDev(self):
        self.fm_dev = self.fmdevBox.value()
        fm_dev = self.fm_dev
        self.reactor.callInThread(self.setFMDev, fm_dev)

    def setFMDev(self, fm_dev):
        self.device.set_fm_dev(fm_dev)
        self.getFMdev()
        self.getFMfreq()

    def onNewFrequency(self):
        frequency = self.frequencyBox.value()
        self.reactor.callInThread(self.setFrequency, frequency)

    def setFrequency(self, frequency):
        self.device.frequency = frequency
        self.reactor.callFromThread(self.displayFrequency, frequency)

    def onNewAmplitude(self):
        amplitude = self.amplitudeBox.value()
        self.reactor.callInThread(self.setAmplitude, amplitude)

    def setAmplitude(self, amplitude):
        self.device.amplitude = amplitude
        self.reactor.callFromThread(self.displayAmplitude, amplitude)

    @inlineCallbacks
    def connectLabrad(self):
        from labrad.wrappers import connectAsync
        self.cxn = yield connectAsync(name=self.name,
                                      host=os.getenv('LABRADHOST'),
                                      password='')
        yield self.cxn.update.signal__signal(self.updateID)
        yield self.cxn.update.addListener(listener=self.receiveUpdate,
                                          source=None,
                                          ID=self.updateID)
        yield self.cxn.update.register(self.name)

    def receiveUpdate(self, c, updateJson):
        update = json.loads(updateJson)
        state = update.get('state')
        if state is not None:
            self.displayState(state)
        frequency = update.get('frequency')
        if frequency is not None:
            self.displayFrequency(frequency)
        amplitude = update.get('amplitude')
        if amplitude is not None:
            self.displayAmplitude(amplitude)

    def closeEvent(self, x):
        self.reactor.stop()
コード例 #9
0
class Repump_RFClient(QtWidgets.QGroupBox):
    name = None
    DeviceProxy = None
    updateID = np.random.randint(0, 2**31 - 1)

    frequencyDisplayUnits = [(0, 'Hz')]
    frequencyDigits = None

    voltageDisplayUnits = [(-3, 'mV')]
    voltageDigits = None

    state = None

    spinboxWidth = 80

    def __init__(self, reactor, cxn=None):
        QtWidgets.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)
        self.connectLabrad()

    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name,
                             host=os.getenv('LABRADHOST'),
                             password='')
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)

    def populateGUI(self):
        self.nameLabel = ClickableLabel('<b>' + self.name + '</b>')

        self.shape1Label = ClickableLabel('679 nm :')

        self.shape1Button = QtWidgets.QPushButton()
        self.shape1Button.setCheckable(True)

        self.dc1Label = ClickableLabel('DC 1 Voltage: ')
        self.dc1Box = SuperSpinBox(self.device._dc_v_range,
                                   self.voltageDisplayUnits,
                                   self.voltageDigits)
        self.dc1Box.setFixedWidth(self.spinboxWidth)

        self.ramp1Label = ClickableLabel('Ramp 1 Freq : ')
        self.ramp1AmpLabel = ClickableLabel('Ramp 1 Amp :')
        self.ramp1OffsetLabel = ClickableLabel('Ramp 1 Offset :')

        self.ramp1FreqBox = SuperSpinBox(self.device._ramp_freq_range,
                                         self.frequencyDisplayUnits,
                                         self.frequencyDigits)
        self.ramp1FreqBox.setFixedWidth(self.spinboxWidth)

        self.ramp1AmpBox = SuperSpinBox(self.device._dc_v_range,
                                        self.voltageDisplayUnits,
                                        self.voltageDigits)
        self.ramp1AmpBox.setFixedWidth(self.spinboxWidth)

        self.ramp1OffsetBox = SuperSpinBox(self.device._dc_v_range,
                                           self.voltageDisplayUnits,
                                           self.voltageDigits)
        self.ramp1OffsetBox.setFixedWidth(self.spinboxWidth)

        self.shape2Label = ClickableLabel('707 nm :')

        self.shape2Button = QtWidgets.QPushButton()
        self.shape2Button.setCheckable(True)

        self.dc2Label = ClickableLabel('DC 2 Voltage: ')
        self.dc2Box = SuperSpinBox(self.device._dc_v_range,
                                   self.voltageDisplayUnits,
                                   self.voltageDigits)
        self.dc2Box.setFixedWidth(self.spinboxWidth)

        self.ramp2Label = ClickableLabel('Ramp 2 Freq : ')
        self.ramp2AmpLabel = ClickableLabel('Ramp 2 Amp :')
        self.ramp2OffsetLabel = ClickableLabel('Ramp 2 Offset :')

        self.ramp2FreqBox = SuperSpinBox(self.device._ramp_freq_range,
                                         self.frequencyDisplayUnits,
                                         self.frequencyDigits)
        self.ramp2FreqBox.setFixedWidth(self.spinboxWidth)

        self.ramp2AmpBox = SuperSpinBox(self.device._dc_v_range,
                                        self.voltageDisplayUnits,
                                        self.voltageDigits)
        self.ramp2AmpBox.setFixedWidth(self.spinboxWidth)

        self.ramp2OffsetBox = SuperSpinBox(self.device._dc_v_range,
                                           self.voltageDisplayUnits,
                                           self.voltageDigits)
        self.ramp2OffsetBox.setFixedWidth(self.spinboxWidth)

        self.layout = QtWidgets.QGridLayout()
        self.layout.addWidget(self.nameLabel, 0, 0, 1, 2,
                              QtCore.Qt.AlignCenter)

        self.layout.addWidget(self.shape1Label, 1, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.shape1Button, 1, 1)

        self.layout.addWidget(self.dc1Label, 2, 0, 1, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.dc1Box, 2, 1)

        self.layout.addWidget(self.ramp1Label, 3, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ramp1FreqBox, 3, 1)

        self.layout.addWidget(self.ramp1AmpLabel, 4, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ramp1AmpBox, 4, 1)
        self.layout.addWidget(self.ramp1OffsetLabel, 5, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ramp1OffsetBox, 5, 1)

        self.layout.addWidget(self.shape2Label, 6, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.shape2Button, 6, 1)

        self.layout.addWidget(self.dc2Label, 7, 0, 1, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.dc2Box, 7, 1)

        self.layout.addWidget(self.ramp2Label, 8, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ramp2FreqBox, 8, 1)

        self.layout.addWidget(self.ramp2AmpLabel, 9, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ramp2AmpBox, 9, 1)
        self.layout.addWidget(self.ramp2OffsetLabel, 10, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ramp2OffsetBox, 10, 1)

        self.setLayout(self.layout)

        self.setWindowTitle(self.name)
        self.setFixedSize(120 + self.spinboxWidth, 300)

        self.connectSignals()
        self.reactor.callInThread(self.getAll)

    def getAll(self):
        self.getShape1()
        self.getShape2()

    def onShape1Button(self):
        shape1 = self.shape1Button.isChecked()
        self.reactor.callInThread(self.setShape1, shape1)

    def setShape1(self, shape1):
        self.device.shape1 = shape1
        self.reactor.callFromThread(self.displayShape1, shape1)

    def getShape1(self):
        shape1 = self.device.shape1
        self.reactor.callFromThread(self.displayShape1, shape1)

    def displayShape1(self, shape1):
        if shape1:
            self.shape1Button.setChecked(1)
            self.shape1Button.setText('DC')
            self.DC1Enable(True)
            self.Ramp1Enable(False)
            self.reactor.callInThread(self.getDC1)
        else:
            self.shape1Button.setChecked(0)
            self.shape1Button.setText('Ramp')
            self.DC1Enable(False)
            self.Ramp1Enable(True)
            self.reactor.callInThread(self.getRamp1)

    def DC1Enable(self, boolean):
        if boolean:
            self.dc1Box.setEnabled(True)
        else:
            self.dc1Box.setDisabled(True)

    def Ramp1Enable(self, boolean):
        if boolean:
            self.ramp1FreqBox.setEnabled(True)
            self.ramp1AmpBox.setEnabled(True)
            self.ramp1OffsetBox.setEnabled(True)
        else:
            self.ramp1FreqBox.setDisabled(True)
            self.ramp1AmpBox.setDisabled(True)
            self.ramp1OffsetBox.setDisabled(True)

    def onShape2Button(self):
        shape2 = self.shape2Button.isChecked()
        self.reactor.callInThread(self.setShape2, shape2)

    def setShape2(self, shape2):
        self.device.shape2 = shape2
        self.reactor.callFromThread(self.displayShape2, shape2)

    def getShape2(self):
        shape2 = self.device.shape2
        self.reactor.callFromThread(self.displayShape2, shape2)

    def displayShape2(self, shape2):
        if shape2:
            self.shape2Button.setChecked(1)
            self.shape2Button.setText('DC')
            self.DC2Enable(True)
            self.Ramp2Enable(False)
            self.reactor.callInThread(self.getDC2)
        else:
            self.shape2Button.setChecked(0)
            self.shape2Button.setText('Ramp')
            self.DC2Enable(False)
            self.Ramp2Enable(True)
            self.reactor.callInThread(self.getRamp2)

    def DC2Enable(self, boolean):
        if boolean:
            self.dc2Box.setEnabled(True)
        else:
            self.dc2Box.setDisabled(True)

    def Ramp2Enable(self, boolean):
        if boolean:
            self.ramp2FreqBox.setEnabled(True)
            self.ramp2AmpBox.setEnabled(True)
            self.ramp2OffsetBox.setEnabled(True)
        else:
            self.ramp2FreqBox.setDisabled(True)
            self.ramp2AmpBox.setDisabled(True)
            self.ramp2OffsetBox.setDisabled(True)

    def connectSignals(self):
        self.nameLabel.clicked.connect(self.onNameLabelClick)

        self.shape1Button.released.connect(self.onShape1Button)
        self.shape2Button.released.connect(self.onShape2Button)

        self.dc1Box.returnPressed.connect(self.onNewDC1)
        self.dc2Box.returnPressed.connect(self.onNewDC2)

        self.ramp1FreqBox.returnPressed.connect(self.onNewRamp1)
        self.ramp1AmpBox.returnPressed.connect(self.onNewRamp1)
        self.ramp1OffsetBox.returnPressed.connect(self.onNewRamp1)

        self.ramp2FreqBox.returnPressed.connect(self.onNewRamp2)
        self.ramp2AmpBox.returnPressed.connect(self.onNewRamp2)
        self.ramp2OffsetBox.returnPressed.connect(self.onNewRamp2)

    def onNameLabelClick(self):
        self.reactor.callInThread(self.getAll)

    def onNewDC1(self):
        dc1 = self.dc1Box.value()
        self.reactor.callInThread(self.setDC1, dc1)

    def setDC1(self, dc1):
        self.device.dc1 = dc1
        self.reactor.callFromThread(self.displayDC1, dc1)

    def getDC1(self):
        dc1 = self.device.dc1
        self.reactor.callFromThread(self.displayDC1, dc1)

    def displayDC1(self, dc1):
        self.dc1Box.display(dc1)

    def onNewRamp1(self):
        freq1 = self.ramp1FreqBox.value()
        amp1 = self.ramp1AmpBox.value()
        offset1 = self.ramp1OffsetBox.value()
        self.reactor.callInThread(self.setRamp1, freq1, amp1, offset1)

    def setRamp1(self, freq1, amp1, offset1):
        self.device.ramp1 = (freq1, amp1, offset1)
        self.reactor.callFromThread(self.displayRamp1, freq1, amp1, offset1)

    def getRamp1(self):
        freq1 = self.device.ramp1[0]
        amp1 = self.device.ramp1[1]
        offset1 = self.device.ramp1[2]
        self.reactor.callFromThread(self.displayRamp1, freq1, amp1, offset1)

    def displayRamp1(self, freq1, amp1, offset1):
        self.ramp1FreqBox.display(freq1)
        self.ramp1AmpBox.display(amp1)
        self.ramp1OffsetBox.display(offset1)

    def onNewDC2(self):
        dc2 = self.dc2Box.value()
        self.reactor.callInThread(self.setDC2, dc2)

    def setDC2(self, dc2):
        self.device.dc2 = dc2
        self.reactor.callFromThread(self.displayDC2, dc2)

    def getDC2(self):
        dc2 = self.device.dc2
        self.reactor.callFromThread(self.displayDC2, dc2)

    def displayDC2(self, dc2):
        self.dc2Box.display(dc2)

    def onNewRamp2(self):
        freq2 = self.ramp2FreqBox.value()
        amp2 = self.ramp2AmpBox.value()
        offset2 = self.ramp2OffsetBox.value()
        self.reactor.callInThread(self.setRamp2, freq2, amp2, offset2)

    def setRamp2(self, freq2, amp2, offset2):
        self.device.ramp2 = (freq2, amp2, offset2)
        self.reactor.callFromThread(self.displayRamp2, freq2, amp2, offset2)

    def getRamp2(self):
        freq2 = self.device.ramp2[0]
        amp2 = self.device.ramp2[1]
        offset2 = self.device.ramp2[2]
        self.reactor.callFromThread(self.displayRamp2, freq2, amp2, offset2)

    def displayRamp2(self, freq2, amp2, offset2):
        self.ramp2FreqBox.display(freq2)
        self.ramp2AmpBox.display(amp2)
        self.ramp2OffsetBox.display(offset2)

    @inlineCallbacks
    def connectLabrad(self):
        from labrad.wrappers import connectAsync
        self.cxn = yield connectAsync(name=self.name,
                                      host=os.getenv('LABRADHOST'),
                                      password='')
        yield self.cxn.update.signal__signal(self.updateID)
        yield self.cxn.update.addListener(listener=self.receiveUpdate,
                                          source=None,
                                          ID=self.updateID)
        yield self.cxn.update.register(self.name)

    def receiveUpdate(self, c, updateJson):
        pass
        # update = json.loads(updateJson)

        # frequency = update.get('frequency')
        # if frequency is not None:
        #     self.displayFrequency(frequency)

    def closeEvent(self, x):
        self.reactor.stop()
コード例 #10
0
class AnalogVoltageManualClient(QtWidgets.QGroupBox):
    hasNewVoltage = False
    mouseHover = pyqtSignal(bool)
    layout = None
    update_time = 100 # [ms]
    voltage_range = (-10., 10.)
    voltage_units = [(0, 'V')]
    voltage_digits = 3
    spinbox_width = 80

    mode = None
    manual_output = None
    
    def __init__(self, reactor, cxn=None, parent=None):
        try:
            QtWidgets.QDialog.__init__(self)
            self.reactor = reactor
            self.cxn = None
            self.parent = parent
            self.sequencer_update_id = np.random.randint(0, 2**31 - 1)
            
            self.connect()
        except Exception as e:
            print(e)
            traceback.print_exc()

    @inlineCallbacks
    def connect(self):
        if self.cxn == None:
            self.cxn = connection()
            yield self.cxn.connect()
        print(1)
        self.populateGUI()
        print(2)
        yield self.connectSignals()
        print(3)
        yield self.getChannelInfo()
        print(4)
        self.updateDisplay()
        print('Connected!')

    @inlineCallbacks
    def get_server_configuration(self):
        yield None

    def populateGUI(self):
        self.mode_button = QtWidgets.QPushButton()
        self.mode_button.setCheckable(1)
        self.mode_button.setFixedWidth(self.spinbox_width)
        
        self.voltage_box = SuperSpinBox(self.voltage_range, self.voltage_units,
                                        self.voltage_digits)
        self.voltage_box.setFixedWidth(self.spinbox_width)
        self.voltage_box.display(0)

        if self.layout is None:
            self.layout = QtWidgets.QGridLayout()

        self.layout.addWidget(QtWidgets.QLabel('<b>'+self.name+'</b>'), 1, 0, 1, 1,
                              QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.mode_button, 1, 1)
        self.layout.addWidget(QtWidgets.QLabel('Voltage: '), 2, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.voltage_box, 2, 1)
        self.setLayout(self.layout)
        self.setFixedSize(100 + self.spinbox_width, 90)

    @inlineCallbacks
    def connectSignals(self):
        server = yield self.cxn.get_server(self.sequencer_servername)
        yield server.signal__update(self.sequencer_update_id)
        yield server.addListener(listener=self.receive_sequencer_update,
                                 source=None, ID=self.sequencer_update_id)
        yield self.cxn.add_on_connect(self.sequencer_servername, self.reinit)
        yield self.cxn.add_on_disconnect(self.sequencer_servername, self.disable)

        self.mode_button.released.connect(self.onNewMode)
        self.voltage_box.returnPressed.connect(self.onNewVoltage)
        self.setMouseTracking(True)
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.writeValues)
        self.timer.start(self.update_time)

    @inlineCallbacks
    def getChannelInfo(self, x=None):
        server = yield self.cxn.get_server(self.sequencer_servername)
        request = {self.board_name: {self.name: None}}
        response_json = yield server.get_channel_infos(json.dumps(request))
        response = json.loads(response_json)
        info = response[self.board_name][self.name]
        for k, v in info.items():
            setattr(self, k, v)

    def updateDisplay(self):
        self.free = False
        if self.mode == 'manual':
            self.mode_button.setChecked(1)
            self.mode_button.setText('Manual')
        if self.mode == 'auto':
            self.mode_button.setChecked(0)
            self.mode_button.setText('Auto')
        if self.manual_output is not None:
            self.voltage_box.display(float(self.manual_output))
        self.free = True

    def receive_sequencer_update(self, c, signal_json):
        signal = json.loads(signal_json)
        for message_type, message in signal.items():
            if message_type == 'channel_manual_outputs':
                manual_output = message.get(self.board_name, {}).get(self.name)
                if manual_output is not None:
                    self.manual_output = float(manual_output)
            if message_type == 'channel_modes':
                mode = message.get(self.board_name, {}).get(self.name)
                if mode is not None:
                    self.mode = mode
        self.updateDisplay()

    def enterEvent(self, c):
        self.mouseHover.emit(True)

    def leaveEvent(self, c):
        self.mouseHover.emit(True)

    @inlineCallbacks
    def onNewMode(self):
        if self.free:
            if self.mode == 'manual':
                mode = 'auto'
            else:
                mode = 'manual'
            server = yield self.cxn.get_server(self.sequencer_servername)
            request = {self.board_name: {self.name: mode}}
            response_json = yield server.channel_modes(json.dumps(request))
            response = json.loads(response_json)
            self.mode = response[self.board_name][self.name]
        self.updateDisplay()


    @inlineCallbacks
    def writeValues(self):
        if self.hasNewVoltage:
            server = yield self.cxn.get_server(self.sequencer_servername)
            manual_output = self.voltage_box.value()
            request = {self.board_name: {self.name: manual_output}}
            response_json = yield server.channel_manual_outputs(json.dumps(request))
            response = json.loads(response_json)
            self.manual_output = response[self.board_name][self.name]
            self.hasNewVoltage = False
        self.updateDisplay()

    def onNewVoltage(self):
        if self.free:
            self.hasNewVoltage = True

    @inlineCallbacks	
    def reinit(self): 
        self.setDisabled(False)
        server = yield self.cxn.get_server(self.servername)
        yield server.signal__update(self.update_id, context=self.context)
        yield server.addListener(listener=self.receive_update, source=None,
                                 ID=self.update_id, context=self.context)
        yield server.send_update()


    def disable(self):
        self.setDisabled(True)
コード例 #11
0
class RFClient(QtGui.QGroupBox):
    update_id = None
    frequency_display_units = None
    frequency_digits = None
    amplitude_display_units = None
    amplitude_digits = None
    offset_display_units = None
    offset_digits = None
    offset_range = None

    def __init__(self, reactor, cxn=None):
        QtGui.QDialog.__init__(self)
        self.reactor = reactor
        self.cxn = cxn
        self.set_defaults()
        self.initialize()

    def set_defaults(self):
        if getattr(self, 'update_id') is None:
            self.update_id = np.random.randint(0, 2**31 - 1)
        if getattr(self, 'frequency_display_units') is None:
            self.frequency_display_units = [(-6, 'uHz'), (-3, 'mHz'),
                                            (0, 'Hz'), (3, 'kHz'), (6, 'MHz'),
                                            (9, 'GHz')]
        if getattr(self, 'frequency_digits') is None:
            self.frequency_digits = 4
        if getattr(self, 'amplitude_display_units') is None:
            self.amplitude_display_units = [(0, '')]
        if getattr(self, 'amplitude_digits') is None:
            self.amplitude_digits = 4
        if getattr(self, 'offset_display_units') is None:
            self.offset_display_units = [(0, 'V')]
        if getattr(self, 'offset_digits') is None:
            self.offset_digits = 4
        if getattr(self, 'offset_range') is None:
            self.offset_range = [0, 0]

    @inlineCallbacks
    def initialize(self):
        if self.cxn is None:
            self.cxn = connection()
            cname = '{} - {} - client'.format(self.servername, self.name)
            yield self.cxn.connect()
        yield self.initialize_device()
        yield self.get_device_info()
        self.populateGUI()
        yield self.connectSignals()
        yield self.requestValues()

    @inlineCallbacks
    def initialize_device(self):
        server = yield self.cxn.get_server(self.servername)
        request = {self.name: {}}
        yield server.initialize_devices(json.dumps(request))

    @inlineCallbacks
    def get_device_info(self):
        server = yield self.cxn.get_server(self.servername)
        request = {self.name: {}}
        response_json = yield server.get_device_infos(json.dumps(request))
        response = json.loads(response_json)
        for k, v in response[self.name].items():
            setattr(self, k, v)

    def populateGUI(self):
        self.state_button = QtGui.QPushButton()
        self.state_button.setCheckable(1)

        self.frequency_box = SuperSpinBox(self.frequency_range,
                                          self.frequency_display_units,
                                          self.frequency_digits)
        self.frequency_box.setFixedWidth(self.spinbox_width)
        self.frequency_box.display(0)

        self.amplitude_box = SuperSpinBox(self.amplitude_range,
                                          self.amplitude_display_units,
                                          self.amplitude_digits)
        self.amplitude_box.setFixedWidth(self.spinbox_width)
        self.amplitude_box.display(0)

        self.offset_box = SuperSpinBox(self.offset_range,
                                       self.offset_display_units,
                                       self.offset_digits)
        self.offset_box.setFixedWidth(self.spinbox_width)
        self.offset_box.display(0)

        self.layout = QtGui.QGridLayout()

        row = 0
        height = 40
        self.layout.addWidget(QtGui.QLabel('<b>' + self.name + '</b>'), 0, 0,
                              1, 1, QtCore.Qt.AlignHCenter)
        if 'state' in self.update_parameters:
            self.layout.addWidget(self.state_button, 0, 1)
        else:
            self.layout.addWidget(QtGui.QLabel('always on'), 0, 0, 1, 1,
                                  QtCore.Qt.AlignHCenter)
        if 'frequency' in self.update_parameters:
            row += 1
            height += 30
            self.layout.addWidget(QtGui.QLabel('Frequency: '), row, 0, 1, 1,
                                  QtCore.Qt.AlignRight)
            self.layout.addWidget(self.frequency_box, row, 1)
        if 'amplitude' in self.update_parameters:
            row += 1
            height += 30
            self.layout.addWidget(QtGui.QLabel('Amplitude: '), row, 0, 1, 1,
                                  QtCore.Qt.AlignRight)
            self.layout.addWidget(self.amplitude_box, row, 1)
        if 'offset' in self.update_parameters:
            row += 1
            height += 30
            self.layout.addWidget(QtGui.QLabel('Offset: '), row, 0, 1, 1,
                                  QtCore.Qt.AlignRight)
            self.layout.addWidget(self.offset_box, row, 1)

        self.setWindowTitle('{} - {} - client'.format(self.servername,
                                                      self.name))
        self.setLayout(self.layout)
        self.setFixedSize(100 + self.spinbox_width, height)

    @inlineCallbacks
    def connectSignals(self):
        self.hasNewState = False
        self.hasNewFrequency = False
        self.hasNewAmplitude = False
        self.hasNewOffset = False
        server = yield self.cxn.get_server(self.servername)
        yield server.signal__update(self.update_id)
        yield server.addListener(listener=self.receive_update,
                                 source=None,
                                 ID=self.update_id)
        yield self.cxn.add_on_connect(self.servername, self.reinitialize)
        yield self.cxn.add_on_disconnect(self.servername, self.disable)

        self.state_button.released.connect(self.onNewState)
        self.frequency_box.returnPressed.connect(self.onNewFrequency)
        self.amplitude_box.returnPressed.connect(self.onNewAmplitude)
        self.offset_box.returnPressed.connect(self.onNewOffset)

        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.writeValues)
        self.timer.start(self.update_time)

    @inlineCallbacks
    def requestValues(self, c=None):
        server = yield self.cxn.get_server(self.servername)
        for parameter in self.update_parameters:
            if parameter == 'frequency':
                method_name = 'frequencies'
            else:
                method_name = parameter + 's'
            method = getattr(server, method_name)
            request = {self.name: None}
            yield method(json.dumps(request))

    def receive_update(self, c, signal_json):
        signal = json.loads(signal_json)
        self.free = False
        for message_type, message in signal.items():
            device_message = message.get(self.name)
            if (message_type == 'states') and (device_message is not None):
                if device_message:
                    self.state_button.setChecked(1)
                    self.state_button.setText('On')
                    self.state = True
                else:
                    self.state_button.setChecked(0)
                    self.state_button.setText('Off')
                    self.state = False

            if (message_type == 'frequencies') and (device_message
                                                    is not None):
                if 'frequency' in self.update_parameters:
                    self.frequency_box.display(device_message)
            if (message_type == 'amplitudes') and (device_message is not None):
                if 'amplitude' in self.update_parameters:
                    self.amplitude_box.display(device_message)
            if (message_type == 'offsets') and (device_message is not None):
                if 'offset' in self.update_parameters:
                    self.offset_box.display(device_message)
        self.free = True

    @inlineCallbacks
    def onNewState(self):
        if self.free:
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: None}
            response = yield server.states(json.dumps(request))
            server_state = json.loads(response)[self.name]
            if server_state == self.state:
                request = {self.name: not self.state}
                yield server.states(json.dumps(request))

    def onNewFrequency(self):
        if self.free:
            self.hasNewFrequency = True

    def onNewAmplitude(self):
        if self.free:
            self.hasNewAmplitude = True

    def onNewOffset(self):
        if self.free:
            self.hasNewOffset = True

    @inlineCallbacks
    def writeValues(self):
        if self.hasNewFrequency:
            self.hasNewFrequency = False
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: self.frequency_box.value()}
            yield server.frequencies(json.dumps(request))
        elif self.hasNewAmplitude:
            self.hasNewAmplitude = False
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: self.amplitude_box.value()}
            yield server.amplitudes(json.dumps(request))
        elif self.hasNewOffset:
            self.hasNewOffset = False
            server = yield self.cxn.get_server(self.servername)
            request = {self.name: self.offset_box.value()}
            yield server.offsets(json.dumps(request))

    def reinitialize(self):
        self.setDisabled(False)

    def disable(self):
        self.setDisabled(True)

    def closeEvent(self, x):
        self.reactor.stop()
コード例 #12
0
class AFGControllerClient(QtWidgets.QGroupBox):
    name = None
    DeviceProxy = None

    updateID = np.random.randint(0, 2**31 - 1)

    scaleDisplayUnits = [(0, '%')]
    scaleDigits = 1

    offsetDisplayUnits = [(-3, 'mV'), (0, 'V')]
    offsetDigits = 3

    spinboxWidth = 100

    def __init__(self, reactor):
        QtWidgets.QDialog.__init__(self)
        self.reactor = reactor
        reactor.callInThread(self.initialize)
        self.connectLabrad()

    @inlineCallbacks
    def connectLabrad(self):
        from labrad.wrappers import connectAsync
        self.cxn = yield connectAsync(name=self.name,
                                      host=os.getenv('LABRADHOST'),
                                      password='')
        yield self.cxn.update.signal__signal(self.updateID)
        yield self.cxn.update.addListener(listener=self.receiveUpdate,
                                          source=None,
                                          ID=self.updateID)
        yield self.cxn.update.register(self.name)

    def receiveUpdate(self, c, updateJson):
        update = json.loads(updateJson)
        dc = update.get('dc')
        if dc is not None:
            self.displayDc(dc)

    def initialize(self):
        import labrad
        cxn = labrad.connect(name=self.name,
                             host=os.getenv('LABRADHOST'),
                             password='')
        self.device = self.DeviceProxy(cxn)
        self.reactor.callFromThread(self.populateGUI)
        self.reactor.callFromThread(self.connectSignals)

    def populateGUI(self):
        self.AFGnameLabel = ClickableLabel('<b> RED MOT AFG </b>')

        self.ch1Label = ClickableLabel('CH1: ')
        self.ch1Button = QtWidgets.QPushButton()
        self.ch1Button.setText('Configure')

        self.scale1Label = ClickableLabel('Scale 1: ')
        self.scale1Box = SuperSpinBox(self.device.scaleRange,
                                      self.scaleDisplayUnits, self.scaleDigits)
        self.scale1Box.setFixedWidth(self.spinboxWidth)

        self.offset1Label = ClickableLabel('Offset 1: ')
        self.offset1Box = SuperSpinBox(self.device.offsetRange,
                                       self.offsetDisplayUnits,
                                       self.offsetDigits)
        self.offset1Box.setFixedWidth(self.spinboxWidth)

        self.ch2Label = ClickableLabel('CH2: ')
        self.ch2Button = QtWidgets.QPushButton()
        self.ch2Button.setText('Configure')

        self.scale2Label = ClickableLabel('Scale 2: ')
        self.scale2Box = SuperSpinBox(self.device.scaleRange,
                                      self.scaleDisplayUnits, self.scaleDigits)
        self.scale2Box.setFixedWidth(self.spinboxWidth)

        self.offset2Label = ClickableLabel('Offset 2: ')
        self.offset2Box = SuperSpinBox(self.device.offsetRange,
                                       self.offsetDisplayUnits,
                                       self.offsetDigits)
        self.offset2Box.setFixedWidth(self.spinboxWidth)

        # lAYOUT #
        self.layout = QtWidgets.QGridLayout()
        self.layout.addWidget(self.AFGnameLabel, 0, 0, 1, 2,
                              QtCore.Qt.AlignHCenter)

        self.layout.addWidget(self.ch1Label, 1, 0, 1, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ch1Button, 1, 1)
        self.layout.addWidget(self.scale1Label, 2, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.scale1Box, 2, 1)
        self.layout.addWidget(self.offset1Label, 3, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.offset1Box, 3, 1)

        self.layout.addWidget(self.ch2Label, 4, 0, 1, 1, QtCore.Qt.AlignRight)
        self.layout.addWidget(self.ch2Button, 4, 1)
        self.layout.addWidget(self.scale2Label, 5, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.scale2Box, 5, 1)
        self.layout.addWidget(self.offset2Label, 6, 0, 1, 1,
                              QtCore.Qt.AlignRight)
        self.layout.addWidget(self.offset2Box, 6, 1)

        self.setWindowTitle(self.name)
        self.setLayout(self.layout)
        self.setFixedSize(180, 200)

        self.reactor.callInThread(self.getAll)

    def getAll(self):
        self.getScale1()
        self.getScale2()

    def connectSignals(self):
        self.AFGnameLabel.clicked.connect(self.onNameLabelClick)

        self.scale1Box.returnPressed.connect(self.onNewScale1)
        self.ch1Button.released.connect(self.onConfigure1)
        self.scale2Box.returnPressed.connect(self.onNewScale2)
        self.ch2Button.released.connect(self.onConfigure2)

    def onNameLabelClick(self):
        self.reactor.callInThread(self.getAll)

    def onConfigure1(self):
        self.reactor.callInThread(self.setConfigure1)

    def setConfigure1(self):
        self.device.stop = 1
        self.device.run = 1

    def onConfigure2(self):
        self.reactor.callInThread(self.setConfigure2)

    def setConfigure2(self):
        self.device.stop = 1
        self.device.run = 1

    def getScale1(self):
        scale1 = self.device.scale1
        self.reactor.callFromThread(self.displayScale1, scale1)

    def displayScale1(self, scale1):
        self.scale1Box.display(scale1)

    def onNewScale1(self):
        scale = self.scale1Box.value()
        self.reactor.callInThread(self.setScale1, scale)

    def setScale1(self, scale):
        self.device.scale1 = scale
        self.reactor.callFromThread(self.displayScale1, scale)

    def getScale2(self):
        scale2 = self.device.scale2
        self.reactor.callFromThread(self.displayScale2, scale2)

    def displayScale2(self, scale2):
        self.scale2Box.display(scale2)

    def onNewScale2(self):
        scale = self.scale2Box.value()
        self.reactor.callInThread(self.setScale2, scale)

    def setScale2(self, scale):
        self.device.scale2 = scale
        self.reactor.callFromThread(self.displayScale2, scale)

    def closeEvent(self, x):
        super(AFGControllerClient, self).closeEvent(x)
        self.reactor.callFromThread(self.reactor.stop)