Owner's manual

Chapter 5
Using the RS-232 Ports
525
The following is a sample ASCII program written in BASIC:
1 REM RS232 to CVIM COMMUNICATIONS SAMPLE PROGRAM
2 REM COPYRIGHT ALLENBRADLEY COMPANY, INC. 10-17-89 jrm
3 :
4 :
10 OPENcom1:9600,n,8,1,DSAS#1: REM Open communications channel
20 DIM R1(17): REM Allocate storage for tool set results
30 HE$=0123456789ABCDEF: REM Used for hex to decimal conversion
50 CLS
60 PRINT RS232 TO ALLENBRADLEY CVIM COMMUNICATIONS PROGRAM
70 PRINT:PRINT
99 :
100 PRINT ‘‘Press 1 or 2 to trigger tool set 1 or 2:’’;
110 K$=INKEY$: IF K$,.‘‘1’’ AND K$,.‘‘2’’ THEN 110
120 PRINT K$: TS = ASC (K$) 48: REM Convert key ‘‘1’’ or‘‘2’’ to number 1 or 2
130 GOSUB 2000: REM Read tool set results to get # of triggers processed
140 IF R1(0)<0 THEN 100 ELSE NT = R1(0)
150 GOSUB 1000: REM Trigger an inspection
200 GOSUB 2000: IF R1(0)=NT THEN 200: REM Read until the trigger is processed
210 GOSUB 2500: REM Convert hex result string RE$ to integers
220 IF R1(0) <0 THEN 100: REM Quit on input error
230 PRINT: FOR X=0 TO 17: PRINT R1(X),: NEXT: PRINT: REM Print results
240 IF R1(4) AND 2 THEN PRINT Window 1 FAIL
250 IF R1(4) AND 8 THEN PRINT Window 2 FAIL
260 IF R1(4) AND 32 THEN PRINT Window 3 FAIL
270 IF R1(4) AND 128 THEN PRINT Window 4 FAIL
400 GOTO 100
999 :
1000 REM Subroutine to trigger an inspection on tool set TS
1050 PRINT#1,>t,ts; CHR$(TS+48);CHR$ (13);: REM Send the command
1080 RETURN
1999 :
2000 REM Subroutine to read discrete results from tool set TS
2040 IF LOC(1) THEN R$=INPUT$(LOC(1),#1): REM clear out any garbage characters
2050 PRINT#1,>rr,p1; CHR$ (TS+48); CHR$(13);: REM Send the command
2060 CR$=INPUT$(2,#1): REM get CR/LF or ?/CR
2070 IF CR$=CHR$(13)+CHR$(10) THEN 2090
2080 PRINTInput error: R$=INPUT$(LOC(1),#1): R1(0)=1: RETURN
2090 R$=INPUT$(1,#1): IF ASC(R$)<32 THEN 2090: REM ignore junk
2100 LINE INPUT#1,RE$: RE$=R$+RE$: REM get entire response
2120 R1(0) = VAL(MID$(RE$,1,9)): R1(1) = VAL(MID$(RE$,10,9))
2130 R$=INPUT$(LOC(1),#1): RETURN: REM Clear out any remaining characters
2499 :
2500 REM Subroutine to convert hex values in discrete result string RE$
2501 REM to integer values
2510 FOR RN=0 TO 15
2515 REM The following line converts each pair of hex digits to an integer
2520 D1=INSTR(HE$,MID$(RE$,25+RN*3,1))1: D2=INSTR(HE$,MID$(RE$,26+RN*3,1))1
2530 R1(RN+2) = 16*D1+D2: NEXT RN: RETURN
ASCII Programming Example