4

I'm working with an Arduino board and Matlab under Linux. Matlab, unfortunately, doesn't recognize the Arduino board when is connected unless I create a symbolic link to the Arduino board in /dev by:

sudo ln -s /dev/ttyACM0 /dev/ttyUSBx

Where x is a number and ttyACM0 is the device associated to the Arduino board. I have to run this line every time I want to work with the Arduino and Matlab. So, my question is pretty simple: Is it possible to automatically create this symbolic link exactly when the Arduino board is connected and remove it when disconnected?

jasonwryan
  • 71,734
  • 34
  • 193
  • 226
Charlie
  • 93
  • 1
  • 6

1 Answers1

3

This is a job for udev, the program that creates entries in /dev based on connected hardware. The following rule creates a symbolic link /dev/ttyUSB9 for the first ttyACM device that is plugged in:

KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyUSB9"

Make it KERNEL=="ttyACM0" if you want the rule to apply to ttyACM0 only (it won't make any difference unless you have multiple boards).

Run udevadm trigger ttyACM0 to reapply the rules to the ttyACM0 (or unplug the device and plug it back in).

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175