예제 #1
0
class Voltage(PluginBase):
    qtcb_voltage = pyqtSignal(int)
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Voltage Bricklet', version)
        
        self.vol = BrickletVoltage(uid, ipcon)
        
        self.qtcb_voltage.connect(self.cb_voltage)
        self.vol.register_callback(self.vol.CALLBACK_VOLTAGE,
                                   self.qtcb_voltage.emit) 
        
        self.voltage_label = CurrentLabel('Voltage: ')
        
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Voltage [mV]', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.voltage_label)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)
        
    def start(self):
        async_call(self.vol.get_voltage, None, self.cb_voltage, self.increase_error_count)
        async_call(self.vol.set_voltage_callback_period, 100, None, self.increase_error_count)
        
        self.plot_widget.stop = False
        
    def stop(self):
        async_call(self.vol.set_voltage_callback_period, 0, None, self.increase_error_count)
        
        self.plot_widget.stop = True

    def get_url_part(self):
        return 'voltage'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletVoltage.DEVICE_IDENTIFIER

    def get_current_value(self):
        return self.current_value

    def cb_voltage(self, voltage):
        self.current_value = voltage
        self.voltage_label.setText(str(voltage/1000.0))
예제 #2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Voltage Bricklet', version)
        
        self.vol = BrickletVoltage(uid, ipcon)
        
        self.qtcb_voltage.connect(self.cb_voltage)
        self.vol.register_callback(self.vol.CALLBACK_VOLTAGE,
                                   self.qtcb_voltage.emit) 
        
        self.voltage_label = CurrentLabel('Voltage: ')
        
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Voltage [mV]', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.voltage_label)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)