问题描述
我正在尝试通过 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",seq) + write + b'\xEE' * (usb_report_size - 5 - len(write)))
seq += 1
idx += len(write)
我认为这可能对我有帮助,但是... HWW_CMD 是 USB 功能吗?在这个例子中:0x0009?什么是 HWW_CID 和 usb_report_side?或者也许有更好的选择将帧发送到设备?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)