11 - 410 11 - 410
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Program Example
10 ' This program sets parameters for a communication channel
20 DIM TBL1%(2),TBL2%(3),TBL3%(3),B%(1)
:
' Defines an arrays
30 A%=1
:
' Communication channel CH1 (RS-232C)
40 TBL1%(0)=4800
:
' Sets the baud rate
50 TBL1%(1)=&H107
:
' Sets the character length and parity bit
60 TBL1%(2)=&H1
:
' Sets the stop bit
70 ZOPEN #A%,TBL1%( )
:
' Opens the communication channel
80 TBL2%(0)=16
:
' Specifies to set the communication
parameters
90 TBL2%(1)=9600
:
' Sets the baud rate
100 TBL2%(2)=&H208
:
' Sets the character length and parity bit
110 TBL2%(3)=&H1
:
' Sets the stop bit
120 ZCNTL #A%,0,TBL2%( )
:
' Executes the setting of the communication
parameters
130 TBL3%(0)=17
:
' Specifies to read the communication
parameters
140 ZCNTL #A%,0,TBL3%( )
:
' Executes reading the communication
parameters
150 PRINT "Baudrate =";TBL3%(1)
:
' Displays the baud rate
160 A$=RIGHT$("0000"+HEX$(TBL3%(2)),4)
:
' Converts TBL3%(2) to a character string
170 L$=RIGHT$(A$,2)
:
' Reads the lower byte
180 H$=LEFT$(A$,2)
:
' Reads the higher byte
190 B%(0)=VAL("&H"+L$)
:
' Converts the lower byte to a numeric
value
200 B%(1)=VAL("&H"+L$)
:
' Converts the higher byte to a numeric
value
210 PRINT "Character length=";B%(0)
:
' Displays the character length
220 PRINT "Parity bit=";B%(1)
:
' Displays the parity bit
230 PRINT "Stop bit=";TBL3%(3)
:
' Displays the stop bit
240 ZCLOSE #A%
:
' Closes the communication channel
250 END