windows 下的 Pywinusb 和 Flyfish FF32 设备。 Pywinusb 只发送零?

Pywinusb and Flyfish FF32 device under windows. Pywinusb sends just zeros?

我正在尝试在 windows 下为 Flyfish FF32 USB-HID IO 板 (http://www.flyfish-tech.com/FF32/index.php) 创建 python 库。我正在使用 pywinusb 库,Python 2.7,windows 7。

设备本身与 flyfish GUI 提供的一起工作。此外,当 运行 "show_hids" 来自 pywinusb 设备的演示可见时:

HID device (vID=0x04d8, pID=0xf8b9, v=0x0032); FLYFISH TECHNOLOGIES; FF32, Path: \?\hid#vid_04d8&pid_f8b9#a&135de629&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

  Path:      \?\hid#vid_04d8&pid_f8b9#a&135de629&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

  Instance:  HID\VID_04D8&PID_F8B9\A&135DE629&1&0000

  Port (ID): 2460

  Port (str):USB\VID_04D8&PID_F8B9&815F95E&0&3

HID device documentation report
===============================

Top Level Details
-----------------

Manufacturer String:    FLYFISH TECHNOLOGIES
Product Sting:          FF32
Serial Number:          ?

Vendor ID:              0x04d8
Product ID:             0xf8b9
Version number:         0x0032

Device Path:            \?\hid#vid_04d8&pid_f8b9#a&135de629&1&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
Device Instance Id:     HID\VID_04D8&PID_F8B9\A&135DE629&1&0000
Parent Instance Id:     2460

Top level usage:        Page=0xff00, Usage=0x01
Usage identification:   Unknown Page/usage
Link collections:       1 collection(s)

Reports
-------

Input Report
~~~~~~~~~~~~
Length:     65 byte(s)
Buttons:    1 button(s)
Values:     0 value(s)

Output Report
~~~~~~~~~~~~~
length:     65 byte(s)
Buttons:    1 button(s)
Values:     0 value(s)

Feature Report
~~~~~~~~~~~~~
Length:     0 byte(s)
Buttons:    0 button(s)
Values:     0 value(s)

*** Input Caps ***

    Usage Range 1~64 (0x1~0x40), Page 0xff00 (Vendor-defined)
        bit_field: 0
        data_index_max: 63
        data_index_min: 0
        designator_max: 0
        designator_min: 0
        is_absolute: 1
        is_alias: 0
        is_button: True
        is_designator_range: 0
        is_range: 1
        is_string_range: 0
        is_value: False
        link_collection: 0
        link_usage: 1 (0x1)
        link_usage_page: 65280 (0xff00)
        report_id: 0
        string_max: 0
        string_min: 0

*** Output Caps ***

    Usage Range 1~64 (0x1~0x40), Page 0xff00 (Vendor-defined)
        bit_field: 0
        data_index_max: 63
        data_index_min: 0
        designator_max: 0
        designator_min: 0
        is_absolute: 1
        is_alias: 0
        is_button: True
        is_designator_range: 0
        is_range: 1
        is_string_range: 0
        is_value: False
        link_collection: 0
        link_usage: 1 (0x1)
        link_usage_page: 65280 (0xff00)
        report_id: 0
        string_max: 0
        string_min: 0

但是当运行以下时,修改demo:

import pywinusb.hid as hid
from time import sleep


def sample_handler(data):
    print("Raw data: {0}".format(data))

filter = hid.HidDeviceFilter(vendor_id = 0x04d8, product_id = 0xf8b9)

hid_device = filter.get_devices()
device = hid_device[0]
device.open()
target_usage = hid.get_full_usage_id(0xff00, 1)
device.set_raw_data_handler(sample_handler)

report = device.find_output_reports()
print(report[0])

buffer = [0x00]*65
buffer[0] = 0
buffer[1] = 0x13


report[0].set_raw_data(buffer)
report[0].send()
sleep(1)

device.close()

执行输出: HID 报告对象(输出报告

t, id=0x00), 63 items included
Raw data: [0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

我没有收到预期的供应商信息。我安装了 USB 嗅探软件,结果发现无论我在 缓冲区 中放入什么,FF32 总是得到 0 数组。

供参考。从 GUI 嗅探的包:

80 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 18 f1 6d 0b 80 fa ff ff
02 00 00 00 40 00 00 00 75 9f b6 0b 80 f8 ff ff
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*13* 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

还有一个来自我的脚本:

80 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 18 f1 6d 0b 80 fa ff ff
02 00 00 00 40 00 00 00 41 57 87 05 80 f8 ff ff
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

有人知道这里出了什么问题吗?

这个设备很奇怪,65 个字节的报告不是预期的,因为这通常受到端点大小的限制。

无论如何,set_raw_data() 预计将用作 "all at once" HID 使用设置的模板,因此它将验证您提供了有效的报告 ID 和可解析的信息(解析由 Windows API).

在您的情况下,如果您想将 "anything" 发送到您的设备,只要报告 ID 列在 HID 描述符(第一个字节)中,只需使用:

report.send(buffer) # this validate buffer[0] matches report id

device.send_output_report(buffer) # this will send anything to your device

在这两种情况下,您都绕过了报告解析逻辑,这些是发送数据的最有效方式,对您发送的内容提供较少的验证。