Hi All,

I'm having some trouble making expect work.

I need it to talk to some vintage equipment over usb serial, and I think I'm getting hung up on opening the port.

When the script runs, it just connects to the device and sits there. I can drive it interactively, but it doesn't attempt to automate anything.

Any ideas? Thanks.

My expect script looks like this:

#!/usr/bin/expect -f

# device
set modem /dev/ttyUSB0

# keep it open
exec sh -c "sleep 3 < $modem" &

# serial port parameters
exec stty -F $modem 2400 raw -clocal -echo -istrip -hup

# connect
send_user "connecting to $modem, exit with ~,\n"
spawn -open [open $modem w+]
interact {
    ~, exit
    ~~ {send "\034"}
}

set force_conservative 1 ;# set to 1 to force conservative mode even if
              ;# script wasn't run conservatively originally
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
        sleep .1
        exp_send -s -- $arg
    }
}

set timeout -1
match_max 100000
send -- "\r"
send -- "\r"
expect  ">"
send -- "p 7d91\r"
expect  ">"
send -- "p b2ff\r"
expect  ">"
send -- "h\r"
expect  ">"
send -- "td\r"
expect "td\r
  18 215  12  24  33\r
>"
send -- "gd 215\r"
expect eof