The problem was that I was using "source" to run my other tcl scripts when I should have been using exec. Now I can allow my device to shut off, then turn back on and communicate again.
Connecting/disconnecting to COM port expect
문제
Can't seem to disconnect properly from the com port in use and end the spawned process. I need to disconnect from the COM port, then reconnect.
# Read the COM port from the command line
if { $argc >= 1 } {
set file [lindex $::argv 0]
} else {
set file /dev/ttyUSB0
}
set fh [open $file RDWR]
fconfigure $fh -mode "115200,n,8,1" -blocking 0 -buffering none -eofchar {}
spawn -open $fh -noecho
해결책 2
다른 팁
To disconnect from the serial port, you've got to close the channel (because that translates into a close on the underlying OS file descriptor). Because you've attached it to an expect spawn_id (the result of the spawn
) you have to close that. You do that with:
close -i $spawn_id
Though if you only have one thing spawned at a time, you can just:
close
You'll have to go through the whole process (open
, fconfigure
and optionally spawn -open
) again to reconnect. You might want to refactor that out into a procedure…
제휴하지 않습니다 StackOverflow