holmes
holmes

Reputation: 578

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.

Upvotes: 3

Views: 3524

Answers (2)

ralf htp
ralf htp

Reputation: 9422

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?

Upvotes: 2

PooSH
PooSH

Reputation: 711

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

Upvotes: 2

Related Questions