C-2
Appendix C, DEMONSTRATION PROGRAMS
100 B$=B$+CR$ ' append a carriage return
110 GOSUB 180 ' output the command B$
120 GOSUB 310: PRINT Z$; ' read and display response
130 IF A$="?" THEN GOSUB 410: GOSUB 470 ' if "?" prompt fetch STATUS%
140 ' and display message
150 WEND ' return to start of loop
160 '
170 '
180 '...output the string B$..............
190 ON ERROR GOTO 510 ' enable error trapping
200 IF LOC(1)>0 THEN A$=INPUT$(LOC(1),#1) ' clear input buffer
210 ON ERROR GOTO 0 ' disable error trapping
220 FOR J1%=1 TO LEN(B$) ' LEN(B$) is number of bytes
230 C$=MID$(B$,J1%,1): PRINT#1,C$; ' send byte
240 WHILE LOC(1)=0: WEND ' wait for byte in input buffer
250 A$=INPUT$(1,#1) ' read input buffer
260 IF A$<>C$ THEN PRINT”handshake error” ' input byte should be echo
270 NEXT J1% ' next byte to be sent or
280 RETURN ' return if no more bytes
290 '
300 '
310 '....read response..................
320 A$="": Z$=""
330 WHILE (A$<>"*" AND A$<>"?") ' read until prompt received
340 Z$=Z$+A$ ' append next byte to string
350 WHILE LOC(1)=0: WEND ' wait for byte in input buffer
360 A$=INPUT$(1,#1) ' read byte from buffer
370 WEND ' next byte to be read
380 RETURN ' return if it is a prompt
390 '
400 '
410 '....fetch status byte..............
420 B$="ST"+CR$ ' "ST" is the status command
430 GOSUB 180 ' output the command
440 GOSUB 310 ' read response into Z$
450 STATUS%=VAL(Z$) ' convert to integer
460 RETURN
470 '....instrument error message.......
480 PRINT"Error prompt, status byte = ";STATUS% ' bits are defined in manual
490 PRINT
500 RETURN
510 '....I/O error routine..............
520 RESUME