def _device_added_cb(self, path): """ Called from hal connection when a new device is plugged. """ if not self.rfid_connected: self.rfid_device = find_device() _logger.debug("DEVICE_ADDED: %s" % self.rfid_device) if self.rfid_device is not None: _logger.debug("DEVICE_ADDED: RFID device is not None!") self.rfid_connected = self._device.do_connect() if self.rfid_connected: _logger.debug("DEVICE_ADDED: Connected!") self.rfid_device.connect("tag-read", self._tag_read_cb) self.rfid_device.connect("disconnected", self._disconnected_cb)
def __init__(self, parent): Plugin.__init__(self) self._parent = parent self._status = False """ The following code will initialize a USB RFID reader. Please note that in order to make this initialization function work, it is necessary to set the permission for the ttyUSB device to 0666. You can do this by adding a rule to /etc/udev/rules.d As root (using sudo or su), copy the following text into a new file in /etc/udev/rules.d/94-ttyUSB-rules KERNEL=="ttyUSB[0-9]",MODE="0666" You only have to do this once. """ self.rfid_connected = False self.rfid_device = find_device() self.rfid_idn = '' if self.rfid_device is not None: _logger.info("RFID device found") self.rfid_connected = self.rfid_device.do_connect() if self.rfid_connected: self.rfid_device.connect("tag-read", self._tag_read_cb) self.rfid_device.connect("disconnected", self._disconnected_cb) loop = DBusGMainLoop() bus = dbus.SystemBus(mainloop=loop) hmgr_iface = dbus.Interface( bus.get_object( HAL_SERVICE, HAL_MGR_PATH), HAL_MGR_IFACE) hmgr_iface.connect_to_signal('DeviceAdded', self._device_added_cb) self._status = True