Modbus communication and automatic establishment method of time sequence historical database of Modbus communication

By reading configuration files and realizing the automatic construction of automatic communication information sending and receiving, debugging interface and historical data query interface, the adaptability and reusability of Modbus communication and its historical database development methods when there are many protocol contents and frequent protocol changes are solved. Problem, efficient development and maintenance are achieved.

CN119396796APending Publication Date: 2025-02-07BEIJING MECHANICAL EQUIP INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411220105.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

The existing Modbus communication and its historical database development methods have weak adaptability and reusability when there are many protocol contents and frequent protocol changes, which are difficult to meet the needs of agile development, easy maintenance, and reusability.

Method used

By reading the configuration file generated based on the preset configuration method, obtaining the protocol information and communication connection information of all slaves in Modbus communication, and automatically sending and receiving communication information. At the same time, communication variable debugging and historical data query functions are implemented based on the human-computer interactive interface, and periodic storage and reading of timing historical data is realized through preset loop subthreads.

Benefits of technology

It realizes the automatic reception, analysis, transmission and storage of Modbus communication, and automatically builds the debugging interface of communication data and the database historical data query interface, which improves the agility of development, the ease of maintenance and the reusability of functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396796A_ABST
    Figure CN119396796A_ABST
Patent Text Reader

Abstract

The invention relates to a Modbus communication method and device, a Modbus communication time sequence historical database automatic building method and device, electronic equipment and a storage medium. The method comprises the following steps: reading a configuration file generated based on a preset configuration method; after the protocol information and the communication connection information are acquired from the configuration file reading module, the communication information is automatically transmitted and received through a preset configuration file input information structural body and a communication output information structural body; interactive display control of communication variable debugging and historical data query functions is realized through a human-computer interaction interface; periodic storage of the time sequence historical data is achieved through the preset loop sub-thread, and reading of the time sequence historical data is achieved based on the preset format formal parameter. According to the method, the Excel table file is used as an input configuration file, and automatic data receiving, data analysis, data sending and data storage of Modbus communication are achieved while it is guaranteed that the method can adapt to different communication modes and different protocol contents.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] Modbus communication is a communication protocol widely used in the field of industrial automation, and is commonly seen in energy management, environmental monitoring, smart home and other fields. There are many types of hardware devices that use Modbus communication, but different types of equipment, different manufacturers, and even different batches of products often have different communication protocol contents. At the same time, for modern equipment, it is extremely important to have the function of storing historical data. Taking the energy management industry as an example, historical data not only helps to monitor energy usage, analyze energy usage patterns, predict future demand, optimize energy allocation, and improve energy efficiency, but also has important value for troubleshooting, fault analysis, fault prediction and risk avoidance.

[0003] In the early days, for devices with low data volumes (such as electric meters), when developing Modbus communication functions, specific protocol content was generally concretized into the code, which was simple, fast and easy to debug. However, with the continuous development of software engineering and hardware performance, we have officially entered the era of big data. The data volume and data storage requirements of many devices are increasing, resulting in a variety of communication protocol contents for devices. The previous communication function development method is difficult to meet the requirements of "agile development, easy maintenance, and reusability". Once the project is changed or even the sub-device is changed, the corresponding code of the communication function and database function often needs to spend a lot of time to rewrite, resulting in a waste of a lot of manpower, material resources and time costs.

[0004] Therefore, in view of the problem that the existing development methods of Modbus communication and its historical database have poor adaptability and reusability due to the large amount of protocol content and frequent protocol changes, an agile development method for Modbus communication and its historical database is needed to meet the requirements of strong protocol adaptability and functional reusability.

[0005] In the prior art, a general acquisition interface software system based on the serial port Modbus communication protocol includes a communication configuration file acquisition module, a custom configuration file acquisition module, a configuration file reading and collating module, a log file generation module, and a serial port data reading and analysis module; the communication configuration file acquisition module is used to read the ini file and obtain configuration information; the custom configuration file acquisition module is used to read the txt file and obtain all variable related information; the configuration file reading and collating module. The present invention can basically adapt to various signal acquisition instruments based on the Modbus protocol, and support various output interfaces at the same time. As an interface software, it performs message collection, automatic data analysis and multiple signal processing methods based on the serial port Modbus protocol, has good cross-platform compatibility, and runs stably. The communication configuration file input in the above method is an ordinary text file such as ini / txt, and does not consider or explain the generation method of the configuration file, nor does it consider the Modbus communication implementation method based on TCP / IP, and does not elaborate and consider the interface related to communication and database.

[0006] In the prior art, a data access method and system based on the Modbus RTU protocol: The present invention discloses a data access method and system based on the Modbus RTU protocol, including a monitoring background and a device, a configuration file is associated with a channel of a corresponding access type device in a communication module; the monitoring background communicates with the corresponding type of device through the channel in the communication module; each device communicates with the monitoring background through a unique channel, and each channel also corresponds to a unique configuration file; each device corresponds to a communication master control, and the corresponding configuration file adapts to the corresponding device according to the type of the communication master control. Different types of devices communicate with the monitoring background through different channels of a communication module, and the same channel also corresponds to a configuration file. When multiple devices are connected to the monitoring background, there is no need to set a communication module for each device, and only one communication module needs to be maintained later, which greatly reduces the later maintenance work. The above method also does not take into account the commonly used Ethernet-based Modbus communication, does not make full use of the configuration file information to automatically build a communication data display interface, and also lacks consideration for the storage of time-series historical data.

[0007] Therefore, one or more methods are needed to solve the above problems.

[0008] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0009] The purpose of the present disclosure is to provide a method, device, electronic device and computer-readable storage medium for automatically building a Modbus communication and a time series history database, thereby overcoming one or more problems caused by limitations and defects of related technologies at least to a certain extent.

[0010] According to one aspect of the present disclosure, a method for automatically building a Modbus communication and a time series history database thereof is provided, comprising:

[0011] Read the configuration file generated based on the preset configuration method, and read the protocol information and communication connection information of all slaves in Modbus communication;

[0012] After acquiring the protocol information and the communication connection information from the configuration file reading module, based on the protocol information and the communication connection information, the communication information is automatically sent and received through the preset configuration file input information structure and the communication output information structure;

[0013] Based on the variable information obtained from the communication output information structure, the interactive display control of communication variable debugging and historical data query functions are realized through the human-computer interaction interface;

[0014] Based on the variable information obtained from the communication output information structure, the periodic storage of the time series historical data is realized through the preset loop sub-thread, and the reading of the time series historical data is realized based on the preset format parameters.

[0015] In an exemplary embodiment of the present disclosure, the method further includes:

[0016] Based on the preset configuration method, the protocol information and communication connection information of all slaves in Modbus communication are entered into the sheets, columns, and rows of the Excel file to generate a configuration file;

[0017] The protocol information includes register address, function code, magnification, offset, variable definition, device slave address, and device name;

[0018] The communication connection information includes communication mode, connection name, timeout period, polling cycle, baud rate, and port number.

[0019] 3. The method according to claim 1, characterized in that the method further comprises:

[0020] The configuration file input information structure includes communication connection configuration information and communication sending and receiving analysis related configuration information;

[0021] The structure of the communication output information includes communication variable real-time information and communication status information.

[0022] 4. The method according to claim 1, characterized in that the method further comprises:

[0023] The communication automatic transceiver module receives the protocol information and communication connection information sent by the configuration file reading module, establishes a communication connection based on the protocol information and communication connection information, and receives, parses, stores and sends the communication information through the preset configuration file input information structure and communication output information structure.

[0024] 5. The method according to claim 4, characterized in that the method further comprises:

[0025] The communication automatic sending and receiving module updates the status information of the communication line in real time based on the results of sending and receiving.

[0026] 6. The method according to claim 1, characterized in that the method further comprises:

[0027] Based on the variable information obtained from the communication output information structure, the database file and database table are initialized, and data is inserted into the database table corresponding to each sub-device through the preset loop sub-thread to realize the periodic storage of time series historical data;

[0028] The reading of time series historical data is realized based on preset format parameters, and the preset format parameters include: a character string composed of all variables to be queried, a start timestamp, an end timestamp, and a time interval.

[0029] 7. The method according to claim 6, characterized in that the method further comprises:

[0030] Establish the communication variable debugging interface of the tree diagram window, and traverse and fill the variable information obtained from the communication output information structure to realize the real-time data display of communication variables;

[0031] Establish a historical data query interface in the tree diagram window, and read historical data from the time series historical data reading and writing module based on the preset format parameters to realize the historical data query function.

[0032] In one aspect of the present disclosure, a Modbus communication and a time series history database automatic construction device are provided, comprising:

[0033] The configuration file reading module is used to read the configuration file generated based on the preset configuration method, and read the protocol information and communication connection information of all slaves in Modbus communication;

[0034] The automatic communication receiving and sending module is used to obtain the protocol information and the communication connection information from the configuration file reading module, and then realize the automatic sending and receiving of the communication information through the preset configuration file input information structure and the communication output information structure based on the protocol information and the communication connection information;

[0035] The human-computer interaction interface module is used to realize the interactive display control of communication variable debugging and historical data query functions through the human-computer interaction interface based on the variable information obtained from the communication output information structure;

[0036] The time series historical data reading and writing module is used to realize the periodic storage of time series historical data through a preset loop sub-thread based on the variable information obtained from the communication output information structure, and to realize the reading of time series historical data based on the preset format parameters.

[0037] In one aspect of the present disclosure, there is provided an electronic device, comprising:

[0038] Processor; and

[0039] A memory having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by the processor, implement the method according to any one of the above items.

[0040] In one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method according to any one of the above items is implemented.

[0041] A Modbus communication and a method for automatically building a time series historical database in an exemplary embodiment of the present disclosure, the method includes: reading a configuration file generated based on a preset configuration method; after obtaining protocol information and communication connection information from a configuration file reading module, the automatic sending and receiving of communication information is realized through a preset configuration file input information structure and a communication output information structure; the interactive display control of communication variable debugging and historical data query functions is realized through a human-computer interaction interface; the periodic storage of time series historical data is realized through a preset loop subthread, and the reading of time series historical data is realized based on a preset format parameter. The present disclosure uses an Excel spreadsheet file as an input configuration file, and realizes Modbus communication to automatically receive data, parse data, send data, and store data while ensuring that it can adapt to different communication methods and different protocol contents.

[0042] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The above and other features and advantages of the present disclosure will become more apparent by describing in detail example embodiments thereof with reference to the attached drawings.

[0044] Figure 1 A flow chart of a Modbus communication and a method for automatically building a time series history database thereof according to an exemplary embodiment of the present disclosure is shown;

[0045] Figure 2 The overall block diagram of the technical solution of a Modbus communication and a method for automatically building a time series history database according to an exemplary embodiment of the present disclosure is shown;

[0046] Figure 3 A schematic diagram of a configuration information input template in an Excel file of a Modbus communication and a method for automatically building a time series history database thereof according to an exemplary embodiment of the present disclosure is shown;

[0047] Figure 4 A schematic diagram of important data structures in a communication automatic transceiver module of a Modbus communication and a method for automatically building a time series history database according to an exemplary embodiment of the present disclosure is shown;

[0048] Figure 5 A main logic diagram of a communication automatic transceiver module of a Modbus communication and a method for automatically building a time series history database according to an exemplary embodiment of the present disclosure is shown;

[0049] Figure 6 A schematic diagram of a communication variable debugging interface of a Modbus communication and a method for automatically building a time series history database thereof according to an exemplary embodiment of the present disclosure is shown;

[0050] Figure 7 A schematic diagram of a historical data query interface for Modbus communication and a method for automatically building a time series historical database thereof according to an exemplary embodiment of the present disclosure is shown;

[0051] Figure 8 A schematic diagram of the main logic of automatic storage of time series historical data of a Modbus communication and a method for automatically building a time series historical database thereof according to an exemplary embodiment of the present disclosure is shown;

[0052] Fig. 9 A schematic block diagram of a Modbus communication and a device for automatically building a time series history database according to an exemplary embodiment of the present disclosure is shown;

[0053] Fig.10 A block diagram schematically shows an electronic device according to an exemplary embodiment of the present disclosure;

[0054] Fig.11A schematic diagram of a computer-readable storage medium according to an exemplary embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0055] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.

[0056] In addition, the described features, structures or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or other methods, components, materials, devices, steps, etc. may be adopted. In other cases, known structures, methods, devices, implementations, materials or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.

[0057] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or these functional entities or parts of functional entities may be implemented in one or more software hardened modules, or these functional entities may be implemented in different networks and / or processor devices and / or microcontroller devices.

[0058] In this example embodiment, a Modbus communication and a method for automatically building a time series history database are first provided; Figure 1 As shown in , the Modbus communication and the automatic construction method of the time series history database can include the following steps:

[0059] Step S110, reading a configuration file generated based on a preset configuration method, and reading protocol information and communication connection information of all slaves in Modbus communication;

[0060] Step S120, after acquiring the protocol information and the communication connection information from the configuration file reading module, based on the protocol information and the communication connection information, the communication information is automatically sent and received through the preset configuration file input information structure and the communication output information structure;

[0061] Step S130, based on the variable information obtained from the communication output information structure, interactive display control of communication variable debugging and historical data query functions are respectively implemented through the human-computer interaction interface;

[0062] Step S140, based on the variable information obtained from the communication output information structure, the periodic storage of the time series historical data is realized through the preset loop sub-thread, and the reading of the time series historical data is realized based on the preset format parameter.

[0063] A Modbus communication and a method for automatically building a time series historical database in an exemplary embodiment of the present disclosure, the method includes: reading a configuration file generated based on a preset configuration method; after obtaining protocol information and communication connection information from a configuration file reading module, the automatic sending and receiving of communication information is realized through a preset configuration file input information structure and a communication output information structure; the interactive display control of communication variable debugging and historical data query functions is realized through a human-computer interaction interface; the periodic storage of time series historical data is realized through a preset loop subthread, and the reading of time series historical data is realized based on a preset format parameter. The present disclosure uses an Excel spreadsheet file as an input configuration file, and realizes Modbus communication to automatically receive data, parse data, send data, and store data while ensuring that it can adapt to different communication methods and different protocol contents.

[0064] Next, a Modbus communication and a method for automatically building a time series history database in this example embodiment will be further described.

[0065] In step S110, a configuration file generated based on a preset configuration method may be read, and protocol information and communication connection information of all slaves in Modbus communication may be read.

[0066] In the embodiment of this example, the method further includes:

[0067] Based on the preset configuration method, the protocol information and communication connection information of all slaves in Modbus communication are entered into the sheets, columns, and rows of the Excel file to generate a configuration file;

[0068] The protocol information includes register address, function code, magnification, offset, variable definition, device slave address, and device name;

[0069] The communication connection information includes communication mode, connection name, timeout period, polling cycle, baud rate, and port number.

[0070] In step S120, after obtaining the protocol information and the communication connection information from the configuration file reading module, the communication information can be automatically sent and received based on the protocol information and the communication connection information through the preset configuration file input information structure and the communication output information structure.

[0071] In the embodiment of this example, the method further includes:

[0072] The configuration file input information structure includes communication connection configuration information and communication sending and receiving analysis related configuration information;

[0073] The structure of the communication output information includes communication variable real-time information and communication status information.

[0074] In the embodiment of this example, the method further includes:

[0075] The communication automatic transceiver module receives the protocol information and communication connection information sent by the configuration file reading module, establishes a communication connection based on the protocol information and communication connection information, and receives, parses, stores and sends the communication information through the preset configuration file input information structure and communication output information structure.

[0076] In the embodiment of this example, the method further includes:

[0077] The communication automatic sending and receiving module updates the status information of the communication line in real time based on the results of sending and receiving.

[0078] In step S130, based on the variable information obtained from the communication output information structure, interactive display control of communication variable debugging and historical data query functions can be implemented through a human-computer interaction interface.

[0079] In the embodiment of this example, the method further includes:

[0080] Based on the variable information obtained from the communication output information structure, the database file and database table are initialized, and data is inserted into the database table corresponding to each sub-device through the preset loop sub-thread to realize the periodic storage of time series historical data;

[0081] The reading of time series historical data is realized based on preset format parameters, and the preset format parameters include: a character string composed of all variables to be queried, a start timestamp, an end timestamp, and a time interval.

[0082] In step S140, based on the variable information obtained from the communication output information structure, the periodic storage of the time series historical data can be implemented through a preset loop sub-thread, and the reading of the time series historical data can be implemented based on the preset format parameters.

[0083] In the embodiment of this example, the method further includes:

[0084] Establish the communication variable debugging interface of the tree diagram window, and traverse and fill the variable information obtained from the communication output information structure to realize the real-time data display of communication variables;

[0085] Establish a historical data query interface in the tree diagram window, and read historical data from the time series historical data reading and writing module based on the preset format parameters to realize the historical data query function.

[0086] In the embodiment of this example, for a system, its subordinate devices may come from different manufacturers and use various different communication protocols, which leads to frequent changes in protocols and inconsistent standards, bringing many problems to system development, integration, testing and maintenance. In the case where the communication mode and communication protocol of the sub-device cannot be unified, in order to achieve the purpose of adaptability to different protocols and different communication modes, high portability of core functions, strong code iterativeness, and cross-platform compatibility, the present invention uses Excel spreadsheet files as input configuration files, while ensuring that it can adapt to different communication modes and different protocol contents, realizes Modbus communication to automatically receive data, parse data, send data and store data, and automatically runs the time series historical data storage of communication data according to the configuration file information and the data obtained by the communication layer interface, and can also automatically build the debugging interface of communication data and the database historical data query interface.

[0087] It should be noted that, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.

[0088] In addition, in this exemplary embodiment, a Modbus communication and a time series history database automatic construction device are also provided. Fig. 9 As shown, a Modbus communication and its automatic construction device 200 of timing history database may include: a configuration file reading module, which is used to read the configuration file generated based on the preset configuration method, and read the protocol information and communication connection information of all slaves in the Modbus communication; a communication automatic transceiver module, which is used to obtain the protocol information and communication connection information from the configuration file reading module, and then realize the automatic transmission and reception of communication information through the preset configuration file input information structure and the communication output information structure based on the protocol information and the communication connection information; a human-computer interaction interface module, which is used to realize the interactive display control of communication variable debugging and historical data query functions through the human-computer interaction interface based on the variable information obtained from the communication output information structure; a timing history data reading and writing module, which is used to realize the periodic storage of timing history data through the preset loop sub-thread based on the variable information obtained from the communication output information structure, and realize the reading of timing history data based on the preset format parameters.

[0089] The overall block diagram of the technical solution is as follows Figure 2 As shown. The functional modules in the solution are divided into four parts, namely:

[0090] Module 1: Read configuration file module;

[0091] Module 2: Communication automatic sending and receiving module;

[0092] Module 3: Human-computer interaction interface module;

[0093] Module 4: Time series historical data reading and writing module.

[0094] Module 1 reads configuration information to support the core function of module 2 to automatically send and receive data. The output of module 2 includes sending data, receiving and parsing communication variable information, and communication status information. These output information serve as inputs for modules 3 and 4, thereby providing a data basis for building a communication debugging interface in module 3 and realizing the time series storage of historical data in module 4. Module 4 provides a historical data query interface to support the function of the historical data query interface in module 3. At this point, a framework for the automatic operation of Modbus communication and its time series historical database that does not depend on specific protocols for changes has been built. After implementing a corresponding code function module based on this framework, this part of the function can be directly transplanted to the overall project. Other business modules (such as the application layer, communication forwarding layer, etc.) can directly call the corresponding interface to obtain and send all the communication information in the protocol, realizing a high degree of decoupling between communication, database, interface and other modules.

[0095] This method uses C++ as the programming language, based on the open source library (libmodbus) for the underlying transmission and reception, QT as the development framework for the user interface, and SQLite as the database. The following will detail the specific functions and implementations of each module in the technical framework:

[0096] In the embodiment of this example, the configuration file reading module includes:

[0097] The configuration file uses Excel files as input, and each communication channel corresponds to a configuration file. When this module reads the contents of the configuration file, it is necessary to agree on the information storage format in the Excel file, such as Figure 3 As shown: Sheet 1 stores the communication connection information, and the second and subsequent sheets store a specific protocol point table of the slave. In the specific point table of the slave protocol, it is mandatory to constrain what information should be entered in each row and column, and there is no limit on the number of variables in the protocol. Theoretically, it can be accumulated infinitely starting from the 5th row.

[0098] Based on the above agreement, we use the QAxObject class to operate the Excel file and read the required information according to different sheets, columns, and rows. According to this method, not only can the specific protocol information (register address, function code, magnification, offset, variable interpretation) of all slaves in the communication be read quickly and accurately from the Excel spreadsheet file, but also the communication connection information configured by the user (communication mode, connection name, timeout, polling cycle, etc.), thereby achieving the design goal of "the code can automatically adapt to different protocols". The above information is stored in the private member variables of the class, and a public information acquisition interface is defined for other modules to call. Compared with the traditional method of reading configuration files (such as reading text files, YAML files, JSON files), this method directly uses Excel files as configuration file input, which not only makes the input of protocol content simpler and faster, but also the popularity of Excel allows even those who do not understand programming or even Modbus communication to easily input protocols.

[0099] In the embodiment of this example, the communication automatic transceiver module includes:

[0100] This module has two important data structures: Figure 4 The ST_MDBPOLL structure and ST_POLLMSGOUT structure in the configuration file are shown in the figure. ST_MDBPOLL is the structure of the configuration file input information. It mainly contains the communication connection configuration information named cfgInfo and the communication transceiver parsing related configuration information named allParseInfo. AllParseInfo is implemented based on std::map. The key is set to a 16-bit unsigned integer to store the slave ID number. The value is a structure variable of type ST_SLAVE. The structure mainly contains various types of information stored by std::vector, including the number of registers, register addresses, function codes, magnifications, offsets, etc. POLLMSGOUT is a structure of communication output information, which is mainly composed of real-time information of communication variable named outInfo and communication status information named statusInfo. OutInfo is implemented based on std::map, and key is set to 16-bit unsigned integer, which is used to store slave ID number. Value is a structure variable of ST_MSGOUT type, which mainly includes slave device name, online status and semaphore list. The semaphore list signalsList is also implemented based on std::map, and key is set to string, which is used to store variable name. Value is a structure variable containing numerical value and interpretation.

[0101] The core functions of this module are: to correctly establish a communication connection according to the configuration information, to correctly parse and store the original communication data received on the bus according to the parsing information, and to be able to send the data to be sent to the communication bus in the agreed form, and to update the status information of this communication line in real time according to the results of sending and receiving. Since Modbus is a polling mechanism, it is necessary to open an independent sub-thread to handle these periodic sending and receiving tasks. In the loop body of the sub-thread running function, it is necessary to periodically process data sending, data receiving and data parsing. The function of the sending interface provided by this module is to store the data to be sent in the sending buffer (using the queue of std::queue as the sending buffer). In the logic of the periodic loop operation in the sub-thread, all slaves will be traversed according to the above-mentioned input ST_MDBPOLL structure information, and relevant operations will be performed on the data to be sent and polled in each slave, and the read and parsed data will be stored in the output ST_POLLMSGOUT structure variable for other modules to call. The main logical operation flow of this module is as follows Figure 5 shown.

[0102] In order to ensure the security of this module, the following two mechanisms are adopted: ① Singleton mode. It provides controlled access to a unique instance (which can be adjusted according to the number of communication lines supported by the hardware platform). The singleton mode can prevent other codes from arbitrarily creating communication objects, maintain the uniqueness of communication objects, and prevent serious software security issues such as memory leaks and memory overflows. ② Smart lock. Since some data of this module will be read and written in multiple threads, if the atomicity of a complex function cannot be guaranteed by atomic operations, then a lock mechanism is needed to ensure it, but at the same time, it is also necessary to avoid abnormal phenomena such as deadlock. Therefore, we use std::lock_guard to manage the locking and unlocking operations of mutex objects to prevent deadlock problems caused by forgetting to unlock or abnormalities in the program.

[0103] In the embodiment of this example, the human-computer interaction interface module includes:

[0104] It consists of a communication variable debugging interface and a historical data query interface, and the interface is implemented based on the QT GUI framework.

[0105] Communication variable debugging interface such as Figure 6As shown, the tree window on the left is created based on QTreeWidget, and the table window on the right is created based on QTableWidget. The variable information of the ST_POLLMSGOUT structure type is obtained by calling the method in module 2, and then the file name information, slave ID and device name are used to define the nodes and sub-nodes of the top-level tree window information respectively. When the user clicks on the device name of a slave, the table information on the right is switched through the QT signal and slot mechanism. The information in the table is filled by traversing the outInfo sub-variable in the ST_POLLMSGOUT structure variable, and the timer is used to periodically refresh the real-time data in the table and the status real-time data in the lower right corner.

[0106] The historical data query interface is as follows Figure 7 As shown, the tree diagram window on the left is created based on QTreeView, and the table window on the right is created based on QTableWidget. The difference from the communication debugging interface is that the primary and secondary nodes of the tree diagram in the historical data query interface need to be made into selection functions in three states of "full selection, half selection and no selection", so that the operator can flexibly select the variables to be queried. The initialization of the tree diagram is also through calling the method in module 2, thereby obtaining the variable information of the ST_POLLMSGOUT structure type from it. Similar to the communication variable debugging interface, the "QStandardItemModel::itemChanged" type signal is used to capture which variables the user has selected in the interface, and it is necessary to judge which device these variables belong to, and classify and store information, and then obtain the query start time, end time and time interval defined by the user in the interface, and use this information as input, and by calling the function interface for reading time series historical data in module 4, the queried data is obtained in the form of function return value, and all the read data are displayed in the table on the right through a second-order loop, forming a closed loop of the batch time series historical data query process.

[0107] In the embodiment of this example, the time series historical data reading and writing module includes:

[0108] The operation object of this module is mainly the database. On platforms with limited hardware performance, we often use the lightweight database SQLite, which is not only open source and free, but also has a database engine library of only a few hundred KB, making it very easy to embed into other applications. When processing large amounts of data, SQLite's operation is fast and flexible, and can meet various needs. SQLite supports various operating systems, including Windows, Linux, Unix, Mac OS X, etc., so it is easy to transplant and exchange data between different platforms.

[0109] Since this module needs to automatically store the time series historical data periodically, it also needs to open a separate sub-thread to process it. The main logic of automatic storage of time series historical data is as follows Figure 8 As shown. Among them, "initializing database files and database tables" and "inserting data into the database tables corresponding to each sub-device" are the two key points. The input of both is the ST_POLLMSGOUT structure information in the external interface of module 2: when there is no database file or table at the beginning of software operation, it needs to be created automatically. By traversing the outInfo container, you can know the number of slaves and the variable information of each slave, and then use the device name as the table name and each variable name as the field name to create a database table; it is worth noting that since the communication variable values ​​stored in the memory are of the same data type, the field types corresponding to these variables are also uniformly specified as one type when creating the table, and the integer field "Un ix timestamp" is used as the only primary key, so that when searching for database data, the data of a certain time period can be quickly found according to the primary key; when inserting data into the database table corresponding to each sub-device in a periodic cycle, in addition to the timestamp of the primary key being obtained from the system in real time, the real-time values ​​corresponding to each variable in each device table are obtained from the outInfo container according to the "key" corresponding to the device, and then the sub-variable signalsList is traversed from the "value" to obtain the value of each variable. Through this traversal operation and combined with the string concatenation operation in C++, an SQL statement for inserting real-time data into all fields of a sub-table can be composed, and finally the interface for executing the SQL statement can be called.

[0110] In this module, a corresponding interface is also sealed for reading time series historical data. Four parameters need to be passed in the interface. Parameter 1 is a string composed of all variables to be queried, parameter 2 is the start timestamp, parameter 3 is the end timestamp, and parameter 4 is the time interval. In this way, the module knows which data in which time period and time interval need to be queried. Therefore, the SQL statement for querying data by time period can be assembled in the function of this module according to the corresponding format of the database execution statement, and then the interface of the sqlite data is called to execute the SQL statement, and the read results are stored in std::vector in sequence. <std::vector <t>>In a nested dynamic array container (or ordinary two-dimensional array), the function return value is provided to the caller of the interface (module 3) for acquisition.

[0111] In the embodiment of this example, the present invention realizes the data interaction requirements of accurate, real-time and two-way communication based on simple configuration file input, solidifies the communication data parsing function that is prone to errors, and realizes the core function of Modbus communication automatic transmission and reception under cross-platform and adaptation to different protocols; the present invention realizes a simple and efficient automatic storage function of time-series historical data, so that even in the case of major changes in the communication protocol, developers do not need to rebuild SQL statements, and all SQL statements for database operations rely on logical automatic construction; the present invention can quickly and automatically build a communication debugging interface and a historical data query interface according to different configuration file information; the present invention realizes a method with agile development, iterative maintenance, strong reusability and adaptability, which solves the problems of cumbersome data collection, large amounts of repeated work content, and heavy dependence on protocols, and can greatly reduce the development cost of the system.

[0112] It should be noted that, although several modules or units of Modbus communication and its timing history database automatic construction device 200 are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.

[0113] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.

[0114] Those skilled in the art will appreciate that various aspects of the present invention may be implemented as systems, methods or program products. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: complete hardware embodiments, complete software embodiments (including firmware, microcode, etc.), or embodiments combining hardware and software aspects, which may be collectively referred to herein as "circuits", "modules" or "systems".

[0115] Refer to the following Fig.10 The electronic device 300 according to such an embodiment of the present invention is described. Fig.10 The electronic device 300 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0116] like Fig.10 As shown, the electronic device 300 is in the form of a general computing device. The components of the electronic device 300 may include but are not limited to: at least one processing unit 310, at least one storage unit 320, a bus 330 connecting different system components (including the storage unit 320 and the processing unit 310), and a display unit 340.

[0117] The storage unit stores program codes, which can be executed by the processing unit 310, so that the processing unit 310 performs the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of this specification. For example, the processing unit 310 can perform the following steps: Figure 1 Steps S110 to S140 shown in FIG.

[0118] The storage unit 320 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 3201 and / or a cache memory unit 3202 , and may further include a read-only memory unit (ROM) 3203 .

[0119] The storage unit 320 may also include a program / utility 3204 having a set (at least one) of program modules 3205, such program modules 3205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0120] Bus 330 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0121] The electronic device 300 may also communicate with one or more external devices 370 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 300, and / or communicate with any device that enables the electronic device 300 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 350. Furthermore, the electronic device 300 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 360. As shown, the network adapter 360 communicates with other modules of the electronic device 300 via a bus 330. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0122] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiment of the present disclosure.

[0123] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible embodiments, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.

[0124] refer to Fig.11 As shown, a program product 400 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0125] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0126] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0127] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0128] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0129] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.

[0130] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.

[0131] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.< / t>

Claims

1. A Modbus communication and a method for automatically building a time series history database, characterized in that: The method comprises: Read the configuration file generated based on the preset configuration method, and read the protocol information and communication connection information of all slaves in Modbus communication; After acquiring the protocol information and the communication connection information from the configuration file reading module, based on the protocol information and the communication connection information, the communication information is automatically sent and received through the preset configuration file input information structure and the communication output information structure; Based on the variable information obtained from the communication output information structure, the interactive display control of communication variable debugging and historical data query functions are realized through the human-computer interaction interface; Based on the variable information obtained from the communication output information structure, the periodic storage of the time series historical data is realized through the preset loop sub-thread, and the reading of the time series historical data is realized based on the preset format parameters.

2. The method according to claim 1, characterized in that The method further comprises: Based on the preset configuration method, the protocol information and communication connection information of all slaves in Modbus communication are entered into the sheets, columns, and rows of the Excel file to generate a configuration file; The protocol information includes register address, function code, magnification, offset, variable definition, device slave address, and device name; The communication connection information includes communication mode, connection name, timeout period, polling cycle, baud rate, and port number.

3. The method according to claim 1, characterized in that The method further comprises: The configuration file input information structure includes communication connection configuration information and communication sending and receiving analysis related configuration information; The structure of the communication output information includes communication variable real-time information and communication status information.

4. The method according to claim 1, characterized in that The method further comprises: The communication automatic transceiver module receives the protocol information and communication connection information sent by the configuration file reading module, establishes a communication connection based on the protocol information and communication connection information, and receives, parses, stores and sends the communication information through the preset configuration file input information structure and communication output information structure.

5. The method according to claim 4, characterized in that The method further comprises: The communication automatic sending and receiving module updates the status information of the communication line in real time based on the results of sending and receiving.

6. The method according to claim 1, characterized in that The method further comprises: Based on the variable information obtained from the communication output information structure, the database file and database table are initialized, and data is inserted into the database table corresponding to each sub-device through the preset loop sub-thread to realize the periodic storage of time series historical data; The reading of time series historical data is realized based on preset format parameters, and the preset format parameters include: a character string composed of all variables to be queried, a start timestamp, an end timestamp, and a time interval.

7. The method according to claim 6, characterized in that The method further comprises: Establish a communication variable debugging interface in the tree window, and traverse and fill the variable information obtained from the communication output information structure to realize real-time data display of communication variables; Establish a historical data query interface in the tree diagram window, and read historical data from the time series historical data reading and writing module based on the preset format parameters to realize the historical data query function.

8. A Modbus communication and automatic construction device of its time series history database, characterized in that: The device comprises: The configuration file reading module is used to read the configuration file generated based on the preset configuration method, and read the protocol information and communication connection information of all slaves in Modbus communication; The automatic communication receiving and sending module is used to obtain the protocol information and the communication connection information from the configuration file reading module, and then realize the automatic sending and receiving of the communication information through the preset configuration file input information structure and the communication output information structure based on the protocol information and the communication connection information; The human-computer interaction interface module is used to realize the interactive display control of communication variable debugging and historical data query functions through the human-computer interaction interface based on the variable information obtained from the communication output information structure; The time series historical data reading and writing module is used to realize the periodic storage of time series historical data through a preset loop sub-thread based on the variable information obtained from the communication output information structure, and to realize the reading of time series historical data based on the preset format parameters.

9. An electronic device, characterized in that: include Processor; and A memory having computer-readable instructions stored thereon, wherein the computer-readable instructions, when executed by the processor, implement the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.