Exemplo n.º 1
0
class DistanceUS(PluginBase):
    qtcb_distance = pyqtSignal(int)
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Distance US Bricklet', version)

        self.dist = BrickletDistanceUS(uid, ipcon)
        
        self.qtcb_distance.connect(self.cb_distance)
        self.dist.register_callback(self.dist.CALLBACK_DISTANCE,
                                    self.qtcb_distance.emit) 
        
        self.distance_label = DistanceLabel('Distance Value: ')
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Distance', plot_list)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.distance_label)
        layout_h1.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addWidget(self.plot_widget)
        layout.addStretch()

    def start(self):
        async_call(self.dist.get_distance_value, None, self.cb_distance, self.increase_error_count)
        async_call(self.dist.set_distance_callback_period, 100, None, self.increase_error_count)
            
        self.plot_widget.stop = False
        
    def stop(self):
        async_call(self.dist.set_distance_callback_period, 0, None, self.increase_error_count)
        
        self.plot_widget.stop = True

    def get_url_part(self):
        return 'distance_us'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletDistanceUS.DEVICE_IDENTIFIER
    
    def get_current_value(self):
        return self.current_value

    def cb_distance(self, distance):
        self.current_value = distance
        self.distance_label.setText(str(distance)) 
Exemplo n.º 2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Distance US Bricklet', version)

        self.dist = BrickletDistanceUS(uid, ipcon)
        
        self.qtcb_distance.connect(self.cb_distance)
        self.dist.register_callback(self.dist.CALLBACK_DISTANCE,
                                    self.qtcb_distance.emit) 
        
        self.distance_label = DistanceLabel('Distance Value: ')
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Distance', plot_list)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.distance_label)
        layout_h1.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addWidget(self.plot_widget)
        layout.addStretch()