libRDI.expect
changeset 7 0373c17d8b57
parent 5 f41d45fe7ae9
child 8 45809527a522
--- a/libRDI.expect	Fri Dec 10 15:45:10 2010 +0000
+++ b/libRDI.expect	Fri Jan 07 23:10:30 2011 +0000
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L I B R D I . E X P E C T 
 #                    doc: Mon Mar  8 02:57:35 2004
-#                    dlm: Fri Dec 10 15:28:39 2010
+#                    dlm: Wed Dec 29 16:00:39 2010
 #                    (c) 2004 A.M. Thurnherr
-#                    uE-Info: 46 0 NIL 0 0 72 2 2 8 NIL ofnI
+#                    uE-Info: 255 0 NIL 0 0 72 2 2 8 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -66,7 +66,7 @@
 set TOGGLE	\024;	# ^T
 set DNLOAD	\030;	# ^X
 
-set cid -1;						# current instrument
+set cid -1;						# current instrument (master or slave)
 
 proc print_version {} {
 	send_user "acquire V1.5\n"
@@ -146,7 +146,7 @@
 }
 
 proc select_master {{toggle_first 1}} {			# select master & check S/N
-	global HELP cid master_sn slave_sn;
+	global cid master_sn slave_sn;
 
 	if {$toggle_first} toggle_instrument;
 	gobble_prompts;
@@ -171,7 +171,7 @@
 }
 
 proc select_slave {{toggle_first 1}} {			# select slave & check S/N
-	global HELP cid master_sn slave_sn;
+	global cid master_sn slave_sn;
 
 	if {$toggle_first} toggle_instrument;
 	gobble_prompts;
@@ -205,7 +205,7 @@
 		-timeout 10 "Instrument 0" {}
 	}
 	set cid 0;
-	sleep 1;				# AMARYLIS
+	sleep 1;
 }
 
 proc reset_instrument {} {			# reset regardless of state
@@ -216,13 +216,30 @@
 			send_error ".";
 			BREAK;			# try again
 		}
-		-timeout 5 ">";			# instrument reacted
+		-timeout 5 ">";			# instrument response received
 	}
 }
 
+# In 2010 on the DIMES UK2 cruise, it was found that the instruments did
+# not communicate correctly, unless the slave was woken up first. On previous
+# cruises it had also been found that the order in which the instruments are
+# woken up can matter, although it had not been recorded which of the instruments
+# has to be woken first. An early workaround consisted in having a commented-out
+# toggle_instrument statement at the beginning of reset_two_instruments. In case
+# the communication did not work, that statement could simply be uncommented.
+# Another workaround would be to switch the serial ports the master/slave
+# ADCPs were connected to. Neither workaround is satisfacory, of course. Therefore
+# I decided to modify the routine reset_two_instruments to wake up an instrument,
+# determine whether it is the slave and, if not, send it back to sleep, toggle,
+# and wake up the other one. I am hoping that this is solves the problems once
+# and for all. If not, the code between the ### WORKAROUND markers should be
+# removed because it slows down comms with the ADCPs even more. In case of
+# wakeup/comms problems, the serial lines should then be switched.
+
 proc reset_two_instruments {} {			# reset regardless of state
+	global cid master_sn slave_sn;
 	set ok 0;
-###	toggle_instrument;
+
 	while {$ok < 2} {
 		no_error_BREAK;
 		send "\r"; expect {
@@ -234,7 +251,33 @@
 		}
 		toggle_instrument;
 	}
-	select_master;
+### WORKAROUND BEGIN
+	send "PS0\r";
+	expect {
+		timeout {error "Can't determine serial number"}
+		-timeout 8 -re "Instrument S/N:  $master_sn.*>|Xducer Ser #:  $master_sn.*>|PS0...>" {
+			put_to_sleep;
+			toggle_instrument;
+			put_to_sleep;
+			reset_two_instruments;
+			toggle_instrument;
+		}
+		-timeout 8 -re "Instrument S/N:  $slave_sn.*>" {
+			toggle_instrument;
+                }
+		send "PS0\r";
+		expect {
+			timeout {error "Can't determine serial number"}
+			-timeout 8 -re "Instrument S/N:  $master_sn.*>|Xducer Ser #:  $master_sn.*>|PS0...>" {}
+			-timeout 8 -re "Instrument S/N:  $slave_sn.*>" {
+				error "Can't switch to master"
+			}
+		}
+       }
+	set cid 0;
+### WORKAROUND ELSE
+#	select_master;
+### WORKAROUND END
 }
 
 proc wait_for_prompt {{tout 5}} {		# wait for prompt