gpt4 book ai didi

macos - 如何从USB外设读取数据?

转载 作者:行者123 更新时间:2023-12-02 20:56:12 28 4
gpt4 key购买 nike

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

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

我想我明白如何执行第 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$

到目前为止,

最佳答案

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

ioreg -w0 -l -p IOUSB 

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

  +-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
| }
|

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

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

关于macos - 如何从USB外设读取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31506857/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com