python将读取的usb数据写进文件,在Python中从USB HID设备简单地读写数据?

博主使用Python的PyWinUSB库尝试从USB HID设备读取数据并成功了,但在尝试写入数据时遇到问题,导致错误。通过研究和调试,最终找到了解决方案,通过设置报告缓冲区并发送数据实现了向设备的写入操作。
摘要由CSDN通过智能技术生成

I've got a fairly simple USB HID device that I've been trying to figure out how to read from and write to using Python. I've been able to read from it using PyWinUSB, but the problem comes in when I try to write to it. Trying to write to it makes things explode.

For example:

device = hid.HidDeviceFilter(vendor_id = 0x0003, product_id = 0x1001).get_devices()[0]

This works fine. Then for reading raw data, which is all that I care about right now (I'll work with that once I can figure out how to write to the cursed thing):

def readData(data):

print(data)

return None

This works fine (in fact, it was quite exciting when I got to see it work). So I would assign the data handler like so:

device.set_raw_data_handler(readData)

And every time I hit a button, it's fine. The data comes through as you would

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值