
9
4.5 Program examples
In the following examples, the PC reads status S1 from two COMPAX devices, for which the following parameters have
previously been set:
Device 1:
P194 = 1 P195 = 9600bit/s
Device 2:
P194 = 5 P195 = 9600bit/s
4.5.1
BASIC program with BCC
!
P196 = 8 in both devices
OPEN "com2:9600,N,8,1" FOR RANDOM AS #1----- Initialization of interface as #1 (channel 1)
com2:
serial interface COM2
9600:
9600 baud transmission rate
N:
no parity bit
8:
8 bit word length
1:
1 stop bit
text$ = "1S1" ---------------------------------------------------- device 1 is to be interrogated for status 1
GOSUB output ------------------------------------------------- calls up subprogram "Output"
GOSUB read---------------------------------------------------- calls up subprogram "Read"
PRINT text$ ----------------------------------------------------- outputs read value to screen
text$ = "5S1" ---------------------------------------------------- device 5 is to be interrogated for status 1
GOSUB output ------------------------------------------------- calls up subprogram "Output"
GOSUB read---------------------------------------------------- calls up subprogram "Read"
PRINT text$ ----------------------------------------------------- outputs read value to screen
END --------------------------------------------------------------- program end
output: ------------------------------------------------------------ start of subprogram "Output"
bcc = 0------------------------------------------------------------ bcc is set to 0
FOR a = 1 TO LEN(text$) ----------------------------------- loop performed for each character in text$
bcc = bcc XOR ASC(MID$(text$, a, 1)) ----------------- XOR operation on all characters to bcc
NEXT a ----------------------------------------------------------- end of loop
PRINT #1, text$ ------------------------------------------------ text$ is output with concluding CR to #1
PRINT #1, CHR$(bcc); --------------------------------------- BCC in bcc is output as character without CR to #1
RETURN --------------------------------------------------------- branch back to main program
read:--------------------------------------------------------------- start of subprogram "Read"
INPUT #1, text$ ------------------------------------------------ value is read from #1 to text$
a$ = INPUT$(2, 1) --------------------------------------------- characters LF and ">" are read from #1
bbcc = 0 ---------------------------------------------------------- bbcc is set to 0
FOR a = 1 TO LEN(text$) ----------------------------------- loop performed for each character in text$
bbcc = bbcc XOR ASC(MID$(text$, a, 1))--------------- XOR operation on all characters to bbcc
NEXT a ----------------------------------------------------------- end of loop
ebcc = ASC(INPUT$(1, 1)) ---------------------------------- BCC is read from #1 to ebcc
IF ebcc = bbcc THEN RETURN---------------------------- BCC read into ebcc is compared with
calculated BCC in bbcc; if values are same,
branch back to main program
PRINT "Transmission error !!!" ----------------------------- error message output on screen
RETURN --------------------------------------------------------- branch back to main program
Содержание Hauser COMPAX 25 S F1 Series
Страница 12: ...COMPAX M S RS485 12 ...