3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
holmes
  • 578
  • 1
  • 7
  • 16

2 Answers2

2

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ralf htp
  • 9,149
  • 4
  • 22
  • 34
2

Create a udev rule file, e.g., /etc/udev/rules.d/99-ttyUSB.rules and put the following line there:

ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", RUN+="/bin/stty -F /dev/%k 19200"

Replace XXXX and YYYY with your vendor/product id values respectively. You can obtain those by running lsusb

PooSH
  • 601
  • 4
  • 11