0

我的问题类似于 Will "Simple reading from/write from/to a USB HID device in Python?" 所建议的问题,但遵循它我没有得到任何结果。问题:我正在尝试处理 Oregon WMRS200 Meteo 站,它将 USB 连接实现为 HID 设备。我开始调整/简化提供的“原始数据.py”示例,如下所示

from time import sleep
from msvcrt import kbhit
import pywinusb.hid as hid

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

def raw_test():
    device = (hid.HidDeviceFilter (vendor_id =0x0fde , product_id = 0xca01). \
                    get_devices())[0]
    device.open()   
    #set custom raw data handler
    device.set_raw_data_handler(sample_handler)
    print("\nWaiting for data...\nPress any (system keyboard) key to stop...")
    while not kbhit() and device.is_plugged():
        #just keep the device opened to receive events
        sleep(0.5)

    device.close()
    return

if __name__ == '__main__':
    raw_test()

数据传输未开始。我在网上发现系统必须初始化一次(在重置或pw失败后)发送缓冲区 0x20 0x00 0x08 0x01 0x00 0x00 0x00 0x00 问题是我不知道如何发送它。做类似发送报告(如上面引用的示例)之类的事情不会得到任何结果。

如果在重置后我开始和停止原始的俄勒冈 sw 一切开始工作,即通道以某种方式初始化。在通信通道上安装嗅探器我想我看到了字节串到设备,但是,我怎样才能发送它?这是带有原始 sw 的嗅探器的输出。我想字节模式可以在 URB 9-10 中看到去设备。

[229 ms]  >>>  URB 1 going down  >>> 
-- URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
  TransferBufferLength = 00000012
  DescriptorType       = 00000001 (USB_DEVICE_DESCRIPTOR_TYPE)

[234 ms]  <<<  URB 1 coming back  <<< 
-- URB_FUNCTION_CONTROL_TRANSFER:
  TransferFlags        = 0000000b (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000012
    00000000: 12 01 10 01 00 00 00 08 de 0f 01 ca 02 03 00 01
    00000010: 00 01
  SetupPacket          =
    00000000: 80 06 00 01 00 00 12 00

[234 ms]  >>>  URB 2 going down  >>> 
-- URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
  TransferBufferLength = 00000009
  DescriptorType       = 00000002 (USB_CONFIGURATION_DESCRIPTOR_TYPE)

[239 ms]  <<<  URB 2 coming back  <<< 
-- URB_FUNCTION_CONTROL_TRANSFER:
  TransferFlags        = 0000000b (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000009
    00000000: 09 02 22 00 01 01 00 80 32
  SetupPacket          =
    00000000: 80 06 00 02 00 00 09 00

[239 ms]  >>>  URB 3 going down  >>> 
-- URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
  TransferBufferLength = 00000022
  DescriptorType       = 00000002 (USB_CONFIGURATION_DESCRIPTOR_TYPE)

[247 ms]  <<<  URB 3 coming back  <<< 
-- URB_FUNCTION_CONTROL_TRANSFER:
  TransferFlags        = 0000000b (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000022
    00000000: 09 02 22 00 01 01 00 80 32 09 04 00 00 01 03 00
    00000010: 00 00 09 21 10 01 00 01 22 22 00 07 05 81 03 08
    00000020: 00 01
  SetupPacket          =
    00000000: 80 06 00 02 00 00 22 00

[247 ms]  >>>  URB 4 going down  >>> 
-- URB_FUNCTION_SELECT_CONFIGURATION:
  ConfigurationDescriptor = 0x899fb730 (configure)
  ConfigurationDescriptor : bLength             = 9
  ConfigurationDescriptor : bDescriptorType     = 0x00000002
  ConfigurationDescriptor : wTotalLength        = 0x00000022
  ConfigurationDescriptor : bNumInterfaces      = 0x00000001
  ConfigurationDescriptor : bConfigurationValue = 0x00000001
  ConfigurationDescriptor : iConfiguration      = 0x00000000
  ConfigurationDescriptor : bmAttributes        = 0x00000080
  ConfigurationDescriptor : MaxPower            = 0x00000032
  ConfigurationHandle     = 0x00000000
  Interface[0]: Length            = 36
  Interface[0]: InterfaceNumber   = 0
  Interface[0]: AlternateSetting  = 0

[280 ms]  <<<  URB 4 coming back  <<< 
-- URB_FUNCTION_SELECT_CONFIGURATION:
  ConfigurationDescriptor = 0x899fb730 (configure)
  ConfigurationDescriptor : bLength             = 9
  ConfigurationDescriptor : bDescriptorType     = 0x00000002
  ConfigurationDescriptor : wTotalLength        = 0x00000022
  ConfigurationDescriptor : bNumInterfaces      = 0x00000001
  ConfigurationDescriptor : bConfigurationValue = 0x00000001
  ConfigurationDescriptor : iConfiguration      = 0x00000000
  ConfigurationDescriptor : bmAttributes        = 0x00000080
  ConfigurationDescriptor : MaxPower            = 0x00000032
  ConfigurationHandle     = 0x89a11ab8
  Interface[0]: Length            = 36
  Interface[0]: InterfaceNumber   = 0
  Interface[0]: AlternateSetting  = 0
  Interface[0]: Class             = 0x00000003
  Interface[0]: SubClass          = 0x00000000
  Interface[0]: Protocol          = 0x00000000
  Interface[0]: InterfaceHandle   = 0x8a2a18b0
  Interface[0]: NumberOfPipes     = 1
  Interface[0]: Pipes[0] : MaximumPacketSize = 0x00000008
  Interface[0]: Pipes[0] : EndpointAddress   = 0x00000081
  Interface[0]: Pipes[0] : Interval          = 0x00000001
  Interface[0]: Pipes[0] : PipeType          = 0x00000003 (UsbdPipeTypeInterrupt)
  Interface[0]: Pipes[0] : PipeHandle        = 0x8a2a18cc
  Interface[0]: Pipes[0] : MaxTransferSize   = 0x00001000
  Interface[0]: Pipes[0] : PipeFlags         = 0x00000000

[280 ms]  >>>  URB 5 going down  >>> 
-- URB_FUNCTION_CLASS_INTERFACE:
  TransferFlags          = 00000000 (USBD_TRANSFER_DIRECTION_OUT, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000000
    no data supplied
  RequestTypeReservedBits = 00000022
  Request                 = 0000000a
  Value                   = 00000000
  Index                   = 00000000

[282 ms]  <<<  URB 5 coming back  <<< 
-- URB_FUNCTION_CONTROL_TRANSFER:
  TransferFlags        = 0000000a (USBD_TRANSFER_DIRECTION_OUT, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000000
  SetupPacket          =
    00000000: 21 0a 00 00 00 00 00 00

[282 ms]  >>>  URB 6 going down  >>> 
-- URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
  TransferBufferLength = 00000062
  DescriptorType       = 00000022 (<illegal descriptor type!>)

[291 ms]  <<<  URB 6 coming back  <<< 
-- URB_FUNCTION_CONTROL_TRANSFER:
  PipeHandle           = 8a2a4198
  TransferFlags        = 0000000b (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000022
    00000000: 06 00 ff 09 01 a1 01 09 01 15 00 26 ff 00 75 08
    00000010: 95 08 81 00 09 02 15 00 26 ff 00 75 08 95 08 91
    00000020: 02 c0
  SetupPacket          =
    00000000: 81 06 00 22 00 00 62 00

[294 ms]  >>>  URB 7 going down  >>> 
-- URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
  TransferFlags        = 00000003 (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000008
[294 ms]  >>>  URB 8 going down  >>> 
-- URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
  TransferFlags        = 00000003 (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000008

[3330 ms]  <<<  URB 7 coming back  <<< 
-- URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
  TransferFlags        = 00000003 (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000008
    00000000: 01 ff 01 cc 01 87 01 00

[3330 ms]  >>>  URB 9 going down  >>> 
-- URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
  TransferFlags        = 00000003 (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000008
[3330 ms]  >>>  URB 10 going down  >>> 
-- URB_FUNCTION_CLASS_INTERFACE:
  TransferFlags          = 00000000
(USBD_TRANSFER_DIRECTION_OUT, ~USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000008
    00000000: 20 00 08 01 00 4d 80 00
  RequestTypeReservedBits = 00000022
  Request                 = 00000009
  Value                   = 00000200
  Index                   = 00000000

从 URB 11 - --> 正常传输也从我的示例脚本开始。

我希望我已经足够清楚.....感谢您的帮助。

4

1 回答 1

0

For sending RAW data (no HID descriptor managed reports), you can use the "device.send_output_report()", pass any list as a parameter (or for better performance, you can pass a ctypes.c_ubyte array.

于 2013-04-22T01:40:39.257 回答