Posts: 136
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa
Contact: Website

C to read and write USB

Sun Jan 19, 2020 9:06 am

I am currently writing some code to send a command to the inverter on my solar system and retrieve the current status.
Looking at wiringpi examples and using part of those examples I am attempting to understand how "/dev/hidraw0" relates to the two USB devices I have connected to that machine.
Those devices are 1) a WiFi connection and 2) a serial connection to the inverter.
How do I ascertain which is /dev/hidraw0 and what the other is called.

Code: Select all

Bus 001 Device 005: ID 0665:5161 Cypress Semiconductor USB to Serial
Bus 001 Device 004: ID 148f:3070 Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
but this tells me nothing that I understand about "/dev/hidraw0"
when I tail -f /var/log/messages and unplug and replug the inverter I get

Code: Select all

Jan 19 09:39:16 RPiDoor kernel: [ 8834.944711] usb 1-1.3: USB disconnect, device number 5
Jan 19 09:39:32 RPiDoor kernel: [ 8851.110475] usb 1-1.3: new low-speed USB device number 6 using dwc_otg
Jan 19 09:39:32 RPiDoor kernel: [ 8851.278926] usb 1-1.3: New USB device found, idVendor=0665, idProduct=5161, bcdDevice= 0.02
Jan 19 09:39:32 RPiDoor kernel: [ 8851.278948] usb 1-1.3: New USB device strings: Mfr=3, Product=1, SerialNumber=0
Jan 19 09:39:32 RPiDoor kernel: [ 8851.297871] hid-generic 0003:0665:5161.0002: hiddev96,hidraw0: USB HID v1.11 Device [HID 0665:5161] on usb-3f980000.usb-1.3/input0
Jan 19 09:39:32 RPiDoor mtp-probe: checking bus 1, device 6: "/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3"
Jan 19 09:39:32 RPiDoor mtp-probe: bus: 1, device: 6 was not an MTP device
which tells me that device 5(which is now 6) is the inverter but again nothing about which device my program shouls be opening, writing to and reading from.

I have attempted using /dev/hidraw0 as well as /dev/hiddev96, as listed above in messages, but with no success.

Posts: 839
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: C to read and write USB

Sun Jan 19, 2020 2:53 pm

I would recommend migrating from WIringPi to Pigpio sooner rather than later - WiringPi no longer supported by the developer and Pigpio has good handful more tools.

That said, your /dev/ folder is where communication ports show up. Is is a folder and as such you can check the contents with

Code: Select all

ls /dev/*
It might be quite a lot, and you device probably shows up as /dev/tty-something, so you can narrow down your search with

Code: Select all

ls /dev/tty*
I've never heard of hidraw... that could just be something in some example and you have to replace it with whatever your device shows up as. Probably /dev/ttyUSB0 or /dev/ttyACM0 or /dev/ttyAMA0. (the zero might be a 1 or 2 if you have more than one serial device attached). Just unplug it, run the ls command, plug it in, then run it again and look for the new device.
Robotics tips, hacks, book extras

User avatar
Posts: 6463
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: C to read and write USB

Mon Feb 24, 2020 2:18 pm

A "usb to serial" should not be detected as a "hid" device, but you are not the only one with the problem. ... 0&tstart=0

So its a bit weird.... ... l-usb.html

Return to “C/C++”