42 lines
715 B
Python
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)
|