Esempio n. 1
0
def open_device(info):
    if HID_INTERFACE == 'hid':
        return HIDDevice(path=info['path'])
    elif HID_INTERFACE == 'hidapi':
        device = hid.device()
        device.open_path(info['path'])
        return device
Esempio n. 2
0
    def _open_dev(self) -> bool:
        vendor_id = 0x22b8
        product_id = 0x7f01

        self.device = device = HIDDevice()
        try:
            device.open(vendor_id, product_id)
            mfr = device.get_manufacturer_string()
            prd = device.get_product_string()
            ser = device.get_serial_number_string().encode()
            if mfr == "Giant Wireless Technology" and prd == "MX240a MOTOROLA MESSENGER" and ser == b"\xd0\x89":
                return True
        except IOError:
            pass

        return False
Esempio n. 3
0
    def open(self) -> None:
        logger.debug("Opening device...")
        self.device = device = HIDDevice()
        try:
            device.open(0x22b8, 0x7f01)
            mfr = device.get_manufacturer_string()
            prd = device.get_product_string()
            ser = device.get_serial_number_string().encode()
            if mfr != "Giant Wireless Technology" or prd != "MX240a MOTOROLA MESSENGER" or ser != b"\xd0\x89":
                raise IOError()
        except IOError:
            logger.error("Error opening device")
            exit(1)

        logger.trace(f"mfr: {device.get_manufacturer_string()}")
        logger.trace(f"prd: {device.get_product_string()}")
        logger.trace(
            f"ser: {to_hex(device.get_serial_number_string().encode())}")

        self.read_thread.start()
        self.write_thread.start()

        logger.debug("Initializing...")
        self.write(b"\xad\xef\x8d\xff")

        packet: Optional[Packet]
        try:
            packet = self.packet_buffer.get(timeout=0.5)
        except queue.Empty:
            packet = None

        if not packet:
            logger.trace("Init reply skipped for some reason?")
        elif packet.packet_type == PacketType.BaseInitReply:
            logger.trace("Init reply: {}", packet)
        else:
            logger.warning(
                "Reading real data, you might want to restart the driver")

        logger.debug("Init complete")

        self.process_thread.start()
        self.poll_thread.start()