| Programmable logic controller(PLC)is the core equipment in the field of industrial automation.There are dozens of commonly used industrial fieldbus protocols.Major PLC manufacturers also basically have their own bus protocols.There is no compatibility between different kinds of PLC communication protocols.At the same time,with more and more PLC accessing the Internet,the problems of network bandwidth waste and unsafe data transmission become more and more obvious.To solve the above problems,this paper designs a multi protocol industrial gateway for PLC.The main research contents are as follows:(1)By analyzing the development status of PLC data acquisition in industrial 4.0environment,a multi protocol industrial gateway for PLC is designed to realize the data acquisition and forwarding of different kinds of PLC;According to the requirements of industrial data processing,the software and hardware platform of the gateway is designed and built: the hardware platform includes the interface planning of the main control chip and the circuit design of the expansion module;The software platform includes the kernel cutting of openwrt system,the transplantation of network card driver and the modification of device tree.(2)In view of the incompatibility between different kinds of PLC communication protocols,according to the idea of software modularization,the data acquisition module of the gateway is designed: according to the requirements of multi task parallel processing,the multi-threaded working mode of the gateway is designed,and the specific threads are planned;According to the communication interface requirements of PLC at this stage,the network port and serial port functions of the gateway are designed,which constitutes the basic acquisition logic and architecture of the gateway;Taking the three PLC communication protocols modbus,AB CIP and S7 as examples,this paper analyzes their communication steps and protocol framework,summarizes the analysis and expansion methods of PLC communication protocol,designs the call framework of PLC communication protocol library according to the polling communication mode of mainstream PLC,and realizes the communication between gateway and different kinds of PLC;According to the data processing requirements of the server,the protocol conversion model of the gateway is designed to map the address of PLC object data,convert different kinds of PLC communication protocol data into a unified message format for forwarding,so as to facilitate the unified call of the server.(3)In view of the waste of network bandwidth and unsafe data transmission at this stage,according to the idea of software modularization,the data forwarding module of the gateway is designed: the cloud interaction protocol system of the gateway is designed based on message queuing telemetry transport(MQTT);By analyzing the composition of different kinds of PLC communication protocol instructions,taking MQTT as the framework,an application layer specification heterogeneous protocol for gateway combined with host computer software to collect terminal PLC data is designed,so as to provide a unified data format specification for industrial PLC communication protocol instead of Java Script object notation(JSON);According to the reading and writing requirements of PLC data,nine MQTT message topics are designed,and the specific logic of message forwarding is designed combined with heterogeneous protocols;According to the security requirements of data forwarding in industrial environment,an encrypted communication module based on state secret SM4 is designed.The experimental comparison shows that the time spent by SM4 algorithm in encrypting and decrypting the same plaintext is 43.2% of that of AES algorithm,which is more efficient.(4)The designed gateway is tested and analyzed: the software development environment is built,and the EMQ server is deployed on the x86 Linux host as the message agent of MQTT;A host computer software based on MQTT communication is designed to remotely configure and manage the gateway through the corresponding MQTT message subject and message forwarding logic;The two-way communication test between PLC gateway host computer software is carried out.The experimental results show that the three can communicate normally.The gateway has good connectivity for the five PLC models tested;The heterogeneous protocol traffic test is carried out.The experimental comparison shows that the message in heterogeneous protocol format saves 73% ~ 75% traffic compared with JSON format. |