CN115174306B - 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
CN115174306B
CN115174306B CN202210779110.7A CN202210779110A CN115174306B CN 115174306 B CN115174306 B CN 115174306B CN 202210779110 A CN202210779110 A CN 202210779110A CN 115174306 B CN115174306 B CN 115174306B
Authority
CN
China
Prior art keywords
communication
modbus
value
packet
communication point
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
Application number
CN202210779110.7A
Other languages
Chinese (zh)
Other versions
CN115174306A (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

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, which comprise the following steps: storing information of each communication point in the Modbus master station to each information unit of a 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 number of the communication points counted currently 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 the 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 present invention relates to the field of data processing, and in particular, to a Modbus communication memory optimization method, a communication method, and a related device.
Background
In the Modbus communication design, a memory storage space of 65536 data items is opened up for each Modbus data model, and a mapping relation between the memory storage space and a communication addressing space of 1 to 1 is established, so that access to the Modbus data items is facilitated. However, in practical applications, all data items are often not used, and even only few data items are used, which may waste memory space. Particularly, when the system is to support multiple Modbus communications and there are few communication data items on each link, if the memory is allocated according to the maximum value, a large and wasted memory resource will be caused. In order to save memory resources, memory optimization is required in the Modbus communication design.
However, the optimal design of the Modbus communication memory in the prior art does not fully utilize the storage capability of each bit of the memory, and does not correctly establish the relationship between the optimized memory address and the addressing address, so that the correct operation of the Modbus communication is easily affected.
Disclosure of Invention
In view of this, the present invention provides a method for optimizing 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 guaranteeing the realization and application of the method in practice.
A Modbus communication data memory optimization method comprises the following steps:
storing information of each communication point in a Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table; wherein 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 distributing a memory space for each Modbus data model required by communication of 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 number of the communication points counted currently 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 the 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 plurality of fields in the information unit further includes a peer device serial number field, a communication direction field, and a data type field, and allocating a memory space for each of the Modbus data models required for communication with each of the peer devices corresponding to the Modbus master station according to the values of each field in the information unit corresponding to each of the communication points, including:
determining the opposite terminal device of each communication point according to the value of the opposite terminal device serial number field in the 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 the information unit corresponding to each communication point, wherein the communication point property is a transmitting communication point or a receiving communication point;
according to the value of the data type field in the information unit corresponding to each communication point, determining a storage space value which each communication point needs to occupy in the corresponding Modbus data model, accumulating the storage space count value of the corresponding Modbus data model of the opposite terminal device where the communication point is located, counting the storage space required by each Modbus data model of each opposite terminal 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 by communication with each opposite terminal device according to the Modbus data model corresponding to each communication point, the opposite terminal device where each communication point is located, the communication point property of each communication point and the communication memory space value required by each Modbus data model, and allocating a memory space for the Modbus data model as the communication memory space value.
Optionally, the determining, according to the number of communication points and the memory location marking unit value of the current statistics of the Modbus data model, the memory location of each communication point in the corresponding Modbus data model includes:
acquiring 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 if the communication point is the memory position of the communication point in the corresponding Modbus data model is 0;
and if the count value is not 0, acquiring a memory location marking unit 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 marking unit value.
A communication processing method, comprising:
acquiring a pre-constructed Modbus packet, 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 consists 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 according to the corresponding format of the Modbus protocol, filling the converted value into the position of the output value field of the communication packet, and obtaining the communication packet to be transmitted corresponding to the communication packet;
the communication packet to be sent is 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 receiving and analyzing the response packet to obtain a communication processing result, and completing a communication processing process.
Optionally, the method further comprises:
when the function code corresponding to the Modbus packet is a read function code, the communication packet is sent 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 Modbus data model memories corresponding to all communication points of the Modbus packet, and completing the communication processing process.
Optionally, the extracting the value of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting according to the format corresponding to the Modbus protocol, and filling the value obtained after conversion into the output value field position of the communication packet includes:
determining the value of a field of a memory address of a first communication point of the Modbus packet as a communication data address-taking first address;
and inputting the value of the number field of the Modbus packet into a discrete quantity/coil/input register/holding register as a reading storage space length value, taking out data with the length meeting the reading storage space length value from a continuous memory space pointed by the address taking 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 output value field 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, filling the converted value into the Modbus data model memory corresponding to each communication point of the Modbus packet, includes:
determining the value of a memory address field of a first communication point of the Modbus packet as a communication data storage first address;
And determining the value of a data value field in the response packet as response data, taking the value of the number field of the local packet input discrete quantity/coil/input register/holding register 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 the corresponding format of the Modbus protocol, and writing the converted value into a continuous memory position pointed by a storage head address of the communication data.
Optionally, the construction process of the Modbus packet 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 an addressing address field in a communication point table information unit corresponding to a 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 a 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 memory space value of the Modbus data model required by each communication point in the Modbus packet to obtain the memory space value of the Modbus data model required by the Modbus packet in communication, wherein the memory space value is the value of the input discrete quantity/coil/input register/holding register number field of the Modbus packet.
A Modbus communication data memory optimization device, comprising:
the first execution unit is used for storing 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; wherein 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 distributing a memory space for each Modbus data model required by communication of each opposite terminal 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 number of the communication points counted currently and the memory position marking unit value of the Modbus data model;
and the second execution unit is used for 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 the 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 preset value of the addressing address field.
A communication processing apparatus comprising:
the communication system comprises an acquisition unit, a communication point acquisition unit and a communication point acquisition unit, wherein the acquisition unit is used for acquiring a pre-constructed Modbus packet, 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 consists of 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 according to the corresponding format of the Modbus protocol, filling the converted value into the position of the output value field of the communication packet, and obtaining the communication packet to be transmitted corresponding to the communication packet;
the sending unit is used for sending the communication packet to be sent to the 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 complete a communication processing process.
The storage medium comprises stored instructions, wherein when the instructions run, equipment in which the storage medium is located is controlled to execute the Modbus communication data memory optimization method.
An electronic device comprising a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to perform the Modbus communication data memory optimization method described above by one or more processors.
Compared with the prior art, the invention has the following advantages:
based on the embodiment provided by the invention, in the process of optimizing Modbus communication memory, the information of each communication point in a Modbus master station is stored 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, wherein 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 distributing a memory space for each Modbus data model required by communication of 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 number of the communication points counted currently 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 the 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 master station communication data memory use optimization method provided by the invention, communication memories can be allocated according to the Modbus data model memory space actually used by each communication point of each Modbus link, 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, modbus communication memory allocation and use optimization can be realized on the basis of meeting Modbus communication requirements, the problem of memory vacancy is solved, memory waste is avoided, and the memory space is fully utilized.
Drawings
Fig. 1 is a flowchart of a method for optimizing a memory of Modbus communication data according to an embodiment of the present invention;
fig. 2 is a flowchart of another method for optimizing a memory of Modbus communication data according to an embodiment of the present invention;
fig. 3 is a flowchart of another method of the memory optimization method for Modbus communication data according to an embodiment of the present invention;
fig. 4 is a flowchart of another method of optimizing a memory of Modbus communication data according to an embodiment of the present invention;
fig. 5 is a device structure diagram of a Modbus communication data memory optimizing 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 following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the 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 "comprise," "include," 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 phrase "comprising one … …" does not exclude the presence of other 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 devices, multiprocessor devices, distributed computing environments that include any of the above devices or devices, and the like.
The embodiment of the invention provides a Modbus communication data memory optimization method, which can be applied to various system platforms, wherein an execution main body of the method can be a processor of a computer terminal or 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.
Wherein 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 Modbus communication points in the configuration is read into the information unit of the Modbus communication point table. The information of the Modbus communication points of the configuration comprises a data type, a communication direction (i.e. whether to transmit or receive), a device serial number of the opposite end (i.e. RTU sub-equipment number/TCP link serial number of the opposite end), a function code and an input discrete quantity/coil/input register/holding register communication addressing address in the Modbus protocol.
The structure of a specific single information unit of the Modbus communication point table is shown in table 1:
data type
Communication direction (transmitting/receiving)
Function code
Opposite end dressSerial number
Addressing addresses
Memory address
TABLE 1
And respectively filling the data type field, the communication direction field, the function code field, the opposite terminal device serial number field and the opposite terminal device serial number field of the information unit corresponding to the communication point with the data type, the communication direction field, the function code field, the opposite terminal device serial number field of the communication point information, the input discrete quantity/coil/input register/holding register communication addressing address in the Modbus protocol and the like.
S102: and 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 distributing a memory space for each Modbus data model required by communication of 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 discrete quantity, coils, a holding register and an 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 exist under the Modbus protocol, a plurality of Modbus communication points can be configured under each Modbus data model, but the Modbus data model corresponding to each Modbus communication point is unique and is determined by the function code of the Modbus communication point. 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 plurality of fields in the information unit further includes a peer device serial number field, a communication direction field, and a data type field, and allocating, according to values of respective fields in the information unit corresponding to each communication point, a memory space for each of the Modbus data models required for communication with respective peer devices corresponding to the Modbus master station includes:
s201: and determining the opposite terminal device where each communication point is located according to the value of the opposite terminal device serial number field in the information unit corresponding to each communication point.
In the embodiment provided by the invention, the serial number of the opposite terminal device where the communication point is located can be determined according to the value of the opposite terminal device serial number field in the information unit corresponding to the communication point, so as to determine the opposite terminal device where the communication point is located, wherein the opposite terminal device serial number can be an RTU sub-equipment number or a TCP link serial number (namely, when communicating with a plurality of TCP slave stations, the number of which TCP slave station 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 transmitting communication point or a receiving communication point.
S203: and determining a storage space value which is required to be occupied by each communication point in a corresponding Modbus data model according to the value of a data type field in the information unit corresponding to each communication point, accumulating the storage space count value of the corresponding Modbus data model of the opposite terminal device where the communication point is located, counting the storage space required by each Modbus data model of each opposite terminal 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 field, such as bool, int, float, in the information unit corresponding to the communication point and a plurality of variable types with quality bits, and the Modbus data model is combined to obtain how much storage space is needed by the communication point in the Modbus data model to store the communication point, and the storage space count value of the corresponding Modbus data model of the opposite terminal device where the communication point is located is accumulated, so that the storage space needed by each Modbus data model of each opposite terminal device is counted, and the storage space value is used as the communication memory space value needed by the Modbus data model.
S204: and determining a communication memory space value of each Modbus data model required for communication with each opposite terminal device according to the Modbus data model corresponding to each communication point, the opposite terminal device where each communication point is located, the communication point property of each communication point and the communication memory space value required by each Modbus data model, and allocating memory space for the Modbus data model as the communication memory space value.
In the embodiment provided by the invention, a plurality of Modbus data models exist under the Modbus protocol, so that communication on one Modbus RTU sub-device/TCP link can also be provided with the communication of the plurality of Modbus data models. And determining the data length of each communication point according to the data type of each communication point, so as to determine how much storage space is needed for storing the communication point in the corresponding Modbus data model of the corresponding opposite terminal device, accumulating the storage space of the corresponding Modbus data model of the opposite terminal device where the communication point is located, counting the memory size needed by each Modbus data model of each opposite terminal device, and distributing the memory of each Modbus data model of each opposite terminal device.
By using the embodiment provided by the invention, the communication memory space occupied by each Modbus data model under each opposite terminal device is counted, the corresponding memory space is allocated for each Modbus data model under each opposite terminal device, and the memory is allocated as required on the basis of meeting the Modbus communication requirement, so that the use of the Modbus communication memory 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 current counted communication point number and the memory position marking unit value of the Modbus data model.
In the embodiment provided by the invention, the memory position of each communication point in the corresponding Modbus data model can be determined on the basis of the memory existing in the Modbus data model according to the number of the communication points counted currently and the value of the memory position marking unit.
Specifically, as shown in fig. 3, the determining, according to the number of communication points and the memory location marking unit value of the current statistics of the Modbus data model, the memory location of the communication point in the corresponding Modbus data model includes:
s301: and acquiring the current counted 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 each opposite terminal device of each Modbus master station, and the initial value is 0 and is used for counting the number of Modbus communication points contained in each Modbus data model of each opposite terminal device; and respectively generating a memory location marking unit with an initial value of 0 for each Modbus data model of each opposite terminal device, wherein the memory location marking unit is used for marking the memory location of each Modbus communication point in the corresponding Modbus data model.
Therefore, determining the memory location of a communication point in its corresponding Modbus data model requires first obtaining the count value of the current statistics 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.
If the count value is 0, S303 is executed, otherwise S304 is executed.
S303: and determining that the memory position of the communication point in the corresponding Modbus data model is 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 Modbus data model corresponding to the communication point 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 location marking unit value of the Modbus data model, and determining the memory location of the communication point in the corresponding Modbus data model as the memory location marking unit value.
And if the count value is not 0, acquiring a memory location marking unit value of the Modbus data model corresponding to the communication point, and taking the value as the memory location of the communication point in the corresponding Modbus data model.
And accumulating the value of a communication point number counter of the Modbus data model corresponding to the communication point to 1 according to the obtained memory position of the communication point in the corresponding Modbus data model, and accumulating the value of a memory position marking unit of the Modbus data model corresponding to the communication point to be the storage space which the communication point needs to occupy in the Modbus data model.
By applying the embodiment provided by the invention, the memory positions of the communication points in the corresponding Modbus data model are determined by acquiring the number of the communication points counted currently and the value of the memory position marking unit of the Modbus data model, 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 the 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 optimizing Modbus communication memory, the information of each communication point in a Modbus master station is stored 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, wherein 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 distributing a memory space for each Modbus data model required by communication of 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 number of the communication points counted currently 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 the 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 master station communication data memory use optimization method provided by the invention, communication memories are 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 Modbus communication requirements, modbus communication memory allocation and use optimization can be realized, the problem of memory vacancy is solved, memory waste is avoided, and the memory space is fully utilized.
In the embodiment provided by the invention, as shown in fig. 4, a process of executing communication processing of a Modbus master station based on a method for optimizing memory of Modbus communication data includes:
s401: and acquiring a pre-constructed Modbus packet, and constructing a communication packet corresponding to the Modbus packet according to the basic information of the Modbus packet and a Modbus communication protocol format corresponding to the function code of the Modbus packet.
It should be noted that, according to a preset Modbus subpackaging algorithm, the number and information of Modbus communication packets under each opposite terminal device of the Modbus master station are constructed and counted, 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 packet needs to be organized according to the basic information structure of the Modbus packet corresponding to the communication packet.
The construction process of the Modbus packet 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 an addressing address field in a communication point table information unit corresponding to a 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 a 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 memory space value of the Modbus data model required by each communication point in the Modbus packet to obtain the memory space value of the Modbus data model required by the Modbus packet in communication, wherein the memory space value is the value of the input discrete quantity/coil/input register/holding register number field of the Modbus packet.
Specifically, a Modbus packet information table is pre-constructed, and in each Modbus packet unit in the Modbus packet information table, the structure of single Modbus packet basic information is shown in table 2, and the single Modbus packet basic information provides necessary information required when the communication packets are assembled and filled.
TABLE 2
In the process of Modbus communication packetizing, when a new Modbus packet is generated, besides the function code of the new packet, the input discrete quantity/coil/input register/holding register number, the addressing address in the information unit corresponding to the first communication point of the Modbus packet is required to be filled into the addressing address field of the first communication point in the information structure of the Modbus packet, and the memory address in the information unit corresponding to the first communication point of the new packet is required to be filled into the memory address field of the first communication point of the packet in the information structure of the Modbus packet. The number of the input discrete quantity/coil/input register/holding register of the Modbus packet is calculated according to accumulated values of memory space of the Modbus data model 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 any 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 codes of the Modbus packet, the number of the input discrete quantity/coils/input registers/holding registers, the initial memory address and the initial addressing address of the Modbus packet are determined, and the method is only executed once during communication initialization, so that the method has higher processing efficiency, effectively saves the processing time of Modbus periodic communication and improves the efficiency of Modbus periodic 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 according to the corresponding format of the Modbus protocol, filling the converted value into the position of the output value field of the communication packet, and obtaining the communication packet to be transmitted 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 and 16, on the basis of constructing the Modbus communication packet according to the Modbus packet, the values in the Modbus data model memory corresponding to each communication point of the Modbus packet are also required to be taken out and converted according to the Modbus protocol, and the converted values are filled in the output value field of the communication packet, namely the position of the output value/register value field, so that the communication packet to be sent is obtained.
It should be noted that, constructing the Modbus communication packet according to the Modbus packet may include the following steps:
if the protocol format of the communication packet relates to an address field, filling the address field content 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 the 'quantity' field, filling the 'present packet input discrete quantity/coil/input register/holding register quantity' field content of the Modbus packet into the 'quantity' field of the communication packet;
if the protocol format of the communication packet relates to the byte count field, the contents of the field of the Modbus packet of the input discrete quantity/coil/input register/holding register are calculated according to the Modbus protocol requirement, and then the field of the Modbus packet of the input discrete quantity/coil/input register/holding register is filled in the field of the byte count of the communication packet.
Specifically, the step of taking out the values of each communication point of the Modbus packet in the corresponding Modbus data model memory, converting according to the format corresponding to the Modbus protocol, filling the converted values into the output value field position of the communication packet, and obtaining the communication packet to be sent corresponding to the communication packet, includes:
Determining the value of a field of a memory address of a first communication point in the Modbus packet as a communication data address-taking first address;
and inputting the value of the number field of the discrete quantity/coil/input register/holding register of the Modbus packet as a reading storage space length value, taking out the data with the length meeting the reading storage space length value from a memory with continuous positions pointed by the address taking 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 output value field of the communication packet.
It can be understood that, based on the address-taking head address of the communication data, the value of "the present packet input discrete quantity/coil/input register/holding register number" of the Modbus packet is taken as the space value size occupied by the taken-out value, the value of which the position continuously meets the read storage space value size is taken out from the memory pointed by the address-taking head address of the communication data at one time and 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 the output value/register value of the communication packet. S403: and sending the communication packet to be sent to the 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 terminal device of the Modbus master station, executing related operation by the opposite terminal device according to the communication packet to be sent, writing a value in the communication packet to be sent into a corresponding position of the opposite terminal 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 opposite terminal device serial number field in the unit information corresponding to each communication point in the Modbus packet corresponding to the communication packet, each opposite terminal device to which the communication packet sent by the Modbus master station needs to be sent can be determined.
S404: and receiving and analyzing the response packet to obtain a communication processing result, and completing a communication processing process.
The Modbus master station receives the response packet sent back by the opposite terminal device, analyzes the response packet, writes analysis corresponding to the function code, and processes according to the Modbus protocol without special operation. And after analysis, obtaining a communication processing result of the operation of sending data to the opposite terminal by the Modbus master station, thereby completing the communication processing process.
In the embodiment provided by the invention, the process of executing Modbus master station communication processing based on the Modbus communication data memory optimization method further comprises the following steps:
When the function code corresponding to the Modbus packet is a read function code, the communication packet is sent 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 completing the communication processing process.
In the embodiment provided by the invention, if the function code corresponding to the Modbus packet is a read function code, determining the Modbus communication protocol format of the communication packet according to the function code of the Modbus packet, and constructing the Modbus communication packet corresponding to the read function code 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 address field content 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;
the field of 'the present packet input discrete quantity/coil/input register/holding register number' of the Modbus packet is filled 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, wherein the opposite end executes related operation according to the communication packet, determines information required to be read by the Modbus master station according to the information of the communication packet, and generates a corresponding response packet according to the information required 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, and fills the converted value into Modbus data model memories corresponding to all communication points of the Modbus packet corresponding to the communication packet to complete the communication processing process of reading the opposite terminal information.
In the embodiment provided by the present invention, 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 into the Modbus data model memory corresponding to each communication point of the Modbus packet includes:
determining the value of a memory address field of a first communication point of the Modbus packet as a communication data storage first address;
and determining the value of a data value field in the response packet as a response value, inputting the value of the data value field in the Modbus packet into a discrete quantity/coil/input register/holding register number field as a length value to be read into a 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 pointed by a storage head address of communication data.
Specifically, a value of a memory address field of a first communication point of a present packet in a Modbus packet corresponding to a communication packet is taken as a communication data storage head address, a value of a discrete quantity/coil/input register/holding register number of the present packet corresponding to the Modbus packet is taken as a space value of read data, the values of a coil state, an input state, a register state and an input register in a response packet are taken as response data based on the communication data storage head address, the response data with the value length meeting the space value of the read data is converted according to Modbus protocol requirements, and the obtained value is continuously filled into a memory with continuous positions pointed by the communication data storage head address at one time.
The communication of the Modbus master station is a process of a periodic process, wherein the periodic process refers to that the Modbus master station sends communication packets to the opposite terminal of the Modbus master station at regular intervals until all the communication packets are sent.
By applying the embodiment of 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 optimizing Modbus communication memory according to different function codes of the Modbus packet sent by the Modbus master station to other devices in the communication process, and the operations corresponding to reading and writing are executed through the initial memory address and the initial addressing address of the Modbus packet, so that the correct data is ensured to be taken out from a Modbus model or written into the correct position, and the Modbus slave station is not required to be changed under the premise of ensuring that Modbus communication is correct, thereby having wide application fields.
The specific implementation process and derivative manner of the above embodiments are all within the protection scope of the present invention.
Corresponding to the method described in fig. 1, the embodiment of the present invention further provides a Modbus communication data memory optimization device, which is used for implementing the method 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 the structural schematic diagram of the Modbus communication data memory optimization device is shown in fig. 5, and specifically includes:
a first execution unit 501, configured to store information of each communication point in a Modbus master station into an information unit corresponding to the communication point, where each information unit forms a communication point table; wherein 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 a Modbus data model corresponding to each communication point according to a value of each field in the information unit corresponding to each communication point, and allocate a memory space for 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 communication points and the value of the memory location marking unit, which are currently counted in the Modbus data model, a memory location of each communication point in the corresponding Modbus data model;
and the second execution unit 504 is configured to fill the memory location of each communication point in the Modbus data model corresponding to the communication point 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 the value of the memory address field in the information unit corresponding to each communication point and the preset value of the addressing address field.
Based on the device provided by the embodiment of the invention, in the process of optimizing Modbus communication memory, a first execution unit stores the information of each communication point in a 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, wherein 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 a 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 distributing a memory space for each Modbus data model required by communication of each opposite terminal device corresponding to a Modbus master station; the second determining unit determines the memory position of each communication point in the corresponding Modbus data model according to the number of the communication points counted currently and the memory position marking unit value of the Modbus data model; and finally, the second execution unit fills the memory position of each communication point in the Modbus data model corresponding to the communication point into the memory address field of the information unit corresponding to the communication point, so as to establish the 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 preset value of the addressing address field.
By applying the Modbus communication data memory optimization device provided by the embodiment of the invention, communication memories can be allocated according to the number of Modbus data model memories actually used by each communication point of each Modbus link, 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 can be established, modbus communication memory allocation and use optimization can be realized on the basis of meeting Modbus communication requirements, the problem of memory vacancy is solved, memory waste is avoided, and memory space is fully utilized.
The specific working process of each unit and each subunit in the memory optimizing device for Modbus communication data disclosed in the above embodiment of the present invention can be referred to the corresponding content in the memory optimizing method for Modbus communication data disclosed in the above embodiment of the present invention, and will not be described herein again.
In the embodiment provided by the invention, the device for optimizing the memory based on Modbus communication data can also obtain a communication processing device, which comprises the following components:
the communication system comprises an acquisition unit, a communication point acquisition unit and a communication point acquisition unit, wherein the acquisition unit is used for acquiring a pre-constructed Modbus packet, 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 consists of a plurality of communication points;
The operation unit is used for filling values obtained by converting the values of all communication points of the Modbus packet in the corresponding Modbus data model memory according to the corresponding format of the Modbus protocol into the output value field position of the communication packet when the function code corresponding to the Modbus packet is a write function code, so as to obtain the communication packet to be transmitted corresponding to the communication packet;
the sending unit is used for sending the communication packet to be sent to the 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 finishing 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 Modbus data model memories corresponding to all communication points of the Modbus packet to complete the communication processing process.
The embodiment of the invention also provides a storage medium, which comprises stored instructions, wherein when the instructions run, equipment where the storage medium is controlled to execute the Modbus communication data memory optimization method.
The embodiment of the present invention further provides an electronic device, whose structural schematic diagram is shown in fig. 6, specifically including 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 the one or more processors 603, where the one or more instructions 602 perform the following operations:
storing information of each communication point in a Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table; wherein 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 distributing a memory space for each Modbus data model required by communication of 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 number of the communication points counted currently 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 the 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 this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for a system or system embodiment, since it is substantially similar to a method embodiment, the description is relatively simple, with reference to the description of the method embodiment being made in part. The systems and system embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
Those of skill would further appreciate that the elements and algorithm steps of the examples 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 solution. 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 (8)

1. The Modbus communication memory optimization method is characterized by comprising the following steps of:
storing information of each communication point in a Modbus master station into an information unit corresponding to the communication point, wherein each information unit forms a communication point table; wherein 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 distributing a memory space for each Modbus data model required by communication of 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 number of the communication points counted currently and the memory position marking unit value of the Modbus data model;
filling the memory position of each communication point in the Modbus data model corresponding to the communication point into the memory address field of the information unit corresponding to the communication point, so as to establish the 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;
If 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, determining a Modbus data model corresponding to each communication point according to the values of the fields in the information unit corresponding to each communication point, and allocating a memory space for each Modbus data model required for communication with each peer device corresponding to the Modbus master station, including:
determining the opposite terminal device of each communication point according to the value of the opposite terminal device serial number field in the 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 the information unit corresponding to each communication point, wherein the communication point property is a transmitting communication point or a receiving communication point;
according to the value of the data type field in the information unit corresponding to each communication point, determining a storage space value which each communication point needs to occupy in the corresponding Modbus data model, accumulating the storage space count value of the corresponding Modbus data model of the opposite terminal device where the communication point is located, counting the storage space required by each Modbus data model of each opposite terminal 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 by communication with each opposite terminal device according to the Modbus data model corresponding to each communication point, the opposite terminal device where each communication point is located, the communication point property of each communication point and the communication memory space value required by each Modbus data model, and allocating a memory space for the Modbus data model as the communication memory space value.
2. The method of claim 1, wherein determining the memory location of each communication point in its corresponding Modbus data model based on the current counted number of communication points and the memory location tag unit value of the Modbus data model comprises:
acquiring 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 if the communication point is the memory position of the communication point in the corresponding Modbus data model is 0;
and if the count value is not 0, acquiring a memory location marking unit 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 marking unit value.
3. A communication processing method, comprising:
acquiring a pre-constructed Modbus packet, and constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus protocol format corresponding to a function code of the Modbus packet, wherein the Modbus packet consists of a plurality of communication points;
when the function code corresponding to the Modbus packet is a write function code, determining the value of a field of a memory address of a first communication point of the Modbus packet as a communication data address-taking first address;
inputting the value of the number field of the Modbus packet into discrete quantity, a coil, an input register and a holding register as a reading storage space length value, taking out data with the length meeting the reading storage space length value from a continuous memory space pointed by the address taking head address of the communication data as a communication value, converting the communication value according to the corresponding format of the Modbus protocol, filling the converted value into the position of the output value field of the communication packet, and obtaining the communication packet to be transmitted corresponding to the communication packet;
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 receiving and analyzing the response packet to obtain a communication processing result, and completing a communication processing process.
4. A method according to claim 3, further comprising:
when the function code corresponding to the Modbus packet is a read function code, the communication packet is sent 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 Modbus data model memories corresponding to all communication points of the Modbus packet, and completing the communication processing process.
5. The method according to claim 4, wherein converting the values of the data value fields in the response packet according to the Modbus protocol corresponding format, filling the converted values into Modbus data model memories corresponding to the communication points of the Modbus packet, includes:
determining the value of a memory address field of a first communication point of the Modbus packet as a communication data storage first address;
and determining the value of a data value field in the response packet as response data, inputting the value of the data value field of the Modbus packet into a discrete quantity, a coil, an input register and a value of the number field of a holding register as a read-in storage space length value, converting response numerical values with the length meeting the read-in storage space length value according to a corresponding format of the Modbus protocol, and writing the converted values into continuous memory positions pointed by a communication data storage head address.
6. The method of claim 3, wherein the process of constructing the Modbus packet 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 an addressing address field in a communication point table information unit corresponding to a 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 a 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 memory space value of the Modbus data model required by each communication point in the Modbus packet to obtain the memory space value of the Modbus data model required by the Modbus packet in communication, wherein the memory space value is the value of the number fields of the input discrete quantity, the coil, the input register and the holding register of the Modbus packet.
7. A Modbus communication data memory optimization device, comprising:
the first execution unit is used for storing 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; wherein 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 distributing a memory space for each Modbus data model required by communication of each opposite terminal 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 number of the communication points counted currently and the memory position marking unit value of the Modbus data model;
the second execution unit is used for 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 the 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;
if 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, a first determining unit configured to determine, according to values of respective fields in the information unit corresponding to each communication point, a Modbus data model corresponding to each communication point, and allocate a memory space for each Modbus data model required for communication with each peer device corresponding to the Modbus master station, is specifically configured to:
Determining the opposite terminal device of each communication point according to the value of the opposite terminal device serial number field in the 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 the information unit corresponding to each communication point, wherein the communication point property is a transmitting communication point or a receiving communication point; according to the value of the data type field in the information unit corresponding to each communication point, determining a storage space value which each communication point needs to occupy in the corresponding Modbus data model, accumulating the storage space count value of the corresponding Modbus data model of the opposite terminal device where the communication point is located, counting the storage space required by each Modbus data model of each opposite terminal 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 by communication with each opposite terminal device according to the Modbus data model corresponding to each communication point, the opposite terminal device where each communication point is located, the communication point property of each communication point and the communication memory space value required by each Modbus data model, and allocating a memory space for the Modbus data model as the communication memory space value.
8. A communication processing apparatus, comprising:
the communication device comprises an acquisition unit, a communication point acquisition unit and a communication point acquisition unit, wherein the acquisition unit is used for acquiring a pre-constructed Modbus packet, constructing a communication packet corresponding to the Modbus packet according to basic information of the Modbus packet and a Modbus protocol format corresponding to a function code of the Modbus packet, and the Modbus packet consists of a plurality of communication points;
the operation unit is used for determining that the value of the field of the memory address of the first communication point of the Modbus packet is the address taking first address of the communication data when the function code corresponding to the Modbus packet is the writing function code; inputting the value of the number field of the Modbus packet into discrete quantity, a coil, an input register and a holding register as a reading storage space length value, taking out data with the length meeting the reading storage space length value from a continuous memory space pointed by the address taking head address of the communication data as a communication value, converting the communication value according to the corresponding format of the Modbus protocol, filling the converted value into the position of the output value field of the communication packet, and obtaining the communication packet to be transmitted corresponding to the communication packet;
the sending unit is used for sending the communication packet to be sent to the 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 complete a 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 CN115174306A (en) 2022-10-11
CN115174306B true 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 (3)

* 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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113938351A (en) * 2020-06-29 2022-01-14 深圳富桂精密工业有限公司 Data acquisition method, system and computer readable storage medium

Patent Citations (3)

* 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

Non-Patent Citations (4)

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

Also Published As

Publication number Publication date
CN115174306A (en) 2022-10-11

Similar Documents

Publication Publication Date Title
US7975120B2 (en) Dynamic allocation of message buffers
CN106878131B (en) PROFIBUS coupler and data transmission method of PROFIBUS
CN104166628B (en) The methods, devices and systems of managing internal memory
CN108369562A (en) Intelligently encoding memory architecture with enhanced access scheduling device
CN107590099A (en) A kind of more main frames access method, expanding unit and the storage medium of slave
CN109921986A (en) A kind of multi-protocol data cut-in method, device, intelligent gateway and storage medium
CN111818060B (en) Communication protocol, method and system for supporting hybrid and discrete data transmission
CN101707564B (en) Processing method and processing device for transmitting and receiving network data in zero-copy buffer queue
CN107800644A (en) Dynamically configurable pipelined token bucket speed limiting method and device
CN114338594A (en) ARP (Address resolution protocol) response-substituting method, device, equipment and storage medium in Kubernetes environment
CN102750249B (en) The method that host computer communicates with slave computer, Apparatus and system
CN101470623B (en) Queue management method and queue management device, method and system for processing queue message
JP2018524751A (en) Computer device and method for reading / writing data by computer device
CN115174306B (en) Modbus communication memory optimization method, communication method and related device
CN112860458A (en) Inter-process communication method and system based on shared memory
CN101141482B (en) Network resource management system and method
CN104135496A (en) Method and device of RPC (Remote Procedure Call) data transmission under homogeneous environment
JP7153718B2 (en) Message passing in data processing systems
CN108322482A (en) A kind of method and device of protocol conversion
CN104052831A (en) Data transmission method and device based on queues and communication system
CN105630727A (en) Access method, apparatus and system among multi-SoC nodes
KR101312035B1 (en) System for supervisory control
CN112698950B (en) Memory optimization method for industrial Internet of things edge equipment
CN209690899U (en) FPGA communication control unit and FPGA based on USB
CN107592677B (en) Data transmission method and device

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