fconfigure 拒绝将波特率设置为 921600 [英] fconfigure refuses to set baud rate to 921600
问题描述
在 expect
脚本中,我试图在 Ubuntu 14.04 下通过直接访问串行端口/控制台来替换 spawn kermit
.
In expect
script, I'm trying to replace the spawn kermit
with a direct access to the serial port/console under Ubuntu 14.04.
代码相当简单:
set device "/dev/ttyUSB1"
set device_handle [open $device w+]
fconfigure $device_handle -mode "921600,n,8,1" -handshake none
#spawn -open $device_handle
我的问题是 Tcl (8.6) 或 Expect (5.45) 拒绝将波特率设置为 921600.
My problem is that the Tcl (8.6) or Expect (5.45) refuse to set the baud rate to 921600.
从 strace
输出中,我可以看到波特率设置为 460800(在 TCSETSW
命令到 ioctl()
中).像这样:
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
我测试了较低的波特率 - 9600、115200、460800 - 并且 Tcl 以正确的波特率调用了 ioctl()
.只有当我尝试设置 921600 时,Tcl 才会设置 460800.(kermit
使用相同的 ioctl()
调用并设置正确的波特率.)
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.)
有什么想法吗?
推荐答案
我已经研究过这个问题,它似乎是一个被刻录到 Tcl 核心中的限制.在 Unix 平台上,我们有一个硬编码的波特率列表,最高为 460800.
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.
如果您喜欢破解 Tcl 核心源代码,您可以将您自己的波特率添加到 unix/tclUnixChan.c(大约第 900 行)中的 speed[] 数组中.我们将努力在下一个版本中获得一组更新的速度.
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
更新:补丁已签入:http://core.tcl.tk/tcl/信息/7c1aae5292b3e6cd
这篇关于fconfigure 拒绝将波特率设置为 921600的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!