如何从USB外围设备读取数据?

Ris*_*shi 5 macos terminal usb driver device

我拿起了一个即将被扔掉的wii鼓组。它有一个 USB 端口,我想将它连接到我的 macbook 以进行项目。我的目标基本上是能够检测到某个鼓何时被敲击在设备上。根据我到目前为止收集的信息,我需要执行以下步骤:

  1. 连接设备并确定它所在的 tty 端口
  2. 使用“屏幕”命令打印出来自鼓的数据
  3. 将 screen 命令的数据输出到一些代码中,为我的项目生成有用的输出

我想我知道如何做 2 和 3,但是我在第 1 步上被挂断了。

如果我在终端中运行“ioreg -Src IOUSBDevice”,我可以确定设备已连接,但我不知道它在哪个 tty 端口上。(输出见下文)

此外,一般来说,是否可以将数据作为字节流从连接到 USB 端口的任何 USB 外围设备打印出来?

编辑:我应该补充一点,如果我运行“ls /dev/tty.*”,我看不到任何 tty.usb 项目,只有 tty.bluetooth 东西。

+-o Harmonix Drum Controller for Nintendo Wii@14200000  <class IOUSBDevice, id $
  | {
  |   "sessionID" = 2111009401078
  |   "iManufacturer" = 1
  |   "bNumConfigurations" = 1
  |   "idProduct" = 5
  |   "bcdDevice" = 4096
  |   "Bus Power Available" = 250
  |   "bMaxPacketSize0" = 64
  |   "USB Product Name" = "Harmonix Drum Controller for Nintendo Wii"
  |   "iProduct" = 2
  |   "iSerialNumber" = 0
  |   "USB Address" = 4
  |   "bDeviceClass" = 0
  |   "locationID" = 337641472
  |   "bDeviceSubClass" = 0
  |   "IOUserClientClass" = "IOUSBDeviceUserClientV2"
  |   "PortNum" = 2
  |   "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.$
  |   "bDeviceProtocol" = 0
  |   "USB Vendor Name" = "Licensed by Nintendo of America "
  |   "Device Speed" = 1
  |   "idVendor" = 7085
  |   "Requested Power" = 50
  |   "IOGeneralInterest" = "IOCommand is not serializable"
  |   "Low Power Displayed" = No
  | }
  | 
  +-o IOUSBCompositeDriver  <class IOUSBCompositeDriver, id 0x100000ebe, !regis$
  +-o IOUSBInterface@0  <class IOUSBInterface, id 0x100000ebf, registered, matc$
+-o IOUSBHIDDriver  <class IOUSBHIDDriver, id 0x100000ec2, registered, matc$
  +-o IOHIDInterface  <class IOHIDInterface, id 0x100000ec4, registered, ma$
  +-o IOHIDLibUserClient  <class IOHIDLibUserClient, id 0x100000ec5, !regis$
  +-o IOHIDLibUserClient  <class IOHIDLibUserClient, id 0x100000ec7, !regis$
Run Code Online (Sandbox Code Playgroud)

迄今为止,

mgf*_*nan 2

我没有您正在寻找的确切答案,但我在尝试从连接到我的 MacBook Pro 的 GPS 设备读取数据时遇到了类似的问题。就我而言,发出命令后:

ioreg -w0 -l -p IOUSB 
Run Code Online (Sandbox Code Playgroud)

我有(剪掉不相关的部分):

  +-o u-blox 7 - GPS/GNSS Receiver@14110000  <class IOUSBDevice, id 0x1000026b0, registered, matched, active, busy 0 (60 ms), retain 12>
  |   {
  |     "sessionID" = 17488341785377
  |     "idProduct" = 423
  |     "bNumConfigurations" = 1
  |     "iManufacturer" = 1
  |     "bcdDevice" = 256
  |     "Bus Power Available" = 250
  |     "bMaxPacketSize0" = 64
  |     "USB Product Name" = "u-blox 7 - GPS/GNSS Receiver"
  |     "iProduct" = 2
  |     "iSerialNumber" = 0
  |     "USB Address" = 12
  |     "IOUserClientClass" = "IOUSBDeviceUserClientV2"
  |     "bDeviceSubClass" = 0
  |     "bDeviceClass" = 2
  |     "bcdUSB" = 272
  |     "locationID" = 336658432
  |     "PortNum" = 1
  |     "IOCFPlugInTypes" = {"9dc7b780-9ec0-11d4-a54f-000a27052861"="IOUSBFamily.kext/Contents/PlugIns/IOUSBLib.bundle"}
  |     "bDeviceProtocol" = 0
  |     "USB Vendor Name" = "u-blox AG - www.u-blox.com"
  |     "Device Speed" = 1
  |     "idVendor" = 5446
  |     "Requested Power" = 50
  |     "IOGeneralInterest" = "IOCommand is not serializable"
  |     "Low Power Displayed" = No
  |   }
  |   
Run Code Online (Sandbox Code Playgroud)

这并不能说明tty.*设备分配在哪个设备上,因此我所做的是ls /dev/tty.*拔掉设备之前和之后的情况。通过这样做,我意识到终端/dev/tty.usbmodem14111消失了。也许在您的情况下不会有tty.usbmodem*,但请注意该14111部分,它与我的设备的 ioreg 行的第一部分部分重合 ( u-blox 7 - GPS/GNSS Receiver@14110000)。也许您可以在您的情况下使用此提示来查看是否发现 tty 设备。

如果您找到更“通用”的方式来发现tty,请分享!祝你好运!