Sunday, January 26, 2014

USB-to-Serial on Fedora 20

Oh boy, was I lucky my USB-to-serial works like a charm on my brand new Fedora 20 install. Plugged it in and it works, and I'll be damned.

And here's how my dmesg output looks:

[11619.109776] usb 3-4: new full-speed USB device number 3 using xhci_hcd
[11619.121660] usb 3-4: New USB device found, idVendor=0557, idProduct=2008
[11619.121666] usb 3-4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[11619.121669] usb 3-4: Product: USB-Serial Controller D
[11619.121672] usb 3-4: Manufacturer: Prolific Technology Inc.
[11619.513465] usbcore: registered new interface driver pl2303
[11619.513486] usbserial: USB Serial support registered for pl2303
[11619.513510] pl2303 3-4:1.0: pl2303 converter detected
[11619.514756] usb 3-4: pl2303 converter now attached to ttyUSB0

And voila! I have /dev/ttyUSB0 ready for outgoing serial connections.

And due to the nature of my work I need to keep a log of what I do. Here's a script which I have loaded onto by bash profile (~/.bash_profile). I know it looks crude, basically all I need to know prior to connecting to the target serial connection is to know what hostname it has as reference. And call the log of the connection as hostname-date_X, where is the number of console log I may already have in existence, and if it already exists, creates a new one by adding a +1 to X.

I actually though of adding traps after read hostname, just to make sure the hostname I enter are appropriately hostnames, but doing it on bash is just cumbersome. Since it's my laptop and my subroutine, heck this should work.

initserial() {
serdev=/dev/ttyUSB0
if [ ! -c ${serdev} ]; then 
echo "Usage: initserial"
echo " ttyUSB0 is not connected"
return 1 
fi
echo -n "Please enter the target server hostname: "
read hostname
i=1
found_console_log_file=0
while [ $found_console_log_file -eq 0 ]; do
console_log=${hostname}-`date +%Y%m%d`
echo ${console_log}_$i | egrep "^(.*)_+[[:digit:]]$" 2>&1 >/dev/null
found_console_log=$?
if [ ! -f ${console_log}_$i ]; then
console_log_file=${console_log}_$i
found_console_log_file=0
break
fi
i=`expr $i + 1`
done
echo "Appending output to $console_log_file"
/usr/bin/script $console_log_file
/usr/bin/screen $serdev 
}

No comments: