How to interact with USB device using PyUSB

怎甘沉沦 提交于 2019-12-06 08:12:36

there is an example in https://github.com/walac/pyusb/blob/master/docs/tutorial.rst chapter Talk to me, honey

>>> msg = 'test'
>>> assert dev.ctrl_transfer(0x40, CTRL_LOOPBACK_WRITE, 0, 0, msg) == len(msg)
>>> ret = dev.ctrl_transfer(0xC0, CTRL_LOOPBACK_READ, 0, 0, len(msg))
>>> sret = ''.join([chr(x) for x in ret])
>>> assert sret == msg

if you want to write to endpoints (bulk transfers etc) you have to obey the USB tree structure: -> configuration -> claim interface -> get endpoint ...

on page 22 of the specification is not USB protocol is GNET protocol (which i do not know). the point is that you do not need low level USB to talk to the device. you can use standard tty programs (echo, screen, putty, socat,...) on linux or something analog in windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!