CN115174306A - Modbus communication memory optimization method, communication method and related device - Google Patents

Modbus communication memory optimization method, communication method and related device Download PDF

Info

Publication number
CN115174306A
CN115174306A CN202210779110.7A CN202210779110A CN115174306A CN 115174306 A CN115174306 A CN 115174306A CN 202210779110 A CN202210779110 A CN 202210779110A CN 115174306 A CN115174306 A CN 115174306A
Authority
CN
China
Prior art keywords
communication
modbus
value
packet
memory
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.)
Granted
Application number
CN202210779110.7A
Other languages
Chinese (zh)
Other versions
CN115174306B (en
Inventor
范丽辰
王静伟
孙星星
王勇
李冠宁
李萌
马忠刚
窦维维
王晓伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Techenergy Co Ltd
Original Assignee
China Techenergy Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by China Techenergy Co Ltd filed Critical China Techenergy Co Ltd
Priority to CN202210779110.7A priority Critical patent/CN115174306B/en
Publication of CN115174306A publication Critical patent/CN115174306A/en
Application granted granted Critical
Publication of CN115174306B publication Critical patent/CN115174306B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L12/40006Architecture of a communication node
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/02Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mobile Radio Communication Systems (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention provides a Modbus communication memory optimization method, a communication method and a related device, wherein the Modbus communication memory optimization method comprises the following steps: storing the information of each communication point in the Modbus master station to each information unit of the communication point table; traversing each information unit of the communication point table, and counting and distributing memory space of each Modbus data model required by communication with each opposite terminal device according to the value of each field in the information unit corresponding to each communication point; and determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model, filling the memory position into the memory address field of the information unit corresponding to the communication point, and establishing mapping between the memory address and the addressing address of the communication point. By applying the method, the communication memory can be fully utilized, and the relation between the memory address and the addressing address of the communication point can be correctly established.

Description

Modbus communication memory optimization method, communication method and related device
Technical Field
The invention relates to the field of data processing, in particular to a Modbus communication memory optimization method, a Modbus communication method and a related device.
Background
In the Modbus communication design, a memory storage space of 65536 corresponding data items is generally opened up for each Modbus data model, and a 1: 1 mapping relationship between the memory space and the communication addressing space is established, so that the access of the Modbus data items is facilitated. However, in practical applications, all data items are not used, even only a few data items are used, which results in wasted memory space. Particularly, when the system supports multiple paths of Modbus communication and the number of communication data items on each link is small, if the memory is allocated according to the maximum value, the memory resource consumption is large and a large amount of memory is wasted. In order to save memory resources, memory optimization needs to be performed in Modbus communication design.
However, the optimization design of the Modbus communication memory in the prior art does not fully utilize the storage capacity of each bit of the memory, and the relationship between the optimized memory address and the addressing address is not correctly established, so that the correct work of the Modbus communication is easily affected.
Disclosure of Invention
In view of this, the present invention provides an optimization method for a Modbus communication memory, by which the storage capacity of the memory can be fully utilized and the relationship between the memory address and the addressing address can be correctly established.
The invention also provides an optimization device of the Modbus communication memory, which is used for ensuring the realization and the application of the method in practice.
A Modbus communication data memory optimization method comprises the following steps:
storing the information of each communication point in the Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field;
traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required for communication with each opposite-end device corresponding to the Modbus master station;
determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model;
and filling the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
Optionally, the multiple fields in the information unit further include an opposite-end device serial number field, a communication direction field, and a data type field, and the allocating, according to the value of each field in the information unit corresponding to each communication point, a memory space for each Modbus data model required for communication with each opposite-end device corresponding to the Modbus master station includes:
determining an opposite terminal device where each communication point is located according to the value of an opposite terminal device sequence number field in an information unit corresponding to each communication point;
determining the communication point property of each communication point according to the value of a communication direction field in an information unit corresponding to each communication point, wherein the communication point property is a sending communication point or a receiving communication point;
determining a storage space value required to be occupied by each communication point in a corresponding Modbus data model according to the value of a data type field in an information unit corresponding to each communication point, and accumulating the storage space count values of the corresponding Modbus data models of the opposite-end device where the communication point is located, so as to calculate the storage space required by each Modbus data model of each opposite-end device, and taking the storage space value as a communication memory space value required by the Modbus data model;
and determining a communication memory space value required by each Modbus data model required for communication with each opposite-end device according to the Modbus data model corresponding to each communication point, the opposite-end device where each communication point is located, the property of each communication point and the communication memory space value required by each Modbus data model, and allocating a memory space to the Modbus data model as the communication memory space value.
Optionally, the determining, according to the current counted number of the communication points and the memory location flag cell value of the Modbus data model, the memory location of each communication point in the corresponding Modbus data model includes:
obtaining a count value obtained by current statistics of a communication point number counter of the Modbus data model corresponding to the communication point;
if the count value is 0, determining that the communication point is the first communication point in the corresponding Modbus data model, and setting the memory position of the communication point in the corresponding Modbus data model to be 0;
if the count value is not 0, obtaining a memory location flag cell value of the Modbus data model, and determining that the memory location of the communication point in the corresponding Modbus data model is the memory location flag cell value.
A method of communication processing, comprising:
the method comprises the steps of obtaining a Modbus packet which is constructed in advance, and constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus communication protocol format corresponding to a function code of the Modbus packet, wherein the Modbus packet is composed of a plurality of communication points;
when the function code corresponding to the Modbus packet is a write function code, taking out the value of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting the value according to the corresponding format of the Modbus protocol, and filling the converted value to the output value field position of the communication packet to obtain the communication packet to be sent corresponding to the communication packet;
sending the communication packet to be sent to an opposite end device of the Modbus master station so that the opposite end device returns a response packet corresponding to the communication packet to be sent;
and receiving and analyzing the response packet to obtain a communication processing result, and finishing the communication processing process.
Optionally, the method further includes:
when the function code corresponding to the Modbus packet is a read function code, sending the communication packet to the opposite terminal according to the Modbus protocol so that the opposite terminal returns a response packet corresponding to the communication packet;
and receiving and analyzing the response packet, converting the value of the data value field in the response packet according to the corresponding format of the Modbus protocol, and filling the converted value into Modbus data model memories corresponding to the communication points of the Modbus packet to complete the communication processing process.
Optionally, the taking out the value of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting the value according to the corresponding format of the Modbus protocol, and filling the converted value in the output value field position of the communication packet includes:
determining the value of the field of the memory address of the first communication point of the Modbus packet in the Modbus packet as the first address of the communication data fetch address;
and inputting the value of the number field of the discrete quantity/coil/input register/holding register of the Modbus packet as a length value of a reading storage space, taking data with the length meeting the length value of the reading storage space from a continuous memory space pointed by the address head address of the communication data as a communication value, converting the communication value according to the corresponding format of the Modbus protocol, and filling the converted value into the field position of the output value of the communication packet.
Optionally, the converting the value of the data value field in the response packet according to the format corresponding to the Modbus protocol, and filling the converted value in a Modbus data model memory corresponding to each communication point of the Modbus packet includes:
determining the value of the memory address field of the first communication point of the Modbus packet as the communication data storage first address;
and determining a value of a data value field in the response packet as response data, inputting a value of a discrete quantity/coil/input register/holding register number field of the Modbus packet as a read-in storage space length value, converting the response value with the length meeting the read-in storage space length value according to a corresponding format of the Modbus protocol, and writing the converted value into a continuous memory position to which the communication data storage head address points.
Optionally, the Modbus packet constructing process includes:
combining a plurality of communication points with the same function code to form a Modbus packet, and determining the function code as the function code of the Modbus packet;
determining the value of the addressing address field in the communication point table information unit corresponding to the first communication point forming the Modbus packet as the value of the addressing address field of the first communication point of the Modbus packet, and determining the value of the memory address field in the communication point table information unit corresponding to the communication point as the value of the memory address field of the first communication point of the Modbus packet;
and counting the Modbus data model memory space value required by each communication point in the Modbus packet to obtain the Modbus data model memory space value required by the Modbus packet during communication, wherein the value is the value of the number field of the input discrete quantity/coil/input register/holding register of the Modbus packet.
A Modbus communication data memory optimizing device comprises:
the first execution unit is used for storing the information of each communication point in the Modbus master station into an information unit corresponding to the communication point, and each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field;
the first determining unit is used for traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required by communication of each opposite-end device corresponding to the Modbus master station;
the second determining unit is used for determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the value of the memory position marking unit of the Modbus data model;
and the second execution unit is configured to fill the memory location of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
A communication processing apparatus comprising:
the Modbus communication system comprises an acquisition unit and a communication unit, wherein the acquisition unit is used for acquiring a Modbus packet which is constructed in advance, and constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus communication protocol format corresponding to a function code of the Modbus packet, and the Modbus packet comprises a plurality of communication points;
the operation unit is used for taking out the values of all communication points of the Modbus packet in the corresponding Modbus data model memory when the function code corresponding to the Modbus packet is a write function code, converting the values according to the corresponding format of the Modbus protocol, and filling the converted values to the output value field position of the communication packet to obtain the communication packet to be sent corresponding to the communication packet;
the sending unit is used for sending the communication packet to be sent to an opposite end of the Modbus master station so that the opposite end returns a response packet corresponding to the communication packet to be sent;
and the analysis unit is used for receiving and analyzing the response packet to obtain a communication processing result and finish the communication processing process.
A storage medium comprises stored instructions, wherein when the instructions are executed, a device where the storage medium is located is controlled to execute the Modbus communication data memory optimization method.
An electronic device comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the Modbus communication datamemory optimization method.
Compared with the prior art, the invention has the following advantages:
based on the embodiment provided by the invention, in the process of Modbus communication memory optimization, the information of each communication point in a Modbus master station is stored into an information unit corresponding to the communication point, and each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field; traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating memory space for each Modbus data model required by communication of each opposite terminal device corresponding to the Modbus master station; determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model; and filling the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
By applying the method for optimizing the use of the Modbus master station communication data memory, provided by the invention, the communication memory can be allocated according to the Modbus data model memory space actually used by each communication point of each Modbus link, and the mapping between the memory address of each communication point in the Modbus data model and the Modbus communication addressing address of each communication point is established.
Drawings
Fig. 1 is a flowchart of a method for optimizing a Modbus communication data memory according to an embodiment of the present invention;
fig. 2 is a flowchart of another method of a Modbus communication data memory optimization method according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating another method of optimizing a Modbus communication data memory according to an embodiment of the present invention;
fig. 4 is a flowchart of another method of a Modbus communication data memory optimization method according to an embodiment of the present invention;
fig. 5 is a device structure diagram of a Modbus communication data memory optimization device according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In this application, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions, and the terms "comprises", "comprising", or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising one of 8230; \8230;" 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The invention is operational with numerous general purpose or special purpose computing device environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet-type devices, multi-processor apparatus, distributed computing environments that include any of the above devices or equipment, and the like.
The embodiment of the invention provides a memory optimization method for Modbus communication data, which can be applied to various system platforms, wherein an execution main body of the method can be a computer terminal or a processor of various mobile devices, and a flow chart of the method is shown in FIG. 1 and specifically comprises the following steps:
s101: and storing the information of each communication point in the Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table.
Each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field.
In the embodiment provided by the invention, the information of the configured Modbus communication points is read into the Modbus communication point table information unit. The information of the configured Modbus communication point includes data type, communication direction (i.e. sending or receiving), serial number of the peer device (i.e. RTU child device number/TCP link serial number of the peer), function code, input discrete quantity/coil/input register/holding register communication addressing address in the Modbus protocol.
The specific structure of a single information unit of the Modbus communication point table is shown in table 1:
data type
Communication direction (transmitting/receiving)
Function code
Peer device serial number
Addressing addresses
Memory address
TABLE 1
And respectively filling the data type, the communication direction, the function code, the RTU sub-equipment number/TCP link serial number of the opposite terminal, the input discrete quantity/coil/input register/holding register communication addressing address equivalent in the Modbus protocol in the configured communication point information into the data type field, the communication direction field, the function code field, the serial number field of the opposite terminal device and the addressing address field of the information unit corresponding to the communication point.
S102: and traversing each information unit in the communication point table, determining the Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating memory space for each Modbus data model required by communication with each opposite-end device corresponding to the Modbus master station.
In the embodiment provided by the invention, the memory of the Modbus data model is used for storing the data content of the communication point, inputting the discrete quantity, the coil, the holding register and the input register, and is four different Modbus data models. The Modbus master station communicates with other sub-devices through a Modbus protocol, a plurality of Modbus data models are arranged under the Modbus protocol, a plurality of Modbus communication points can be configured under each Modbus data model, and the Modbus data model corresponding to each Modbus communication point is unique and is determined by function codes of the Modbus communication points. Therefore, according to the values of the function code fields in the information units in the communication point table, the Modbus data model uniquely corresponding to each communication point can be determined.
Specifically, as shown in fig. 2, the allocating memory space for each Modbus data model required for communication with each peer device corresponding to the Modbus master station according to the value of each field in the information unit corresponding to each communication point further includes an peer device serial number field, a communication direction field, and a data type field, and includes:
s201: and determining the opposite terminal device where each communication point is located according to the value of the opposite terminal device sequence number field in the information unit corresponding to each communication point.
In the embodiment provided by the invention, according to the value of the sequence number field of the opposite terminal device in the information unit corresponding to the communication point, the sequence number of the opposite terminal device where the communication point is located can be determined, so as to determine the opposite terminal device where the communication point is located, and the sequence number of the opposite terminal device can be an RTU sub-device number or a TCP link sequence number (that is, when communicating with a plurality of TCP slave stations, the number of TCP slave stations is marked).
S202: and determining the communication point property of each communication point according to the value of the communication direction field in the information unit corresponding to each communication point.
Wherein the communication point property is a sending communication point or a receiving communication point.
S203: and determining a storage space value required to be occupied by each communication point in the corresponding Modbus data model according to the value of the data type field in the information unit corresponding to each communication point, and accumulating the storage space count value of the corresponding Modbus data model of the opposite-end device where the communication point is located, so as to count the storage space required by each Modbus data model of each opposite-end device, and taking the storage space value as the communication memory space value required by the Modbus data model.
In the embodiment provided by the invention, the variable length of the communication point is determined according to the data type fields, such as the cool, int, float and various variable types with quality bits, in the information unit corresponding to the communication point, the storage space required by the communication point in the Modbus data model is obtained by combining the Modbus data model, the storage space count value of the corresponding Modbus data model of the opposite-end device where the communication point is located is accumulated, the storage space required by each Modbus data model of each opposite-end device is counted, and the storage space value is used as the communication memory space value required by the Modbus data model.
S204: and determining a communication memory space value of each Modbus data model required for communication with each opposite-end device according to the Modbus data model corresponding to each communication point, the opposite-end device where each communication point is located, the property of each communication point and the communication memory space value required by each Modbus data model, and allocating a memory space to the Modbus data model as the communication memory space value.
In the embodiment provided by the invention, various Modbus data models exist under the Modbus protocol, so that the communication on one Modbus RTU sub-device/TCP link can also have the communication of various Modbus data models. One communication point corresponds to a unique data model, so that the communication point table is traversed, an opposite-end device where each communication point is located is determined, a Modbus data model corresponding to each communication point is determined according to a function code of each communication point, the data length of each communication point is determined according to the data type of each communication point, the storage space of each communication point in the corresponding Modbus data model of the corresponding opposite-end device can be determined, the storage space of the corresponding Modbus data model of the opposite-end device where the communication point is located is accumulated, the size of a memory required by each Modbus data model under each opposite-end device is counted, and the memory of each Modbus data model under each opposite-end device is distributed.
By applying the embodiment provided by the invention, the communication memory space occupied by each Modbus data model under each opposite-end device is counted, and the corresponding memory space is allocated to each Modbus data model under each opposite-end device, so that the memory is allocated according to the requirement on the basis of meeting the Modbus communication requirement, the Modbus communication memory usage can be greatly reduced, and the memory waste is avoided.
S103: and determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model.
In the embodiment provided by the invention, according to the number of the currently counted communication points of the Modbus data model and the value of the memory location marking unit, the memory location of each communication point in the corresponding Modbus data model can be determined on the basis of the memory of the Modbus data model.
Specifically, as shown in fig. 3, the determining, according to the currently counted number of communication points and the memory location flag cell value of the Modbus data model, a memory location of the communication point in the corresponding Modbus data model includes:
s301: and obtaining the current statistical count value of the communication point number counter of the Modbus data model corresponding to the communication point.
In the embodiment provided by the invention, a communication point number counter is respectively configured for each Modbus data model in an opposite-end device of each Modbus master station, the initial value is 0, and the Modbus number counter is used for counting the number of Modbus communication points contained in each Modbus data model of each opposite-end device; and respectively generating a memory position marking unit for each Modbus data model of each opposite-end device, wherein the initial value is 0 and is used for marking the memory position of each Modbus communication point in the corresponding Modbus data model.
Therefore, determining the memory position of a communication point in the corresponding Modbus data model requires first obtaining the current counted value of the communication point number counter of the Modbus data model corresponding to the current communication point.
S302: and judging whether the count value is 0 or not.
If the count value is 0, then S303 is executed, otherwise S304 is executed.
S303: and determining the memory position of the communication point in the corresponding Modbus data model to be 0.
If the count value is 0, the communication point is the first communication point of the corresponding Modbus data model, and at this time, the value of the memory location marking unit of the corresponding Modbus data model is the initial value 0, that is, the memory location of the communication point in the corresponding Modbus data model is 0.
S304: and acquiring a memory position marking unit value of the Modbus data model, and determining that the memory position of the communication point in the corresponding Modbus data model is the memory position marking unit value.
And if the count value is not 0, acquiring a memory position marking unit value of the Modbus data model corresponding to the communication point, and taking the value as the memory position of the communication point in the corresponding Modbus data model.
And after the obtained memory position of the communication point in the corresponding Modbus data model is obtained, accumulating the value of the number counter of the communication point of the Modbus data model corresponding to the communication point by 1, and accumulating the value of the memory position marking unit of the Modbus data model corresponding to the communication point into the storage space size occupied by the communication point in the Modbus data model.
By applying the embodiment provided by the invention, the current counted number of the communication points of the Modbus data model and the value of the memory position marking unit are obtained, the memory positions of the communication points in the corresponding Modbus data model are determined for the communication points, and the communication points are closely arranged in the memory of the Modbus data model, so that the memory space in the Modbus data model can be fully utilized.
S104: and filling the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
In the embodiment provided by the invention, the value of the memory location marking unit of the Modbus data model corresponding to the communication point is filled in the memory address field of the information unit corresponding to the communication point, and the mapping between the memory address of the Modbus communication point and the communication addressing address is established according to the value in the preset addressing address.
Based on the embodiment provided by the invention, in the process of Modbus communication memory optimization, the information of each communication point in a Modbus master station is stored into an information unit corresponding to the communication point, and each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field; traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required by communication with each opposite terminal device corresponding to the Modbus master station; determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model; and filling the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
By applying the method for optimizing the use of the Modbus master station communication data memory, the communication memory is allocated according to the Modbus data model memory space actually used by each communication point of each Modbus link, and the mapping between the memory address of the communication point in the Modbus data model and the Modbus communication addressing address of the communication point is established, so that on the basis of meeting the Modbus communication requirement, the allocation and use optimization of the Modbus communication memory can be realized, the problem of memory vacancy is solved, the memory waste is avoided, and the memory space is fully utilized.
In the embodiment provided by the present invention, as shown in fig. 4, a process of executing communication processing of a Modbus master station based on a Modbus communication data memory optimization method includes:
s401: and acquiring a Modbus packet which is constructed in advance, and constructing a communication packet corresponding to the Modbus packet according to the basic information of the Modbus packet and the Modbus communication protocol format corresponding to the function code of the Modbus packet.
It should be noted that, the number and the information of Modbus communication packets under each opposite terminal device of the Modbus master station are constructed and counted according to a preset Modbus packet algorithm, and each Modbus packet is composed of a plurality of communication points. The communication packets are data packets actually sent by the device during communication, each Modbus packet corresponds to one communication packet, and the content of the communication packets needs to be organized according to the basic information structure of the Modbus packet corresponding to the communication packet.
Wherein, the construction process of the Modbus package comprises the following steps:
combining a plurality of communication points with the same function code to form a Modbus packet, and determining the function code as the function code of the Modbus packet;
determining the value of the addressing address field in the communication point table information unit corresponding to the first communication point forming the Modbus packet as the value of the addressing address field of the first communication point of the Modbus packet, and determining the value of the memory address field in the communication point table information unit corresponding to the communication point as the value of the memory address field of the first communication point of the Modbus packet;
and counting the Modbus data model memory space value required by each communication point in the Modbus packet to obtain the Modbus data model memory space value required by the Modbus packet during communication, wherein the value is the value of the number field of the input discrete quantity/coil/input register/holding register of the Modbus packet.
Specifically, a Modbus packet information table is constructed in advance, and the structure of the single Modbus packet base information in each Modbus packet unit in the Modbus packet information table is shown in table 2, and the single Modbus packet base information provides necessary information required for packaging and filling the communication packets.
Figure BDA0003728312340000131
TABLE 2
In the Modbus communication sub-packaging process, when a new Modbus packet is generated, in addition to the need to record the function code of the new packet, input the discrete quantity/the coil/the input register/the number of the holding registers, the addressing address in the information unit corresponding to the first communication point of the Modbus packet needs to be filled into the addressing address field of the first communication point in the packet information structure, and the memory address in the information unit corresponding to the first communication point of the new packet needs to be filled into the memory address field of the first communication point of the packet in the packet information structure. The number of the input discrete quantity/coils/input registers/holding registers of the packet is calculated according to the accumulated value of Modbus data model memory space required by each communication point in the Modbus packet.
The input discrete quantity, the coil, the holding register and the input register are four different Modbus data models, and only one of the discrete quantity/the coil/the input register/the holding register corresponds to the Modbus data model in the Modbus packet.
By applying the embodiment provided by the invention, the Modbus packet is initialized during Modbus communication, the function code of the Modbus packet, the number of the input discrete quantity/coil/input register/holding register, the initial memory address and the initial addressing address of the Modbus packet are determined, and the Modbus packet is executed only once during communication initialization, so that the method has higher processing efficiency, effectively saves the processing time of Modbus cycle communication, and improves the efficiency of Modbus cycle communication.
S402: and when the function code corresponding to the Modbus packet is a write function code, taking out the value of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting the value according to the corresponding format of the Modbus protocol, filling the converted value to the output value field position of the communication packet, and obtaining the communication packet to be sent corresponding to the communication packet.
In the embodiment provided by the invention, if the function code corresponding to the Modbus packet is a write function code, such as 5,6, 15, 16, on the basis of constructing the Modbus communication packet according to the Modbus packet, the value in the Modbus data model memory corresponding to each communication point of the Modbus packet needs to be taken out and converted according to the Modbus protocol requirement, and the converted value is filled in the output value field of the communication packet, i.e. the position of the output value/register value field, so as to obtain the communication packet to be sent.
It should be noted that, constructing a Modbus communication packet according to a Modbus packet may include the following steps:
if the protocol format of the communication packet relates to an address field, filling the content of the address field of the first communication point of the Modbus packet into the address field of the communication packet;
filling the 'function code' field of the Modbus packet into the 'function code' field of the communication packet;
if the protocol format of the communication packet relates to a 'number' field, filling the 'number' field content of the 'packet input discrete quantity/coil/input register/holding register number' field of the Modbus packet into the 'number' field of the communication packet;
if the protocol format of the communication packet relates to a 'byte count' field, calculating the content of the 'this packet input discrete quantity/coil/input register/holding register number' field of the Modbus packet according to the Modbus protocol requirement, and filling the content into the 'byte count' field of the communication packet.
Specifically, the step of taking out the value of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting the value according to the corresponding format of the Modbus protocol, and filling the converted value in the output value field position of the communication packet to obtain the communication packet to be sent corresponding to the communication packet includes:
determining the value of the field of the memory address of the first communication point in the Modbus packet as the communication data address initial address;
and inputting the value of the number field of the Modbus packet into a discrete quantity/coil/input register/holding register as a read storage space length value, taking data with the length meeting the read storage space length value from a continuous memory at a position pointed by the communication data address head address as a communication value, converting the communication value according to the corresponding format of the Modbus protocol, and filling the converted value into the position of the output value field of the communication packet.
It can be understood that, based on the communication data address head address, the value of "this packet input discrete quantity/coil/input register/holding register number" of the Modbus packet is taken as the size of the space value occupied by the fetch value, the value continuously satisfying the size of the fetch storage space value is fetched from the memory pointed by the communication data address head address at one time and continuously taken out from the position to which the communication data address head address points, the value is taken as the communication value, the communication value is converted according to the Modbus protocol requirement, and the converted value is filled in the position of "output value"/"register value" of the communication packet. S403: and sending the communication packet to be sent to an opposite terminal device of the Modbus master station, so that the opposite terminal device returns a response packet corresponding to the communication packet to be sent.
And sending the communication packet to be sent to an opposite-end device of the Modbus master station, executing relevant operations by the opposite-end device according to the communication packet to be sent, writing the value in the communication packet to be sent into the corresponding position of the opposite-end device, generating a response packet corresponding to the communication packet to be sent according to an execution result, and finally returning the response packet to the Modbus master station.
According to the value of the serial number field of the opposite terminal device in the unit information corresponding to each communication point in the Modbus packet corresponding to the communication packet, each opposite terminal device, which needs to be sent, of the communication packet sent by the Modbus master station can be determined.
S404: and receiving and analyzing the response packet to obtain a communication processing result, and finishing the communication processing process.
The Modbus main website receives the response package that the opposite terminal device sent back to, analyzes this response package, writes the analysis that the function code corresponds, according to Modbus agreement handle can, need not special operation. And obtaining a communication processing result of the operation of sending the data to the opposite terminal by the Modbus master station after analysis, thereby completing the communication processing process.
In the embodiment provided by the invention, the Modbus master station communication processing process is executed based on the Modbus communication data memory optimization method, and the Modbus master station communication processing method further comprises the following steps:
when the function code corresponding to the Modbus packet is a read function code, sending the communication packet to the opposite terminal according to the Modbus protocol so that the opposite terminal returns a response packet corresponding to the communication packet; and receiving and analyzing the response packet, converting the value of the data value field in the response packet according to the corresponding format of the Modbus protocol, filling the converted value into a Modbus data model memory corresponding to each communication point of the Modbus packet, and finishing the communication processing process.
In the embodiment of the present invention, if the function code corresponding to the Modbus packet is the read function code, the Modbus communication protocol format of the communication packet is determined according to the function code of the Modbus packet, and the Modbus communication packet corresponding to the read function code is constructed according to the basic information of the Modbus packet, specifically:
if the protocol format of the communication packet relates to an address field, filling the content of the address field of the first communication point of the Modbus packet into the address field of the communication packet;
filling the 'function code' field of the Modbus packet into the 'function code' field of the communication packet;
and filling the field of 'the present packet input discrete quantity/coil/input register/holding register number' of the Modbus packet into the field of 'the input discrete quantity/coil/input register/holding register number' of the communication packet.
And sending the communication packet to be sent to an opposite end of the Modbus master station, executing related operation by the opposite end according to the communication packet, determining information to be read by the Modbus master station according to the information of the communication packet, and generating a corresponding response packet according to the information to be read by the Modbus master station. And the Modbus master station receives the response packet sent back by the opposite terminal device, analyzes the response packet, converts the data value field content in the response packet according to the Modbus protocol requirement, fills the converted value in the Modbus data model memory corresponding to each communication point of the Modbus packet corresponding to the communication packet, and finishes the communication processing process of reading the opposite terminal information.
In the embodiment of the present invention, the converting the value of the data value field in the response packet according to the corresponding format of the Modbus protocol, and filling the converted value in the Modbus data model memory corresponding to each communication point of the Modbus packet includes:
determining the value of the memory address field of the first communication point of the Modbus packet as the communication data storage first address;
and determining the value of a data value field in the response packet as a response numerical value, inputting the value of a discrete quantity/coil/input register/holding register number field of the Modbus packet as a length value to be read into a storage space, converting the response numerical value with the length meeting the length value of the read storage space according to a corresponding format of the Modbus protocol, and writing the converted value into the continuous memory to which the first storage address of the communication data points.
Specifically, the value of the "memory address of the first communication point of the packet" field in the Modbus packet corresponding to the communication packet is used as the communication data storage initial address, the value of the "discrete input amount/coil/input register/holding register number" of the packet corresponding to the Modbus packet is used as the size of the occupied space value of the read data, the values of the "coil state", "input state", "register state" and "input register" in the response packet are used as the response data based on the communication data storage initial address, the response data with the numerical value length satisfying the size of the occupied space value of the read data is converted according to the Modbus protocol requirement, and the obtained value is continuously filled into the memory with the continuous position to which the communication data storage initial address points at one time.
It should be noted that, the Modbus master station communication is a process of a cycle process, where the cycle process refers to that the Modbus master station sends communication packets to its opposite end at regular intervals until all the communication packets are sent.
By applying the embodiment provided by the invention, the mapping between the memory address and the communication addressing address of the initial Modbus communication point in the Modbus packet is established on the basis of Modbus communication memory optimization according to different function codes of Modbus packets sent to other equipment by the Modbus master station in the communication process, and the corresponding operations of reading and writing are executed through the initial memory address and the initial addressing address of the Modbus packet, so that correct data is ensured to be taken out from a Modbus model or written into a correct position, and the Modbus slave station is not required to be modified on the premise of ensuring the Modbus communication to be correct, so that the Modbus communication method has wide application scenes.
The specific implementation procedures and derivatives thereof of the above embodiments are within the scope of the present invention.
Corresponding to the method shown in fig. 1, an embodiment of the present invention further provides a Modbus communication data memory optimization device, which is used to specifically implement the method shown in fig. 1, where the Modbus communication data memory optimization device provided in the embodiment of the present invention may be applied to a computer terminal or various mobile devices, and a schematic structural diagram of the Modbus communication data memory optimization device is shown in fig. 5, and specifically includes:
the first execution unit 501 is configured to store information of each communication point in the Modbus master station into an information unit corresponding to the communication point, where each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field;
a first determining unit 502, configured to traverse each information unit in the communication point table, determine, according to a value of each field in the information unit corresponding to each communication point, a Modbus data model corresponding to each communication point, and allocate a memory space to each Modbus data model required for communication with each peer device corresponding to the Modbus master station;
a second determining unit 503, configured to determine, according to the number of currently counted communication points of the Modbus data model and the memory location marking unit value, a memory location of each communication point in the corresponding Modbus data model;
a second executing unit 504, configured to fill the memory location of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish a mapping between the memory address and the addressing address of each communication point according to a value of the memory address field in the information unit corresponding to each communication point and a value of a preset addressing address field.
Based on the device provided by the embodiment of the invention, in the process of Modbus communication memory optimization, the first execution unit stores the information of each communication point in the Modbus master station into the information unit corresponding to the communication point, and each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field; traversing each information unit in the communication point table by the first determining unit, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating memory space for each Modbus data model required by communication of each opposite-end device corresponding to the Modbus master station; the second determining unit determines the memory position of each communication point in the corresponding Modbus data model according to the current counted number of the communication points and the value of the memory position marking unit of the Modbus data model; and finally, the second execution unit fills the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
By applying the Modbus communication data memory optimization device provided by the embodiment of the invention, communication memories can be distributed according to the number of Modbus data model memories actually used by each communication point of each Modbus link, and the mapping between the memory address of the communication point in the Modbus data model and the Modbus communication addressing address of the communication point is established.
For specific working processes of each unit and subunit in the Modbus communication data memory optimization device disclosed in the above embodiment of the present invention, reference may be made to corresponding contents in the Modbus communication data memory optimization method disclosed in the above embodiment of the present invention, and details are not described here again.
In the embodiment provided by the invention, the communication processing device can be obtained based on the Modbus communication data memory optimization device, and comprises:
the Modbus communication system comprises an acquisition unit and a communication unit, wherein the acquisition unit is used for acquiring a Modbus packet which is constructed in advance, and constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus communication protocol format corresponding to a function code of the Modbus packet, and the Modbus packet comprises a plurality of communication points;
the operation unit is used for filling values of all communication points of the Modbus packet in a corresponding Modbus data model memory after conversion according to a corresponding Modbus protocol format to output value field positions of the communication packets to obtain communication packets to be sent corresponding to the communication packets when the function codes corresponding to the Modbus packets are write function codes;
the sending unit is used for sending the communication packet to be sent to an opposite end of the Modbus master station so that the opposite end returns a response packet corresponding to the communication packet to be sent;
and the analysis unit is used for receiving and analyzing the response packet to obtain a communication processing result and finish the communication processing process if the function code corresponding to the received response packet is the writing function code. And if the function code corresponding to the received response packet is a read function code, receiving and analyzing the response packet, converting the value of the data value field in the response packet according to the corresponding format of the Modbus protocol, and filling the converted value into a Modbus data model memory corresponding to each communication point of the Modbus packet to complete the communication processing process.
The embodiment of the invention also provides a storage medium, wherein the storage medium comprises a stored instruction, and when the instruction runs, the equipment where the storage medium is located is controlled to execute the Modbus communication data memory optimization method.
An electronic device is provided in an embodiment of the present invention, and the structural diagram of the electronic device is shown in fig. 6, which specifically includes a memory 601 and one or more instructions 602, where the one or more instructions 602 are stored in the memory 601 and configured to be executed by one or more processors 603 to perform the following operations on the one or more instructions 602:
storing the information of each communication point in the Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field;
traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required for communication with each opposite-end device corresponding to the Modbus master station;
determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model;
and filling the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
All the embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, the system or system embodiments are substantially similar to the method embodiments and therefore are described in a relatively simple manner, and reference may be made to some of the descriptions of the method embodiments for related points. The above-described system and system embodiments are only illustrative, wherein the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both.
To clearly illustrate this interchangeability of hardware and software, various illustrative components and steps have been described above generally in terms of their functionality. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A Modbus communication memory optimization method is characterized by comprising the following steps:
storing the information of each communication point in the Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field;
traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required for communication with each opposite-end device corresponding to the Modbus master station;
determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model;
and filling the memory position of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
2. The method of claim 1, wherein the plurality of fields in the information unit further include a peer device serial number field, a communication direction field, and a data type field, and wherein allocating memory space for each Modbus data model required for communication with a respective peer device corresponding to the Modbus master station based on the value of the respective field in the information unit corresponding to each communication point comprises:
determining an opposite terminal device where each communication point is located according to the value of an opposite terminal device sequence number field in an information unit corresponding to each communication point;
determining the communication point property of each communication point according to the value of a communication direction field in an information unit corresponding to each communication point, wherein the communication point property is a sending communication point or a receiving communication point;
determining a storage space value required to be occupied by each communication point in a corresponding Modbus data model according to the value of a data type field in an information unit corresponding to each communication point, and accumulating the storage space count values of the corresponding Modbus data models of the opposite-end device where the communication point is located, so as to calculate the storage space required by each Modbus data model of each opposite-end device, and taking the storage space value as a communication memory space value required by the Modbus data model;
and determining a communication memory space value required by each Modbus data model required for communication with each opposite-end device according to the Modbus data model corresponding to each communication point, the opposite-end device where each communication point is located, the property of the communication point of each communication point and the communication memory space value required by each Modbus data model, and allocating a memory space to the Modbus data model as the communication memory space value.
3. The method according to claim 1, wherein determining the memory location of each communication point in its corresponding Modbus data model according to the currently counted number of communication points and the memory location flag cell value of the Modbus data model comprises:
obtaining a count value obtained by current statistics of a communication point number counter of the Modbus data model corresponding to the communication point;
if the count value is 0, determining that the communication point is the first communication point in the corresponding Modbus data model, and setting the memory position of the communication point in the corresponding Modbus data model to be 0;
if the count value is not 0, obtaining a memory location flag cell value of the Modbus data model, and determining that the memory location of the communication point in the corresponding Modbus data model is the memory location flag cell value.
4. A communication processing method, comprising:
the method comprises the steps of obtaining a Modbus packet which is constructed in advance, and constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus communication protocol format corresponding to a function code of the Modbus packet, wherein the Modbus packet is composed of a plurality of communication points;
when the function code corresponding to the Modbus packet is the write function code, taking out the value of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting the value according to the corresponding format of the Modbus protocol, and filling the converted value in the field position of the output value of the communication packet to obtain the communication packet to be sent corresponding to the communication packet;
sending the communication packet to be sent to an opposite-end device of the Modbus master station so that the opposite-end device returns a response packet corresponding to the communication packet to be sent;
and receiving and analyzing the response packet to obtain a communication processing result, and finishing the communication processing process.
5. The method of claim 4, further comprising:
when the function code corresponding to the Modbus packet is a read function code, sending the communication packet to the opposite terminal according to the Modbus protocol so that the opposite terminal returns a response packet corresponding to the communication packet;
and receiving and analyzing the response packet, converting the value of the data value field in the response packet according to the corresponding format of the Modbus protocol, and filling the converted value into Modbus data model memories corresponding to the communication points of the Modbus packet to complete the communication processing process.
6. The method according to claim 4, wherein the extracting the value of each communication point of the Modbus packet from the corresponding Modbus data model memory, converting the value into a corresponding Modbus protocol format, and filling the converted value into the output value field position of the communication packet comprises:
determining the value of the field of the memory address of the first communication point of the Modbus packet as the communication data address initial address;
and inputting the value of the number field of the Modbus packet into a discrete quantity/coil/input register/holding register as a length value of a read storage space, taking data with the length meeting the length value of the read storage space from a continuous memory space pointed by the address head address of the communication data as a communication value, converting the communication value according to the corresponding format of the Modbus protocol, and filling the converted value into the position of the field of the output value of the communication packet.
7. The method according to claim 5, wherein the converting the value of the data value field in the response packet according to the corresponding format of the Modbus protocol, and filling the converted value in the Modbus data model memory corresponding to each communication point of the Modbus packet comprises:
determining the value of the memory address field of the first communication point of the Modbus packet as the communication data storage first address;
and determining a value of a data value field in the response packet as response data, inputting a value of a discrete quantity/coil/input register/holding register number field of the Modbus packet as a length value of a read-in storage space, converting the response value with the length meeting the length value of the read-in storage space according to a corresponding format of the Modbus protocol, and writing the converted value into a continuous memory position to which a communication data storage head address points.
8. The method according to claim 4, wherein the Modbus packet building process comprises:
combining a plurality of communication points with the same function code to form a Modbus packet, and determining the function code as the function code of the Modbus packet;
determining the value of the addressing address field in the communication point table information unit corresponding to the first communication point forming the Modbus packet as the value of the addressing address field of the first communication point of the Modbus packet, and determining the value of the memory address field in the communication point table information unit corresponding to the communication point as the value of the memory address field of the first communication point of the Modbus packet;
and counting the Modbus data model memory space value required by each communication point in the Modbus packet to obtain the Modbus data model memory space value required by the Modbus packet during communication, wherein the value is the value of the number field of the input discrete quantity/coil/input register/holding register of the Modbus packet.
9. The utility model provides a Modbus communication data memory optimizing apparatus which characterized in that includes:
the first execution unit is used for storing the information of each communication point in the Modbus master station into an information unit corresponding to the communication point, and each information unit forms a communication point table; each information unit comprises a plurality of fields, and each field comprises a function code field, a memory address field and an addressing address field;
the first determining unit is used for traversing each information unit in the communication point table, determining a Modbus data model corresponding to each communication point according to the value of each field in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required by communication of each opposite-end device corresponding to the Modbus master station;
the second determining unit is used for determining the memory position of each communication point in the corresponding Modbus data model according to the currently counted number of the communication points and the memory position marking unit value of the Modbus data model;
and the second execution unit is used for filling the memory location of each communication point in the corresponding Modbus data model into the memory address field of the information unit corresponding to the communication point, so as to establish mapping between the memory address and the addressing address of each communication point according to the value of the memory address field in the information unit corresponding to each communication point and the value of the preset addressing address field.
10. A communication processing apparatus, comprising:
the Modbus communication system comprises an acquisition unit and a communication unit, wherein the acquisition unit is used for acquiring a Modbus packet which is constructed in advance, and constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus communication protocol format corresponding to a function code of the Modbus packet, and the Modbus packet comprises a plurality of communication points;
the operation unit is used for taking out the value of each communication point of the Modbus packet in the corresponding Modbus data model memory when the function code corresponding to the Modbus packet is a write function code, converting the value according to the corresponding format of the Modbus protocol, filling the converted value to the field position of the output value of the communication packet, and obtaining the communication packet to be sent corresponding to the communication packet;
the sending unit is used for sending the communication packet to be sent to an opposite end of the Modbus master station so that the opposite end returns a response packet corresponding to the communication packet to be sent;
and the analysis unit is used for receiving and analyzing the response packet to obtain a communication processing result and finish the communication processing process.
CN202210779110.7A 2022-07-04 2022-07-04 Modbus communication memory optimization method, communication method and related device Active CN115174306B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210779110.7A CN115174306B (en) 2022-07-04 2022-07-04 Modbus communication memory optimization method, communication method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210779110.7A CN115174306B (en) 2022-07-04 2022-07-04 Modbus communication memory optimization method, communication method and related device

Publications (2)

Publication Number Publication Date
CN115174306A true CN115174306A (en) 2022-10-11
CN115174306B CN115174306B (en) 2023-07-25

Family

ID=83491408

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210779110.7A Active CN115174306B (en) 2022-07-04 2022-07-04 Modbus communication memory optimization method, communication method and related device

Country Status (1)

Country Link
CN (1) CN115174306B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106506307A (en) * 2016-12-22 2017-03-15 南京因泰莱电器股份有限公司 A kind of Modbus frame formats self-described method
CN109450756A (en) * 2018-10-18 2019-03-08 南京海桐环境科技有限公司 A kind of ModbusRTU signal procedure based on SIMATIC S7-200 SMART
CN112311808A (en) * 2020-11-11 2021-02-02 上海电器科学研究所(集团)有限公司 Method for automatically mapping Modbus protocol data to OPCUA address space
US20210409371A1 (en) * 2020-06-29 2021-12-30 Shenzhen Fugui Precision Ind. Co., Ltd. Method and system of data collecting

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106506307A (en) * 2016-12-22 2017-03-15 南京因泰莱电器股份有限公司 A kind of Modbus frame formats self-described method
CN109450756A (en) * 2018-10-18 2019-03-08 南京海桐环境科技有限公司 A kind of ModbusRTU signal procedure based on SIMATIC S7-200 SMART
US20210409371A1 (en) * 2020-06-29 2021-12-30 Shenzhen Fugui Precision Ind. Co., Ltd. Method and system of data collecting
CN112311808A (en) * 2020-11-11 2021-02-02 上海电器科学研究所(集团)有限公司 Method for automatically mapping Modbus protocol data to OPCUA address space

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
王德文;阎春雨;毕建刚;袁帅;: "变电站状态监测通信网关中Modbus与IEC61850的映射方法", 电力系统自动化, no. 19 *
王鼎: "一种核安全级数字化仪控系统现场控制站的冗余设计", 《原子能科学技术》 *
詹静: "一种基于共享内存百度的Modbus/TCP安全通信方法", 《中国科技论文》 *
马忠刚: "核电安全级数字化仪控系统内存诊断涉及与实现", 《自动化博览》 *

Also Published As

Publication number Publication date
CN115174306B (en) 2023-07-25

Similar Documents

Publication Publication Date Title
CN107590099A (en) A kind of more main frames access method, expanding unit and the storage medium of slave
CN108369562A (en) Intelligently encoding memory architecture with enhanced access scheduling device
CN106878131B (en) PROFIBUS coupler and data transmission method of PROFIBUS
CN108874688A (en) A kind of message data caching method and device
CN107783727A (en) A kind of access method of memory device, device and system
CN102750249B (en) The method that host computer communicates with slave computer, Apparatus and system
CN107800644A (en) Dynamically configurable pipelined token bucket speed limiting method and device
CN109587072A (en) Distributed system overall situation speed limiting system and method
CN102567278A (en) On-chip multi-core data transmission method and device
CN105426322B (en) A kind of forecasting method and device of data
US7761683B2 (en) Variable width memory system and method
CN115174306A (en) Modbus communication memory optimization method, communication method and related device
CN110515872B (en) Direct memory access method, device, special computing chip and heterogeneous computing system
CN109189336A (en) A kind of storage system thread method of adjustment, system and electronic equipment and storage medium
CN108322482A (en) A kind of method and device of protocol conversion
CN109710409B (en) Memory management method, system, device and readable storage medium
CN113923061B (en) GPU network communication method based on intelligent network card, medium and equipment
CN111782561B (en) SRAM storage space allocation method, device and chip
CN112698950B (en) Memory optimization method for industrial Internet of things edge equipment
CN108737352A (en) The radio physical layer processing system and method for compatible multi-protocols and nonstandard protocol
CN112306420B (en) Data read-write method, device and equipment based on storage pool and storage medium
CN114169292A (en) Byte stream data conversion method, device, equipment and storage medium
CN107592677B (en) Data transmission method and device
CN102207900A (en) Debugging tool and method of digital signal processing system
TWI779938B (en) Method for accessing system memory and associated processing circuit arranged on network interface card

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