1 Star 1 Fork 0

徐瑞骏/ultrasound_scan_pc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
usbd.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
徐瑞骏 提交于 2021-07-09 15:03 . first commit
import usb.core
import usb.util
class USBDevice:
def __init__(self, *args, **kwargs):
dev = usb.core.find(*args, **kwargs)
if dev is None:
raise ValueError('Device not found')
if dev.is_kernel_driver_active(0):
dev.detach_kernel_driver(0)
dev.reset()
cfg = dev.get_active_configuration()
intf = cfg[(0, 0)]
ep_read = usb.util.find_descriptor(
intf,
# match the first IN endpoint
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN
)
ep_write = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT
)
self.dev = dev
self.ep_read = ep_read
self.ep_write = ep_write
def read(self, n):
return self.ep_read.read(n)
def write(self, data):
self.ep_write.write(data)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xu-ruijun/ultrasound_scan_pc.git
[email protected]:xu-ruijun/ultrasound_scan_pc.git
xu-ruijun
ultrasound_scan_pc
ultrasound_scan_pc
master

搜索帮助