python - Python - 将数据帧发送到 HID 设备
问题描述
我正在尝试通过 Python 向我的 HID 设备发送帧。我可以连接到我的设备,但不能向它发送帧。下面是我要发送的帧示例(来自 Wireshark 的屏幕):
我在 Python 中的框架:
data = bytearray(64)
data[0] = 0x02
data[5] = 0x82
first_data = bytes(data)
它看起来像来自 Wireshark 的数据包。但它不起作用:
h.write(first_data)
我在 Wireshark 中看不到通讯。所以我发现了这样的东西:
def send_frame(data, device):
data = bytearray(data)
data_len = len(data)
seq = 0
idx = 0
write = []
while idx < data_len:
if idx == 0:
# INIT frame
write = data[idx: idx + min(data_len, usb_report_size - 7)]
device.write(b'\0' + struct.pack(">IBH", HWW_CID, HWW_CMD, data_len & 0xFFFF) + write + b'\xEE' * (usb_report_size - 7 - len(write)))
else:
# CONT frame
write = data[idx: idx + min(data_len, usb_report_size - 5)]
device.write(b'\0' + struct.pack(">IB", HWW_CID, seq) + write + b'\xEE' * (usb_report_size - 5 - len(write)))
seq += 1
idx += len(write)
我认为这可能对我有帮助,但是... HWW_CMD 是 USB 功能吗?在本例中:0x0009?什么是 HWW_CID 和 usb_report_side?或者也许有更好的选择将帧发送到设备?
解决方案
推荐阅读
- c# - 以非常特定的顺序构造字符串列表
- javascript - 如何在没有任何 HTML 或 CSS 的情况下在 Web 浏览器中呈现和查看网站的未格式化 Json 源代码以获得完整的网页
- c# - 解析 Open Weather Map API 响应失败
- python-3.x - 解决:AttributeError:模块'tensorflow'没有属性'app'
- javascript - 使用yii2框架-vis.js库的序列图
- java - 无法对 AmazonS3Client 的重试参数进行单元测试
- sandbox - sandbox-exec 文件写入行为异常
- deep-learning - 初始化深度学习模型的权重
- java - 尝试构建 java-cef 时出现 CERTIFICATE_VERIFY_FAILED
- android - 房间数据库返回 1 个额外的对象