Appendix DSample Programs Including Commands for Host Computer
126
190 INPUT #1,COMMAND$ :’Data reception via the PC line.
200 T$=LEFT$(COMMAND$,LEN(COMMAND$)–3) :’Checks the FCS.
210 GOSUB *FCS
220 IF FCS$<>MID$(COMMAND$,LEN(COMMAND$)–2,2) THEN ENDCODE$=”1004”:GOTO *RE-
SPONSE
240 CMNDCODE$=MID$(COMMAND$,27,4) :’Checks the command code.
250 IF CMNDCODE$<>”0101” THEN ENDCODE$=”0401”:GOTO *RESPONSE
260 FOR I=0 TO VAL(”&H”+MID$(COMMAND$,39,4))–1 :’Set the data to be read.
270 RESPDATA$=RESPDATA$+CHDATA$(I)
280 NEXT I
290 PRINT ”Reception data:”;RESPDATA$
300 ENDCODE$=”0000” :’Assigns 0000 to the response code.
310 ’*****************************************
320 *RESPONSE :’Creates a response frame.
330 RSV$=MID$(COMMAND$,9,2) :’Returns the RSV and SID that
340 DA$=MID$(COMMAND$,19,6) :’were received.
350 SA$=MID$(COMMAND$,13,6) :’Exchanges DNA, DA1, and DA2 with
360 SID$=MID$(COMMAND$,25,2) :’SNA, SA1, and SA2 and returns them.
370 TS=”@000F00C0”+RSV$+”02”+DA$+SA$+SID$+CMNDCODE$+ENDCODE$+RESPDATA$
380 GOSUB *FCS
390 RESPONSE$=T$+FCS$+”*”
410 PRINT #1,RESPONSE$ :’Transmits the data via the PC line.
420 GOTO 180
430 ’*****************************************
440 ’******FCS Operation Processing Subroutine*******
450 ’*****************************************
460 *FCS :’Calculates the FCS.
470 L=LEN(T$)
480 A=0
490 FOR J=1 TO L
500 TJ$=MID$(T$,J,I)
510 A=ASC(TJ$) XOR A
520 NEXT J
530 FCS$=HEX$(A)
540 IF LEN(FCS$)=1 THEN FCS$=”0”+FCS$
550 RETURN
560 ’*****************************************
570 ’********** Error processing **********
580 ’*****************************************
590 *EROPE
600 PRINT ”ERL=”:ERL,”ERR”;ERR
610 CLOSE 1
620 END