When my USB-serial dongle initializes, it comes up with the RTS line asserted. I get the same behavior if it's plugged in during boot or if I plug in the dongle after boot.

This is for my hamshack computer, where the serial port is connected to my transceiver. The RTS line puts the rig into transmit mode, which I would rather not have as the default. Of course, once I run fldigi or wsjtx, the RTS line behaves.

Is there a place to set that default? I've poked around a bit in /etc, but I haven't found any init or config file where the default might be. It could be as simple as putting 'stty -F /dev/ttyUSB0 -crtscts' somewhere, but where?

This computer doesn't have a built-in serial port, so the dongle is the only option here.

Running 16.04 LTS release.

  • There may be a chance to define a udev rule (see crashcourse.ca/wiki/index.php/Udev) to set the serial lines when the dongle is activated. You will have to get familiar with udev rules.. – ridgy Feb 11 '17 at 17:40
  • Thanks for pointing me to that wiki. I've got a place to start now. It's not clear to me yet if a udev rule can do something specific like setting modem control lines. – G Weast Feb 13 '17 at 1:58
  • For more info and to avoid common mistakes, see e.g the answers here and here or search for udev rules RUN. – ridgy Feb 13 '17 at 10:26

In the end after some research I succeeded in answering your question.

Assume your USB-to-serial dongle is connected and available as /dev/USB0. Then you first have to find out some information for configuring udev.rules:

udevadm info -n ttyUSB0 -a will walk you through the information tree. If, for example, you want the rule to create to match only this specific dongle, you may refer to vendor, product and serial Id:

$ udevadm info -n ttyUSB0 -a

then these are the attributes to respect in your rule.

Next, create a udev rule in /etc/udev/rules.d for this device:

$ sudo vi /etc/udev/rules.d/99-ttyUSB.rules

ACTION=="add", SUBSYSTEMS="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTHL8XKY", RUN+="/bin/stty -F /dev/%k -crtscts"

(Enter the values for your device rsp.). The line reads:

Only when the dongle is added (ACTION="add"), and when vendor, product and serial match the given values, then run the action, which is defined as you wanted, where '%k' is the kernel name of the device, in this case ttyUSB0(but may be different next time).

The name of your rules file is arbitrary, but you should respect the naming conventions used by udev. To see what is going to be executed, you may test by udevadm test -a add /devices/pci0000:00/0000:00:13.2/usb2/2-4/2-4.1/2-4.1:1.0/ttyUSB0/tty/ttyUSB0 (the device path is shown in the udev info, first line).

To see if this works, you may have a look at /var/log/syslog when plugging in the dongle. First configure udev to show not only error messages by modifying /etc/udev/udev.conf to read udev_log="debug"; otherwise you will only see error messages. Restart the udevservice (sudo systemctl restart udev), then:

$ tail -f  /var/log/syslog | grep udev
Feb 13 14:47:42 desk systemd-udevd[16013]: starting '/bin/stty -F /dev/ttyUSB0 -crtscts'
Feb 13 14:47:42 desk systemd-udevd[15995]: Process '/bin/stty -F /dev/ttyUSB0 -crtscts' succeeded.

This should also show errors if it does not succeed. udevtries to run the command different times in different stages, so there will be some errors, but in the end it should succeed.

If you want to have a fixed device symlink created whenever you plug in the dongle, this is also possible. Just add the action to your rule:

ACTION=="add", SUBSYSTEMS="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="FTHL8XKY", SYMLINK+="mynewserial", RUN+="/bin/stty -F /dev/%k -crtscts"

This will create a symlink /dev/mynewserial you can use in your programs, without regards to dynanmically created devices.

There are a lot more possibilities; this should only give some impression on how to proceed.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.