10 DIM ANS$(2),MES$(2):M%=2:TOUT%=2:echo%=0:stol%=6:gosub 631:gosub 646:GOTO 360
170 '
180 ON ERROR GOTO 220
190 ANS$=ANS$+INPUT$(LOC(PFLAG%),PFLAG%):IF LEN(ANS$)<ECHOL% THEN GOTO 190
200 ON ERROR GOTO 0
210 RETURN
220 RESUME 190
230 '
240 IF LOC(PFLAG%)<>0 THEN GOSUB 180:GOTO 240
250 ANS$="":C$=CO$+CHR$(13)
260 FOR I%=1 TO LEN(C$):LSET Z$(PFLAG%)=MID$(C$,I%,1):PUT #PFLAG%,1:NEXT I%
270 T1=TIMER
280 IF LOC(PFLAG%)<>0 THEN GOTO 180
290 IF TIMER-T1>TOUT% THEN PRINT "timeout port ";PFLAG%:GOTO 250
300 GOTO 280
310 '
320 CO$="05":ECHOL%=1:GOSUB 240:RETURN
330 CO$="2"+CHR$(&H31)+CHR$(&H36):ECHOL%=1:GOSUB 240:RETURN ' sets up ac+dc measurements
340 CO$="30":ECHOL%=16:GOSUB 240:RETURN
350 '
360 FOR PFLAG%=1 TO M%
370 GOSUB 320 ' initialize interface & make sure mx55 talks back
380 IF ANS$<>CHR$(6) THEN PRINT "port ";PFLAG%;" failed initialization":GOTO 750
390 GOSUB 330 ' configure mx55 to report dc measurements
400 NEXT PFLAG%
410 '
420 LOCATE 15,10:PRINT "press s to start";:gosub 671
430 Q$=INKEY$:IF Q$<>"s" AND Q$<>"S" THEN GOTO 430
440 OPEN "o",#3,F$:PRINT #3,"PrimaryVoltage[V],SecondaryVoltage[V]"
450 gosub 672
460 LOCATE 15,10:color 14,0:PRINT "press:<space> to take a measurement   <t> to terminate";:color 10,0
470 Q$=INKEY$:IF Q$="t" OR Q$="T" THEN GOTO 750
480 IF Q$<>" " THEN GOTO 470 
481 gosub 672
490 FOR PFLAG%=1 TO M%
500 GOSUB 340:ANS$(PFLAG%)=ANS$:LANS$=LEFT$(ANS$,stol%)
510 gosub 670
511 locate 17,20:color 12,0:PRINT "stabilizing measurement";PFLAG%;:color 10,0
520 GOSUB 340:if left$(ans$,stol%)<>lans$ then goto 500
521 gosub 340:if LANS$<>LEFT$(ANS$,stol%) THEN GOTO 500
522 if instr(ans$,"X")<>0 then goto 490
530 gosub 670
540 NEXT PFLAG%
550 FOR PFLAG%=1 TO M%
560 RDP$="E+00":RDG$=LEFT$(ANS$(PFLAG%),7):IF LEFT$(RDG$,1)=" " THEN MID$(RDG$,1,1)="+"
570 IF INSTR(ANS$(PFLAG%),"m")<>0 THEN RDP$="E-03"
580 IF INSTR(ANS$(PFLAG%),"u")<>0 THEN RDP$="E-06"
590 MES$(PFLAG%)= RDG$+RDP$
600 NEXT PFLAG%
604 locate 16,10:print mes$(1);" ";LEFT$(ANS$(1),LEN(ANS$(1))-1),MES$(2);" ";ANS$(2);
607 print #3,MES$(1);",";MES$(2)
621 locate 18,30:print "memory ";fre("");
622 GOTO 450
625 '
631 CLS:KEY OFF:color 10,0
632 PRINT "              AC and DC Transformer: (c) 2005, 2011 by Stuart Hutton"
633 print "  PrimaryVoltmeter (com1)   : Scale set on V  with leads connected to V and COM"
634 print "  SecondaryVoltmeter (com2) : Scale set on V  with leads connected to V and COM"
635 print "  Please make sure that for both meters, the following is true:"
636 print "  (1) MX55 is on low input impedance & (2) RS232 port is initialized"
638 PRINT:locate 7,1
639 INPUT "What is the datafile to be named (8 letters maximum, no periods)";F$
640 if f$="" then f$="Xformer"
641 F$="i:\"+F$+".csv"
642 locate 14,15:PRINT "The ouput data file is named ";F$
643 gosub 671
644 return
645 '
646 OPEN "com2:2400,n,8,1,cs 0,ds 0,cd 0,bin" FOR RANDOM AS #2:FIELD 2,1 AS Z$(2)
647 OPEN "com1:2400,n,8,1,cs 0,ds 0,cd 0,bin" FOR RANDOM AS #1:FIELD 1,1 AS Z$(1)
648 return
649 '
670 x%=17:goto 680
671 x%=7:goto 680
672 x%=15:goto 670
680 locate x%,1:print STRING$(75," "):return
750 CLOSE #1:CLOSE #2:CLOSE #3
760 END