Portál AbcLinuxu, 7. května 2025 19:54
|__ Port 2: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 12M
import usb.core, usb.util, usb.control import crc16 vendorId = 0x0665 productId = 0x5161 interface = 0 dev = usb.core.find(idVendor=vendorId, idProduct=productId) if dev.is_kernel_driver_active(interface): dev.detach_kernel_driver(interface) dev.set_interface_altsetting(0,0) def getCommand(cmd): cmd = cmd.encode('utf-8') crc = crc16.crc16xmodem(cmd).to_bytes(2,'big') cmd = cmd+crc cmd = cmd+b'\r' while len(cmd)<8: cmd = cmd+b'\0' return cmd def sendCommand(cmd): dev.ctrl_transfer(0x21, 0x9, 0x200, 0, cmd) def getResult(timeout=100): res="" i=0 while '\r' not in res and i<20: try: res+="".join([chr(i) for i in dev.read(0x81, 8, timeout) if i!=0x00]) except usb.core.USBError as e: if e.errno == 110: pass else: raise i+=1 return res sendCommand(getCommand('QPI')) res = getResult() print(res)Na základě chyb, kterým jsem jakš takš porozuměl doinstaloval
apt-get install python-usb pip install crc16ale s tímto nevím jestli si budu vědět rady:
Traceback (most recent call last): File "pip.py", line 37, in <module> sendCommand(getCommand('QPI')) File "pip.py", line 13, in getCommand crc = crc16.crc16xmodem(cmd).to_bytes(2,'big') AttributeError: 'int' object has no attribute 'to_bytes'Jestli nepoužít nějaký jiný modul crc, nebo nevím. Chápu asi, že crc16.crc16xmodem(cmd) je typu int a int nemá metodu to_bytes, ale jak to udělat, aby ji měl, to netuším. Poradí někdo? Díky.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.