11 - 158 11 - 158
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Program Example
(Executed in BASIC on the AD51H)
10 ' This program receives data continually and ends only when an interrupt occurs from CH2
20 ON ERROR GOTO 500
:
' Branches to line 500 if an error occurs
30 CLS
40 ON COM(2) GOSUB 340
:
' Branches to line 340 when there is an
interrupt from CH2
50 COM(2) ON
:
' Allows an interrupt
60 DIM TBL1%(2),CNT%(10),TBL2%(2)
70 '***** RS-232C CH.OPEN *****
80 CH%=2
:
' Defines a communication channel
90 TBL1%(0)=4800
:
' Sets the baud rate
100 TBL1%(1)=&H8
:
' Sets character length, parity bit,
110 TBL1%(2)=&H1
:
' and stop bit
120 ZOPEN #CH%,TBL1%( )
:
' Opens the communication channel
130 '
140 '***** PORT CNTL *****
150 CNT%(0)=32
:
' Specifies control by the RS and ER
signals
160 CNT%(1)=&H1
:
' Turns the RS control signal on
170 ZCNTL #CH%,0,CNT%( )
:
' Executes
180 '
190 '***** MAIN PROGRAM *****
200 J=0
:
' Displays on the screen
210 LOCATE 0,J
220 PRINT "MAIN PROGRAM"
230 J=J+1
240 IF J=10 THEN J=0
250 FOR I=0 TO 100
260 NEXT I
270 CLS
280 GOTO 210
290 '
300 '***** RS-232C CH.CLOSE *****
310 ZCLOSE #CH%
320 END
330 '
340 '***** DATA RECEIVE *****
350 TBL2%(0)=12
:
' Specifies the number of transmission
request bytes
360 TBL2%(1)=0
:
' Stores the number of bytes transmitted
370 TBL2%(2)=300
:
' Specifies the timeout value
380 WOR%=TBL2%(0)/2
390 DIM CTBL%(WOR%-1)