Tuesday, February 12, 2013

Forcing Serial device to use the same Serial port

EDIT: Note, that this caused an error that I'm currently trying to work out. I'll remove this once I've figured it out. Basically, it doesn't treat the second device as a serial port.

Note, that I'm currently writing this to use on my Raspberry Pi to make it work better with BotQueue's client software, bumblebee. When you unplug a usb serial device, and plug it back in, the serial port changes.  So, if you have it as /dev/ttyACM0, unplug it and plug it back in, you'll see it's now at /dev/ttyACM1.

Throughout this tutorial, I'm going to use /dev/ttyACM0 since that's the current port of the device I'm trying to get to stay.  Note, that this is a device rename, not a symlink. I'll be using /dev/ttyJasmine for the new port since Jasmine is the name of my printer.

First up, let's find some info about the device:
udevadm info -q property -p $(udevadm info -q path -n /dev/ttyACM0)
It should spit out some info. The line that we need to pay attention to is ID_SERIAL_SHORT.

So in the case of my arduino, (excluding all irrelevant fields):
ID_SERIAL_SHORT=<removed for the blog post>
Now it's time to set up what's called a udev rule.  Run the following command, replacing nano with your editor of choice: (Note, that I chose 45 arbitrarily. Just for fun, you might want to research how the numbering system works)
sudo nano /etc/udev/rules.d/45-serial-devices.rules
Go ahead, and add the following line, replacing the items in < > their appropriate values.  So in my case, I'd replace <SUBSYSTEM> with tty and <ID_SERIAL_SHORT> with the serial device I found earlier. (Note, that this is all one line)
SUBSYSTEMS=="usb", ATTR{serial}=="<ID_SERIAL_SHORT>", NAME="ttyJasmine", GROUP="dialout", MODE="777"
Go ahead and save the file. After a fresh reboot, you should see your device have the name that you assigned to it.  If not, then run the following command to see what the problem might be:
cat /var/log/daemon.log | grep udev
Remember to change your config.json to use the new port if you did this for botqueue.