Data reading method, system, electronic device and storage medium for Modbus protocol
By extracting all register data from the Modbus terminal and generating optimized read messages based on user configuration, the problem of low data reading efficiency under the Modbus protocol is solved and more efficient data collection is achieved.
Patent Information
- Application Number
- CN202211566970.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-07
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-12-07
AI Technical Summary
When using the Modbus protocol for data collection, single point reading results in too many network requests and is inefficient; batch point reading results in a large amount of useless data, which wastes bandwidth resources and results in low data reading efficiency.
Extract all register data from the specified Modbus terminal in advance, match the target point according to the user-configured target point address and data type, convert and encode the data, generate optimized read messages, and dynamically group points to reduce the number of network communications.
It improves data reading efficiency, solves the problem of long time-consuming reading of a single point and invalid data in batch point reading, and optimizes network requests and bandwidth usage.
Smart Images

Figure CN115914437B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data reading, and in particular to a data reading method, system, electronic device and storage medium for Modbus protocol. Background Art
[0002] With the popularization of industrial Internet of Things, the demand for data collection of industrial equipment is also expanding, and enterprises can configure data collection faster. Modbus protocol, as a serial communication protocol, was first released by Modicon in 1979 for communication with programmable logic controllers. At present, Modbus protocol has become the most widely used communication protocol in the industrial field. Since the protocol is publicly published and has no copyright requirements, each manufacturer has no standard method to describe the specific data of the data object for each data node. When collecting data from devices that support the Modbus protocol, it is necessary to know the starting address and data type of each data node in advance to correctly parse the data content, that is, first configure the point address, data type and other configuration information, first configure the data point according to the Modbus point list, and then send it to the data acquisition gateway for collection. After the collection is successful, check the correctness of the data.
[0003] However, since the point data of the register may contain discrete data points, if a single point is read, there will be a large number of network requests, resulting in low collection efficiency and a large loss of time. If batch points are read, there will be a large amount of useless data in the read message, wasting bandwidth resources and making the data reading efficiency low. Summary of the invention
[0004] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0005] In view of the above-mentioned shortcomings of the prior art, the present invention discloses a data reading method, system, electronic device and storage medium for Modbus protocol to improve data reading efficiency.
[0006] The present invention provides a data reading method for a Modbus protocol, comprising: extracting register data corresponding to all registers from a designated Modbus terminal in advance, wherein each of the registers comprises at least one storage point, and the register data comprises original data corresponding to each of the storage points; obtaining a data reading request configured by a user, wherein the data reading request comprises a target point address and a target data type; matching a point address corresponding to each of the storage points according to the target point address, and determining a target point from the storage points based on a matching result; converting the original data corresponding to the target point into data of the target data type to obtain target data, and encoding the target data to obtain a read message corresponding to the data reading request.
[0007] Optionally, the target data is encoded to obtain a read message corresponding to the data read request, including: determining the register corresponding to the target point as the target register; sorting the target points according to the register addresses corresponding to each of the target registers to obtain a point sequence; grouping the target points corresponding to the target registers in the point sequence according to a preset register reading number to obtain a point group; encoding the target data corresponding to each target node in each of the point groups respectively to obtain a read message corresponding to each of the point groups.
[0008] Optionally, the target points corresponding to the target registers in the point sequence are grouped according to a preset register read quantity to obtain point groups, including: counting the register quantity of the target register, and calculating the register quantity of the target register according to a preset proportional coefficient to obtain a dynamic read quantity; if the dynamic read quantity is less than or equal to a preset maximum quantity threshold, the dynamic read quantity is used as the register read quantity, and the target points corresponding to the target registers in the point sequence are grouped according to the register read quantity to obtain a point group; if the dynamic read quantity is greater than the maximum quantity threshold, the maximum quantity threshold is used as the register read quantity, and the target points corresponding to the target registers in the point sequence are grouped according to the register read quantity to obtain a point group.
[0009] Optionally, obtaining a data reading request configured by a user includes: receiving the data reading request configured by the user through a preset first display page, wherein the first display page is also used to display the original data corresponding to each of the storage points according to a preset data base format.
[0010] Optionally, after converting the original data corresponding to the target point into data of the target data type to obtain the target data, the method further includes: displaying the target data through a preset second display page; if an adjusted data type input by the user is received through the second display page, converting the original data corresponding to the target point into data of the adjusted data type to obtain new target data.
[0011] Optionally, register data corresponding to all registers are extracted from the designated Modbus terminal in advance, including: obtaining the point register type and Modbus protocol type corresponding to the designated Modbus terminal; scanning the designated Modbus terminal according to the function code corresponding to the point register type, and extracting the scanned Modbus message; parsing the Modbus message according to the Modbus protocol type to obtain the original data corresponding to each of the storage points; using a preset gateway to cache the original data corresponding to the storage point to obtain register data.
[0012] Optionally, the Modbus protocol type includes at least one of Modbus TCP, Modbus RTU, and Modbus ASII.
[0013] The present invention provides a data reading system for Modbus protocol, comprising: a cache module, used for pre-extracting register data corresponding to all registers from a specified Modbus terminal, wherein each of the registers comprises at least one storage point, and the register data comprises original data corresponding to each of the storage points; an acquisition module, used for acquiring a data reading request configured by a user, wherein the data reading request comprises a target point address and a target data type; a determination module, used for matching a point address corresponding to each of the storage points according to the target point address, and determining a target point from the storage points based on a matching result; and a reading module, used for converting the original data corresponding to the target point into data of the target data type to obtain target data, and encoding the target data to obtain a reading message corresponding to the data reading request.
[0014] The present invention provides an electronic device, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the above method.
[0015] The present invention provides a computer-readable storage medium on which a computer program is stored: when the computer program is executed by a processor, the above method is implemented.
[0016] Beneficial effects of the present invention:
[0017] By extracting the original data corresponding to each storage point from the specified Modbus terminal in advance, determining the target point match from the storage point according to the target point address configured by the user, and converting the original data corresponding to the target point into the target data according to the target data type configured by the user, and then generating a read message corresponding to the data read request. In this way, compared with reading data directly from the register through a data read request, the register data corresponding to all registers is first extracted from the specified Modbus terminal, and then the data is extracted from the register data according to the data read request configured by the user, which solves the problem of long time consumption when reading data according to a single point and invalid data when reading according to batch points, thereby improving data reading efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of a data reading method for Modbus protocol in an embodiment of the present invention;
[0019] Figure 2 It is a flow chart of a method for generating a read message for the Modbus protocol in an embodiment of the present invention;
[0020] Figure 3 Schematic diagram of the relationship between a ModBus register and a ModBus function code in an embodiment of the present invention;
[0021] Figure 4 It is a structural schematic diagram of a data reading system for Modbus protocol in an embodiment of the present invention;
[0022] Figure 5 is a schematic diagram of an electronic device in an embodiment of the present invention. DETAILED DESCRIPTION
[0023] The following describes the embodiments of the present invention through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and sub-samples in the embodiments can be combined with each other without conflict.
[0024] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0025] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.
[0026] The terms "first", "second", etc. in the specification and claims of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so as to describe the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0027] Unless otherwise stated, the term "plurality" means two or more.
[0028] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.
[0029] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0030] Combination Figure 1 As shown, the embodiment of the present disclosure provides a data reading method for the Modbus protocol, comprising:
[0031] Step S101, extracting register data corresponding to all registers from a designated Modbus terminal in advance;
[0032] Wherein, each register includes at least one storage point, and the register data includes original data corresponding to each storage point;
[0033] Step S102, obtaining a data reading request configured by a user;
[0034] The data read request includes a target point address and a target data type;
[0035] Step S103, matching the point addresses corresponding to the storage points according to the target point address, and determining the target point from the storage points based on the matching result;
[0036] Step S104, converting the original data corresponding to the target point into data of the target data type to obtain the target data, and encoding the target data to obtain a read message corresponding to the data read request.
[0037] The data reading method for the Modbus protocol provided by the embodiment of the present disclosure is adopted, by extracting the original data corresponding to each storage point from the specified Modbus terminal in advance, determining the target point match from the storage point according to the target point address configured by the user, and converting the original data corresponding to the target point into target data according to the target data type configured by the user, and then generating a read message corresponding to the data read request. In this way, compared with directly reading data from the register through the data read request, the register data corresponding to all registers is first extracted from the specified Modbus terminal, and then the data is extracted from the register data according to the data read request configured by the user, which solves the problem of long time consumption when reading data according to a single point and invalid data when reading according to batch points, thereby improving the data reading efficiency.
[0038] Optionally, the target data is encoded to obtain a read message corresponding to the data read request, including: determining the register corresponding to the target point as the target register; sorting the target points according to the register addresses corresponding to each target register to obtain a point sequence; grouping the target points corresponding to the target registers in the point sequence according to a preset register reading quantity to obtain a point group; encoding the target data corresponding to each target node in each point group respectively to obtain a read message corresponding to each point group.
[0039] Optionally, the target points corresponding to the target registers in the point sequence are grouped according to a preset register read quantity to obtain a point grouping, including: counting the register quantity of the target register, and calculating the register quantity of the target register according to a preset proportional coefficient to obtain a dynamic read quantity; if the dynamic read quantity is less than or equal to a preset maximum quantity threshold, the dynamic read quantity is used as the register read quantity, and the target points corresponding to the target registers in the point sequence are grouped according to the register read quantity to obtain a point grouping; if the dynamic read quantity is greater than the maximum quantity threshold, the maximum quantity threshold is used as the register read quantity, and the target points corresponding to the target registers in the point sequence are grouped according to the register read quantity to obtain a point grouping.
[0040] In some embodiments, the preset proportionality factor includes 60%-80%, for example, the preset proportionality factor is 75%.
[0041] In some embodiments, the maximum number threshold comprises 120.
[0042] Combination Figure 2 As shown, the embodiment of the present disclosure provides a method for generating a read message for the Modbus protocol, comprising:
[0043] Step S201, loading the target point configured by the user, and determining the target register corresponding to the target point;
[0044] Step S202, sorting the target points according to the register addresses corresponding to the target registers to obtain a point sequence;
[0045] The data points are sorted from largest to smallest by register address, and then the starting address of the group is adjusted to the smallest register address configured by the user;
[0046] Step S203, grouping the target points corresponding to the target registers in the point sequence to obtain point groups;
[0047] By default, the data points are grouped in a way that a maximum of 120 registers are read at a time (this number can be configured);
[0048] Step S204, calculating the number of registers of the point grouping;
[0049] Among them, the number of registers in the guaranteed point grouping accounts for more than 75% of the target number of registers;
[0050] Step S205 , encoding is performed according to the target data corresponding to each target node in each point group, to obtain a read message corresponding to each point group.
[0051] In this way, after the user configuration is completed, if the user-configured points have discontinuous addresses, it is inefficient to read directly at a single point. Therefore, for discrete data after the configuration is completed, the gateway will dynamically group the user-configured points by installation register type, and then sort them from large to small by address number. Then, the appropriate register starting address and register quantity are selected from the configured points to reduce the number of network communications with the device and the size of a single request message, thereby improving reading efficiency.
[0052] Optionally, obtaining a data reading request configured by a user includes: receiving the data reading request configured by the user through a preset first display page, wherein the first display page is also used to display original data corresponding to each storage point in accordance with a preset data base format.
[0053] In some embodiments, the default data format is hexadecimal.
[0054] In some embodiments, by scanning and accessing all register data on the target slave station before configuring the data point on the gateway, the original data is saved in the gateway cache as a device data shadow. When configuring the point, the user can monitor the data of each register and each address in real time, and can view the data node content that he has collected on the monitoring interface.
[0055] In this way, compared with the normal configuration process, the user first configures the point address, data type and then debugs the data. After sending a request to the device and getting the result, the user checks the data again. If the configuration is wrong, the previous operation must be repeated. We have reversed the order of the configuration process. The gateway first scans the full register data of the specified device. Then the user configures the data point. After the configuration is completed, the data accuracy can be checked without communicating with the device. When the data type or starting address is wrong, the configuration can be directly modified and the result can be checked to improve the configuration efficiency.
[0056] Optionally, after converting the original data corresponding to the target point into data of the target data type to obtain the target data, the method also includes: displaying the target data through a preset second display page; if an adjusted data type input by the user is received through the second display page, converting the original data corresponding to the target point into data of the adjusted data type to obtain new target data.
[0057] In some embodiments, the user finds the corresponding register address to adjust the data type according to the point he needs to configure. The configuration interface dynamically converts data according to the data type, helping the user to configure data points faster in an intuitive way.
[0058] Optionally, register data corresponding to all registers are extracted from the specified Modbus terminal in advance, including: obtaining the point register type and Modbus protocol type corresponding to the specified Modbus terminal; scanning the specified Modbus terminal according to the function code corresponding to the point register type, and extracting the scanned Modbus message; parsing the Modbus message according to the Modbus protocol type to obtain the original data corresponding to each storage point; using the preset gateway to cache the original data corresponding to the storage point to obtain the register data.
[0059] Optionally, the Modbus protocol types include Modbus TCP (Transmission Control Protocol), Modbus RTU (Remote Terminal Unit), Modbus ASII, etc.
[0060] Optionally, the point register types include COILS register, DISCRETE register, INPUT register, HOLDING register, etc.; wherein, COILS register represents coil register, indicating that the unit of the register is 1 bit data, the type is switch quantity, and can be read and written; DISCRETE register represents discrete input register, and can only read switch quantity; HOLDING register represents holding register, the unit of this register is 2 bytes, can store specific data amount, and is readable and writable, and INPUT register represents input register, and can only read holding register data.
[0061] In some embodiments, the registers in the Modbus terminal are divided into four data fields, each of which has different operational characteristics. Hardware R&D engineers will map them to specific PLC (instrument) register addresses in the PLC (instrument). When N positions are offset from the first ModBus register address, it is equivalent to offsetting the first PLC register address corresponding to ModBus by N units.
[0062] In some embodiments, the ModBus function code determines what operation the ModBus message will perform. A simple explanation is that a specific function code represents a specific action. In addition to representing different operations and data operation scale differences, there are other similarities and differences. The ModBus register data fields operated by these function codes are different. Among them, the relationship between the ModBus register (data field) and the ModBus function code is as follows: Figure 3 shown.
[0063] In some embodiments, a portion of the function codes are shown in Table 1.
[0064] Table 1
[0065] Function code illustrate Operated register range Data Types Operational capabilities 01 Read coil status 00001-09999 Bool One or more 02 Read discrete input status 10001-19999 Bool One or more 03 Read Holding Registers 40001-49999 Word One or more 04 Read Input Register 30001-39999 Word One or more 05 Write single coil status 00001-09999 Bool single 06 Writing a Single Holding Register 40001-49999 Word single 15 Write multiple coil states 00001-09999 Bool Multiple 16 Writing multiple holding registers 40001-49999 Word Multiple
[0066] Combination Figure 4As shown, the embodiment of the present disclosure provides a data reading system for Modbus protocol, including a cache module 401, an acquisition module 402, a determination module 403 and a reading module 404. The cache module 401 is used to extract register data corresponding to all registers from the specified Modbus terminal in advance, wherein each register includes at least one storage point, and the register data includes the original data corresponding to each storage point; the acquisition module 402 is used to obtain a data reading request configured by the user, wherein the data reading request includes a target point address and a target data type; the determination module 403 is used to match the point address corresponding to each storage point according to the target point address, and determine the target point from the storage point based on the matching result; the reading module 404 is used to convert the original data corresponding to the target point into data of the target data type, obtain the target data, and encode the target data to obtain a read message corresponding to the data reading request.
[0067] The data reading system for Modbus protocol provided by the embodiment of the present disclosure is adopted, by extracting the original data corresponding to each storage point from the specified Modbus terminal in advance, determining the target point match from the storage point according to the target point address configured by the user, and converting the original data corresponding to the target point into target data according to the target data type configured by the user, and then generating a read message corresponding to the data read request. In this way, compared with directly reading data from the register through the data read request, the register data corresponding to all registers is first extracted from the specified Modbus terminal, and then the data is extracted from the register data according to the data read request configured by the user, which solves the problem of long time consumption when reading data according to a single point and invalid data when reading according to batch points, thereby improving the data reading efficiency.
[0068] Figure 5 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Figure 5 The computer system 500 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0069] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage part 508 to the random access memory (RAM) 503, such as executing the method in the above embodiment. In the RAM 503, various programs and data required for system operation are also stored. The CPU 501, the ROM 502 and the RAM 503 are connected to each other through the bus 504. The input / output (I / O) interface 505 is also connected to the bus 504.
[0070] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed so that a computer program read therefrom is installed into the storage section 508 as needed.
[0071] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 509, and / or installed from a removable medium 511. When the computer program is executed by a central processing unit (CPU) 501, various functions defined in the system of the present application are executed.
[0072] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a 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. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-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. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0073] The embodiments of the present disclosure further provide a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, any one of the methods in the embodiments is implemented.
[0074] The computer-readable storage medium in the embodiments of the present disclosure can be understood by ordinary technicians in the field: all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to the computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, the execution includes the steps of the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0075] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication with each other. The memory is used to store computer programs, the communication interface is used to communicate, and the processor and the transceiver are used to run the computer program so that the electronic device executes each step of the above method.
[0076] In this embodiment, the memory may include a random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0077] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0078] The above description and accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. Parts and subsamples of some embodiments may be included in or replace parts and subsamples of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of a stated sub-sample, whole, step, operation, element, and / or component, but do not exclude the presence or addition of one or more other sub-samples, wholes, steps, operations, elements, components and / or groups of these. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the various embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0079] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0080] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0081] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A data reading method for Modbus protocol, characterized in that, include: Extracting register data corresponding to all registers from a designated Modbus terminal in advance, wherein each of the registers includes at least one storage point, and the register data includes original data corresponding to each of the storage points; Obtaining a data read request configured by a user, wherein the data read request includes a target point address and a target data type; Matching the point addresses corresponding to the storage points according to the target point address, and determining the target point from the storage points based on the matching result; Converting the original data corresponding to the target point into data of the target data type to obtain target data, and encoding the target data to obtain a read message corresponding to the data read request; The pre-extracting register data corresponding to all registers from the designated Modbus terminal includes: obtaining the point register type and Modbus protocol type corresponding to the designated Modbus terminal; scanning the designated Modbus terminal according to the function code corresponding to the point register type, and extracting the scanned Modbus message; parsing the Modbus message according to the Modbus protocol type to obtain the original data corresponding to each of the storage points; using a preset gateway to cache the original data corresponding to the storage point to obtain register data; The encoding of the target data to obtain a read message corresponding to the data read request includes: determining the register corresponding to the target point as the target register; sorting the target points according to the register addresses corresponding to the target registers to obtain a point sequence; grouping the target points corresponding to the target registers in the point sequence according to a preset register reading quantity to obtain a point group; encoding the target data corresponding to each target node in each point group to obtain a read message corresponding to each point group; The target points corresponding to the target registers in the point sequence are grouped according to a preset register read quantity to obtain point groups, including: counting the register quantity of the target register, and calculating the register quantity of the target register according to a preset proportional coefficient to obtain a dynamic read quantity; if the dynamic read quantity is less than or equal to a preset maximum quantity threshold, the dynamic read quantity is used as the register read quantity, and the target points corresponding to the target registers in the point sequence are grouped according to the register read quantity to obtain a point group; if the dynamic read quantity is greater than the maximum quantity threshold, the maximum quantity threshold is used as the register read quantity, and the target points corresponding to the target registers in the point sequence are grouped according to the register read quantity to obtain a point group.
2. The method according to claim 1, characterized in that Get the data read request configured by the user, including: A data reading request configured by a user is received through a preset first display page, wherein the first display page is also used to display the original data corresponding to each of the storage points according to a preset data base format.
3. The method according to claim 1, characterized in that After converting the original data corresponding to the target point into data of the target data type, and obtaining the target data, the method further includes: Displaying the target data through a preset second display page; If the adjusted data type input by the user is received through the second display page, the original data corresponding to the target point is converted into data of the adjusted data type to obtain new target data.
4. The method according to claim 1, characterized in that: The Modbus protocol type includes at least one of Modbus TCP, Modbus RTU, and Modbus ASII.
5. A data reading system for Modbus protocol, characterized in that: include: A cache module, used to extract register data corresponding to all registers from a specified Modbus terminal in advance, wherein each of the registers includes at least one storage point, and the register data includes original data corresponding to each of the storage points; An acquisition module, used for acquiring a data read request configured by a user, wherein the data read request includes a target point address and a target data type; A determination module, configured to match the point addresses corresponding to the storage points according to the target point address, and determine the target point from the storage points based on the matching result; A reading module, used for converting the original data corresponding to the target point into data of the target data type to obtain the target data, and encoding the target data to obtain a reading message corresponding to the data reading request; The cache module extracts the register data corresponding to all registers from the designated Modbus terminal in the following manner: obtains the point register type and Modbus protocol type corresponding to the designated Modbus terminal; scans the designated Modbus terminal according to the function code corresponding to the point register type, and extracts the scanned Modbus message; parses the Modbus message according to the Modbus protocol type to obtain the original data corresponding to each of the storage points; uses a preset gateway to cache the original data corresponding to the storage point to obtain the register data; The reading module performs the encoding of the target data to obtain the read message corresponding to the data read request in the following manner: determining the register corresponding to the target point as the target register; sorting the target points according to the register addresses corresponding to the target registers to obtain a point sequence; grouping the target points corresponding to the target registers in the point sequence according to a preset register reading quantity to obtain a point group; encoding the target data corresponding to each target node in each point group respectively to obtain a read message corresponding to each point group; The reading module performs the grouping of the target points corresponding to the target register in the point sequence according to the preset register reading number to obtain the point grouping in the following manner: counting the register number of the target register, and calculating the register number of the target register according to the preset proportional coefficient to obtain the dynamic reading number; if the dynamic reading number is less than or equal to the preset maximum number threshold, the dynamic reading number is used as the register reading number, and the target points corresponding to the target register in the point sequence are grouped according to the register reading number to obtain the point grouping; if the dynamic reading number is greater than the maximum number threshold, the maximum number threshold is used as the register reading number, and the target points corresponding to the target register in the point sequence are grouped according to the register reading number to obtain the point grouping.
6. An electronic device, characterized in that: include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method according to any one of claims 1 to 4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
