11 - 467 11 - 467
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
(Executed in BASIC on the LM7000)
10 ' This program sends data from a console (LM7000 is the reception side)
20 ON ERROR GOTO 390
:
'Branches to line 360 if an error occurs
30 '
40 '***** RS-232C CH.OPEN *****
50 DIM T%(8)
:
' Defines an array
60 CH%=18
:
' Defines a channel number
70 T%(0)=4800
:
' Sets the baud rate
80 T%(1)=&H8
:
' Sets the character length, parity bit,
90 T%(2)=&H1
:
' stop bit, and DC control
100 T%(3)=0
:
' Sets control by signals
110 T%(4)=0
:
' Sets the receive buffer
120 T%(5)=0
:
' Sets DC1 code and DC code
130 T%(6)=0
:
' Sets DC3 code and DC2 code
140 T%(7)=0
:
' Sets DC4 code
150 ZOPEN #CH%,T%( )
:
' Opens the communication channel
160 '
170 '***** DATA RECEIVE *****
180 DIM TBL%(6)
:
' Defines an array
190 TBL%(0)=30
:
' Sets the number of characters requested
to be received
200 TBL%(1)=0
:
' Stores the number of characters received
210 TBL%(2)=300
:
' Sets the timeout value
220 TBL%(3)=0
:
' Sets the number of break characters
230 TBL%(4)=0
:
' Sets break characters 1 and 2
240 TBL%(5)=0
:
' Sets break characters 3 and 4
250 TBL%(6)=0
:
' Sets break character 5
260 WOR%=TBL%(0)/2
:
' Reads 2 bytes
270 DIM CT%(WOR%-1)
:
' Defines an array
280 ZRECEIVE #CH%,0,TBL%( ),CT%( )
:
' Executes the reception
290 PRINT "RECEIVE CHARACTER =";TBL%(1)
:
' Displays the number of characters
received
300 FOR I%=0 TO WOR%-1
310 PRINT "RECEIVE DATA =&H";HEX$(CT%(I%))
:
' Displays the data received
320 NEXT I%
330 '
340 '***** RS-232C CH.CLOSE *****
350 ZCLOSE #CH%
:
' Closes the communication channel
360 END
:
' Ends the execution
370 '
380 '***** ERROR ROUTIME *****
390 ERTYPE%=ERR:ERLINE%=ERL
:
' Stores the error occurred and the line
where it occurred
400 IF ERTYPE%=94 THEN ERTYPE%=ZERROR(1) :
' Displays the error if it is Z related
410 PRINT "ERROR CODE =";ERTYPE%
:
' Displays the error code
420 PRINT "ERROR LINE =";ERTYPE%
:
' Displays the line where the error occurred
430 RESUME 350
:
' Returns the processing to line 350