#!/usr/bin/expect -- #Note: the file .kermrc has the command "prompt k>>" # v3 141016 # v4 180523 -- include COM1 to mini PC log_user 0 set setupfile "$env(DAQSWFOLDER)/setup/su.txt" #============== ## READ SETUP FILE FOR IP ADDRESS #============== spawn -noecho getsetupinfo $setupfile "SERIAL HUB IP" expect -re "(\.*)(\r)"; set hubip $expect_out(1,string) send_user "SERIAL HUB IP: $hubip\n" ## SERIAL SERVER VIA ETHERNET if { [string first "dev" $hubip] == -1 } { send_user "serial server hub\n" #============== ## READ SETUP FILE FOR PORT NUMBER #============== spawn -noecho getsetupinfo $setupfile "ROSR PORT" expect -re "(\.*)(\r)"; set portnumber $expect_out(1,string) send_user "ROSR PORT: $portnumber\n" # START PROCESS -- KERMIT FOR MODEM spawn sudo kermit expect { "assword" { send "r0srr0sr\n" } ">>" { send "\n" } } set PDS $spawn_id set timeout 4 expect { timeout {"KERMIT FAILS TO OPEN\n"; exit 1} ">>" } ## OPEN THE PORT send "set host $hubip $portnumber\r" expect ">>" send_user "set host $hubip $portnumber\n"; ## FINE TUNING TCP/IP send "set tcp keepalive on\r\n" expect ">>" send "set tcp linger\r\n" expect ">>" send "set tcp nodelay on\r\n" expect ">>" # v2 send "set telnet echo local\r\n" expect ">>" ## this is important for using the rsr menu ## raw means send CR by itself, not CRLF and NOT CRNul send "set telnet newline-mode nvt raw\r\n" expect ">>" # LOG THE SESSION set logpath "$env(DAQDATAFOLDER)/capture_rosr.txt" send_user "log to $logpath\n"; send "log session $logpath append\r\n" expect ">>" ## CONNECT send "connect\r" expect { "Conn*---" {send_user "CONNECTED\r\n"} timeout {send_user "TIMEOUT, NO CONNECT"; exit 1} } set spawn_id $PDS interact ## RS232 SERIAL DIRECT TO COM } else { spawn sudo kermit expect { "assword" { send "r0srr0sr\n" } ">>" { send "\n" } } set ROSR $spawn_id set timeout 4 expect { -i ROSR timeout {"KERMIT FAILS TO OPEN\n"; exit 1} ">>" } ## OPEN THE PORT send "set line $hubip\r" expect ">>" #send_user "set line $hubip\n"; ## SPEED send "set speed 9600\r" ## DUPLEX send "set duplex full\r" expect ">>" ## LOCAL ECHO send "set local-echo on\r" expect ">>" ## FLOW CONTROL send "set flow none\r" expect ">>" ## CARRIER WATCH send "set carrier-watch off\r" expect ">>" ## LOG send "log session ../data/capture.txt append\r" expect ">>" ## CONNECT send "connect\r" expect { "Conn*---" {send_user "TTY CONNECTED\n"} timeout {send_user "TIMEOUT, NO CONNECT"; exit 1} } set spawn_id $ROSR interact } exit; exit 0