The following describes the method for setting up the free communication port of a PLC as a common communication method for data acquisition.
1. Configure freeport communication parameters
Use the SL1 port to set basic parameters.
For example, the M218 PLC has two serial communication ports, SL1 and SL2. We choose SL1 as the target. SL1 uses an RJ45 interface. When making the connecting cable, pay attention to the pin relationships and cable shielding.
2. Select the received data frame format
You can choose to use a start character and an end character; you can determine the end of a frame by checking the data frame length; or you can determine the end of a frame by checking for a timeout (for example, if the timeout is set to 5ms, the frame ends if no other characters are received within 5ms after the last character is received). (In this example, a frame is defined as 10 bytes received.)
Introduction to ASCII Manager Configuration Parameters
3. The transmit register is defined in byte format.
The program and related data use the SEND_RECV_MSG function block. X5 and X7 are defined as arrays of type BYTE.
4. Set up sending (example format is hexadecimal)
X4 = 16#0A bytes, the data to be sent is 10 bytes from array X5.
5. Data received by the equipment
The ten bytes received are the ten bytes of array X5.
6. Ten bytes of data sent by the device
The ten bytes received by the 7PLC are stored in register X7 of the receive area.
Note: If the transmit register is set to INT format, for example, transmit word register data 16#1234, the device will receive it in the order of 16#3412, which is a high-low byte order issue.