Modbus data acquisition method, electronic equipment and storage medium
By setting device parameters and configuration files in the Modbus system, the universality and flexibility of multi-device data acquisition are achieved, and the problem of redeveloping software when the equipment increases or changes is solved, improving efficiency and code reuse.
Patent Information
- Application Number
- CN202310634822.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2043-05-31
AI Technical Summary
In the Modbus system, due to the large number and types of equipment to be collected and the complex configuration management, software and code need to be redeveloped for every additional device or changed, resulting in cumbersome development process, low efficiency and high cost.
By setting the relevant parameters of the device to be collected in the Modbus configuration file, obtaining the system configuration file and acquisition configuration file, creating thread acquisition data based on the device type and communication address, and analyzing the data, realizing the universality and flexibility of multi-device data acquisition sex.
Improves the reusability and development efficiency of code and reduces costs. Users only need to set device parameters in the configuration file to collect data from multiple devices, without redeveloping the software to adapt to device changes.
Smart Images

Figure CN119065687A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of data processing, and more specifically, to a modbus data acquisition method, an electronic device, and a storage medium. Background Art
[0002] Modbus is a serial communication protocol. As one of the most mainstream communication protocols in the field of intelligent buildings and industrial control, it has the significant advantages of being standard, open, widely used, and supporting multiple types of electrical interfaces. However, in the modbus system, due to the large number and types of devices to be collected, cumbersome configuration management, and complex device management, each addition or change of a device requires software redevelopment and corresponding code writing, resulting in cumbersome development and use processes, low efficiency, and high costs. Summary of the invention
[0003] The disclosed embodiment provides a modbus data acquisition method, electronic device and storage medium. A universal modbus configuration file can be defined to improve the versatility of the code.
[0004] In a first aspect, the present embodiment provides a modbus data acquisition method, comprising: setting relevant parameters of a device to be acquired in a modbus configuration file, the modbus configuration file comprising a system configuration file and an acquisition configuration file, the relevant parameters comprising a type of the device to be acquired, a communication address, data acquisition parameters and data parsing parameters; obtaining the system configuration file and the acquisition configuration file, and obtaining the type and communication address of the device to be processed from the system configuration file; obtaining the data acquisition parameters and data parsing parameters of the device to be acquired from the acquisition configuration file according to the type of the device to be acquired; creating a thread for the device to be acquired according to the communication address, data acquisition parameters and data parsing parameters of the device to be acquired; acquiring data of the device to be acquired through the thread, and parsing the data.
[0005] In a second aspect, an embodiment of the present application provides a storage medium having computer instructions stored thereon, wherein the computer instructions, when executed by a processor, implement the steps of the method described in any one of the first aspects above.
[0006] In a third aspect, an embodiment of the present application provides an electronic device having a processor and a memory, wherein the memory stores computer instructions, and when the computer instructions are executed by the processor, the steps of the method described in any one of the first aspects are implemented.
[0007] One beneficial effect of the disclosed embodiment is that when collecting data through the modbus protocol, the relevant parameters of the device to be collected can be set in the modbus configuration file, and then the system configuration file of the modbus including the system configuration file and the collection configuration file is obtained, and the type and communication address of the device to be collected are obtained from the system configuration file, and the data collection parameters and data parsing parameters of the device to be collected are obtained from the collection configuration file based on the type of the device to be collected, and according to the communication address, data collection parameters and parsing parameters of the device to be collected, a thread is created for the device to be collected, and data is collected and parsed. In this way, the relevant software of modbus only needs to be developed once for the modbus configuration file containing the system configuration and relevant parameters of the collection configuration of multiple devices to be collected in the modbus system, and the data of multiple devices to be collected can be collected according to the configuration file. And when the device to be collected in the modbus system changes, increases, decreases or changes, the user only needs to increase or decrease the relevant parameters in the process of setting the parameters of the device to be collected, and the data of the device can be continued to be collected through the developed software, and there is no need to redevelop the software and modify the code, which improves the reusability of the code, improves the efficiency and reduces the cost.
[0008] Other features and advantages of the embodiments of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the embodiments of the present disclosure.
[0010] Figure 1 A flow chart of a modbus data acquisition method according to an embodiment of the present disclosure is shown.
[0011] Figure 2 A schematic diagram of a system configuration file according to an embodiment of the present disclosure is shown.
[0012] Figure 3 A schematic diagram of a collection configuration file according to an embodiment of the present disclosure is shown.
[0013] Figure 4 A collection flow chart of multiple collection cycles according to an embodiment of the present disclosure is shown.
[0014] Figure 5 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0015] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless otherwise specifically stated.
[0016] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the invention, its application, or uses.
[0017] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0018] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0019] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0020] like Figure 1 As shown, an embodiment of the present application discloses a modbus data acquisition method, which includes steps S11 to S15.
[0021] Step S11, setting relevant parameters of the device to be collected in the modbus configuration file, the modbus configuration file includes a system configuration file and a collection configuration file, and the relevant parameters include the type of the device to be collected, the communication address, the data collection parameters and the data analysis parameters.
[0022] In an example of this embodiment, the modbus configuration file is a configuration file that defines various parameters of the device to be collected. Before obtaining the modbus configuration file, the user can pre-configure the modbus configuration file based on the actual situation of the device to be processed. For example, in the modbus configuration file, the number, name, type, communication address of the device to be collected and the relevant parameters of collection and analysis are set. The modbus configuration file includes a system configuration file and a collection configuration file. The system configuration file can be configured with parameters such as the number of devices to be collected, the name, type, and communication address of each device to be collected, etc.
[0023] In an example of this embodiment, the modbus configuration file is a configuration file that defines various parameters of the device to be collected. Before obtaining the modbus configuration file, the user can pre-configure the modbus configuration file based on actual conditions. The modbus configuration file includes a system configuration file and a collection configuration file. The system configuration file can be configured with parameters such as the number of devices to be collected, the name, type, and communication address of each device to be collected.
[0024] In one example, the system configuration file can be set up as follows Figure 2 As shown, dev_num=2, which means that the number of devices to be collected is 2, [device0] and [device1] represent different devices to be collected, and for the parameters in device [device0], name=dev1, which means that the name of device [device0] is dev1, TYPE=PCS0, which means that the device type of device [device0] is PCS0, and ip=192.168.100.100, which means that the communication address of device [device0] is 192.168.100.100. For the parameters in device [device1], name=dev2, which means that the name of device [device1] is dev2, TYPE=PCS1, which means that the device type of device [device1] is PCS1, and ip=192.168.100.101, which means that the communication address of device [device1] is 192.168.100.101. Before using Modbus for data collection, users can configure the number, name, type and IP address of the devices to be collected in the system configuration file in advance. In the event of changes in the devices to be collected, data collection can be achieved by simply modifying the configuration file, thereby improving the versatility of the code.
[0025] In an example of this embodiment, the data collection configuration file is configured with data collection parameters and data analysis parameters. The data collection parameters include the collection period, collection mode, register address to be collected and collection address length of each type of device to be collected; the data analysis parameters include the offset of the first register address of each type of device to be collected, the number of registers to be combined and analyzed, data attributes and collection accuracy.
[0026] In one example, the collection configuration file can be set up as follows: Figure 3As shown, the configuration file mainly includes two parts, datas and keys. The parameters in the datas part are the data acquisition parameters of the device to be collected. Different data acquisition parameters can be set for different types of devices. For example, the parameters in TYPE PCS0 are the data acquisition parameters of the device to be collected with the type PCS0 in the system configuration file. Among them, period represents the acquisition period, period: 1000 means that the acquisition period is 1000ms, and function represents the acquisition method of different devices to be collected. adrrs represents the register address of the device to be collected, where adr represents the register address of the device to be collected, and length represents the length of the register address. For example, addr: 0x0001, length: 1 means that the register address to be collected is 0x0001, and the length of the address is 1, that is, only the address itself is collected. addr: 0x0002, length: 26, means the first register address to be collected is 0x0002, length is 26, that is, the data of the 26 register addresses from 0x0002 to 0x0027 are collected, so as to realize segment collection of continuous register addresses and improve collection efficiency. In addition, for the same type of collection equipment, different sets of collection configurations can be set, specifically, different collection cycles and register addresses to be collected can be set.
[0027] In addition to the above parameters, the acquisition parameters can also include the name and sequence of the table stored after acquisition, and the slave address of the device to be acquired. For example, table: TABLE1 means the name of the table is TABLE1, id: 1 means the sequence of the table is 1. Slave_id: 100 means the slave address of the device to be acquired is 100.
[0028] like Figure 3 As shown, the parameters in the keys part are the data parsing parameters of the device to be collected. Different data parsing parameters can be set for different types of devices. The parameters in TYPE PCS0 are the data parsing parameters of the device to be collected with the type PCS0 in the system configuration file. Among them, start represents the offset of the first register address of the device to be collected, and len represents the number of registers to be merged and parsed. For example, len: 1 means that the data of the register does not need to be merged and parsed, but only needs to be parsed separately. len: 2 means that the data in the two registers need to be merged and parsed together. type is the data attribute. Depending on the device, the attribute of the data in the register may also be different. scale represents the data accuracy. In addition, for the same type of collection device that includes multiple sets of collection configurations, corresponding multiple sets of parsing configurations can be set to parse the collected data. In the case of changes in the device to be collected, you only need to modify the configuration file to achieve data parsing and improve the versatility of the code.
[0029] In addition to the above parameters, the acquisition parameters may also include the meaning of the register address to be acquired, change parsing parameters, batch parsing parameters, and endian configuration parameters. For example, "colname":POINTNAME1" means that the meaning of the register address to be acquired is POINTNAME1, so that in subsequent processing, it can be clearly determined what data is being acquired and parsed. Change is a change parsing parameter, which is used to characterize whether the device to be processed is configured for change parsing. Group is a batch parsing parameter. When the user needs to perform batch parsing on the register data, this parameter can be adjusted. Generally, it can be set to 0. BiglittleEndian is a big-endian configuration parameter, which is used to characterize whether the device to be acquired is configured in big-endian or little-endian order. When parsing data, corresponding processing can be performed.
[0030] In one example, if the device to be collected in the modbus system has not changed, when collecting data, step S12 can be directly executed to directly collect and analyze data based on the previously set configuration file.
[0031] Step S12, obtaining a system configuration file and a collection configuration file, and obtaining the type and communication address of the device to be processed from the system configuration file.
[0032] Step S13, according to the type of the device to be collected, obtain the data collection parameters and data analysis parameters of the device to be collected from the collection configuration file.
[0033] After setting the relevant parameters of the device to be collected in the modbus configuration file, you can obtain and read the system configuration file and the collection configuration file, and obtain the type and corresponding communication address of each device to be processed in the system configuration file. Then, according to the type of each device to be processed, you can read the corresponding type of data collection parameters and data parsing parameters from the collection configuration file.
[0034] Step S14: creating a thread for the device to be collected according to the communication address, data collection parameters and data parsing parameters of the device to be collected.
[0035] Step S15, collect the data of the device to be collected through the thread, and analyze the data.
[0036] In an example of this embodiment, a thread is created for the device to be collected based on the communication address, data collection parameters and data parsing parameters of the device to be collected, including: writing the communication address, data collection parameters and data parsing parameters of the device to be collected into a cache structure to obtain the structural data of the device to be processed; and creating a thread for the device to be collected based on the structural data.
[0037] In this embodiment, when writing the communication address, data collection parameters and data parsing parameters of the device to be collected into the cache structure, various types of cache structures can be used, such as the map cache structure. After obtaining the communication address, data collection parameters and data parsing parameters of each device to be collected, the parameters of each device to be processed can be written into the map cache structure to obtain the map structure data of each device to be processed, so as to subsequently call the Linux thread interface to start the collection thread of each device to be processed through the map structure data, collect and parse the data of the device to be processed. Specifically, the connection with the device to be collected can be established through the communication address of the device to be collected, the thread can be started, and the data of the device to be collected can be collected based on the data collection parameters, and the collected data of the device to be collected can be parsed based on the data parsing parameters.
[0038] When collecting data through the modbus protocol, the relevant parameters of the device to be collected can be set in the modbus configuration file first, and then the system configuration file of the modbus including the system configuration file and the collection configuration file is obtained, and the type and communication address of the device to be collected are obtained from the system configuration file, and the data collection parameters and data parsing parameters of the device to be collected are obtained from the collection configuration file based on the type of the device to be collected, and according to the communication address, data collection parameters and parsing parameters of the device to be collected, a thread is created for the device to be collected, and data is collected and parsed. In this way, the relevant software of modbus only needs to be developed once for the modbus configuration file containing the system configuration and relevant parameters of the collection configuration of multiple devices to be collected in the modbus system, and the data of multiple devices to be collected can be collected according to the configuration file. And when the device to be collected in the modbus system changes, increases, decreases or changes, the user only needs to increase or decrease the relevant parameters in the process of setting the parameters of the device to be collected, and the data of the device can be continued to be collected through the developed software, and there is no need to redevelop the software and modify the code, which improves the reusability of the code, improves efficiency and reduces costs.
[0039] In an example of the present embodiment, collecting data of the device to be collected includes: when the collection cycle of the device to be collected is one, collecting the data of the device to be collected based on the collection cycle; when the device to be collected includes multiple collection cycles, determining the collection time interval of the device to be collected according to the multiple collection cycles, and collecting the data of the device to be collected according to the collection time interval.
[0040] In this embodiment, the collection period of the device to be collected can be set to one or more. If the collection period is set to one, a timer can be used to collect a single period in a single collection thread. However, the timer can only be timed at a fixed time interval and cannot collect multiple periods at the same time in one thread. Therefore, the data of the device to be collected can be collected by determining the collection time delay.
[0041] In an example of the present embodiment, in the case where the device to be collected includes multiple collection cycles, the collection time interval of the device to be collected is determined according to the multiple collection cycles, and the data of the device to be collected is collected according to the collection time interval, including: backing up the multiple collection cycles and determining the lowest common multiple of the multiple collection cycles; determining relevant parameters and collection time intervals according to the multiple collection cycles, and collecting the data of the device to be collected after the collection time interval; determining whether the first parameter among the relevant parameters is equal to the lowest common multiple, and initializing the multiple collection cycles and relevant parameters when the first parameter is equal to the lowest common multiple, wherein the multiple collection cycles are initialized through backup, and the first parameter is the minimum value among the multiple collection cycles; and performing the steps of determining the collection time interval and relevant parameters again, collecting the data of the device to be collected after the collection time interval, and determining whether the first parameter among the relevant parameters is equal to the lowest common multiple.
[0042] In an example of the present embodiment, relevant parameters and a collection time interval are determined according to a plurality of collection cycles, and data of the device to be collected is collected after the collection time interval has passed, including: determining the collection time interval and a first parameter, wherein the value of the first parameter is equal to the minimum value among the plurality of collection cycles, and the collection time interval is equal to the difference between the first parameter and the second parameter, wherein the initial value of the second parameter is 0, and the initial value is used to initialize the second parameter; after the collection time interval has passed, determining in turn whether the first cycle among the plurality of collection cycles is equal to the first parameter, the first cycle being any one of the plurality of collection cycles; when the first cycle is equal to the first parameter, data of the device to be collected is collected, and the values of the first cycle and the second parameter are updated, wherein the updated first cycle is equal to the sum of the first cycle before the update and the initial value of the first cycle, and the second parameter is equal to the first parameter.
[0043] The specific process is as follows Figure 4As shown, in one example, for example, a certain device to be collected includes cycle A and cycle B, which are two collection cycles of 200ms and 500ms respectively. At this time, the lowest common multiple of the two collection cycles can be calculated to be 1000ms, and then the first parameter and the collection time interval are determined. The value of the first parameter is the minimum value of multiple collection cycles, that is, 200ms, and the initial value of the second parameter is 0. The value of the collection time interval is the difference between the first parameter and the second parameter, that is, 200ms. After 200ms, it can be determined in sequence whether each cycle in the multiple collection cycles is equal to the first parameter, where cycle A is 200ms and is equal to the first parameter. At this time, the data of the devices to be collected in sequence can be collected according to the address of the register in the configuration file, and the value of cycle A and the second parameter can be updated. At this time, the updated cycle A is equal to the sum of the cycle A before the update and the initial value of cycle A, that is, 400ms, and the second parameter is equal to the first parameter, that is, 200ms. After that, it is determined whether another cycle B500ms is equal to the first parameter 200ms. Since the other cycle is not equal to the first parameter, the collection is not triggered. Afterwards, it is determined whether the first parameter 200 ms is equal to the least common multiple. If not, the step of determining the acquisition time interval and the first parameter is performed again.
[0044] Determine the first parameter and the acquisition time interval again. At this time, the value of the first parameter is the minimum value among multiple acquisition cycles, that is, 400ms. The acquisition time interval is the difference between the first parameter and the second parameter, that is, 400ms-200ms=200ms. After 200ms, continue to determine in turn whether each cycle in the multiple acquisition cycles is equal to the first parameter 400ms, where cycle A 400ms is equal to it. Continue to collect once and update cycle A and the second parameter. The updated cycle A is 600ms and the second parameter is 400ms. After that, determine whether cycle B is equal to the first parameter. Since the other cycle is not equal to the first parameter, the acquisition is not triggered. After that, determine whether the first parameter 400ms is equal to the lowest common multiple. If it is not equal, re-execute the steps of determining the acquisition time interval and the first parameter.
[0045] Again, determine the first parameter and the acquisition time interval. At this time, the value of the first parameter is the minimum value of multiple acquisition cycles, that is, 500ms. The acquisition time interval is the difference between the first parameter and the second parameter, that is, 500-400=100ms. After 100ms, continue to determine in turn whether each cycle in the multiple acquisition cycles is equal to the first parameter 500ms, where cycle B 500ms is equal to it. Continue to collect once and update cycle B and the second parameter. The updated cycle B is the sum of cycle B and the initial value of cycle B, that is, 1000ms. The second parameter is equal to the first parameter, that is, 500ms. After that, determine whether cycle A is equal to the first parameter. Since the other cycle is not equal to the first parameter, the acquisition is not triggered. After that, determine whether the first parameter 500ms is equal to the lowest common multiple. If it is not equal, re-execute the steps of determining the acquisition time interval and the first parameter.
[0046] It should be noted that the register addresses corresponding to different acquisition cycles may be different, and the specific acquisition address can be determined according to the parameters in the acquisition configuration file.
[0047] The intermediate process is similar to the above process, and will not be described in detail. Finally, when both cycle A and cycle B are 1000ms, the first parameter and the collection time interval are determined. At this time, the value of the first parameter is the minimum value among multiple collection cycles, that is, 1000ms, and the collection time interval is the difference between the first parameter and the second parameter, that is, 1000-800=200ms. After 200ms, it is continued to determine whether each cycle in the multiple collection cycles is equal to the first parameter 1000ms, where cycles A and B are both 1000ms, which is equal to the first parameter. At this time, the collection thread can be collected once and the cycles A and B can be updated. At this time, after 1000ms, the collection thread has collected 5 times according to cycle A and 2 times according to cycle B, completing a cycle. After that, it is determined whether the first parameter 1000ms is equal to the lowest common multiple. If it is equal, all multiple collection cycles and related parameters are initialized, and the collection is performed again according to the multi-cycle strategy.
[0048] In one example, when the first cycle is not equal to the first parameter, continue to determine whether other acquisition cycles in the multiple acquisition cycles are equal to the first parameter, or perform the step of determining whether the first parameter in the related parameters is equal to the least common multiple.
[0049] In one example, the operation to be performed when the first cycle is not equal to the first parameter can be determined based on whether there are other cycles in the multiple acquisition cycles that need to be compared with the first parameter. For example, when the first cycle is the last cycle in the multiple acquisition cycles to be compared with the first parameter, the step of determining whether the first parameter is equal to the least common multiple can be continued when the first cycle is not equal to the first parameter. And when the first cycle is not the last cycle in the multiple acquisition cycles to be compared with the first parameter, when the first cycle is not equal to the first parameter, it can be continued to determine whether other cycles in the multiple acquisition cycles are equal to the first parameter.
[0050] In one example, before performing multi-cycle acquisition on the acquisition device, a cycle set consisting of multiple cycles may be backed up first. In the process of obtaining the initial value or initialization of the cycle, corresponding data may be obtained from the backed-up cycle set.
[0051] In this example, when the device to be processed includes multiple collection cycles, data collection of multiple cycles can be performed simultaneously in the same collection thread by determining the collection time interval, thereby improving thread utilization efficiency and performance.
[0052] In an example of this embodiment, the data parsing parameters also include a change parsing parameter, which is used to characterize whether the device to be processed is configured for change parsing; parsing the data includes: when the device to be processed is configured for change parsing, parsing the data that has changed in the data of the device to be processed; when the device to be processed is not configured for change parsing, parsing all the data.
[0053] In one example of this embodiment, Figure 3 As shown, change is a change resolution parameter, which is used to characterize whether the device to be processed is configured for change resolution. For example, change: 1 can be set to change resolution, and change: 0 can be set to non-change resolution. When the device to be processed is configured for change resolution, the data of the device to be processed collected in this period can be compared with the data of the previous period, and only the changed data collected in this period is analyzed. When the device to be processed is not configured for change resolution, all the data collected in this period are analyzed.
[0054] In an example of this embodiment, after collecting data of the device to be collected through a thread and parsing the data, the method also includes: writing the parsed data of the device to be processed into the head of the processing queue, and reading the data from the tail of the processing queue for corresponding processing.
[0055] In this embodiment, after acquiring and parsing the data of multiple devices to be processed through the modbus protocol, a thread can be started to store the parsed data of each device to be processed in a processing queue. The processing queue can be a queue queue. The collected data of each device to be processed can be stored in the head of the queue and acquired from the tail for corresponding processing, such as uploading to a server, storing locally, or processing the data through other devices or software. After acquiring the data at the tail, the data can be deleted from the tail to ensure that the data in the queue does not overflow.
[0056] This embodiment provides an electronic device 100, such as Figure 5 As shown, it includes: a processor 101 and a memory 102. The memory 102 stores a computer program, and when the computer program is executed by the processor 101, each process of the above-mentioned modbus data acquisition method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0057] This embodiment provides a storage medium, which stores computer instructions. When the computer instructions are executed by a processor, the various processes of the above-mentioned modbus data acquisition method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not repeated here.
[0058] Each embodiment in the present disclosure is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and equipment embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0059] The above describes specific embodiments of the present disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0060] The embodiments of the present disclosure may be systems, methods and / or computer program products. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the embodiments of the present disclosure.
[0061] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0062] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0063] The computer program instructions for performing the operation of the embodiments of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of a computer-readable program instruction, and the electronic circuit may execute a computer-readable program instruction, thereby realizing various aspects of the embodiments of the present disclosure.
[0064] Various aspects of the embodiments of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0065] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0066] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0067] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments 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 an instruction, and a part of a module, a program segment or an instruction 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, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0068] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A modbus data acquisition method, characterized in that: The method comprises: Setting relevant parameters of the device to be collected in the modbus configuration file, the modbus configuration file includes a system configuration file and a collection configuration file, and the relevant parameters include the type of the device to be collected, the communication address, the data collection parameters and the data parsing parameters; Obtaining the system configuration file and the collection configuration file, and obtaining the type and communication address of the device to be processed from the system configuration file; According to the type of the device to be collected, obtain the data collection parameters and data analysis parameters of the device to be collected from the collection configuration file; Creating a thread for the device to be collected according to the communication address, data collection parameters and data parsing parameters of the device to be collected; The data of the device to be collected is collected through the thread, and the data is analyzed.
2. The method according to claim 1, characterized in that: The data acquisition parameters include the acquisition cycle, acquisition mode, register address to be acquired and acquisition address length of each type of the device to be acquired; The data analysis parameters include the offset of the first register address of each type of the device to be collected, the number of registers to be combined and analyzed, data attributes and collection accuracy.
3. The method according to claim 1, characterized in that The step of creating a thread for the device to be collected according to the communication address, data collection parameters and data parsing parameters of the device to be collected includes: Writing the communication address, data collection parameters and data parsing parameters of the device to be collected into a cache structure to obtain the structural data of the device to be processed; A thread is created for the device to be collected according to the structural data.
4. The method according to claim 1, characterized in that: Collecting the data of the device to be collected through the thread includes: In a case where the collection cycle of the device to be collected is one, collecting the data of the device to be collected based on the collection cycle; In the case that the device to be collected includes multiple collection cycles, the collection time interval of the device to be collected is determined according to the multiple collection cycles, and the data of the device to be collected is collected according to the collection time interval.
5. The method according to claim 4, characterized in that In the case where the device to be collected includes multiple collection cycles, determining the collection time interval of the device to be collected according to the multiple collection cycles, and collecting the data of the device to be collected according to the collection time interval, includes: Backing up the multiple acquisition cycles and determining the least common multiple of the multiple acquisition cycles; Determine relevant parameters and the collection time interval according to the multiple collection cycles, and collect the data of the device to be collected after the collection time interval has passed; Determine whether a first parameter among the related parameters is equal to the least common multiple, and if the first parameter is equal to the least common multiple, initialize the multiple acquisition cycles and related parameters, wherein the multiple acquisition cycles are initialized through the backup, and the first parameter is a minimum value among the multiple acquisition cycles; The steps of determining the collection time interval and related parameters are performed again, and after the collection time interval, the data of the device to be collected is collected, and whether the first parameter of the related parameters is equal to the least common multiple is determined.
6. The method according to claim 5, characterized in that The determining of the relevant parameters and the collection time interval according to the multiple collection cycles, and collecting the data of the device to be collected after the collection time interval has passed, includes: Determine the collection time interval and the first parameter, wherein the value of the first parameter is equal to the minimum value of the multiple collection cycles, and the collection time interval is equal to the difference between the first parameter and the second parameter, wherein the initial value of the second parameter is 0, and the initial value is used to initialize the second parameter; After the acquisition time interval has passed, determining in sequence whether a first cycle among the multiple acquisition cycles is equal to the first parameter, the first cycle being any one of the multiple acquisition cycles; When the first period is equal to the first parameter, data from the device to be collected is collected, and the values of the first period and the second parameter are updated, wherein the updated first period is equal to the sum of the first period before the update and the initial value of the first period, and the second parameter is equal to the first parameter.
7. The method according to claim 6, characterized in that The method further comprises: When the first cycle is not equal to the first parameter, continue to determine whether other acquisition cycles in the multiple acquisition cycles are equal to the first parameter, or perform the step of determining whether the first parameter in the related parameters is equal to the least common multiple.
8. The method according to claim 1, characterized in that The data analysis parameters also include a change analysis parameter, and the change analysis parameter is used to indicate whether the device to be processed is configured for change analysis; The parsing of the data comprises: When the device to be processed is configured for change analysis, analyzing the data in which changes occur in the data of the device to be processed; In the case that the device to be processed is not configured for change analysis, all the data are analyzed.
9. The method according to claim 1, characterized in that: After collecting the data of the device to be collected through the thread and parsing the data, the method further includes: The parsed data of the device to be processed is written into the head of the processing queue, and the data is read from the tail of the processing queue to perform corresponding processing.
10. A storage medium, characterized in that: Computer instructions are stored thereon, and when the computer instructions are executed by a processor, the steps of the method described in any one of claims 1 to 9 are implemented.
11. An electronic device, characterized in that: A processor and a memory are provided, wherein the memory stores computer instructions, and when the computer instructions are executed by the processor, the steps of the method described in any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Industrial field data collecting and analyzing system based on Modbus
CN103792928A
Modbus protocol-based analysis method, device and system
CN112995133A
Soft control method for high-speed acquisition and processing of multi-source heterogeneous data of hoisting machinery
CN113468168A
Data acquisition method and system, storage medium and electronic equipment
CN114185585A
Industrial data acquisition and storage method, device and system
CN115269593A
Cited By
Communication code generation method based on XML configuration file and storage medium
CN120994174A
