문제

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

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.

다른 팁

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…

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top