fconfigure refuses to set baud rate to 921600

1.1k views Asked by At

In expect script, I'm trying to replace the spawn kermit with a direct access to the serial port/console under Ubuntu 14.04.

The code is fairly simple:

set device "/dev/ttyUSB1"
set device_handle [open $device w+]
fconfigure $device_handle -mode "921600,n,8,1" -handshake none
#spawn -open $device_handle

My problem is that the Tcl (8.6) or Expect (5.45) refuse to set the baud rate to 921600.

From the strace output, I can see that the baud rate is set to 460800 instead (in TCSETSW command to ioctl()). Like this:

$ grep TCSETSW strace.out.*
strace.out.28667:ioctl(6, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B460800 -opost -isig -icanon -echo ...}) = 0
strace.out.28667:ioctl(6, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B460800 -opost -isig -icanon -echo ...}) = 0
strace.out.28667:ioctl(6, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B460800 -opost -isig -icanon -echo ...}) = 0

I have tested with lower baud rates - 9600, 115200, 460800 - and Tcl calls the ioctl() with the correct baud rates. Only if I try to set the 921600, Tcl sets the 460800 instead. (The kermit uses the same ioctl() call and sets the correct baudrate.)

Any ideas?

1

There are 1 answers

1
Sean Woods On BEST ANSWER

I have researched the issue, and it appears to be a limitation that is burned into the Tcl core. On the Unix platform, we have a hard coded list of baud rates, and the highest is 460800.

If you are comfortable hacking the Tcl core sources, you can add you own baud rates to the speeds[] array that is populated in unix/tclUnixChan.c (around line 900). We'll be working on getting a more up to date set of speeds into the next release.

--Sean "The Hypnotoad" Woods

Update: The patch is checked in: http://core.tcl.tk/tcl/info/7c1aae5292b3e6cd