CN110505136B - Layered MODBUS communication system and method - Google Patents
Layered MODBUS communication system and method Download PDFInfo
- Publication number
- CN110505136B CN110505136B CN201910979151.9A CN201910979151A CN110505136B CN 110505136 B CN110505136 B CN 110505136B CN 201910979151 A CN201910979151 A CN 201910979151A CN 110505136 B CN110505136 B CN 110505136B
- Authority
- CN
- China
- Prior art keywords
- layer
- communication
- equipment
- message
- service processing
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/26—Special purpose or proprietary protocols or architectures
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L2012/40208—Bus networks characterized by the use of a particular bus standard
- H04L2012/40228—Modbus
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Computing Systems (AREA)
- Communication Control (AREA)
Abstract
The invention discloses a layered MODBUS communication system and a layered MODBUS communication method, which solve the technical problem that the conventional MODBUS communication mode cannot be compatible with a host computer, a slave computer and code structure redundancy. The invention comprises a communication hardware layer, a protocol analysis layer and an equipment service processing layer; the communication hardware layer is used for stipulating the electrical parameters of the equipment and finishing information interaction with the protocol analysis layer; the protocol analysis layer is used for judging the legality of the message sent by the communication hardware layer; the equipment service processing layer is used for executing the legal message sent by the protocol analysis layer. The MODBUS communication method comprises the steps of defining parameters by a hardware layer, identifying and judging messages by an analytic layer and executing the messages by a service layer. The invention has the beneficial technical effects that: the method has strong universality, can be compatible with host computer and slave computer modes, and has a simple code structure.
Description
Technical Field
The invention relates to the technical field of communication, in particular to a layered MODBUS communication system and a layered MODBUS communication method.
Background
MODBUS is a serial communication protocol and is widely applied to the field of industrial control communication. MODBUS adopts a master-slave mode, and only one master can be used for one-time communication to control a plurality of slaves. The network structure is simple, the deployment and the maintenance are easy, but the practical application is not flexible enough, and the compatibility is not enough.
Chinese patent documents: CN 103941700B-an automatic process safety monitoring system based on Modbus protocol discloses a system for enabling the slave machines to communicate with each other, a plurality of slave machines are divided into a plurality of clusters, one slave machine capable of receiving the data of other slave machines in the cluster is selected from each cluster, namely, local area network communication is arranged among the slave machines under the whole system framework; chinese patent document CN107465576A, a multi-host communication system and method based on Modbus protocol, discloses a communication system using multiple hosts, which is still a host in a single communication, but each host is accessed to a polling interrupt program, and after one communication is finished, another host is selected for the next communication, so as to implement the multi-host communication system.
However, the above method requires deep customization of each device in the system with respect to its hardware layer, so that the software part of the product has insufficient portability and cannot be compatible with the master and the slave; moreover, each device needs to be reprogrammed, resulting in a very large amount of repetitive code and structural redundancy.
Disclosure of Invention
The invention provides a layered MODBUS communication system and a layered MODBUS communication method, which aim to solve the technical problem that the conventional MODBUS communication mode cannot be compatible with a host and a slave and has redundant code structures.
In order to solve the technical problems, the invention adopts the following technical scheme:
designing a layered MODBUS communication system, which comprises a communication hardware layer, a protocol analysis layer and an equipment service processing layer; the communication hardware layer is used for stipulating the electrical parameters of the equipment and finishing information interaction with the protocol analysis layer; the protocol analysis layer is used for judging the legality of the message sent by the communication hardware layer; the equipment service processing layer is used for executing the legal message sent by the protocol analysis layer.
Furthermore, the communication hardware layer comprises a hardware driving unit, a data receiving and transmitting unit and a data organizing unit, wherein the hardware driving unit is used for converting the control signal into an energy supply signal which can be identified by equipment; the data receiving and transmitting unit is used for completing information transmission between the communication hardware layer and the protocol analysis layer; the data organization unit is used for converting the data generated by the communication hardware layer into a data format which can be received by the protocol analysis layer.
Further, the protocol analysis layer comprises a hardware layer connection unit, a message judgment unit and a message preparation unit, the hardware layer connection unit is used for realizing the connection between the protocol analysis layer and the communication hardware layer, the message judgment unit is used for judging whether the message sent by the communication hardware layer conforms to the format specified by the MODBUS protocol, and the message preparation unit is used for sending the legal message identified by the message judgment unit to the equipment service processing layer.
Further, the device service processing layer includes a conventional service processing unit and a customized service processing unit, the conventional service processing unit includes a general operation module specified in the MODBUS protocol, and the customized service processing unit includes an operation module separately manufactured for realizing the device function.
A layered MODBUS communication method is also designed, and comprises the following steps:
s1: defining electrical parameters of access equipment through a communication hardware layer, and marking master and slave machine attributes of the equipment;
s2: if the access equipment is the master equipment, the access equipment sends a message carrying a control command, or if the access equipment is the slave equipment, the access equipment receives the control command message sent by the equipment marked as the master equipment;
s3: the protocol analysis layer judges whether the access equipment is set to be a host or a slave according to the communication hardware layer, and judges the legality of the message received or sent by the equipment; if the message is legal, the message is sent to a device service processing layer for execution; if not, the message is cleared.
Further, in step S3, when the device service processing layer executes a legal message and determines that the message is a basic operation function predefined in the MODBUS communication protocol according to the message content, the device service processing layer directly calls the function to execute the message content.
Further, in step S3, in the process that the legal packet is executed by the service processing layer, if packet interaction is required, the host set in the communication hardware layer sends a corresponding packet to the slave set in the communication hardware layer.
Compared with the prior art, the invention has the main beneficial technical effects that:
1. the invention marks the accessed equipment through the hardware layer, but not directly predefining the attribute of the equipment, weakens the recognition function of the attribute of the equipment in the network by the mode, the same equipment can be either slave equipment or master equipment in the same communication network, when the equipment needing to be accessed is used as the master equipment, the communication hardware layer adds the master equipment mark on the collected equipment information, the protocol analysis layer recognizes the mark and then organizes communication, and similarly, the slave equipment mark is added when the slave equipment needs to be completed.
2. The invention separately encapsulates the services of different devices into a service processing layer, which can be conveniently accessed to various devices; the service processing layer is a function layer customized for different devices, and the hardware layer binds the physical hardware device and the service physical layer, so the invention can automatically execute the bound service processing function during execution.
3. The invention adds a conventional service processing layer, encapsulates some universal functional modules, and is convenient for all equipment to call, thereby improving the universality of software, enabling all equipment to load the same software structure and avoiding the need of independently designing software for different equipment; on the other hand, the program code is simplified, and the same function does not need to be written for many times.
Drawings
Fig. 1 is a schematic structural diagram of a layered MODBUS communication system according to the present invention.
Fig. 2 is a schematic diagram of an embodiment of a layered MODBUS communication method according to the present invention.
Detailed Description
The following examples are intended to illustrate the present invention in detail and should not be construed as limiting the scope of the present invention in any way.
The procedures involved in or relied on in the following examples are conventional procedures or simple procedures in the art, and those skilled in the art can make routine selection or adaptation according to specific application scenarios, if not specifically stated.
Example 1: a layered MODBUS communication system, as shown in FIG. 1, includes a communication hardware layer, a protocol analysis layer, and an equipment service processing layer; the communication hardware layer defines the electrical parameters of the equipment, and marks whether the accessed equipment is the master equipment or the slave equipment, wherein the master equipment processes the data stream according to the master equipment, and the slave equipment processes the data stream according to the slave equipment; the protocol analysis layer is used for judging whether the data format sent and received by the communication hardware layer is legal or not, sending the legal data into the service processing layer for execution, and discarding the illegal data, specifically:
the communication hardware layer comprises a hardware driving unit, a data transceiving unit and a data organization unit, wherein the hardware driving unit is used for providing electric energy for a physical port of the equipment to start the equipment, then the master-slave attribute of the equipment is set, if the equipment is the master equipment, the data transceiving unit issues tasks to the slave equipment according to the running mode of the master equipment, and if the equipment is the slave equipment, the data transceiving unit receives the tasks issued by the master equipment in the system; the data organization unit stores the data received or sent by the data transceiver unit in a specific data structure, and the data structure contains a certain volume of data BUF and some attribute data related to data reception, such as data buffer pointer, data buffer size, etc. When data is put into the data structure, attribute data of the data cache area can be correspondingly updated, so that data is conveniently fetched by the data analysis layer;
the protocol analysis layer comprises a hardware layer connection unit, a message judgment unit and a message preparation unit, wherein the hardware layer connection unit receives a message sent by a communication hardware layer, the message judgment unit judges whether the message sent by the communication hardware layer conforms to a format specified by an MODBUS protocol, if the message is legal, the message preparation unit sends the message to an equipment service processing layer, and if the message is illegal, the message is discarded;
in the device service processing layer, the conventional service processing unit and the customized service processing unit are included, the conventional service processing unit is composed of a general operation module specified in an MODBUS protocol, if the message indicates conventional operation, such as 'coil reading', 'input register reading', and the like, preset conventional functions can be directly called, and through integration of the general functions, repeated coding is greatly reduced, so that the whole system is simpler.
Example 2: the implementation of a layered MODBUS communication method, see fig. 2, includes a case that a device operating the layered MODBUS communication method communicates with a common host and a common slave at the same time, hereinafter the "device operating the layered MODBUS communication protocol" is called the present invention, and "common MODBUS host" is abbreviated as common host "and" common MODBUS slave "is abbreviated as common slave".
For a common slave, after a connected physical port is determined, the port is driven at a communication hardware layer, a cache region is planned for the physical port, an instruction stream processing function is written, and data is put into the cache region according to a certain mode; then do some work bound to the hardware port: setting a communication address, setting whether the equipment is a master equipment or a slave equipment, binding a data stream cache region of hardware to a defined equipment port, and binding a service processing function. The master device or the slave device is arranged on a hardware layer to realize the switching of the master function and the slave function of the device to realize 'full function', the conventional MODBUS communication mode needs to be predefined aiming at the device, namely the device only plays a role in a communication network, either the master device or the slave device, because the host device and the slave device have different data processing modes, the host device or the slave device is independently defined to ensure that the coding process is relatively simple, but the corresponding universality is not strong and can not be transplanted, only a communication protocol can be reloaded when the master property and the slave property of the device are required to be changed, the device is arranged to be the master device or the slave device, the device is distributed according to the system requirement, for example, the conventional MODBUS communication protocol has strong dependence, the device is deeply customized aiming at the bottom layer of a certain product, and the device is specified to be the master device or the slave device, the invention adds a hardware layer to set the device as master or slave, so that the device can freely switch the master-slave property according to the role of the device in the communication system, and the use is very flexible.
The layer can strictly analyze the data in the data cache region bound by the physical layer according to the communication protocol of MODBUS, and judges whether the address is correct or not according to the communication address bound by the physical layer; automatically analyzing the data stream according to the set master-slave mode according to the master-slave equipment identifier bound by the physical layer; verifying whether a frame of message is correct according to CRC specified by modbus, if so, handing the correct message to a service processing layer function bound by a physical layer to process complete frame data, and if not, discarding the message;
and finally, a service processing layer completes corresponding processing of the message according to the function to be realized by the equipment, and if the conventional service clearly specified by MODBUS is used, a function representing the conventional service is called for processing. And the conventional service processing layer encapsulates a plurality of conventional processing functions established by MODBUS for the service layer of each device to call. If the master device and the slave device need to perform message interaction in the process of executing the legal message, the service processing layer sends a response message to the slave device through the host arranged on the communication hardware layer. The hardware layer processing function binds the physical hardware equipment and the service physical layer, and the communication protocol can automatically execute the bound service processing function when executing. The invention packages the services of different devices into a service processing layer, improves the universality of the communication protocol, facilitates the access of different devices to the network, extracts the conventional service processing layer from the service processing layer, reduces most repeated codes, realizes full-function communication, facilitates the loading and calling of different devices, and simplifies the network coding structure.
While the present invention has been described in detail with reference to the drawings and the embodiments, those skilled in the art will understand that various specific parameters in the above embodiments can be changed without departing from the spirit of the present invention, and a plurality of specific embodiments are formed, which are common variation ranges of the present invention, and will not be described in detail herein.
Claims (5)
1. A layered MODBUS communication system is applied to communication equipment and is characterized by comprising a communication hardware layer, a protocol analysis layer and an equipment service processing layer; the communication hardware layer is used for stipulating that the electrical parameter of the communication equipment indicates whether the communication equipment is the master equipment or the slave equipment, and finishing information interaction with the protocol analysis layer; the protocol analysis layer is used for judging the legality of the message sent by the communication hardware layer; the equipment service processing layer is used for executing a legal message sent by the protocol analysis layer; specifically, the method comprises the following steps:
the communication hardware layer comprises a hardware driving unit, a data receiving and transmitting unit and a data organization unit, wherein the hardware driving unit provides electric energy for a physical port of the communication equipment to start the communication equipment, and then sets master-slave attributes of the communication equipment; the data organization unit is used for putting the data in the data receiving and sending unit into a buffer area so as to facilitate the extraction of the protocol analysis layer;
the device service processing layer comprises a conventional service processing unit and a customized service processing unit, the conventional service processing unit comprises a general operation module specified in an MODBUS protocol, and the customized service processing unit comprises an operation module which is independently manufactured for realizing the device function.
2. The layered MODBUS communication system according to claim 1, wherein the protocol analysis layer comprises a hardware layer connection unit, a message determination unit, and a message preparation unit, the hardware layer connection unit is used to implement the connection between the protocol analysis layer and the communication hardware layer, the message determination unit is used to determine whether the message sent by the communication hardware layer conforms to the format specified by the MODBUS protocol, and the message preparation unit is used to send the legal message identified by the message determination unit to the device service processing layer.
3. A layered MODBUS communication method is applied to communication equipment and is characterized by comprising the following steps:
s1: defining electrical parameters of the communication equipment through a communication hardware layer, and marking master-slave equipment attributes of the communication equipment;
s2: if the communication equipment is the master equipment, the communication equipment sends a message carrying a control command, or if the communication equipment is the slave equipment, the communication equipment receives the control command message sent by the communication equipment marked as the master equipment;
s3: the protocol analysis layer judges the legality of the message received or sent by the communication equipment according to whether the communication hardware layer sets the accessed communication equipment to be master equipment or slave equipment; if the message is legal, the message is sent to a device service processing layer for execution; if not, the message is cleared.
4. The layered MODBUS communication method according to claim 3, wherein in step S3, when the device service processing layer executes a legal message, and determines that the message is a predefined basic operation function in the MODBUS communication protocol according to the message content, it directly calls the function to execute the message content.
5. The layered MODBUS communication method according to claim 3, wherein in step S3, in the process that the legal message is executed by the service processing layer, if message interaction is required, the master device installed in the communication hardware layer sends a corresponding message to the slave device installed in the master device.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910979151.9A CN110505136B (en) | 2019-10-15 | 2019-10-15 | Layered MODBUS communication system and method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910979151.9A CN110505136B (en) | 2019-10-15 | 2019-10-15 | Layered MODBUS communication system and method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110505136A CN110505136A (en) | 2019-11-26 |
CN110505136B true CN110505136B (en) | 2021-07-27 |
Family
ID=68593244
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910979151.9A Active CN110505136B (en) | 2019-10-15 | 2019-10-15 | Layered MODBUS communication system and method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110505136B (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6301527B1 (en) * | 1996-04-03 | 2001-10-09 | General Electric Company | Utilities communications architecture compliant power management control system |
CN103067238A (en) * | 2012-12-28 | 2013-04-24 | 深圳市研控自动化科技有限公司 | Data collection method compatible with MODBUS bus |
CN107682247A (en) * | 2017-09-15 | 2018-02-09 | 广东芬尼克兹节能设备有限公司 | A kind of high efficiency communication method of main frame and multiple slaves |
CN110099058A (en) * | 2019-05-06 | 2019-08-06 | 江苏亨通工控安全研究院有限公司 | Modbus message detecting method, device, electronic equipment and storage medium |
-
2019
- 2019-10-15 CN CN201910979151.9A patent/CN110505136B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6301527B1 (en) * | 1996-04-03 | 2001-10-09 | General Electric Company | Utilities communications architecture compliant power management control system |
CN103067238A (en) * | 2012-12-28 | 2013-04-24 | 深圳市研控自动化科技有限公司 | Data collection method compatible with MODBUS bus |
CN107682247A (en) * | 2017-09-15 | 2018-02-09 | 广东芬尼克兹节能设备有限公司 | A kind of high efficiency communication method of main frame and multiple slaves |
CN110099058A (en) * | 2019-05-06 | 2019-08-06 | 江苏亨通工控安全研究院有限公司 | Modbus message detecting method, device, electronic equipment and storage medium |
Non-Patent Citations (2)
Title |
---|
Communication Platform for Energy Management System in a Master-slave Control Structure Microgrid;Yixin Zhu等;《2012 IEEE 7th International Power Electronics and Motion Control Conference》;20120505;全文 * |
通用串口到Modbus RTU的协议转换器设计与实现;杨艳华等;《计算机测量与控制》;20140225;全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN110505136A (en) | 2019-11-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2023284699A1 (en) | Protocol stack data transmission method based on linux system, and computer device and storage medium | |
EP2512163B1 (en) | Method, system for defining message in machine-to-machine platform, and machine-to-machine platform | |
EP0478942A2 (en) | Remote control of a computer processor | |
CN102075389B (en) | Debugging method and equipment | |
CN104965700A (en) | Method and system for implementing driving on SPI equipment under VxWorks operating system | |
CN105848310A (en) | Multi-standby terminal of Android system and method for realizing multi-standby of terminal | |
EP2466943B1 (en) | Method and device for monitoring running state of card | |
EP2320328B1 (en) | Operation mode switching of data card and its control method, device and data card | |
CN113076144A (en) | Power amplifier adaptation method, terminal device, storage medium and computer program product | |
CN111444609A (en) | Data processing method and simulation system | |
CN111510481A (en) | Software and hardware interactive interface applied to B L E5.0 protocol system | |
CN110505136B (en) | Layered MODBUS communication system and method | |
CN104199789B (en) | Method, management system, drive system and the system of autosensing configuration | |
CN111885564B (en) | Data transmission method, equipment upgrading method and computer readable storage medium | |
JP2008065823A (en) | Method for improving communication speed of hid device | |
WO2016179944A1 (en) | Function multiplexing method and apparatus for communication interface | |
CN111168668A (en) | Robot control method and robot | |
EP2530995B1 (en) | Method and apparatus for implementing network device function of wireless communication terminal | |
CN102591839B (en) | USB (universal serial bus) multiprotocol self-adaptive method | |
CN110177104B (en) | Method for converting serial port protocol into USB protocol for industrial control and related equipment | |
CN108307286A (en) | It is a kind of to realize the method and system communicated between Android device based on NFC | |
CN109347656B (en) | Method and system for configuring virtual host uplink network card | |
CN106970884B (en) | Method and device for processing serial port command applied to android system running layer | |
CN108322616B (en) | Data processing method and voice data card | |
CN103246618A (en) | Method and device for achieving universal serial bus (USB) functions on basis of embedded system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |