11 - 356 11 - 356
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Program Example
10 ' This program writes data to extension registers (TASK 1)
20 ZODV O
:
'Displays on the console
30 DIM A%(9)
:
'Defines an array
40 DEF ZEVENT 1
:
'Defines an event
50 ZEVENT ENABLE 1
:
'Enables event generation
60 A$="TASK 1 writing data"
:
'Defines an message
70 B$="TASK 1 writing data completed"
80 FOR I=1 TO 10
:
'Writes the data
90 A%(I-1)=I
100 NEXT I
110 ZRESERVE 1
:
'Reserves resource number 1
120 LOCATE 0,2
:
'Specifies the display position
130 PRINT A$
:
'Displays the message
140 PUTMEM TO W@(ED,0),0 FROM A%( ),0,20
:
'Executes the write operation
150 PRINT B$
:
'Displays the message
160 ZSIGNAL 1
:
'Event generation
170 PRINT "Data written"
:
'Displays the data written
180 FOR I=1 TO 10
190 PRINT A%(I-1),
200 NEXT I
210 ZRELEASE 1
:
'Releases resource number 1
220 END
:
'Ends the execution
10 ' This program reads data from extension registers (TASK 2)
20 ZODV O
:
'Displays on the console
30 DIM B%(9)
:
'Defines an array
40 C$="TASK 2 reading data"
:
'Defines a message
50 D$="TASK 2 reading data completed"
60 FOR I=0 TO 9
:
'Stores dummy values
70 B%(I)=0
80 NEXT I
90 ZWAIT EVENT 1
:
'Waits for event generation
100 ZRESERVE 1
:
'Reserves resource number 1
110 LOCATE 0,15
:
'Specifies the display position
120 PRINT C$
:
'Displays the message
130 GETMEM TO B%( ),0 FROM W@(ED,0),0,20
:
'Executes the read operation
140 PRINT D$
:
'Displays the message
150 PRINT "Data read"
:
'Displays the data read
160 FOR I=1 TO 10
170 PRINT B%(I-1),
180 NEXT I
190 ZRELEASE 1
:
'Releases resource number 1
200 END
:
'Ends the execution
REMARK
See the GETMEM instruction and Section 8.5.1.