How to read data from a usb peripheral?

I took the wii drum that I was about to throw away. It has a USB port and I want to connect it to my macbook for a project. My goal is mainly to be able to detect when a certain drum has been triggered on a device. Based on what I have collected so far, I need to do the following steps:

  • Connect the device and determine which tty port it is connected to.
  • use the "screen" command to print out the data coming from the drums.
  • output data from a screen command to some code that generates useful output for my project

I think I understand how to do 2 and 3, but I hung up in step 1.

If I run "ioreg -Src IOUSBDevice" in a terminal, I can determine that the device is connected, but I don't know which tty port it is on. (see below for output)

Also, in general, is it possible to print data as a byte stream from any usb peripheral connected to the USB port?

EDIT: I must add that if I run "ls / dev / tty. *" I don't see any tty.usb items, only tty.bluetooth stuff.

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


Still

+3


source to share


2 answers


I don't have the exact answer you are looking for, but I ran into a similar issue while trying to read data from a GPS device connected to my MacBook Pro. In my case, after issuing the command:

ioreg -w0 -l -p IOUSB 

      

I have (clipping non-matching parts):



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

      

It doesn't tell you which device tty.*

is allocated, so I did it ls /dev/tty.*

before and after unplugging the device. After doing this, I realized that the terminal was /dev/tty.usbmodem14111

gone. You might not have one tty.usbmodem*

in your case, but note the part 14111

that overlaps with the first part of the ioreg line for my device ( u-blox 7 - GPS/GNSS Receiver@14110000

). Perhaps you can use this hint in your case to see if you are opening a tty device.

If you find a more "general" way to open tty

, share it! Good luck!

+1


source


It looks like your drum kit is identified as a HID device and not a serial / TTY port. OSX has custom HID APIs that will allow you to validate the report descriptor and collect HID reports, i.e. Events. Check out IOHIDDeviceGetReportWithCallback . Alternatively, the HID transaction API may be easier to work with as it deals with the messy business of parsing reports and descriptors for you.



+1


source







All Articles