Python PyUSB修改数据并将其发送,就像它来自USB设备本身一样

2024-06-17 09:12:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用PyUSB来捕获数据,对其进行更改,然后将其发送到PC,就好像它直接来自所讨论的设备一样。我尝试连接的设备是Wacom One平板电脑

到目前为止,我已经能够使用以下代码从平板电脑中提取数据:

import usb.core
import usb.util
import usb.backend.libusb1

# find our device
dev = usb.core.find(idVendor=0x056A, idProduct=0x037A)

# was it found?
if dev is None:
    raise ValueError('Device not found')

print(dev)


# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

# first endpoint
endpoint = dev[0][(0,0)][0]

# read a data packet
data = None
while True:
    try:
        data = dev.read(endpoint.bEndpointAddress,
                endpoint.wMaxPacketSize)
        print(data)

    except usb.core.USBError as e:
        data = None
        if e.args == ('Operation timed out',):
            continue

但目前,随着平板电脑与内核分离,光标没有移动。这很好,但我只能找到将数据发送回Wacom平板电脑的方法,我需要筛选、编辑平板电脑的数据(我在一个单独的程序中完成),最后将其发送到PC,以便Wacom驱动程序可以读取。我之所以希望数据被发送,就好像它没有被编辑过一样,是因为我不想重写平板电脑的整个驱动程序,因为Wacom的驱动程序很好,只是缺少了一些通过操纵数据而添加的功能


Tags: the数据coredevimportnonedata驱动程序