c - Detect certain connected USB device -
I am working with a USB device in Linux and wrote a library to control this device.
Without access to too many details, the device uses a standard URL protocol, so what I have to do is open a serial connection with The library works fine, however, it is difficult to believe that this device is / dev / ttyUSB0. That is, this is what I pass through What I want to do is find that this device is present, even if it is I can write code to choose some registers on device which gives serial number, product ID and so I can figure out what is actually on the other side of the USB that is actually Actually my device is ... but how do I list the connected USB devices again, in the original C Or a more elegant way to do this, such as the interface with its kernel module , or something else? I can actually use the USB driver, but I'm lost while searching for code. Thanks for any insights. When this is connected, to create a descriptive symlink for your device, This is a bit modified version of a real udev rule. The research group uses the battery-powered raspberry pie box to collect data from USB devices, which automatically runs a script, in which Naturally you can add Multiple defects are a bit more complicated, but there are lots of examples of udev rules. open , baud rate Start, baud rate, stop bit, parity, etc, and bit-banging registers.
open . If open fails, then I exit.
/ dev / ttyUSB0 ,
/ dev / ttyUSB1 , Etc. And even this can also be detected that these devices are connected to these devices.
udev < The elegant method is to use / code> like this
/etc/udev/rules.d
SUBSYSTEM == "tty", env {ID_MODEL} == "My_FlowMeter_Model", add a line to ENV {ID_USB_INTERFACE_NUM} == "00", SYMLINK + = "flowmeter", ruin + = "/ bin / su-pi -c / home / pi / rcod-flomometer.S
stty -f / dev / flowmeter 500000 If you want to know the "real" device file name, you can do
readlink / dev / flowmeter . For more uses You can only use the link:
fd = open ("/ dev / flowmeter"); (or pass it as an argument in your program)
flumer along with an abbreviation for your device < Based on the output from the code> lsusb , change the
ID_MODEL .
Comments
Post a Comment