Search code examples
ubuntuserial-portusbstty

How can I set the baud rate automatically when a device connects?


I can use stty -F /dev/ttyUSB0 19200 to set the baud rate whenever I want. But I'd like to set it automatically when a device is plugged in. Is there some sort of configuration file I can put this in?

I'm doing this on a Ubuntu 14.04 (Trusty Tahr) system.


Solution

  • You can use udev for this.

    Write a udev rule in directory /etc/udev/rules.d for your device that executes the shell script you want.

    See udev (Arch Linux) for writing udev rules. You can use i.e. USB vendorID and productID to identify the device. For that, you write the script

    KERNEL=="sd*", ATTRS{idVendor}=="12ba", ATTRS{idProduct}=="58ea", ATTRS{model}=="XYZ42", ATTRS{serial}=="123465789", RUN+="/pathto/script"

    How can I run custom scripts upon USB device plug-in?