如何用tcl语言实现串口数据的读取?
答案:2 悬赏:10 手机版
解决时间 2021-04-11 14:20
- 提问者网友:我们很暧昧
- 2021-04-11 00:45
我已经用一个脚本实现了从pc到设备之间的串口连接,现在的图形界面类似于secureCRT,可以进行login、查询和修改各种配置等。
最佳答案
- 五星知识达人网友:酒安江南
- 2021-04-11 00:59
proc ComSetup {ComPort ComRate} {
set iChannel [open $ComPort w+]
set rate $ComRate
fconfigure $iChannel -mode $ComRate,n,8,1
fconfigure $iChannel -blocking 0
fconfigure $iChannel -buffering none
fileevent $iChannel readable ""
return $iChannel
}
proc GetData {iChannel} {
global output
update
after 2000
set cap [read -nonewline $iChannel]
return "$cap"
}
proc SendCmd {channel command} {
global output debug
set letter_delay 10
set commandlen [string length $command]
for {set i 0} {$i < $commandlen} {incr i} {
set letter [string index $command $i]
after $letter_delay
puts -nonewline $channel $letter
if {$debug(dutConfig) == 1} {puts -nonewline $output "$letter"}
}
after $letter_delay
puts -nonewline $channel "\n"
if {$debug(dutConfig) == 1} {puts $output ""}
after 500
flush $channel
}
慢慢看吧~应该明白
set iChannel [open $ComPort w+]
set rate $ComRate
fconfigure $iChannel -mode $ComRate,n,8,1
fconfigure $iChannel -blocking 0
fconfigure $iChannel -buffering none
fileevent $iChannel readable ""
return $iChannel
}
proc GetData {iChannel} {
global output
update
after 2000
set cap [read -nonewline $iChannel]
return "$cap"
}
proc SendCmd {channel command} {
global output debug
set letter_delay 10
set commandlen [string length $command]
for {set i 0} {$i < $commandlen} {incr i} {
set letter [string index $command $i]
after $letter_delay
puts -nonewline $channel $letter
if {$debug(dutConfig) == 1} {puts -nonewline $output "$letter"}
}
after $letter_delay
puts -nonewline $channel "\n"
if {$debug(dutConfig) == 1} {puts $output ""}
after 500
flush $channel
}
慢慢看吧~应该明白
全部回答
- 1楼网友:渡鹤影
- 2021-04-11 01:35
你说呢...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯