50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
from config import *
|
|
from client import MMClient
|
|
import asyncio
|
|
from glob import glob
|
|
from os.path import join
|
|
from device.serial import SerialDevice
|
|
|
|
serial_mapping = {
|
|
'usb-Symbol*': (SerialDevice, 'zebra'),
|
|
'usb-Honeywell*': (SerialDevice, 'honeywell'),
|
|
'usb-XinChip*': (SerialDevice, 'china')
|
|
}
|
|
|
|
class USBSerialDetect:
|
|
def __init__(self, mm):
|
|
self.devices = {}
|
|
self.mm = mm
|
|
|
|
async def detect(self):
|
|
while 1:
|
|
for pat, handler in serial_mapping.items():
|
|
for dev in glob(join('/dev/serial/by-id', pat)):
|
|
if self.devices.get(dev):
|
|
if self.devices[dev].ser.is_open:
|
|
continue
|
|
else:
|
|
print("Destroying device.")
|
|
del self.devices[dev]
|
|
|
|
print("Adding", dev, 'as', handler)
|
|
self.devices[dev] = handler[0](dev, self.mm, handler[1])
|
|
self.devices[dev].start()
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
async def main():
|
|
|
|
print("Connecting...")
|
|
mm = MMClient()
|
|
asyncio.create_task(mm.run())
|
|
|
|
print("Detecting barcodes...")
|
|
a = USBSerialDetect(mm)
|
|
asyncio.create_task(a.detect())
|
|
|
|
while 1:
|
|
await asyncio.sleep(100)
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|