Cannot set baud rate on USB serial port for Ubuntu 12.04
I just upgraded from Ubuntu 10.04 on a project that connects an embedded device through a USB serial port at 115,200 baud. After upgrading this, it did not work, but I rebooted and was able to connect. Since shutting down and restarting my system I have not been able to connect. The serial line looks like it is connected at the wrong baud rate (fast string of characters like looking like:
"'''''''''''''''''ppppp'''''''''''''''pppppp'''''''''''"...
The USB device is being recognized and set up as /dev/ttyUSB0
. When I try setting the baud rate with stty
I get:
$ sudo stty -F /dev/ttyUSB0 115200
stty: /dev/ttyUSB0: unable to perform all requested operations
If I try setting to 9600
it seems to work:
$ sudo stty -F /dev/ttyUSB0 9600
But anything else fails:
$ sudo stty -F /dev/ttyUSB0 4800
stty: /dev/ttyUSB0: unable to perform all requested operations
Here is what stty sees:
$ stty -F /dev/ttyUSB0
speed 9600 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
I can change other values using stty (echo, echoe, etc.), but not the baud rate.
I saw a comment online that someone could set baud with Minicom, but not from the command line, so I got Minicom and tried it, but I get the same result (what appears to be the wrong baud rate).
I also tried setserial, but that also refuses to accept the /dev/ttyUSB
devices:
$ sudo setserial /dev/ttyUSB0 -a
Cannot get serial info: Invalid argument
$ sudo setserial /dev/ttyS0 -a
/dev/ttyS0, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4
Baud_base: 115200, close_delay: 50, divisor: 0
closing_wait: 3000
Flags: spd_normal skip_test
Finally, here are the devices, and their setup from dmesg:
$ ls -l /dev/ttyUSB*
crw-rw-rw- 1 root dialout 188, 0 Nov 19 15:53 /dev/ttyUSB0
crw-rw-rw- 1 root dialout 188, 1 Nov 19 16:00 /dev/ttyUSB1
$ dmesg | grep ttyUSB
[ 32.444445] usb 4-1: generic converter now attached to ttyUSB0
[ 32.444549] usb 8-2: generic converter now attached to ttyUSB1
I had been working with this device under Ubuntu 10.04 for a few months and was able to use them last week, but since shutting down and rebooting I have not been able to. I've looked online and found a few people with a similar problem, but none with solutions. How can I fix this problem?
I still don't know what happened, but it is working now. For anyone who runs into the same problem, I tried "modprobe -r usbserial" (my thought was to see if the old driver could be loaded with modprobe -f; it couldn't), and then reloaded the module "modprobe usbserial". This time the serial worked correctly - I don't know why.
Now when I do stty it reports:
~$ stty -F /dev/ttyUSB0
speed 115200 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon -iexten -echo
and I can change the baud rate (I changed it to 9600 and then back to 115200).
So there is no satisfactory answer, but apparently playing with it can make it work - just like it started working the first time after a reboot.
Write permission to the device file is required to change the settings. You can control it with simple listing. Eg.
$ ls -l
crw-rw-r-T 1 root dialout 188, 0 jan 9 16:16 /dev/ttyUSB0
In the case above everybody have read permission ( r
) the superuser root
and the dialout
group have write permission too ( rw
).
If you are member of the dialout
group you can change the speed without any extra thing by the above mentioned stty -F /dev/ttyUSB0 115200
command otherwise you need use sudo
.
You can control your membership status with the id
command.
上一篇: 只将应用程序脚本公开给某些脚本