libRDI.expect
changeset 7 0373c17d8b57
parent 5 f41d45fe7ae9
child 8 45809527a522
equal deleted inserted replaced
6:1ab5767c18dd 7:0373c17d8b57
     1 #!/usr/bin/expect -f
     1 #!/usr/bin/expect -f
     2 #======================================================================
     2 #======================================================================
     3 #                    L I B R D I . E X P E C T 
     3 #                    L I B R D I . E X P E C T 
     4 #                    doc: Mon Mar  8 02:57:35 2004
     4 #                    doc: Mon Mar  8 02:57:35 2004
     5 #                    dlm: Fri Dec 10 15:28:39 2010
     5 #                    dlm: Wed Dec 29 16:00:39 2010
     6 #                    (c) 2004 A.M. Thurnherr
     6 #                    (c) 2004 A.M. Thurnherr
     7 #                    uE-Info: 46 0 NIL 0 0 72 2 2 8 NIL ofnI
     7 #                    uE-Info: 255 0 NIL 0 0 72 2 2 8 NIL ofnI
     8 #======================================================================
     8 #======================================================================
     9 
     9 
    10 # HISTORY:
    10 # HISTORY:
    11 # Mar  8, 2004: - incepted (NBP0402)
    11 # Mar  8, 2004: - incepted (NBP0402)
    12 # Mar 15, 2004: - released
    12 # Mar 15, 2004: - released
    64 set BREAK 	\003;	# ^C
    64 set BREAK 	\003;	# ^C
    65 set HELP	\010;	# ^H
    65 set HELP	\010;	# ^H
    66 set TOGGLE	\024;	# ^T
    66 set TOGGLE	\024;	# ^T
    67 set DNLOAD	\030;	# ^X
    67 set DNLOAD	\030;	# ^X
    68 
    68 
    69 set cid -1;						# current instrument
    69 set cid -1;						# current instrument (master or slave)
    70 
    70 
    71 proc print_version {} {
    71 proc print_version {} {
    72 	send_user "acquire V1.5\n"
    72 	send_user "acquire V1.5\n"
    73 }
    73 }
    74 
    74 
   144 	}
   144 	}
   145 	if {$cid == 0} {set cid 1} else {set cid 0}
   145 	if {$cid == 0} {set cid 1} else {set cid 0}
   146 }
   146 }
   147 
   147 
   148 proc select_master {{toggle_first 1}} {			# select master & check S/N
   148 proc select_master {{toggle_first 1}} {			# select master & check S/N
   149 	global HELP cid master_sn slave_sn;
   149 	global cid master_sn slave_sn;
   150 
   150 
   151 	if {$toggle_first} toggle_instrument;
   151 	if {$toggle_first} toggle_instrument;
   152 	gobble_prompts;
   152 	gobble_prompts;
   153 	send "\r"; wait_for_prompt;			# save current value
   153 	send "\r"; wait_for_prompt;			# save current value
   154 	send "PS0\r";
   154 	send "PS0\r";
   169 	}
   169 	}
   170 	set cid 0;
   170 	set cid 0;
   171 }
   171 }
   172 
   172 
   173 proc select_slave {{toggle_first 1}} {			# select slave & check S/N
   173 proc select_slave {{toggle_first 1}} {			# select slave & check S/N
   174 	global HELP cid master_sn slave_sn;
   174 	global cid master_sn slave_sn;
   175 
   175 
   176 	if {$toggle_first} toggle_instrument;
   176 	if {$toggle_first} toggle_instrument;
   177 	gobble_prompts;
   177 	gobble_prompts;
   178 	send "\r"; wait_for_prompt;			# save current value
   178 	send "\r"; wait_for_prompt;			# save current value
   179 	send "PS0\r";
   179 	send "PS0\r";
   203 			error "No such device: cables plugged in???"
   203 			error "No such device: cables plugged in???"
   204 		}
   204 		}
   205 		-timeout 10 "Instrument 0" {}
   205 		-timeout 10 "Instrument 0" {}
   206 	}
   206 	}
   207 	set cid 0;
   207 	set cid 0;
   208 	sleep 1;				# AMARYLIS
   208 	sleep 1;
   209 }
   209 }
   210 
   210 
   211 proc reset_instrument {} {			# reset regardless of state
   211 proc reset_instrument {} {			# reset regardless of state
   212 	no_error_BREAK;
   212 	no_error_BREAK;
   213 	send "\r";				# send NOP command
   213 	send "\r";				# send NOP command
   214 	expect {
   214 	expect {
   215 		timeout {
   215 		timeout {
   216 			send_error ".";
   216 			send_error ".";
   217 			BREAK;			# try again
   217 			BREAK;			# try again
   218 		}
   218 		}
   219 		-timeout 5 ">";			# instrument reacted
   219 		-timeout 5 ">";			# instrument response received
   220 	}
   220 	}
   221 }
   221 }
       
   222 
       
   223 # In 2010 on the DIMES UK2 cruise, it was found that the instruments did
       
   224 # not communicate correctly, unless the slave was woken up first. On previous
       
   225 # cruises it had also been found that the order in which the instruments are
       
   226 # woken up can matter, although it had not been recorded which of the instruments
       
   227 # has to be woken first. An early workaround consisted in having a commented-out
       
   228 # toggle_instrument statement at the beginning of reset_two_instruments. In case
       
   229 # the communication did not work, that statement could simply be uncommented.
       
   230 # Another workaround would be to switch the serial ports the master/slave
       
   231 # ADCPs were connected to. Neither workaround is satisfacory, of course. Therefore
       
   232 # I decided to modify the routine reset_two_instruments to wake up an instrument,
       
   233 # determine whether it is the slave and, if not, send it back to sleep, toggle,
       
   234 # and wake up the other one. I am hoping that this is solves the problems once
       
   235 # and for all. If not, the code between the ### WORKAROUND markers should be
       
   236 # removed because it slows down comms with the ADCPs even more. In case of
       
   237 # wakeup/comms problems, the serial lines should then be switched.
   222 
   238 
   223 proc reset_two_instruments {} {			# reset regardless of state
   239 proc reset_two_instruments {} {			# reset regardless of state
       
   240 	global cid master_sn slave_sn;
   224 	set ok 0;
   241 	set ok 0;
   225 ###	toggle_instrument;
   242 
   226 	while {$ok < 2} {
   243 	while {$ok < 2} {
   227 		no_error_BREAK;
   244 		no_error_BREAK;
   228 		send "\r"; expect {
   245 		send "\r"; expect {
   229 			timeout {
   246 			timeout {
   230 				set ok 0;
   247 				set ok 0;
   232 			}
   249 			}
   233 			-timeout 5 ">" {incr ok}
   250 			-timeout 5 ">" {incr ok}
   234 		}
   251 		}
   235 		toggle_instrument;
   252 		toggle_instrument;
   236 	}
   253 	}
   237 	select_master;
   254 ### WORKAROUND BEGIN
       
   255 	send "PS0\r";
       
   256 	expect {
       
   257 		timeout {error "Can't determine serial number"}
       
   258 		-timeout 8 -re "Instrument S/N:  $master_sn.*>|Xducer Ser #:  $master_sn.*>|PS0...>" {
       
   259 			put_to_sleep;
       
   260 			toggle_instrument;
       
   261 			put_to_sleep;
       
   262 			reset_two_instruments;
       
   263 			toggle_instrument;
       
   264 		}
       
   265 		-timeout 8 -re "Instrument S/N:  $slave_sn.*>" {
       
   266 			toggle_instrument;
       
   267                 }
       
   268 		send "PS0\r";
       
   269 		expect {
       
   270 			timeout {error "Can't determine serial number"}
       
   271 			-timeout 8 -re "Instrument S/N:  $master_sn.*>|Xducer Ser #:  $master_sn.*>|PS0...>" {}
       
   272 			-timeout 8 -re "Instrument S/N:  $slave_sn.*>" {
       
   273 				error "Can't switch to master"
       
   274 			}
       
   275 		}
       
   276        }
       
   277 	set cid 0;
       
   278 ### WORKAROUND ELSE
       
   279 #	select_master;
       
   280 ### WORKAROUND END
   238 }
   281 }
   239 
   282 
   240 proc wait_for_prompt {{tout 5}} {		# wait for prompt
   283 proc wait_for_prompt {{tout 5}} {		# wait for prompt
   241 	expect {
   284 	expect {
   242 		timeout {error "Can't get prompt"}
   285 		timeout {error "Can't get prompt"}