Im setting up some RPi systems with attached serial (USB) devices, and at restart Im not 100% certain that the USB (FTDI USB Serial Device) devices will always retain their same names. So rather than count on /dev/ttyACM0 always being a correct port-name I want to sort it out thru some solid code.
Ive tried a number of things, for instance using the lsusb command gets me the following:
pi@raspberrypi:/dev $ lsusb
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 004: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)
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.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
but that doesnt tell me what System.SerialPort(port#) the device is connected to, only what its position on the bus is.
Newer linux distributions have good support for the dmesg command, and when I use that I can see this
pi@raspberrypi:/dev $ dmesg | grep -i ttyUSB
[22880.344951] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB0
[23141.726348] usb 1-1.4: pl2303 converter now attached to ttyUSB1
My thought was to use a Shell.Execute to pull this data, then knowing that I want to know about PL2303, I could use the information telling me that its on ttyUSB1 and loop over System.SerialPort(i).Name values to find the right one.
This isnt ideal, because the dmesg | grep -i ttyUSB command doesnt return information consistently across all linux distributions.
Another complication is that a couple of attached USB devices (in my case a series of weighing scales) both use identical drivers, so the lsusb info returns two identical lines for both of the attached scales.
Having said all that, my question is if theres a way to use a Shell or other means of asking the RPi about its attached serial devices, using the returned information to set the correct System.SerialPort(port#).