14 External Device SER instruction
6.14.1 RS instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
RS | Serial data transfer | 16 | No | RS S m D n | 9 |
RS is a transceiver instruction that automatically sends the data stored in the specific register to the serial port sequentially and stores the data received by serial port in the specific area. It is equivalent to directly access the communication buffer.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | |||||||||||||||
m | √ | √ | √ | |||||||||||||
D | √ | |||||||||||||||
n | √ | √ | √ |
COM2 (communication port): it uses RS485, it supports program protocol (PLC protocol), MODBUS protocol (MODBUS-RTU slave, MODBUS-RTU master, MODBUS-ASCII slave, MODBUS-ASCII master), N:N network protocol (so far, only available in LX3VP series PLC). The communication protocol is set by D8126, the communication parameters are set by D8120, the detailed as below.
Communication setting for COM2 | ||
Protocol | The value of D8126 | Communication parameters |
HMI monitor protocol (PLC protocol) | 0x01 | Set by D8120 |
MODBUS-RTU slave | 0x02 | Set by D8120 |
MODBUS-ASCII slave | 0x03 | Set by D8120 |
User-defined protocol | 0x10 | Set by D8120 |
MODBUS-RTU master | 0x20 | Set by D8120 |
MODBUS-ASCII master | 0x30 | Set by D8120 |
Item | Parameter | Bit value of D8120 | |||||||
b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | ||
Baud rate (Bps) | 115200 | 1 | 1 | 0 | 0 | - | - | - | - |
57600 | 1 | 0 | 1 | 1 | - | - | - | - | |
38400 | 1 | 0 | 1 | 0 | - | - | - | - | |
19200 | 1 | 0 | 0 | 1 | - | - | - | - | |
9600 | 1 | 0 | 0 | 0 | - | - | - | - | |
4800 | 0 | 1 | 1 | 1 | - | - | - | - | |
Stop bit | 1 bit | - | - | - | - | 0 | - | - | - |
2 bit | - | - | - | - | 1 | - | - | - | |
Parity | None | - | - | - | - | - | 0 | 0 | - |
Odd | - | - | - | - | - | 0 | 1 | - | |
Even | - | - | - | - | - | 1 | 1 | - | |
Data bit | 7 bit | - | - | - | - | - | - | - | 0 |
8 bit | - | - | - | - | - | - | - | 1 | |
Example: the communication format is 9600.1.8.None, b7b6b5b4=1000, b3=0, b2b1=00, b 0=1. D8120=81H ( (10000001)2=81H, 81H means hexadecimal number) |
RS (user-defined Protocol) Instruction Description
- S: the head address of the register where the to be sent data stored in
- m: the length of the to be sent data (byte), 0 to 256.
- D: the head address of the register where the receive data stored in
- n: the length of the receive data(byte),0 to 256
Example
When X1 is ON, the receive data and the sand data is shown as below.
The RS (MODBUS mode) instruction automatically sets the M8123 once every time a transmit data is received and the acknowledge operation is received. Using this flag, it is possible to determine whether the RS instruction has been executed.
In actual programming, you need to do some preparation for serial communication and configuration, such as baud rate, check bit, timeout judgment condition, protocol etc. The same example, a relatively complete set of RS communication procedures are as follows.
RS (MODBUS Protocol) Instruction Description
The definitions of each operand in the RS (MODBUS mode) instruction are different from those of a standard RS instruction (user-defined protocol).
- S: Slave address (high byte), communication command (low byte, defined by MODBUS protocol);
- m: Start address of accessing slave;
- D: Data length, unit: word;
- n: Start address of data storage, the take up length of the subsequent address defined by D;
Program example
The PLC is set to MODBUS-RTU master mode, it reads data from address 100 of Slave 1, and read the data stored in D10.
6.14.2 RS2 instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
RS2 | Serial data transfer 2 | 16 | No | RS S m D n n1 | 11 |
This instruction is mainly used for serial data transfer instruction in BD board module.
RS2 is a transceiver instruction that automatically sends the data stored in the specific register to the serial port sequentially and stores the data received by serial port in the specific area. It is equivalent to directly access the communication buffer.
The RS2 instruction is used to configure the communication protocol according to the CPAVL instruction. For details, refer to the LX3V-2RS485-BD User's Manual, LX3V-ETH-BD User's Manual or the CPAVL Instruction Manual.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | |||||||||||||||
m | √ | √ | √ | |||||||||||||
D | √ | |||||||||||||||
n | √ | √ | √ | |||||||||||||
n1 | √ | √ | √ |
In LX3V-2RS485-BD module
- User-defined protocol
S: Starting address of transmitted data.
m: Length of transmitted data, the range is 0~256
D: Starting address for storage data.
n: Length of received data, the range is 0~256
n1: Serial port Number, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.
In this example, n1 is set K2, so the RS2 instruction is used in COM2. When X1 is triggered program will transfer data as below shows.
- MODBUS protocol
The definitions of each operand in the RS2 (MODBUS mode) instruction are different from those of a standard RS instruction (user-defined protocol).
S: Slave station address (high byte), communicational command (low byte, define by MODBUS protocol);
M: Register start address of call on slave station;
D: Data length will be read or write, units is word;
N: Memory units original address for read or write data, engross continuous address units, length decided by D;
n1: Serial port Number, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.
In this example, n1 is set K2, so the RS2 instruction is used in COM2. When X1 is triggered program will transfer data as below shows.
In LX3V-ETH-BD module
- MODBUS TCP protocol
S: The address of slave (high byte) and communication command (low byte, defined by MODBUS protocol);
m: The starting address number of the slave
D: The length of the data (read or writes), the unit is word. (The specific setting is shown in the following table)
Function code | Length | Length (HEX) |
Write coils | 1968 | 0x7B0 |
Read coils | 2000 | 0x7D0 |
Write registers | 123 | 0x7B |
Read registers | 125 | 0x7D |
n: The starting address of the storage unit for reading or writing data, occupying the subsequent address unit, and the length is determined by the D
n1: The connection number corresponding to the Ethernet port connection number (specific settings is shown as the following table)
Ethernet port 1 | Connection number | Ethernet port 2 | Connection number | ||
![]() | Connection 1 | 1000 | ![]() | Connection 1 | 1100 |
Connection 2 | 1001 | Connection 2 | 1101 | ||
Connection 3 | 1002 | Connection 3 | 1102 | ||
Connection 4 | 1003 | Connection 4 | 1103 | ||
Connection 5 | 1004 | Connection 5 | 1104 | ||
Connection 6 | 1005 | Connection 6 | 1105 | ||
Connection 7 | 1006 | Connection 7 | 1106 | ||
Connection 8 | 1007 | Connection 8 | 1107 |
In this example n1 is set as K1002, then RS2 is configured for Ethernet port 1, connection 3. When x1 is ON, the data is shown as below.
6.14.3 RSLIST instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
RSLIST | Formulated communication instructions | 16 | No | RSLIST S1 S2 m1 | 9 |
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S1 | √ | |||||||||||||||
S2 | √ | |||||||||||||||
m1 | √ |
Only LX3VP series and above plc (advanced series) support RSLIST instruction, and major version number and this version number of LX3VP series plc must be "25103" and "16001" and above edition, while major version number and this version number of LX3VPE series plc must be "25201" and "16001" and above edition.
This instruction is the one tabulating RS instruction, which replaces communication protocol by changing D8126 (communication protocol). Most of its functions are the same as the ones of RS instruction, but with simplified cumbersome engineering writing, in which, parameters of each transmission command are directly set by table.
S1 is the starting device address controlled by table, with value range of D0~D7999; The addresses of starting device between S1~S4+4+n*6 couldnot be occupied by other instructions. (As far as possible, store data in power-down save (latched) (D200-D7999) to avoid data loss).
Communication table of RSLIST instruction (MODBUS protocol) | |||
Address | Name | Function description | |
S1+0 | Header | Header = 50h, correct MODBUS and MODBUSASC protocol communication form. ( No modification ) | |
S1+1 | Communication command number | Communication command number: A transmission needs to use six devices to describe, that is, six devices describe a data transmission. ( No modification ) | |
S1+2 | Check bit of header and communication command number | Check header and communication command number ( No modification ) | |
S1+3 | Error replication number (retry times) (for all commands) | Error replication number (retry times) (0-255) | |
S1+4 | Slave station number of current communication | Function code | Station number: 0 ~ 255 (0 means that the master station broadcast to all slave station, while slave station does not respond to the received information.) Function code: please check the table below. |
S1+5 | Start address of Slave data | Word is valid. Define start address of Slave. | |
S1+6 | Data length | Word is valid, range: 1~126 (word data), 1 ~ 2039 (bit data). | |
S1+7 | Master stores data starting device | Word is valid. Define Master to receive the start address of data. | |
S1+8 | Sending control bit | Sending control bit: no running temporarily as long as it’s 0. (when it is not 0, no execution) | |
S1+9 | Single error replication number(retry times) | Single error replication number (retry times)(0-255) | |
S1+10 | Slave station number | Function code | Description of second data transmission |
S1+11 | Start address of Slave data | ||
S1+12 | Data length | ||
S1+13 | Master stores data starting device | ||
S1+14 | Sending control bit | ||
S1+15 | Single error replication number (Retry times) | ||
… | … | … | |
S1+4+n*6 | Save | N is the total number of data transmission commands |
Communication table of RSLIST instruction (User-defined protocol) | ||
Address | Name | Function description |
S1+0 | Header | Header = 51h, correct MODBUS and MODBUSASC protocol communication form. ( No modification ) |
S1+1 | Communication command number | Communication command number: A transmission needs to use six devices to describe, that is, six devices describe a data transmission. ( No modification ) |
S1+2 | Check bit of header and communication command number | Check header and communication command number ( No modification ) |
S1+3 | Error replication number (retry times) (for all commands) | Error replication number (retry times) (0-255) |
S1+4 | Master sends data starting device | Receive the start address of data. |
S1+5 | Data length of Master | Word is valid. PLC determines data length according to cache block. (LX3VP:0~528) |
S1+6 | Master receives data starting device | Word is valid. Define Master to send the start address of data. |
S1+7 | Data length of slave station | Word is valid. PLC determines data length according to cache block. (LX3VP:0~528) |
S1+8 | Sending control bit | Sending control bit: no running temporarily as long as it’s 0. (when it is not 0, no execution) |
S1+9 | Single error replication number (Retry times) | Single error replication number(Retry times) (0-255) |
S1+10 | Data length of Master | Description of second data transmission. |
S1+11 | Data length of Slave | |
S1+12 | Master sends data starting device | |
S1+13 | Master receives data starting device | |
S1+14 | Sending control bit | |
S1+15 | Single error replication number (Retry time) | |
… | … | … |
S1+4+n*6 | Save | N is the total number of data transmission commands |
S2 is the starting device address of table cache, with value range of D0~D7999; the addresses of cache starting device between S2~S2+12 couldnot be occupied by other instructions.
Note: any random data in the above operation-forbidden area will lead to communication anomalies.
Address | High byte | Low byte | Operated |
S2+0 | Operation serial number: indicate which command is operating at present. | No | |
S2+1 | Result code: = 0, normal; = Other value, abnormal | No | |
S2+2 | Slave station device number | Function code | No |
User-defined Protocol: master station sends starting device | No | ||
S2+3 | Start address of Master device (User-defined protocol: Master receives the start address of data) | No | |
S2+4 | Received or sent data size (User-defined protocol: data size received by master | No | |
S2+5 | Error replication number(Retry times) of current command | No | |
S2+6 | Error times record | No | |
S2+7 | Bit0 = 1, Port has been occupied, this command waits for data transmission rights; Bit4, communication transmission output indication is represented by "M1"; Bit5, communication error output indication is represented by "M1 + 1"; Bit6, communication completion output indication is represented by "M1 + 2". | No | |
S2+8 | Select which command to implement | Yes | |
S2+9 | Select which command to open and close: which command | Yes | |
S2+10 | Select which command to open and close: 0: none, 1: close, 2: open; | Yes | |
S2+11 | (System occupancy) | No |
Name | Numerical value | Function description |
Function code | 01H | Read the state of consecutive multiple single-points from Slave |
03H | Read data of consecutive multiple registers from Slave | |
05H | Write the state of individual single-point into Slave | |
06H | Write data of single register into Slave | |
0FH | Write the state of consecutive multiple single-points into Slave | |
10H | Write data of consecutive multiple registers into Slave | |
Result code (error code) | 0x00 | successful communication transaction |
0x01 | frame error | |
0x02 | illegal communication table (header error) | |
0x04 | Data length error (the position read or written by command is beyond range of device size) | |
0x05 | the set read and write length range is beyond device range (starting device plus the length is beyond the range of D0-D7999) | |
0x06 | Function code error (incorrect function code or not supporting this function code). | |
0x07 | Slave station number error | |
0x08 | Slave | |
0x09 | No response in Slave ( abnormal time-out) | |
0x0A | Abnormal communications (receive erroneous data or slave station responses to error message). | |
0x0B | selected commands exceed maximum number of commands | |
0x0F | Skip this command (the sending control bit of this command is not 0) |
m1 is the start address of communication flag, with value range of M0 ~ M3068; (m1~m1+2) couldnot be used by other instructions.
Address | Function |
m1+0 | Transmission flag |
m1+1 | Error flag |
m1+2 | Completion flag |
Other related settings are listed below:
Item | Parameter | Bit value of D8120 | |||||||
b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | ||
Baud rate (Bps) | 115200 | 1 | 1 | 0 | 0 | - | - | - | - |
57600 | 1 | 0 | 1 | 1 | - | - | - | - | |
38400 | 1 | 0 | 1 | 0 | - | - | - | - | |
19200 | 1 | 0 | 0 | 1 | - | - | - | - | |
9600 | 1 | 0 | 0 | 0 | - | - | - | - | |
4800 | 0 | 1 | 1 | 1 | - | - | - | - | |
Stop bit | 1 bit | - | - | - | - | 0 | - | - | - |
2 bit | - | - | - | - | 1 | - | - | - | |
Parity | None | - | - | - | - | - | 0 | 0 | - |
Odd | - | - | - | - | - | 0 | 1 | - | |
Even | - | - | - | - | - | 1 | 1 | - | |
Data bit | 7 bit | - | - | - | - | - | - | - | 0 |
8 bit | - | - | - | - | - | - | - | 1 | |
Example: the communication format is 9600.1.8.None, b7b6b5b4=1000, b3=0, b2b1=00, b 0=1. D8120=81H ( (10000001)2=81H, 81H means hexadecimal number) |
Address | Description |
D8120 | Com2 port communication format, interface configuration settings (see the above table for details). |
D8122 | User-defined protocol: send remaining data (for RS instruction only); MODBUS protocol: command sending interval, 0 = 5ms. Unit 0.1ms |
D8124 | starting character STX (only for RS user-defined protocol) |
D8125 | terminating character ETX (only for RS user-defined protocol) |
D8126 | Communication protocol settings, interface configuration settings |
D8129 | MODBUS: determine the time of communication timeout, interface configuration settings, the default is 10 (10ms) RS user-defined protocol: inter-character timeout, interface configuration settings, the default is 10 (10ms) |
D8172 | First character timeout, interface configuration settings, the default is 10 (10ms) First character timeout is not calculated when M8172 is 0. (only for RS user-defined protocol) |
Create new RSLIST table
Right click (Project Manager -> Project Property -> Extended Function -> RSLIST Table) to create or edit table, as shown below:
- Table setting interface as below
- Communication protocol: should be consistent with the configuration of communication protocol control address (D8126, etc.) (Modbus Master / RS user-defined protocol).
- Default error repeat count: use the replication number (retry times)of a single error when it is not 0; use the error replication number (retry times) set in header when it is 0; default 3 times when both are 0. The set replication number includes number of times for the first run, that is, repeat errors only for two times and then turn to the next when the set replication number is 2.
- Table initial address: should be consistent with in the corresponding RSLIST instruction.
- Address allocation: Table space could be automatically configured or selected as fixed length (4 + n * 6), where n is the number of communication commands.
✎Note: Number of table commands should be less than 255. And do address planning to avoid data confusion caused by repeatedly occupied addresses.
Modbus Protocol Configuration
- Ladder configuration
- Table configuration
Table start address is D300, which corresponds to the RSLIST instruction in ladder.
When M1 = ON, RSLIST instruction starts execution. When "YES" in "whether to enable command” is selected as instruction in the table ", number 1 and 3 instructions in execution table are executed cyclically; when “No” is selected, execution is controlled by “S2+8”=D208. As shown in the above ladder, D208 = 2 is triggered every 500ms, that is, number 2 instruction in the table is executed every 500ms. (Read data of 20 addresses starting from station 100 and store the read data in D500-D519 separately).
- Communication command configuration
Slave station number: (limited between 0-255). Account 0 is used as broadcast and will not receive. See "Function Code List".
The data start address (D device) range in master station is (D0-D7999). Store relevant data in power-down save (D200-D7999) to avoid data loss. Store data start address in slave station.
Byte of data: (bit length in bits, word length in words), range 1 to 126 (word data), 1 to 2039 (bit data).
Error repeat time: 0 indicates that this error replication number (retry times) is the same as the one in table edit.
Default starting command:
Yes: execute cyclically when RSLIST is started;
No: execute only when +8 is in action.
RS User-defined Protocol
- Ladder configuration
- Table configuration
The table start address is D800, which corresponds to the RSLIST instruction in ladder.
When M2=ON, RSLIST instruction starts execution. When "YES" in "whether to enable command” is selected as instruction in the table ", number 2 instructions in execution table are executed cyclically; when “No” is selected, execution is controlled by“S2+8”=D208. As shown in the above ladder, D708 = 1 is triggered every 500ms, that is, number 1 instruction in the table is executed every 500ms. (Send data of the 20 addresses starting from D1000 to device and store the returned data in the 20 addressed starting from D1020.)
- Communication command configuration
Starting address of delivery (D device) range is (D0-D7999). Store relevant data in power-down save (D200-D7999) to avoid data loss.
Sending length: the length here is in BYTE (range LX3VP: 0-528). No sending when the sent data length is 0.The receiving start address (D device) range is (D0-D7999). Store relevant data in power-down save (D200-D7999) to avoid data loss.
Receiving length: the length here is in BYTE (range LX3VP: 0-528). No receiving when the received data length is 0.
Error repeat count: 0 indicates that this error replication number (retry times)is the same as the one in table edit.
Default starting command:
Yes: execute cyclically when RSLIST is started;
No: execute only when +8 is in action;
6.14.4 CPAVL instruction (Ethernet port)
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
CPAVL | Communication port setting | 16 | No | CPAVL S D M | 7 |
- S: The starting address of “D” device;
- D: The starting address of “M” device;
- M: Serial port Number, 0 means using COM0, 1 means using COM1, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | |||||||||||||||
D | √ | |||||||||||||||
m | √ | √ |
Connection number description | ||
CPAVL instruction | Port | Connection number |
Ethernet port 1 | 1000 | |
Ethernet port 2 | 1100 |
✎Note:
Only need one CPAVL instruction to configure multiple connections. The RS instruction needs to be used for the corresponding connection.
Address definition
- M device (Bit)
Bit address | Description | Connection | Bit address | Description | Connection |
D+0 | Reserved | Connection 1 Configuration | D+10 | Reserved | Connection2 Configuration |
D+1 | Instruction execution | D+11 | Instruction execution | ||
D+2 | Instruction execution state | D+12 | Instruction execution state | ||
D+3 | Communication error flag | D+13 | Communication error flag | ||
D+4 | Reserved | D+14 | Reserved | ||
D+5 | Reserved | D+15 | Reserved | ||
D+6 | Reserved | D+16 | Reserved | ||
D+7 | Reserved | D+17 | Reserved | ||
D+8 | Reserved | D+18 | Reserved | ||
D+9 | Timeout flag | D+19 | Timeout flag | ||
D+20 | … | … | D+30 | … | … |
- D device (Word)
Word Address | Description D | Detailed description | Other instructions | Read and write features |
0 | Version number | BD Board parameter settings | R | |
1 | BD Board IP Address | IP First 1 Section | R/W | |
2 | IP First 2 Section | R/W | ||
3 | IP First 3 Section | R/W | ||
4 | IP First 4 Section | R/W | ||
5 | Port | 0 default K502 | R/W | |
6 | Gateway | Gateway first 1 Section | R/W | |
7 | Gateway first 2 Section | R/W | ||
8 | Gateway first 3 Section | R/W | ||
9 | Gateway first 4 Section | R/W | ||
10 | Subnet mask | Subnet mask first 1 Section | R/W | |
11 | Subnet mask first 2 Section | R/W | ||
12 | Subnet mask first 3 Section | R/W | ||
13 | Subnet mask first 4 Section | R/W | ||
14 | MAC | MAC First 1 Section | R | |
15 | MAC First 2 Section | R | ||
16 | MAC First 3 Section | R | ||
17 | MAC First 4 Section | R | ||
18 | MAC First 5 Section | R | ||
19 | MAC First6 Section | R | ||
20 | (Reserved) | R/W | ||
21 | (Reserved) | R/W | ||
22 | Number of connections | How many connections are required to set the number of connections | R/W | |
23 | Protocol | Protocol | Connection 1 Configuration | R/W |
24 | Slaves IP | IP First 1 Section | R/W | |
25 | IP First 2 Section | R/W | ||
26 | IP First 3 Section | R/W | ||
27 | IP First 4 Section | R/W | ||
28 | Port | 0 default K502 | R/W | |
29 | (Reserved) | R/W | ||
30 | Instruction sending interval | Set the instruction sending interval. Unit: 0.1ms | R/W | |
31 | (Reserved) | R/W | ||
32 | (Reserved) | R/W | ||
33 | (Reserved) | R/W | ||
34 | Timeout | R/W | ||
35 | Protocol | Communication protocol | Connection 2 Configuration | R/W |
36 | Slaves IP | IP First 1 Section | R/W | |
37 | IP First 2 Section | R/W | ||
38 | IP First 3 Section | R/W | ||
39 | IP First 4 Section | R/W | ||
40 | Port | 0 default K502 | R/W | |
41 | (Reserved) | R/W | ||
42 | (Reserved) | R/W | ||
43 | (Reserved) | R/W | ||
44 | (Reserved) | R/W | ||
45 | (Reserved) | R/W | ||
46 | Timeout | R/W | ||
47 | … | … | … | R/W |
Program example
Use the Ethernet port 1, and the parameter table start from D300 and M300.
- The Ethernet parameter setting of LX3V-ETH-BD
- MODBUS protocol setting
6.14.5 CPAVL instruction (Serial port)
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
CPAVL | Communication port setting | 16 | No | CPAVL S D M | 7 |
- S: The starting address of “D” device;
- D: The starting address of “M” device;
- M: Serial port Number, 0 means using COM0, 1 means using COM1, 2 means using COM2, 3 means using COM3, 4 means using COM4, 5 means using COM5, 6 means using COM6; Program could write multiple RS2 instructions, but only one RS2 instruction could be triggered at the same time.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | |||||||||||||||
D | √ | |||||||||||||||
m | √ | √ |
Address definition
Setting the parameters of COM4 are in 20 consecutive addresses beginning of D0 and M0.
Bit address | Content | Word address | Content |
D+0 | Retention | S+0 | Communication format, defined is 0 |
D+1 | Sending(RS2) | S+1 | Station number, defined is 0 |
D+2 | Sending flag (RS2) Instruction state (MODBUS) | S+2 | Remaining amount of data transmission(RS2) Interval of sending(MODBUS) |
D+3 | Receiving flag(RS2) Communication error flag (MODBUS) | S+3 | The number of receiving data (RS2) |
D+4 | Receiving (RS2) | S+4 | Starting code STX(RS2) |
D+5 | Retention | S+5 | Ending code ETX(RS2) |
D+6 | Retention | S+6 | Communication protocol |
D+7 | Retention | S+7 | Retention |
D+8 | Retention | S+8 | Retention |
D+9 | Timeout flag | S+9 | Timeout, defined is 10 (10ms) |
D+10~ D+19 | Retention | S+10~ S+19 | Retention |
Program example
- MODBUS RTU Master
Users could set MODBUS RTU master communication by RS2 instruction, as above example shows. RS2 is a communication instruction, which could send data in the specified register area to the serial port and store receive data to specified register. Equivalent to the user program directly access the communication cache, with the help of the user program processing of the communication cache, to achieve the communication. RS instruction only is available in COM2 port, but RS2 instruction could be available in COM3/ COM4/ COM5/ COM6 ports.
- MODBUS ASCII Slave
When plc switches from stop to run state, PLC performs MODBUS RTU Slave communication; the function code and address mapping are consistent with COM2.
PLC internal address | MODBUS address | Number | Description |
D0~D8255 | 0 (0) | 8256 | |
T0~T255 | 0x F000 (61440) | 256 | |
C0~C199 | 0x F400 (62464) | 200 | |
C200~C255 | 0x F700 (63232) | 56 | 32-bit register |
- User-defined
6.14.6 PRUN instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
PRUN | Transmission of Octal bits | 16 | No | PRUN S D | 5 |
PRUNP | 16 | Yes | 5 | ||
DPRUN | 32 | No | 9 | ||
DPRUNP | 32 | Yes | 9 |
The instruction is used for coping the bit variables (the width unit is of octal) of the continuous addresses starting with S to the bit variable set starting with D in batch.
- S: The starting address of the bit variables to be copied, where the unit digit of the addresses must be 0, such as X10, M20;
- D: The starting address of the target bit variables, where the unit digit of the addresses must be 0, such as X10, M20;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | ||||||||||||||
D | √ | √ |
Program example
Example 1
Example 2
6.14.7 ASCI instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
ASCI | Converts a data value from hexadecimal to ASCII | 16 | No | ASCI S D n | 7 |
ASCIP | 16 | Yes | 7 |
This instruction reads n hexadecimal data characters from head source address (S) and converts them in to the equivalent ASCII code.
- S: The source address;
- D: The store address;
- n: The data length;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n | Constant, n=1~256 |
Program example
The M8161 flag determines the width mode of the target variable for calculation result storage. When M8161=OFF, it is 16bit mode, which means the higher byte and lower byte are saved respectively. When M8161=ON, it is 8bit mode, which means that only the lower byte is used to save result and the actual variable range length is longer.
- When M8161=OFF
When M8161=ON
Points to note
Instructions such as RS / HEX / ASCI / CCD share the M8161 mode flag, please pay attention on it when programming.
6.14.8 HEX instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
HEX | Converts a data value from hexadecimal to ASCII | 16 | No | HEX S D n | 7 |
HEXP | 16 | Yes | 7 |
This instruction reads n ASCII data bytes from head source address (S) and converts them in to the equivalent Hexadecimal character, and saved result in D.
- S: The variable address or constant to be converted. If it is a register variable, the conversion interval will has a width of a 32bit variable.
- D: The starting address for storing the ASCII code.
- n: The data length;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n | Constant, n=1~256 |
Program example
For example, the following data is starting from D100.
The M8161 flag determines the width mode of the target variable for calculation result storage. When M8161=OFF, it is 16bit mode, which means the higher byte and lower byte are saved respectively. When M8161=ON, it is 8bit mode, which means that only the lower byte is used to save result and the actual variable range length is longer.
- When M8161=OFF
- When M8161=ON
Points to note
- Instructions such as RS / HEX / ASCI / CCD share the M8161 mode flag, please pay attention on it when programming;
- S data area of the source data must be ASCII characters, or error occur when conversion;
- If the output data is in BCD format please do BCD-BIN conversion after HEX conversion, then users could get correct value;
6.14.9 CCD instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
CCD | Check Code | 16 | No | CCD S D n | 7 |
CCDP | 16 | Yes | 7 |
This instruction looks at a byte stack of data from head address (S) for n bytes and checks the vertical bit pattern for parity and sums the total data stack. These two pieces of data are then stored at the destination (D).
- S: The starting address of variables, which are to be checked and calculated;
- D: Respectively used for saving “SUM” result (D+1) is respectively used for saving “XOR” result;
- n: The bit number occupied by variables for checking
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | |||||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n | Constant, n=1~256 |
Program example
The M8161 flag determines the width mode of the target variable for calculation result storage. When M8161=OFF, it is 16bit mode, which means the higher byte and lower byte are saved respectively. When M8161=ON, it is 8bit mode, which means that only the lower byte is used to save result and the actual variable range length is longer.
The “SUM” is quite simply a summation of the total quantity of data in the data stack.
The "XOR" logical calculation means:
- The involved variables are converted to binary format.
- Then it counts the number of variables with bit0=1. If it is even, the calculation result of bit0 is 0. If it is odd, the calculation result of bit0 is 1.
- Then it counts the number of variables with bit1=1. If it is even, the calculation result of bit1 is 0; if it is odd, the calculation result of bit1 is 1.
- In the same way, calculation is implemented from bit2 to bit7. After that, the binary HEX value converted from binary is the “XOR” result (polarity value).
Note for use
- Instructions such as RS / HEX / ASCI / CCD share the M8161 mode flag, please pay attention on it when programming;
6.14.10 PID instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
PID | PID operation | 16 | No | PID S1 S2 S3 D | 9 |
This instruction is for PID operation; it is used for control of close-loop system parameter. PID control is widely used in mechanical equipment, pneumatic equipment, constant pressure water supply, electronic equipment and so on.
- S1: The predefined set value;
- S2: The current value;
- S3: The operation parameter, it takes the next 25 addresses, the value range is D0 ~ D7975, it is best to specify the retentive memory, for saving parameter when power OFF;
- D: The destination device, it is better to specify the non-retentive memory, otherwise users need to initialize it before executing instruction;
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S1 | √ | |||||||||||||||
S2 | √ | |||||||||||||||
S3 | √ | |||||||||||||||
D | √ |
Program example
D9 is target value, D10 is current value, the unit for D9 and D10 must be the same.
D200~D224 are used for storing the set value and process value of PID operation. These values must be set item by item before executing PID operation.
D130 is used for storing the calculated value, it is used for controlling the implementation of the action.
Operation parameters (S3+N) | ||
Unit | Function | Description |
S3 | Sample time(Ts) | Setting range 1~32767(ms), but must longer than scouldning cycle of plc program |
S3+1 | Reaction direction(ACT) | bit0: 0=positive action; 1=negative action; bit3: 0=one way; 1=two way; bit4: 0=disable self-tuning; 1=enable self-tuning; Others couldnot be used. |
S3+2 | Maximum climbing(Delta T) | Setting range 0~320 |
S3+3 | Proportional gain(Kp) | Setting range: 0~32767, note:this value is magnified 256 times, actual value is Kp/256 |
S3+4 | Integral gain(Ki) | Setting range: 0~32767, Ki=16384Ts/Ti, Ti is integral time |
S3+5 | Derivative gain(Kd) | Setting time: 0~32767, Kd≈Td/Ts, Td is derivative time |
S3+6 | Filter (C0) | Range: 0~1024 |
S3+7 | Output lower limit | Recommended range: -2000~2000, when S3+1 bit3=0, please set 0; S3+1 bit3=1, please set -2000 |
S3+8 | Output upper limit | Recommended values: 2000 |
S3+9 | Retain | Retain |
- Self-tuning example
Error code
If an error occurs in the set value of the control parameters or in the PID operation, the operation error flag M8067 turns on and the following data is stored in D8067 according to the error details.
Error code | Error content | State | Processing method |
K6705 | Operand of application instruction outside of target device | Stop PID operation | Please check data for PID operation |
K6706 | Operand of application instruction outside of target device | ||
K6730 | (TS< 0 ) Sampling time(TS) outside of target device (TS< 0 ) | ||
K6731 | Filter (C0) outside (C0<0 or 1024≤C0) | ||
K6732 | Maximum rate of raise(DeltaT) outsideΔT<0 or 320≤ΔT | ||
K6733 | Proportional gain(KP) outside of target range | ||
K6734 | Integral gain (KI)outside of target range(KI<0) | ||
K6735 | Derivative gain outside of target range(KD<0) | ||
K6740 | Sampling time≤ operation cycle | Continue PID operation | |
K6742 | Variation of measured value exceed ((PV<-32768 or 32767 < ( PV ) | ||
K6751 | Direction of Self-tuning isn’t match | Continue PID self-tuning | The action direction between set value and current value are not match. Please correct the target value, self-tuning output, estimated value, then self-tuning. |
K6752 | Self-tuning action is improper | Self-tuning | Self-tuning measured value couldnot be correct action, due to changes in the upper and lower. Please make the sampling time is much greater than the output change cycle, increase the input filter constant. After changing the setting, please perform auto-tuning again. |
Note for use
The correct measured value must be read into the PID measured value (PV) before the PID operation is executed. In particular, pay attention to the conversion time when performing PID operation on the value of the analog input module.
PID instruction could be used multiple times and executed at the same time, but variable area of PID instruction couldnot overlap; it also could be used in step instruction, jump instruction, timer interruption, subroutine, but please delete S3+9 cache unit before execute PID instruction.
The maximum error of sampling time TS is - (1 execution cycle+ l ms)~ +(1 execution cycle). If sampling time TS≤1 execution cycle OF PLC, then will have below PID operational error (K6740), and execute PID algorithm as TS = execution cycle, in that case, it is better to use constant scouldning mode or use the PID instruction in timer interrupt (16□□~18□□)