简体   繁体   English

覆盆子,无法写入USB串行转换器

[英]raspberry, cannot write to USB-Serial converter

I'm working on a small Python script on a raspberry that interacts with an external device. 我正在研究与外部设备交互的树莓派上的一个小型Python脚本。 that external device has either RS232 and USB ports and I'm using it through the USB port. 该外部设备具有RS232和USB端口,而我正在通过USB端口使用它。

lsusb shows: Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial So i guess that the USB port in the embedded device internally has a USB to Serial converter. lsusb显示: Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial因此,我猜嵌入式设备的USB端口内部具有USB到串行转换器。

Till there everything is fine, except that when I open the device through PyUSB I can only get an IN endpoint (0x81) but not an OUT endpoint. 到此为止一切都很好,只不过当我通过PyUSB打开设备时,我只能获得IN端点(0x81),而不能获得OUT端点。

So I decided to inspect through lsusb -v: 因此,我决定通过lsusb -v检查:

Bus 001 Device 004: ID 0665:5161 Cypress Semiconductor USB to Serial
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x0665 Cypress Semiconductor
  idProduct          0x5161 USB to Serial
  bcdDevice            0.02
  iManufacturer           3 (error)
  iProduct                1 (error)
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      27
          Report Descriptor: (length is 27)
            Item(Global): Usage Page, data= [ 0x00 0xff ] 65280
                            (null)
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Local ): Usage, data= [ 0x02 ] 2
                            (null)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Main  ): Input, data= [ 0x82 ] 130
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Volatile Bitfield
            Item(Local ): Usage, data= [ 0x02 ] 2
                            (null)
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Main  ): Output, data= [ 0x82 ] 130
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Volatile Bitfield
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              12
Device Status:     0x0000
  (Bus Powered)

There is only one configuration, one interface, one endpoint and that's marked as IN. 只有一种配置,一个接口,一个端点,并且标记为IN。 Is that possible? 那可能吗?

Thanks in advance! 提前致谢!

This hint is: 这个提示是:

bInterfaceClass 3 Human Interface Device

HID transports data to the PC (IN) via an interrupt endpoint. HID通过中断端点将数据传输到PC(IN)。 The reverse direction uses the default control endpoint (EP0). 反向使用默认控制端点(EP0)。

So i guess that the USB port in the embedded device internally has a USB to Serial converter. 所以我想嵌入式设备中的USB端口内部有一个USB到串行转换器。

While this may be the case, it uses an unusual configuration. 尽管可能是这种情况,但它使用了不同寻常的配置。 The HID protocol won't require (OEM) drivers on a PC, but has much lower limits on data rates- which is OK for devices like an UPS. HID协议在PC上不需要(OEM)驱动程序,但是对数据速率的限制要低得多-这对于UPS等设备来说是可以的。

TL;DR Just access the device like any other HID device with pyUSB, and use control messages for the OUT (Pi=>device) direction. TL; DR只需像使用pyUSB的任何其他HID设备一样访问该设备,并将控制消息用于OUT(Pi => device)方向即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM