11 - 413 11 - 413
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Program Example
1 ' This program sets and reads the communication control parameters
10 DIM TBL1%(2),TBL2%(3),TBL3%(3),B%(1)
:
' Defines arrays
20 CH%=1
:
' Defines a channel number
30 TBL1%(0)=4800
:
' Sets the baud rate
40 TBL1%(1)=&H8
:
' Sets the character length and parity bit
50 TBL1%(2)=&H2
:
' Sets the stop bit
60 ZOPEN #CH%,TBL1%( )
:
' Opens the communication channel
70 TBL1%(0)=18
:
' Specifies to set the communication control
parameters
80 TBL2%(1)=&HA03
:
' Specifies to enable DC1/DC3
transmission/reception control
90 TBL2%(3)=1024
:
' Sets the receive buffer size to 1024 bytes
100 ZCNTL #CH%,0,TBL2%( )
:
' Executes the setting operation
110 TBL3%(0)=19
:
' Specifies to read the communication
control parameters
120 ZCNTL #CH%,0,TBL3%( )
:
' Executes the reading operation
130 PRINT "Setting status of the communication control parameters" :'Displays the result of reading
140 A$=RIGHT$("0000"+HEX$(TBL3%(1)),4)
150 L$=RIGTH$(A$,2)
160 H$=LEFT$(A$,2)
170 B%(0)=VAL("&H"+L$)
:
' The value of the lower byte of TBL%(3)
180 B%(1)=VAL("&H"+H$)
:
' The value of the higher byte of TBL%(3)
190 B=RDSET(1,B%(0))
:
' Checks the first bit of the lower byte
200 IF B=1 THEN PRINT "DC1/DC3 reception control enabled"
210 IF B<>1 THEN PRINT "DC1/DC3 reception control disabled"
220 C=RDSET(3,B%(0))
:
' Checks the 3rd bit of the lower byte
230 IF C=1 THEN PRINT "DC1/DC3 transmission control enabled"
240 IF C<>1 THEN PRINT "DC1/DC3 transmission control disabled"
250 FOR I=1 TO 4
260 D=RDSET(I-1,B%(1))
:
' Checks the 0th to 3rd bits of the higher
byte
270 ON I GOSUB 320,350,380,410
280 D=0
290 NEXT I
300 ZCLOSE
310 END
320 IF D=1 THEN PRINT "RS control enabled"
330 IF D<>1 THEN PRINT "RS control disabled"
340 RETURN
350 IF D=1 THEN PRINT "ER control enabled"
360 IF D<>1 THEN PRINT "ER control disabled"
370 RETURN
380 IF D=1 THEN PRINT "CS control enabled"
390 IF D<>1 THEN PRINT "CS control disabled"
400 RETURN
410 IF D=1 THEN PRINT "DR control enabled"
420 IF D<>1 THEN PRINT "DR control disabled"
430 RETURN