Preface: Siemens S7-200 PLC is widely used in the field of industrial control and is a high-performance and stable controller. This time, we will connect Siemens' S7-200 PLC to the EMCP Internet of Things Cloud Platform (EMCP) through Modbus driver, enabling remote monitoring of the 200 PLC through computer web pages, mobile apps, and WeChat.
1) S7-200 (It is recommended to use a PLC with CPU226 or CPU224 and two serial ports, with port 1 for program download and online monitoring, and port 0 for Modbus RTU slave station and EG20 gateway communication). Smart200PLC can also be used (using the old 200PLC as a case study below).
2) One EG20 gateway, antenna, and power adapter from Hebei Blue Bee Technology (using EG20 as an example below).
3) One SIM card with data, large card (China Mobile, China Unicom or Telecom card).
4) DP9 needle male head.
5) One networked computer (WinXP/Win7/Win8/Win10 operating system)
The material preparation is as follows:;
The technical parameters and usage instructions related to the gateway can refer to the EG20 User Manual.
1. Ensure that the gateway can be connected to the internet normally, either through a 4G card (China Mobile/China Unicom/Telecom data card, large card) (with the antenna attached to the gateway) or through a network cable (with the router's network cable connected to the gateway's WAN port);
2. Connect the gateway to a 12V or 24V DC power supply and power it on. (Note that the positive and negative terminals of the power supply should not be reversed).
Connect the 200PLC to a power supply (note whether the power supply is 24VDC or 220VAC), prepare a 9-pin serial port connector (as shown in the figure below), and solder the 3 and 8-pin connectors with two wires respectively (as described in the 200PLC system manual, the 3 and 8-pin connectors are RS485 communication ports). At this point, we will connect the 3 pins of the PLC prot0 serial port to the "RS485A" terminal of the EG20 gateway, and connect the 8 pins to the "RS485B" terminal of the EG20 gateway.
1. Connect the 200PLC to the computer through programming, open the Step7 MicroWin programming software, create a new project, and add the Modbus Slave Port0 function blocks (MBUS-INIT, MBUS_SLAVE) to the main program.
library file
The Siemens Modbus slave protocol library includes two instructions: the MBUS-INIT instruction and the MBUS_SLAVE instruction.
The MBUS_SLAVE instruction is used to service requests issued by Modbus master devices.
The MBUS-INIT command is used to enable, initialize, or disable Modbus slave communication. Before using the MBUS_SLAVE instruction, the MBUS-INIT instruction must be executed correctly. Set the 'Finish' bit immediately after the instruction is completed before continuing to execute the next instruction.
Please refer to the help in the "STEP 7-MicroWIN" software for instructions on MBUS-INIT and MBUS_SLAVE.
Note: When setting the MBUS-INIT instruction on CPU222, "MAXAI" should be set to "16".
Above, we started the Modbus hold register area from VB1000 (HoldStart=VB1000) and kept the register as 100 words (MaxHold=100). Since the hold register is measured in words (two bytes), this communication buffer actually occupies a total of 200 bytes from VB1000 to VB1200.
2. Set up inventory storage areas.
Click on "File" in the menu bar, select "Inventory Storage Area Allocation" in the drop-down box, and enter the starting address of the inventory storage area in the opened dialog box. Be careful to avoid overlapping this address with other addresses already used or planned to be used in the program. You can click on "Suggested Address" to avoid overlapping addresses occupied by the Modbus function block and register addresses in the program.
3. Compile the program and download it to the PLC via PPI cable (if the PLC only has one serial port and this serial port is configured as a Modbus port, we need to turn the PLC's running switch to the "stop" position when downloading the program). After downloading, turn off the power and open the program monitoring to check if the "Error" pin output of the MBUS-INIT and MBUS_SLAVE instructions is normal (0 is normal, other values are faults, please refer to the fault list in the Siemens PLC technical manual).
Log in to the EMCP platform with an administrator account (it is recommended to use 360 Browser Speed Mode, Chrome browser, or a browser that supports Chromium kernel), and set up the EMCP cloud platform. Please refer to the "EMCP IoT Cloud Platform User Manual" for specific operations. After logging into EMCP, the first step is to enter the device list display page. As we have not created any devices, it is an empty page. We need to follow the steps below to proceed.
Step: Click on (only management accounts have this permission) → → [EG Device Management] → [+Add] → Fill in device information → Click [Save]. Among them, is required, and all other options can be optional.
The two main areas that need to be configured in the EG device management gateway configuration are configuring network serial communication parameters and creating Modbus drivers. The following will explain this function step by step. Note: The gateway can only be remotely configured after it is online.
Step: Click on [Step 2: Gateway and Instrument Management] → → Fill in and → [Confirm].
The SN and verification code are on the chassis label of the gateway. The SN is a 12 digit pure Arabic numeral, and the verification code is a 6-digit English letter. [Note] can be filled in according to the requirements. After editing, click [OK].
(with * required fields)
At this point, in the "Gateway Basic Information" section, you can see whether the bound gateway is connected to the platform (if you successfully log in to the platform, you can see the green word "Online"; if not, the gray word "Offline" will be displayed. Please check the network or network signal at this time).
To use serial port RS485 communication, RS485 communication parameters need to be set.
Each device connected to the gateway needs to establish a corresponding device driver. Just like inserting a mouse into a computer, only when the driver for this mouse is installed in the computer system can the computer recognize it. Add drivers to the communication port through which the device is connected to the gateway. As shown in the figure, click on "Add Driver" after "RS485" to display the basic configuration table on the right for configuration.
Note: After configuration is complete, click save.
Basic configuration introduction:
: Required field, customizable, differentiate when there are multiple drivers.
【 Brand 】: Required field, select 'Universal Modbus Device'.
[Model]: Required field, select "Modbus RTU".
: Required field. The equipment address is filled in according to the slave station number set by the 200PLC. In this case, the PLC slave station number is "1", so "1" is filled in here.
【 Minimum Collection Cycle 】: It is the time interval for the gateway to collect device data, measured in milliseconds. If set to 1000ms, the gateway will collect device data once every 1 second.
[Communication waiting time]: The waiting time for the gateway to receive communication data. Adjustments can be made as needed, with a default of 1000ms.
[16 bit integer], [32-bit integer], [32-bit floating-point type]: Refers to the decoding order of the corresponding data type. Default settings are sufficient
[Block Collection Method]: 0- Block by Maximum Length: The collection block is processed according to the maximum block length, and multiple blocks with discontinuous but similar addresses are divided into one block and read at once to optimize the collection efficiency; 1- Block by continuous address: Collect blocks based on address continuity, and for multiple blocks with discontinuous addresses, only collect continuous addresses at a time without optimization processing. Simply select the default option.
[4-zone 16 digit write function code]: Select the function code when writing single characters in zone 4. Simply select the default option.
Step: Click on [Step 3: Variable Management] ->[+Add Variable] ->Fill in variable information ->[Save].
Variable introduction:
【 Instrumentation, PLC 】: Required, select the driver just created. Choose according to the actual situation.
: Required, customizable. Be careful not to have duplicate names.
[Unit]: Not required, can be customized. When displaying in a list, variables will be displayed with units.
【 Register Type 】: Required. In Siemens PLC, point Q corresponds to 【 Coil (0x) 】, point I corresponds to 【 Discrete Input (1X) 】, V corresponds to 【 Hold Register (4X) 】, and AI corresponds to 【 Input Register (3X) 】.
: Required, the address should be filled in without the storage area identifier. Please refer to the image below for specific settings.
: Required, select according to actual needs.
[Number of decimal places]: Not required, fill in according to requirements.
[Dead Zone Setting]: Not required, default is sufficient. Fill in as needed. For a more detailed explanation, please refer to the "?" help section later.
: Not required. Numerical values can be directly mapped to text. If the value is "10" and the mapping field is "device failure", then when the value of the collected variable is "10", "device failure" will be directly displayed in the device monitoring and historical reports.
: Not required. The collected data can be calculated according to the formula filled in. For more detailed instructions, please refer to the "?" help section below.
[Read/Write Method]: You can modify the read/write method of this register according to your needs, and it defaults to read-only.
The example of adding and filling in variables for each storage area of PLC on the platform is shown in the following figure:
After adding, the 'Variable Management' is shown in the following figure. At this point, you can click the 'Data Testing' button to check whether the variable values can be collected or whether the values are correct.
Open the "Program Status Monitoring" and "Status Table Monitoring" of the Step7 MicroWin programming software to view the running status of the program and the numerical display of internal data. Through the status table, we can view the current values of each data and enforce the data. As shown in the figure below.
Users can log in to the EMCP platform, click on the image or device name of the "S7-200" device, and enter the EG device to view and modify relevant data.