Listing 2: Automation Control program
10 REM Telecomputer Controller with CM11A
11 REM TELEX10.BAS by M Chan 5/9
35 DEFINT A?Z
36 DATA 8,16,24,32,40,48,56,0
40 DIM code(8)
41 FOR i = 1 TO 8
43 READ code(i)
44 NEXT i
48 NULL = 0
50 READY = &H55
52 OPEN "COM1:4800,N,8,1,bin,CD0,CS0,DS0,op0,RS" FOR RANDOM AS #1
54 COM(1) ON
55 pport = 888
58 OUT pport + 2, 0
80 REM Hangup routine
90 OUT pport, 0
95 SLEEP 5
100 REM routine to check incoming rings
104 REM check ring signal
105 WAIT pport + 1, 128, 128
110 tim = 0
120 dead = 0
128 REM check ring signal stops
130 WAIT pport + 1, 128, 0
135 PRINT "pause between rings"
136 IF tim = 3 GOTO 200
137 SLEEP 1
140 WHILE (INP(pport + 1) >= 128)
150 dead = dead + 1
151 PRINT "between rings", dead
155 IF (dead > 8000) GOTO 100
160 WEND
180 tim = tim + 1
181 PRINT "no of rings :", tim
190 GOTO 120
200 REM answer after three rings
210 OUT pport, 2
211 PRINT "answer after three rings"
300 REM routine checking codes
302 SLEEP 2
310 notdone = 1
312 ik = 0
314 WHILE notdone
316 ik = ik + 1
320 tim = 0
330 WHILE ((INP(pport + 1) AND 64) = 0)
340 tim = tim + 1
345 PRINT "waiting for code :", tim, i
350 IF tim > 8000 GOTO 80
360 WEND
362 FOR j = 1 TO 500
363 FOR k = 1 TO 100
364 NEXT k
366 NEXT j
370 decode = INP(pport + 1) AND 56
371 PRINT i, "decode :", decode
375 FOR i = 1 TO 8
376 IF decode = code(i) GOTO 382
377 NEXT i
378 PRINT "illegal code"
380 GOTO 80
382 FOR j = 1 TO 800
383 PRINT i, "decode", decode
385 NEXT j
390 IF ik > 4 GOTO 400
392 IF ik <> i THEN PRINT "wrong password!"
394 IF ik <> i GOTO 80
398 GOTO 550
400 ON i GOTO 410, 430, 450, 470
405 GOTO 490
410 REM key 1=turn aircon (A1) ON
412 BYTE1 = &H4: BYTE2 = &H66: GOSUB 800
414 BYTE1 = &H6: BYTE2 = &H62: GOSUB 800
416 GOTO 550
430 REM key 2=turn garage door (A2) ON
432 BYTE1 = &H4: BYTE2 = &H6E: GOSUB 800
434 BYTE1 = &H6: BYTE2 = &H62: GOSUB 800
440 GOTO 550
450 REM key 3=turn porch light (A3) on
452 BYTE1 = &H4: BYTE2 = &H62: GOSUB 800
454 BYTE1 = &H6: BYTE2 = &H62: GOSUB 800
460 GOTO 550
470 REM key 4=set alarm (A4) OFF
472 BYTE1 = &H4: BYTE2 = &H6A: GOSUB 800
474 BYTE1 = &H6: BYTE2 = &H63: GOSUB 800
480 GOTO 550
490 REM key greater than 4=hang up phone
500 PRINT "case >4 == quit"
510 notdone = 0
550 WEND
555 COM(1) OFF
560 GOTO 80
600 STOP
610 END
800 REM routine to send 2 bytes to interface CM11A
850 CHK = BYTE1 + BYTE2
860 CHK = CHK AND &HFF
870 PRINT "sending address/function... chksum : ", HEX$(CHK)
880 STATE = 1
890 WHILE STATE
900 PUT #1, 1, BYTE1
910 PUT #1, 1, BYTE2
920 SLEEP 1
930 ON COM(1) GOSUB 1100
940 IF TM = CHK THEN STATE = 0
950 IF STATE = 1 THEN PRINT "inteface checksum NOT MATCHED"
960 WEND
970 PRINT "device address/function noted"
980 STATE = 1
990 PRINT "pc ready"
1000 WHILE STATE
1010 PUT #1, 1, NULL
1020 SLEEP 1
1030 ON COM(1) GOSUB 1100
1040 IF TM = READY THEN STATE = 0
1050 IF STATE = 1 THEN PRINT "interface not ready "
1060 WEND
1070 PRINT "Interface returned ready signal"
1080 RETURN
1090 STATE = 1
1100 GET #1, 1, CHKSUM
1110 TM = CHKSUM AND &HFF
1120 PRINT "interface returns CHECKSUM : ", HEX$(TM)
1130 RETURN