This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
CMS/5.MISC/usb数据传输/Pyusb.py
2024-11-19 17:19:21 +08:00

42 lines
715 B
Python

import usb.core
import usb.util
import time
VID = 0x0403
PID = 0x6014
dev = usb.core.find(idVendor=VID, idProduct=PID)
if not dev:
print("Could not find USB :(")
exit(1)
else:
pass
# print("Yeeha! Found a usb device!")
dev.reset()
if dev.is_kernel_driver_active(0):
dev.detach_kernel_driver(0)
dev.set_configuration()
def Read():
# a = 256
# while a > 0:
r = dev.read(0x81, 64, 50)
# a = a - 1
print(len(r))
print(r)
buf = bytearray(64) # 创建一个64字节的字节数组
for i in range(64):
buf[i] = 1
def Write():
print(buf)
w = 0
while w == 0:
w = dev.write(0x02, buf) # 发送64字节的缓冲区
# print(w)