CN112003837B - Intelligent equipment adaptation method and device based on Modbus protocol and storage medium - Google Patents

Intelligent equipment adaptation method and device based on Modbus protocol and storage medium Download PDF

Info

Publication number
CN112003837B
CN112003837B CN202010780305.4A CN202010780305A CN112003837B CN 112003837 B CN112003837 B CN 112003837B CN 202010780305 A CN202010780305 A CN 202010780305A CN 112003837 B CN112003837 B CN 112003837B
Authority
CN
China
Prior art keywords
protocol
field
linked list
class object
equipment
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
CN202010780305.4A
Other languages
Chinese (zh)
Other versions
CN112003837A (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.)
Shenzhen Zhongwu Internet Technology Development Co ltd
Original Assignee
Shenzhen Zhongwu Internet Technology Development 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 Shenzhen Zhongwu Internet Technology Development Co ltd filed Critical Shenzhen Zhongwu Internet Technology Development Co ltd
Priority to CN202010780305.4A priority Critical patent/CN112003837B/en
Publication of CN112003837A publication Critical patent/CN112003837A/en
Application granted granted Critical
Publication of CN112003837B publication Critical patent/CN112003837B/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
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/03Protocol definition or specification 
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer And Data Communications (AREA)
  • Communication Control (AREA)

Abstract

The invention provides a device intelligent adaptation method and device based on a Modbus protocol and a storage medium, wherein the device intelligent adaptation method based on the Modbus protocol comprises the following steps: reading a preset device configuration file to obtain a data class object linked list; sequentially searching the data class object linked list based on the table pointer to determine target equipment to be accessed; forming a Modbus protocol ADU message of the target equipment to be accessed based on the equipment class object linked list and the protocol class object linked list; calling a basic interface function of a Modbus protocol to execute the message access of the Modbus protocol ADU of the target equipment; and receiving a message returned by the target equipment, and analyzing and processing data in the message by using the corresponding parameter class object linked list. The invention also provides an intelligent equipment adapting device based on the Modbus protocol and a storage medium. The technical scheme provided by the invention can effectively solve the problem of equipment adaptation based on the Modubus protocol, so that the data acquisition has higher universality, robustness and easy maintenance.

Description

Intelligent equipment adaptation method and device based on Modbus protocol and storage medium
Technical Field
The invention relates to the technical field of data acquisition of the Internet of things, in particular to an intelligent equipment adaptation method and device based on a Modbus protocol and a storage medium.
Background
Modbus is a master-slave serial bus communication protocol, and the Chinese national standard is GB/Z19582.1-2004. The method is widely applied to the industries of instruments, industrial control, internet of things data acquisition and the like at present due to the fact that the protocol is simple, the implementation cost is low, and the popularization and application are early. In the application of the Modbus communication protocol, there may be many different manufacturers and different types of devices under one serial bus, and their device address IDs, access function codes and register addresses are different. The traditional data acquisition method is to develop a data acquisition software by self and write the access parameters of the equipment into an application program in advance, and the method has the defects that different projects or application scenes need to customize individual application programs, so that huge cost is increased for development and maintenance of software projects.
Disclosure of Invention
The invention provides an intelligent equipment adaptation method and device based on a Modbus protocol and a storage medium, and aims to solve the problem of equipment adaptation when data acquisition in the Internet of things is based on the Modbus protocol.
In order to achieve the above object, the present invention provides an intelligent equipment adapting method based on a Modbus protocol, which includes:
step S10: reading a preset device configuration file to obtain a data class object linked list; the data class object linked list comprises a device class object linked list, a protocol class object linked list and a parameter class object linked list; the data type object linked list comprises a table pointer and a MeterTypeID field, wherein the table pointer is used for realizing the link pointing of a table, and the MeterTypeID field is used for identifying the type of equipment;
step S20: sequentially searching the data class object linked list based on the table pointer to determine target equipment to be accessed;
step S30: forming a Modbus protocol ADU message of the target equipment to be accessed based on the equipment class object linked list and the protocol class object linked list;
step S40: calling a basic interface function of a Modbus protocol to execute message access to the Modbus protocol ADU of the target equipment;
step S50: and receiving a message returned by the target equipment, and analyzing and processing data in the message by using the corresponding parameter class object linked list.
Further, the device profile is a profile of a target device to be accessed, the device profile including a device table, a protocol table, and a parameter table; the device table is used for describing the identity of the target device; the protocol table is used for appointing the content format of the Modbus protocol message when accessing the target equipment; and the parameter table is used for describing each parameter format in the target equipment, and analyzing and extracting data in the message according to the parameter format when the Modbus protocol message is received.
Further, the device table includes a meterID field, a meterName field, a PortN field, a ModbusID field, and a meterTypeID field; the MeterID field is used for recording the code number of the target equipment in the item, and the item has uniqueness; the MeterName field is used for describing the name and the annotation purpose of the target equipment; the PortN field is used for recording a serial port bus port number to which the target equipment belongs; the ModbusID field is used for recording a device access address of the target device in a Modbus protocol; the MeterTypeID field is used to record the type of the target device.
Further, the protocol table comprises a protocol ID field, a Fun field, a RegAddr field, a RegCnt field and a MetarTypeID field; the protocol ID field is used for recording the code number of the Modbus protocol message; the Fun field is used for recording the code number of the function code in the message; the RegAddr field is used for recording the starting address of a target device register to be accessed; the RegCnt field is used for recording the number of registers to be read/written continuously in a single message; the MeterTypeID field is used to record the target device type.
Further, the parameter table includes a parameterID field, a RegAddr field, a DataType field, a MeterTypeID field, a DataItemID field; the ParameterID field is used for recording records in a search parameter table; the RegAddr field is used for recording the register address of the parameter in the target equipment; the DataType field is used for recording the data type of the parameter; the MeterTypeID field is used to record the target device type.
Further, the device configuration file is a database file.
Further, the intelligent equipment adapting method based on the Modbus protocol further comprises the following steps: reading the equipment table to create an equipment class object linked list, reading the protocol table to create a protocol class object linked list, reading the parameter table to create a parameter class object linked list, associating the equipment class object linked list, the protocol class object linked list and the parameter class object linked list through a MeterTypeID field, and executing Modbus protocol ADU message access to all target equipment in a polling mode.
Further, the device class object linked list includes a protocol linked list pointer pproptocol owned by the device object, and the protocol linked list pointer pproptocol points to the protocol class object linked list corresponding to the device.
In addition, the invention provides a device intelligent adapting apparatus based on the Modbus protocol, which includes a memory and a processor, wherein the memory stores a device intelligent adapting program based on the Modbus protocol, which can run on the processor, and when being executed by the processor, the device intelligent adapting apparatus based on the Modbus protocol implements the steps of the device intelligent adapting method based on the Modbus protocol.
Meanwhile, the invention provides a storage medium which is a computer-readable storage medium, wherein the storage medium is stored with a device intelligent adaptation program based on the Modbus protocol, and the device intelligent adaptation program based on the Modbus protocol can be executed by one or more processors to realize the steps of the device intelligent adaptation method based on the Modbus protocol.
According to the intelligent equipment adaptation method, device and storage medium based on the Modbus protocol, the target equipment is accessed by reading the equipment configuration file, so that data acquisition is independent of specific equipment deployment, different types of equipment can be supported, relevant equipment can be automatically accessed by configuring the database file through correct equipment, the intelligent adaptation characteristic is achieved, and the data acquisition has high universality, robustness and easy maintenance.
Drawings
Fig. 1 is a schematic flowchart of an intelligent device adapting method based on a Modbus protocol according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a device class object linked list according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a linked list of protocol class objects according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a parameter class object linked list according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a device class object linked list and an associated protocol class object linked list according to an embodiment of the present invention;
fig. 6A is a first part of a schematic program implementation flow chart of an intelligent Modbus protocol-based device adaptation method according to an embodiment of the present invention;
fig. 6B is a second part of a program implementation flow diagram of the intelligent device adapting method based on the Modbus protocol according to an embodiment of the present invention;
fig. 7 is a schematic diagram of an internal structure of an intelligent adapting apparatus for devices according to a Modbus protocol according to an embodiment of the present invention;
fig. 8 is a schematic program module diagram of an intelligent Modbus protocol-based device adaptation program in an embodiment of the intelligent Modbus protocol-based device adaptation apparatus according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the invention.
Referring to fig. 1, the present invention provides an intelligent device adapting method based on a Modbus protocol, where the method includes:
step S10: reading a preset device configuration file to obtain a data class object linked list; the data class object linked list comprises a device class object linked list, a protocol class object linked list and a parameter class object linked list; the data type object linked list comprises a table pointer and a MeterTypeID field, wherein the table pointer is used for realizing the link pointing of a table, and the MeterTypeID field is used for identifying the type of equipment;
step S20: sequentially searching the data class object linked list based on the table pointer to determine target equipment to be accessed;
step S30: forming a Modbus protocol ADU message of the target equipment to be accessed based on the equipment class object linked list and the protocol class object linked list; the ADU message is an Application Data Unit (ADU) in the Modubus protocol;
step S40: calling a basic interface function of a Modbus protocol to execute the message access of the Modbus protocol ADU of the target equipment;
step S50: and receiving a message returned by the target equipment, and analyzing and processing data in the message by using the corresponding parameter class object linked list.
Specifically, the device profile is a profile of a target device to be accessed, and the device profile includes a device table, a protocol table, and a parameter table; the device table is used for describing the identity of the target device; the protocol table is used for appointing the content format of the Modbus protocol message when accessing the target equipment; and the parameter table is used for describing each parameter format in the target equipment, and analyzing and extracting data in the message according to the parameter format when the Modbus protocol message is received. The device configuration file is a database file, the type of the database can be SQLite, simpleSQL, mySQL and the like, and the device configuration file is characterized in that the device configuration file can be quickly edited in a PC through visual database software of the device configuration file, and can also be read and written by using API interfaces of C/C + + or other programming languages in data acquisition equipment. The database of the device configuration file is internally provided with a device table, a protocol table and a parameter table.
The equipment table comprises a MeterID field, a MeterName field, a PortN field, a ModbusID field and a MeterTypeID field; the MeterID field is used for recording the code number of the target equipment in the item, and the item has uniqueness; the MeterName field is used for describing the name and the annotation purpose of the target equipment; the PortN field is used for recording the port number of a serial port bus to which the target equipment belongs; the ModbusID field is used for recording a device access address of the target device in a Modbus protocol; the MeterTypeID field is used to record the type of target device. There may be multiple devices with the same metertypecid on the same serial bus, and the metertypecid field can be used for distinguishing.
The protocol table comprises a protocol ID field, a Fun field, a RegAddr field, a RegCnt field and a MeterTypeID field; the protocol ID field is used for recording the code number of the Modbus protocol message; the Fun field is used for recording the code number of the function code in the message; the RegAddr field is used for recording the starting address of a target device register to be accessed; the RegCnt field is used for recording the number of registers to be read/written continuously in a single message; the MeterTypeID field is used to record the target device type.
The parameter table comprises a ParameterID field, a RegAddr field, a DataType field, a MeterTypeID field and a DataItemID field; the ParameterID field is used for recording records in a search parameter table; the RegAddr field is used for recording the register address of the parameter in the target equipment; the DataType field is used for recording the data type of the parameter; the MeterTypeID field is used to record the target device type.
The intelligent equipment adaptation method based on the Modbus protocol further comprises the following steps: reading the equipment table to create an equipment class object linked list, reading the protocol table to create a protocol class object linked list, reading the parameter table to create a parameter class object linked list, associating the equipment class object linked list, the protocol class object linked list and the parameter class object linked list through a MeterTypeID field, and executing Modbus protocol ADU message access to all target equipment in a polling mode.
Referring to fig. 2, fig. 3, and fig. 4 together, in an embodiment, a Meter _ Class is used to represent a device Class object linked list, a Protocol _ Class is used to represent a Protocol Class object linked list, and a Parameter _ Class is used to represent a Parameter Class object linked list, respectively, and the data Class object linked list is defined based on a C + + programming language, but the implementation method is not limited to the C + + language:
the device class: meter _ Class
class Meter_Class{
public:
int MeterID; // device ID
The cstring MeterName; // device name
BYTE PortN; // bus port number
BYTE ModbusID; // Modbus device Access Address
int MeterTypeID; // device type ID
Meter _ Class × pNext; // device object pointer
Protocol _ Class × ppprotocol; v/device object owned protocol Link Table pointer
}
The application creates a Meter _ Class object for each record in the "device Table" and concatenates the Meter _ Class objects into a Meter _ Class object chain using pNext object pointers, as shown in FIG. 2.
Protocol class: protocol _ Class
class Protocol_Class{
public:
int protocol id; // protocol index ID
BYTE Fun; // Modbus function code
short int RegAddr; // Modbus device Access Start register Address
short int RegCnt; // number of registers
short int metertypeID; // device type ID
Protocol _ Class × pNext; // object pointer
}
The application creates a Protocol _ Class object for each record in the "Protocol table" and concatenates the pNext object pointers into a Protocol _ Class object chain, as shown in FIG. 3.
Parameter classes: parameter _ Class
class Parameter_Class{
public:
int ParameterID; // parameter index ID
short int RegAddr; // Modbus register address of parameter in device
short int DataType; data type of parameter
short int metertypeID; // device type ID
short int DataItemID; // parameter type ID
Parameter _ Class × pNext; // object pointer
}
The application creates a Parameter _ Class object for each record in the Parameter table and concatenates the Parameter _ Class object chains with the pNext object pointers, as shown in FIG. 4.
Referring to fig. 5, the device class object linked list includes a protocol linked list pointer pproptocol owned by the device object, and the protocol linked list pointer pproptocol points to a protocol class object linked list corresponding to the device. The device table and the Protocol table are associated through a MeterTypeID field, each Meter _ Class object is provided with a Protocol _ Class object linked list which is subordinate to the Meter _ Class object, and a pProtocol pointer of the Meter _ Class object points to the Protocol _ Class object linked list. Usually, only 1 Protocol _ Class object is in a self-owned Protocol _ Class object chain table of each Meter _ Class object, and a plurality of Protocol _ Class objects are in a self-owned Protocol _ Class object chain table of a few Meter _ Class objects, as shown in fig. 5. Therefore, when the data acquisition application program processes the access message of the Meter _ Class object, the whole global Protocol _ Class object linked list does not need to be polled, and the program processing efficiency is improved.
Referring to fig. 6A and 6B, in an embodiment of the present invention, a program implementation flow of the intelligent device adapting method based on the Modbus protocol is as follows:
step 1: reading the equipment configuration file, establishing a Meter _ Class object linked list, a Protocol _ Class object linked list and a Parameter _ Class object linked list, and then executing the step 2;
and 2, step: acquiring a first equipment object in a Meter _ Class object linked list as a current object, and then executing step 3;
and 3, step 3: newly building a temporary pointer variable pProtocoTmp of a Protocol _ Class;
and 4, step 4: acquiring a MeterTypeID value in a current Meter _ Class object, and then executing step 5;
and 5: acquiring a first Protocol object in a Protocol _ Class object linked list as a current Protocol _ Class object, and then executing step 6;
step 6: acquiring a MeterTypeID value in a current Protocol _ Class object, and then executing a step 7;
and 7: if the current Meter _ Class object and the current Protocol _ Class object have the same MeterTypeID value, executing step 8; otherwise, executing step 11;
and 8: copying the current Protocol _ Class object, and then executing step 9;
and step 9: judging whether a pProtocol pointer of the current Meter _ Class object is empty, if so, executing the step 10, otherwise, executing the step 16;
step 10: pointing a pProtocol pointer of the current Meter _ Class object to the Protocol _ Class object copied in the step 8, and then executing a step 11;
step 11: acquiring a next object from the Protocol _ Class linked list, and then executing step 12;
step 12: judging whether the current Protocol _ Class object is effective or not, if so, returning to the step 6, otherwise, executing a step 13;
step 13: if the current Protocol _ Class object is invalid, the current Meter _ Class object represents that the Protocol _ Class linked list is completely retrieved by the current Meter _ Class object, the pNext pointer value of the pprotocol tmp pointing object is cleared to be 0, and then step 14 is executed;
step 14: acquiring a next Meter _ Class object, and then executing step 15;
step 15: judging whether the newly acquired Meter _ Class object is effective, if so, returning to the step 3, otherwise, indicating that the Meter _ Class linked list is completely searched, finishing the association processing between the 'equipment table' and the 'protocol table', and then turning to an equipment access processing flow step 18;
step 16: the pNext of the pProtocoTmp pointer is pointed to the Protocol _ Class object copied in the step 8, and then the step 17 is executed;
and step 17: updating a pProtocoTmp pointer to point to the latest copied Protocol _ Class object, and then executing step 11;
step 18: starting an equipment access processing flow, acquiring a first object in a Meter _ Class object linked list as a current object, and then executing step 19;
step 19: acquiring a first object in a Protocol _ Class object linked list from a pProtocol pointer of a current Meter _ Class object as a current Protocol _ Class object, and then executing step 20;
step 20: the member information of the current Meter _ Class object and the current Protocol _ Class object is utilized to combine necessary information in a Modbus Protocol ADU message, and then step 21 is executed;
step 21: calling a basic interface function of the Modbus protocol to execute Modbus protocol message access operation, and then executing a step 22;
step 22: the data acquisition equipment receives the message returned by the equipment and then executes step 23;
step 23: analyzing and processing data in the message according to the Parameter _ Class object linked list, and then executing step 24;
step 25: judging whether the current Protocol _ Class object is valid, if so, returning to the step 20, otherwise, executing the step 26;
step 26: acquiring the next Meter _ Class object, and then executing step 27;
step 27: and judging whether the current Meter _ Class object is valid, if so, returning to the step 19 to start the next Meter _ Class object process, and otherwise, returning to the step 18 to start a new round of Meter _ Class object processing.
Therefore, the intelligent equipment adaptation method based on the Modbus protocol is applied to data acquisition equipment for acquiring data by realizing intelligent adaptation of target equipment based on the Modbus protocol, and specifically, a preset equipment configuration file is read to obtain a data class object linked list; sequentially retrieving a data type object linked list based on a table pointer to determine target equipment to be accessed, matching a MeterTypeID field in a Meter _ Class with a MeterTypeID field in a Protocol _ Class pointed by a Protocol linked list pointer pProtocol, determining the Meter _ Class object and a corresponding Protocol _ Class object according to the pointing of a pNext table pointer in the Protocol _ Class until finding out the Protocol _ Class object with pNext being zero, combining the Meter _ Class object and the corresponding Protocol _ Class object into a Modbus Protocol ADU message according to member information of the Meter _ Class object and the Protocol _ Class object, and calling a Modbus Protocol basic interface function to access the Modbus Protocol ADU message of the target equipment; and receiving the message returned by the target equipment, and analyzing and processing the data in the message by using the corresponding Parameter _ Class object linked list.
Compared with the prior art, the intelligent equipment adaptation method, the intelligent equipment adaptation device and the storage medium based on the Modbus protocol realize access to target equipment by reading the equipment configuration file, enable data acquisition to be independent of specific equipment deployment, can support different types of equipment, can automatically access related equipment by correctly configuring a database file through the equipment, have the characteristic of intelligent adaptation, and enable the data acquisition to have higher universality, robustness and easy maintenance.
The invention adopts a parameterized equipment access method, so that an application program can further expand some unique functions on the basis of the method, for example, in some system reconstruction projects, part of equipment cannot find related communication interface data provided by original manufacturers or maintenance manufacturers due to various reasons (the equipment supports a standard Modbus protocol), and the intelligent reconstruction difficulty is extremely high under the condition.
In order to achieve the above object, the present invention further provides a device intelligent adapting apparatus based on a Modbus protocol, where the device intelligent adapting apparatus based on a Modbus protocol includes a memory and a processor, and a device intelligent adapting program based on a Modbus protocol and capable of running on the processor is stored in the memory, and when executed by the processor, the device intelligent adapting program based on a Modbus protocol implements the steps of the device intelligent adapting method based on a Modbus protocol; specifically, in an embodiment of the present invention, the device intelligent adapter based on a Modbus protocol is a data acquisition device based on a Modbus protocol.
In addition, the present invention provides a storage medium, which is a computer-readable storage medium, and the storage medium stores thereon a Modbus protocol-based device intelligent adaptation program, which is executable by one or more processors to implement the steps of the Modbus protocol-based device intelligent adaptation method described above.
Referring to fig. 7, an internal structural diagram of an intelligent adapting apparatus for devices based on a Modbus protocol according to an embodiment of the present invention is provided, where the intelligent adapting apparatus for devices based on a Modbus protocol at least includes a memory 11, a processor 12, a communication bus 13, and a network interface 14.
The memory 11 includes at least one type of readable storage medium, which includes flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like. The memory 11 may be an internal storage unit of the Modbus protocol-based device intelligent adapter in some embodiments, for example, a hard disk of the Modbus protocol-based device intelligent adapter. The memory 11 may also be an external storage device of the Modbus protocol-based device intelligent adapter, such as a plug-in hard disk equipped on the Modbus protocol-based device intelligent adapter, a Smart Memory Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and so on. Further, the memory 11 may also include both an internal memory unit and an external memory device of the Modbus protocol-based device intelligent adapter. The memory 11 can be used for storing not only application software installed in the Modbus protocol-based device intelligent adapter and various types of data, such as codes of Modbus protocol-based device intelligent adapter programs, but also temporarily storing data that has been output or will be output.
The processor 12, which in some embodiments may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor or other data Processing chip, is configured to execute program codes stored in the memory 11 or process data, such as executing a device intelligent adapter based on a Modbus protocol.
The communication bus 13 is used to realize connection communication between these components.
The network interface 14 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the Modbus protocol-based device intelligent adapter and other electronic devices.
Optionally, the Modbus protocol-based device intelligent adapting apparatus may further include a user interface, where the user interface may include a Display (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface may also include a standard wired interface and a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or a display unit, is used to display information processed in the Modbus protocol-based device intelligent adapter and to display a visual user interface.
While fig. 7 shows only Modbus protocol-based device smart adapters having components 11-14 and a Modbus protocol-based device smart adapter program, those skilled in the art will appreciate that the architecture shown in fig. 7 does not constitute a limitation of Modbus protocol-based device smart adapters, and may include fewer or more components than shown, or some components in combination, or a different arrangement of components.
In the embodiment of the device intelligent adapting apparatus based on the Modbus protocol shown in fig. 7, the memory 11 stores a device intelligent adapting program based on the Modbus protocol; the processor 12 executes the Modbus protocol-based device intelligent adapter program stored in the memory 11 to implement the following steps:
step S10: reading a preset device configuration file to obtain a data class object linked list;
step S20: sequentially searching the data class object linked list based on the table pointer to determine target equipment to be accessed;
step S30: forming a Modbus protocol ADU message of the target equipment to be accessed based on the equipment class object linked list and the protocol class object linked list;
step S40: calling a basic interface function of a Modbus protocol to execute message access to the Modbus protocol ADU of the target equipment;
step S50: and receiving a message returned by the target equipment, and analyzing and processing data in the message by using the corresponding parameter class object linked list.
Referring to fig. 8, a schematic block diagram of a program module of a Modbus protocol-based device intelligent adaptation program in an embodiment of the Modbus protocol-based device intelligent adaptation apparatus of the present invention is shown, in which the Modbus protocol-based device intelligent adaptation program in this embodiment may be divided into a setting module 10, a calculating module 20, a collecting module 30, and an analyzing module 40, and exemplarily:
a setting module 10 for setting a configuration file;
the calculation module 20 is configured to retrieve and calculate a data class object linked list to obtain a Modbus protocol ADU packet of the target device to be accessed;
the acquisition module 30 is configured to perform access to the Modbus protocol ADU message of the target device;
and the analysis module 40 is configured to analyze and process the received message returned by the target device.
The functions or operation steps implemented by the program modules such as the setting module 10, the calculating module 20, the collecting module 30 and the analyzing module 40 are substantially the same as those of the above embodiment, and are not described herein again.
In addition, an embodiment of the present invention further provides a storage medium, where the storage medium is a computer-readable storage medium, and the storage medium stores a Modbus protocol-based device intelligent adaptation program, where the Modbus protocol-based device intelligent adaptation program is executable by one or more processors to implement the following operations:
step S10: reading a preset device configuration file to obtain a data class object linked list;
step S20: sequentially searching the data class object linked list based on the table pointer to determine target equipment to be accessed;
step S30: forming a Modbus protocol ADU message of the target equipment to be accessed based on the equipment class object linked list and the protocol class object linked list;
step S40: calling a basic interface function of a Modbus protocol to execute message access to the Modbus protocol ADU of the target equipment;
step S50: and receiving a message returned by the target equipment, and analyzing and processing data in the message by using the corresponding parameter class object linked list.
The specific implementation of the storage medium of the present invention is substantially the same as the above-mentioned embodiments of the method and apparatus for intelligent adaptation of devices based on the Modbus protocol, and will not be described herein again.
It should be noted that, the above numbers of the embodiments of the present invention are only for description, and do not represent the advantages and disadvantages of the embodiments. And the terms "comprises," "comprising," or any other variation thereof, herein are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method 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, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising one of 8230, and" comprising 8230does not exclude the presence of additional like elements in a process, apparatus, article, or method comprising the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention or the portions contributing to the prior art may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above and includes several instructions for enabling a terminal device (which may be a drone, a mobile phone, a computer, a server, or a network device, etc.) to execute the method according to the embodiments of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (9)

1. An intelligent equipment adaptation method based on a Modbus protocol is characterized by comprising the following steps:
step S10: reading a preset device configuration file to obtain a data class object linked list; the data class object linked list comprises a device class object linked list, a protocol class object linked list and a parameter class object linked list; the data type object linked list comprises a table pointer and a MetarTypeID field, wherein the table pointer is used for realizing the link pointing of a table, and the MetarTypeID field is used for identifying the type of equipment; the device class object linked list comprises a protocol linked list pointer pProtocol owned by a device object, and the protocol linked list pointer pProtocol points to a protocol class object linked list corresponding to the device;
step S20: sequentially searching the data class object linked list based on the table pointer to determine target equipment to be accessed, matching a MeterTypeID field in the equipment class object linked list with a MeterTypeID field in a protocol linked list pointer pProtocol pointing protocol class object linked list, directly finding a protocol class object linked list object with zero pNext according to the pointing direction of a table pointer pNext in the protocol class object linked list, and determining the equipment class object linked list object and a corresponding protocol class object linked list object;
step S30: according to the member information of the equipment class object linked list object and the protocol class object linked list object, combining a Modbus protocol ADU message of the target equipment to be accessed;
step S40: calling a basic interface function of a Modbus protocol to execute the message access of the Modbus protocol ADU of the target equipment;
step S50: and receiving a message returned by the target equipment, and analyzing and processing data in the message by using the corresponding parameter class object linked list.
2. The intelligent Modbus protocol-based device adapting method according to claim 1, wherein the device profiles are profiles of target devices to be accessed, the device profiles including a device table, a protocol table, and a parameter table; the device table is used for describing the identity of the target device; the protocol table is used for appointing the content format of the Modbus protocol message when accessing the target equipment; and the parameter table is used for describing each parameter format in the target equipment, and analyzing and extracting data in the message according to the parameter format when the Modbus protocol message is received.
3. The intelligent Modbus protocol-based device adapting method according to claim 2, wherein the device table comprises a MeterID field, a MeterName field, a PortN field, a ModbusID field and a MeterTypeID field; the MeterID field is used for recording the code number of the target equipment in the item, and the item has uniqueness; the MeterName field is used for describing the name and the annotation purpose of the target equipment; the PortN field is used for recording a serial port bus port number to which the target equipment belongs; the ModbusID field is used for recording a device access address of the target device in a Modbus protocol; the MeterTypeID field is used to record the type of the target device.
4. The intelligent Modbus protocol-based device adapting method according to claim 2, wherein the protocol table comprises a protocol ID field, a Fun field, a RegAddr field, a RegCnt field and a MeterTypeID field; the protocol ID field is used for recording the code number of the Modbus protocol message; the Fun field is used for recording the code number of the function code in the message; the RegAddr field is used for recording the starting address of a target device register to be accessed; the RegCnt field is used for recording the number of registers to be read/written continuously in a single message; the MeterTypeID field is used to record the target device type.
5. The Modbus protocol-based device intelligent adaptation method according to claim 2, wherein the parameter table comprises a ParameterID field, a RegAddr field, a DataType field, a MeterTypeID field, and a DataItemID field; the ParameterID field is used for recording records in a search parameter table; the RegAddr field is used for recording the register address of the parameter in the target equipment; the DataType field is used for recording the data type of the parameter; the MeterTypeID field is used to record the target device type.
6. The intelligent Modbus protocol-based device adaptation method of claim 2, wherein the device configuration file is a database file.
7. The intelligent Modbus protocol-based device adapting method according to claim 2, further comprising: reading the equipment table to create an equipment class object linked list, reading the protocol table to create a protocol class object linked list, reading the parameter table to create a parameter class object linked list, wherein the equipment class object linked list, the protocol class object linked list and the parameter class object linked list are associated through a MeterTypeID field, and performing Modbus protocol ADU message access on all target equipment in a polling mode.
8. A Modbus protocol-based device intelligent adapting apparatus, which comprises a memory and a processor, wherein the memory stores a Modbus protocol-based device intelligent adapting program which can run on the processor, and the Modbus protocol-based device intelligent adapting program realizes the steps of the Modbus protocol-based device intelligent adapting method according to any one of claims 1 to 7 when being executed by the processor.
9. A storage medium which is computer readable and has stored thereon a Modbus protocol-based device intelligence adaptation program, which is executable by one or more processors to implement the steps of the Modbus protocol-based device intelligence adaptation method of any one of claims 1 to 7.
CN202010780305.4A 2020-08-05 2020-08-05 Intelligent equipment adaptation method and device based on Modbus protocol and storage medium Active CN112003837B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010780305.4A CN112003837B (en) 2020-08-05 2020-08-05 Intelligent equipment adaptation method and device based on Modbus protocol and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010780305.4A CN112003837B (en) 2020-08-05 2020-08-05 Intelligent equipment adaptation method and device based on Modbus protocol and storage medium

Publications (2)

Publication Number Publication Date
CN112003837A CN112003837A (en) 2020-11-27
CN112003837B true CN112003837B (en) 2023-01-13

Family

ID=73463093

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010780305.4A Active CN112003837B (en) 2020-08-05 2020-08-05 Intelligent equipment adaptation method and device based on Modbus protocol and storage medium

Country Status (1)

Country Link
CN (1) CN112003837B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113242534B (en) * 2021-06-11 2022-05-10 合肥工业大学 General type multi-protocol digital instrument thing allies oneself with module based on WI-FI

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050256939A1 (en) * 2004-05-03 2005-11-17 Schneider Automation Sas Automatic Configuration of Network Automation Devices
CN104539502B (en) * 2015-01-26 2018-02-13 北海恒久天成技术开发有限公司 A kind of method of self-defined addition modbus equipment
CN108540584B (en) * 2018-02-10 2021-01-15 西安融盛智汇电子科技有限公司 Universal Modbus protocol address configuration method
CN108416069A (en) * 2018-05-10 2018-08-17 湖南利能新能源有限公司 A kind of data acquisition device and method
CN109245980B (en) * 2018-11-20 2021-08-06 厦门科灿信息技术有限公司 Modbus communication protocol analysis method, system, equipment and storage medium
CN110474896B (en) * 2019-08-06 2022-01-04 厦门科灿信息技术有限公司 Data communication method based on Modbus protocol standard and related equipment
CN110502461B (en) * 2019-08-27 2023-03-24 深圳市中物互联技术发展有限公司 RS485 communication protocol-based efficient data acquisition method
CN111431784A (en) * 2020-04-21 2020-07-17 长念(上海)技术开发有限公司 Universal MODBUS protocol data analysis method

Also Published As

Publication number Publication date
CN112003837A (en) 2020-11-27

Similar Documents

Publication Publication Date Title
CN108427705B (en) Electronic device, distributed system log query method and storage medium
CN109902105B (en) Data query system, method, device and storage medium for micro-service architecture
CN105357204B (en) Method and device for generating terminal identification information
CN108334609B (en) Method, device, equipment and storage medium for realizing JSON format data access in Oracle
CN110659210A (en) Information acquisition method and device, electronic equipment and storage medium
CN112506910A (en) Multi-source data acquisition method and device, electronic equipment and storage medium
CN116644213A (en) XML file reading method, device, equipment and storage medium
CN113609128B (en) Method, device, terminal equipment and storage medium for generating database entity class
CN112003837B (en) Intelligent equipment adaptation method and device based on Modbus protocol and storage medium
CN117033249B (en) Test case generation method and device, computer equipment and storage medium
CN108694172B (en) Information output method and device
CN112671878A (en) Block chain information subscription method, device, server and storage medium
CN111913777A (en) Information processing method, information processing device, electronic equipment and storage medium
CN111158777A (en) Component calling method and device and computer readable storage medium
CN115640578A (en) Vulnerability reachability analysis method, device, equipment and medium for application program
CN116414689A (en) Interface parameter verification method and system based on reflection mechanism
CN115129598A (en) Risk detection method, device, system and medium for SQL (structured query language) statements
CN115033592A (en) SQL statement processing method, device, equipment and storage medium based on database
CN114625372A (en) Automatic component compiling method and device, computer equipment and storage medium
CN114169318A (en) Process identification method, apparatus, device, medium, and program
CN116107971A (en) Model data processing method and device, electronic equipment and storage medium
CN111610908B (en) Method for generating frame diagram, computer equipment and readable storage medium
CN108334621B (en) Database operation method, device, equipment and computer readable storage medium
CN111258628A (en) Rule file comparison method and device, readable storage medium and terminal equipment
CN115136120A (en) Database synchronization test method and device, computer equipment and storage medium

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
CB02 Change of applicant information

Address after: 518000 1603, west block, Tian'an Innovation Technology Plaza (phase II), intersection of Binhe Road and Xiangmihu Road, Tian'an community, Shatou street, Futian District, Shenzhen, Guangdong Province

Applicant after: Shenzhen Zhongwu Internet Technology Development Co.,Ltd.

Address before: 518000 1905, west block, phase II, Tian'an Innovation Technology Plaza, Tairan 10th Road, Tian'an community, Shatou street, Futian District, Shenzhen, Guangdong Province

Applicant before: Shenzhen Zhongwu Internet Technology Development Co.,Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant