Hello,
I'm having a problem getting an expect script to work with a serial port. In the past, I've had success with expect using telnet & ssh, but I left scripting for some time. Now I'm back to it & working on automating some operations taking place over a serial port. So I have a simple script that opens the serial port, expects a set of 3 strings to come across, & lets me know they arrived. This is a simple test but I can't get it to consistently work. Most of the time, the script fails with; 'expect: spawn_id exp10 not open'. I'm too dense to pull out of the book on expect any reason why this happens & am hoping someone here may help. I'll try to post enough script details for a possible answer while not overdoing it ...
proc openSerial {baud_rate ser_dev} {
set portId [open $ser_dev RDWR]
if {[catch {chan configure $portId -mode "$baud_rate,n,8,1" } error]} {
exp_send_user "could not configure &ser_dev parms\n"
return 0
} else {
spawn -open $portId -noecho
return $spawn_id
}
return 0
}
Main body of script ...
Opening the serial port:
set baud 115200
set serDev /dev/ttyUSB0
set comId00 [openSerial $baud $serDev]
sleep 5
puts "serial spawn id is $comId00\n"
At this point I see exp10 output as the spawn ID ... so I do the following:
expect {
"<first string>"
{ puts "got it ...\n"
expect "<next string>"
puts "got string 2 ...\n"
expect "<last string>"
puts "got final string ...\n" }
timeout { do timeout stuff ... }
}
When I run this, I see string 1 & string 2 as expected. Then I see the 'spawn id not open' message & the script fails. I guess I don't really understand what's happening with spawn & how that relates to the serial port? I need to continue working with this port & can't even get started so far. Any help will be appreciated.
ACE