-
- Posts: 39
- Joined: Fri Apr 04, 2014 11:23 pm
Assigning same USBtty linux to a device every time
I have 2 serial communication devices connected to pi, which tty/USB0 and tty/USB1. I have defined in my code tty/USB0 for one device serial initialization and tty/USB1 for another device serial initializtion. But sometimes, what happens is that USB0 and USB1 get interchanged and causes a problem for me. HOw can I fix this so that each device uses that particular tty/USB all the time even after a reboot.
Re: Assigning same USBtty linux to a device every time
You may be able to do it with a udev rule if the devices have different serial numbers.
To find the serial numbers, plug in the devices and do this
Do the same for ttyUSB1.
Now create a rules file:
(Put in the serial numbers that you get from the above info command).
Now when you plug in the USB devices they will still get ttyUSB0 and ttyUSB1 seemingly randomly, but they will also get ttyUSBPort1 and ttyUSBPort2 which will always be assigned to that particular device.
You may need a "sudo udevadm control --reload-rules" to get the new rule to be read, but I've never needed that.
To find the serial numbers, plug in the devices and do this
Code: Select all
pi@raspberrypi:~$ sudo udevadm info --query=property --name=/dev/ttyUSB0 | grep SERIAL
ID_SERIAL=Generic_USB_to_Serial_Converter_OCB6NCRD
ID_SERIAL_SHORT=OCB6NCRD
Now create a rules file:
Code: Select all
pi@raspberrypi:~$ sudo nano /etc/udev/rules.d/99-usbserial.rules
(add these lines)
ACTION=="add",ENV{ID_BUS}=="usb",ENV{ID_SERIAL_SHORT}=="OCB6NCRD",SYMLINK+="ttyUSBPort1"
ACTION=="add",ENV{ID_BUS}=="usb",ENV{ID_SERIAL_SHORT}=="JHG7GJFF",SYMLINK+="ttyUSBPort2"
(save and exit)
Now when you plug in the USB devices they will still get ttyUSB0 and ttyUSB1 seemingly randomly, but they will also get ttyUSBPort1 and ttyUSBPort2 which will always be assigned to that particular device.
You may need a "sudo udevadm control --reload-rules" to get the new rule to be read, but I've never needed that.
Re: Assigning same USBtty linux to a device every time
this is great. ive got one of those x10 "firecracker" modules, through a usb->db9 rs232 adaptors, and i added a rc.local rule to create the "firecracker" dev symlink to the usb device, but sometimes other peripherals grabbed ttyUSB0 first, and it drove me crazy trying to figure out why my system randomly broke. i think ill add rules for every usb device i use, so thing are predictable.
/*
Kris Tucker
http://pyrotuc.com
http://pirhotech.com
alias webExposedEmail='rpiforum@pyrotuc.com'
sudo echo "1" > /sys/class/awesome
*/
Kris Tucker
http://pyrotuc.com
http://pirhotech.com
alias webExposedEmail='rpiforum@pyrotuc.com'
sudo echo "1" > /sys/class/awesome
*/
-
- Posts: 39
- Joined: Fri Apr 04, 2014 11:23 pm
Re: Assigning same USBtty linux to a device every time
Thank you. But are these assignments done at boot or after boot ?rpdom wrote:You may be able to do it with a udev rule if the devices have different serial numbers.
To find the serial numbers, plug in the devices and do thisDo the same for ttyUSB1.Code: Select all
pi@raspberrypi:~$ sudo udevadm info --query=property --name=/dev/ttyUSB0 | grep SERIAL ID_SERIAL=Generic_USB_to_Serial_Converter_OCB6NCRD ID_SERIAL_SHORT=OCB6NCRD
Now create a rules file:(Put in the serial numbers that you get from the above info command).Code: Select all
pi@raspberrypi:~$ sudo nano /etc/udev/rules.d/99-usbserial.rules (add these lines) ACTION=="add",ENV{ID_BUS}=="usb",ENV{ID_SERIAL_SHORT}=="OCB6NCRD",SYMLINK+="ttyUSBPort1" ACTION=="add",ENV{ID_BUS}=="usb",ENV{ID_SERIAL_SHORT}=="JHG7GJFF",SYMLINK+="ttyUSBPort2" (save and exit)
Now when you plug in the USB devices they will still get ttyUSB0 and ttyUSB1 seemingly randomly, but they will also get ttyUSBPort1 and ttyUSBPort2 which will always be assigned to that particular device.
You may need a "sudo udevadm control --reload-rules" to get the new rule to be read, but I've never needed that.
Re: Assigning same USBtty linux to a device every time
I had the same problem and found the syntax for the rule to be quite critical. Also, I never found a single document that explained everything I wanted to know about this topic. So I compiled one of my own, to be found here. I hope it's useful to some.
- Richard-TX
- Posts: 1549
- Joined: Tue May 28, 2013 3:24 pm
- Location: North Texas
Re: Assigning same USBtty linux to a device every time
Welcome to udev hell.
Udev is what happens when someone does not think about the negative consequences of adding a feature and then burns their bridges behind them.
Udev should be something that is optional or at least provide an easy way to hard code device names. Adding device names via a udev entry is simply a work around to compensate for poor architectural planning.
The best I can say about udev is that it works mostly.
Richard
"The measure of success is not determined by how well a process is adhered to, but in how well the exceptions are handled."
Udev is what happens when someone does not think about the negative consequences of adding a feature and then burns their bridges behind them.
Udev should be something that is optional or at least provide an easy way to hard code device names. Adding device names via a udev entry is simply a work around to compensate for poor architectural planning.
The best I can say about udev is that it works mostly.
Richard
"The measure of success is not determined by how well a process is adhered to, but in how well the exceptions are handled."
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip