Example #1
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Temperature IR Bricklet', version)
        
        self.tem = BrickletTemperatureIR(uid, ipcon)
        
        self.qtcb_ambient_temperature.connect(self.cb_ambient_temperature)
        self.tem.register_callback(self.tem.CALLBACK_AMBIENT_TEMPERATURE,
                                   self.qtcb_ambient_temperature.emit)
        self.qtcb_object_temperature.connect(self.cb_object_temperature)
        self.tem.register_callback(self.tem.CALLBACK_OBJECT_TEMPERATURE,
                                   self.qtcb_object_temperature.emit) 
        
        self.ambient_label = AmbientLabel()
        self.object_label = ObjectLabel()
        
        self.emissivity_label = QLabel('Emissivity: ')
        self.emissivity_edit = QLineEdit()
        self.emissivity_button = QPushButton('Save')
        self.emissivity_layout = QHBoxLayout()
        self.emissivity_layout.addWidget(self.emissivity_label)
        self.emissivity_layout.addWidget(self.emissivity_edit)
        self.emissivity_layout.addWidget(self.emissivity_button)
        
        self.emissivity_button.pressed.connect(self.emissivity_pressed)
        
        self.current_ambient = None
        self.current_object = None
        
        plot_list = [['amb', Qt.blue, self.get_current_ambient],
                     ['obj', Qt.red, self.get_current_object]]
        
        self.plot_widget = PlotWidget('Temperature [%cC]' % 0xB0, plot_list)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.ambient_label)
        layout_h1.addStretch()

        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.object_label)
        layout_h2.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addWidget(self.plot_widget)
        layout.addLayout(self.emissivity_layout)
Example #2
0
class TemperatureIR(PluginBase):
    qtcb_ambient_temperature = pyqtSignal(int)
    qtcb_object_temperature = pyqtSignal(int)
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Temperature IR Bricklet', version)
        
        self.tem = BrickletTemperatureIR(uid, ipcon)
        
        self.qtcb_ambient_temperature.connect(self.cb_ambient_temperature)
        self.tem.register_callback(self.tem.CALLBACK_AMBIENT_TEMPERATURE,
                                   self.qtcb_ambient_temperature.emit)
        self.qtcb_object_temperature.connect(self.cb_object_temperature)
        self.tem.register_callback(self.tem.CALLBACK_OBJECT_TEMPERATURE,
                                   self.qtcb_object_temperature.emit) 
        
        self.ambient_label = AmbientLabel()
        self.object_label = ObjectLabel()
        
        self.emissivity_label = QLabel('Emissivity: ')
        self.emissivity_edit = QLineEdit()
        self.emissivity_button = QPushButton('Save')
        self.emissivity_layout = QHBoxLayout()
        self.emissivity_layout.addWidget(self.emissivity_label)
        self.emissivity_layout.addWidget(self.emissivity_edit)
        self.emissivity_layout.addWidget(self.emissivity_button)
        
        self.emissivity_button.pressed.connect(self.emissivity_pressed)
        
        self.current_ambient = None
        self.current_object = None
        
        plot_list = [['amb', Qt.blue, self.get_current_ambient],
                     ['obj', Qt.red, self.get_current_object]]
        
        self.plot_widget = PlotWidget('Temperature [%cC]' % 0xB0, plot_list)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.ambient_label)
        layout_h1.addStretch()

        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.object_label)
        layout_h2.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addWidget(self.plot_widget)
        layout.addLayout(self.emissivity_layout)
        
    def start(self):
        async_call(self.tem.get_ambient_temperature, None, self.cb_ambient_temperature, self.increase_error_count)
        async_call(self.tem.get_object_temperature, None, self.cb_object_temperature, self.increase_error_count)
        async_call(self.tem.get_emissivity, None, self.cb_emissivity, self.increase_error_count)
        
        async_call(self.tem.set_ambient_temperature_callback_period, 250, None, self.increase_error_count)
        async_call(self.tem.set_object_temperature_callback_period, 250, None, self.increase_error_count)
        
        self.plot_widget.stop = False
        
    def stop(self):
        async_call(self.tem.set_ambient_temperature_callback_period, 0, None, self.increase_error_count)
        async_call(self.tem.set_object_temperature_callback_period, 0, None, self.increase_error_count)
        
        self.plot_widget.stop = True

    def get_url_part(self):
        return 'temperature_ir'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletTemperatureIR.DEVICE_IDENTIFIER
    
    def get_current_ambient(self):
        return self.current_ambient
    
    def get_current_object(self):
        return self.current_object

    def cb_object_temperature(self, temperature):
        self.current_object = temperature/10.0
        self.object_label.setText(str(self.current_object))
        
    def cb_ambient_temperature(self, temperature):
        self.current_ambient = temperature/10.0
        self.ambient_label.setText(str(self.current_ambient))
        
    def cb_emissivity(self, emissivity):
        self.emissivity_edit.setText(str(emissivity))
        
    def emissivity_pressed(self):
        value = int(self.emissivity_edit.text())
        try:
            self.tem.set_emissivity(value)
        except ip_connection.Error:
            return