Hello!
I have been using an USB to Serial converter (like an FTDI ) to read output from a microcontroller. Just today, my script to output the data from the microcontroller started hanging. A few echo debug lines showed that it would hang when the exec command was executed to redirect the serial device to a file descriptor. The command used was:
exec 3</dev/ttyPIC
This command is executed after the stty command to set up the serial communications had completed successfully. The script has worked flawlessly for months. I am completely stumped. Here is a bit more about the set up.
The microcontroller writes data from a built in USART. This goes through a TTL to RS232 converted. This, in turn, is plugged in to the serial to USB. This, of course, is plugged in to the USB. On the PC side, the following udev rule gives my user and group permissions to the device:
tom@asimo:~> cat /etc/udev/rules.d/51-rs232.rules
KERNEL=="ttyUSB*", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", MODE:="0666", SYMLINK+="ttyPIC"
KERNEL=="ttyUSB*", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", OWNER:="tom" GROUP:="users"
The udev rule seems to still work. With the device plugged in, I can issue the stty command without error:
stty -F /dev/ttyPIC raw ispeed 19200 ospeed 19200 cs8 -cstopb -parenb -echo
If the device is unplugged, an input/output error is thrown as expected. If I try to assign the device to a file descriptor via:
exec 3</dev/ttyPIC, bash or the script simply hang.
I've tried the following to debug/solve. I tried unplugging/replugging, different USB ports on different hubs ( I have a few built in to the laptop ). I've logged out and back in. I've rebooted. ls /dev shows that the udev rule has set up the file for ttyPIC. lsusb shows the device has registered ( the last in the list here ):
asimo:/home/tom # lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 0cf3:3005 Atheros Communications, Inc. AR3011 Bluetooth
Bus 001 Device 004: ID 058f:b003 Alcor Micro Corp.
Bus 002 Device 003: ID 046d:c52f Logitech, Inc. Wireless Mouse M305
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 006: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
I've executed the following:
asimo:/home/tom # stty -F /dev/ttyPIC raw ispeed 19200 ospeed 19200 cs8 -cstopb -parenb -echo
asimo:/home/tom # setserial -a /dev/ttyPIC
/dev/ttyPIC, Line 0, UART: 16654, Port: 0x0000, IRQ: 0
Baud_base: 460800, close_delay: 0, divisor: 0
closing_wait: infinte
Flags: spd_normal
I usually start my script and then power on the microcontroller, so I tried the stty and exec in bash with just the serial to USB device connected. I get the same behavior. For reference, here is the script that used to work:
Code:
#!/bin/bash
cleanUp()
{
echo ' '
echo 'The user has ended listening on ttyUSB.'
exec 3<&-
exit $?
}
# Set up to trap Ctrl-C
trap cleanUp SIGINT
# Port setting
stty -F /dev/ttyPIC raw ispeed 19200 ospeed 19200 cs8 -cstopb -parenb -echo
exec 3</dev/ttyPIC
echo 'bar'
clear
echo 'Listening on ttyUSB:'
while [ 1 ]
do
read line 0<&3
if [ "$line" = "clear" ]
then
clear
echo 'Listening on ttyUSB:'
else
echo $line
fi
done
I am running OpenSuse 12.1 on a Toshiba Qosmio laptop with Gnome 3 in Fallback mode and bumblebee for the Optimus.
tom@asimo:~> uname -a
Linux asimo.site 3.1.10-1.16-desktop #1 SMP PREEMPT Wed Jun 27 05:21:40 UTC 2012 (d016078) x86_64 x86_64 x86_64 GNU/Linux
So I read the sticky on hardware, and decided to make a test and read dmesg. I found the last few lines of dmesg. I plugged in the serial to USB converter. I executed stty and the exec commands. I unplugged the device to restore the shell. I grabbed all the new lines of dmesg. Here they are:
[ 3522.753052] usb 3-1: new full speed USB device number 8 using xhci_hcd
[ 3522.777744] xhci_hcd 0000:06:00.0: WARN: short transfer on control ep
[ 3522.780782] xhci_hcd 0000:06:00.0: WARN: short transfer on control ep
[ 3522.783772] xhci_hcd 0000:06:00.0: WARN: short transfer on control ep
[ 3522.784751] usb 3-1: New USB device found, idVendor=067b, idProduct=2303
[ 3522.784755] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3522.784758] usb 3-1: Product: USB-Serial Controller
[ 3522.784760] usb 3-1: Manufacturer: Prolific Technology Inc.
[ 3522.786825] pl2303 3-1:1.0: pl2303 converter detected
[ 3522.814909] usb 3-1: pl2303 converter now attached to ttyUSB0
[ 3592.719389] xhci_hcd 0000:06:00.0: WARN: transfer error on endpoint
[ 3592.719432] usb 3-1: USB disconnect, device number 8
[ 3592.720038] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0
[ 3592.720052] pl2303 3-1:1.0: device disconnected
Thanks in advance for any advice/help you can offer!
Tom