Data acquisition method of modbus, electronic device and storage medium
By setting device parameters in the Modbus configuration file, obtaining the system and acquisition configuration files, and creating threads to acquire device data, the problem of complex device management in the Modbus system is solved, and efficient and low-cost data acquisition and parsing are achieved.
Patent Information
- Application Number
- CN202310634822.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-31
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2043-05-31
AI Technical Summary
In the Modbus system, the number and types of devices to be collected are large, and the configuration and management are cumbersome, resulting in a complicated development and usage process that is inefficient and costly.
By setting the relevant parameters of the device to be acquired in the Modbus configuration file, obtaining the system and acquisition configuration file, creating threads according to the device type and communication address, acquiring and parsing data, the code achieves universality and reusability.
It improves the efficiency of data acquisition in the Modbus system, reduces development and maintenance costs, and eliminates the need for software redevelopment when adapting to equipment changes.
Smart Images

Figure CN119065687B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present disclosure relate to the field of data processing, and more particularly, to a modbus data collection method, an electronic device, and a storage medium. BACKGROUND
[0002] Modbus is a serial communication protocol, as one of the most mainstream communication protocols in the field of intelligent buildings and industrial control, has the significant advantages of standard, open, wide application, and support for multiple types of electrical interfaces. However, in the modbus system, due to the large number and variety of devices to be collected, complicated configuration management, and complex device management, the software needs to be redeveloped and corresponding code needs to be written every time a device is added or changed, which leads to a complicated development and use process, low efficiency, and high cost. SUMMARY
[0003] Embodiments of the present disclosure provide a modbus data collection method, an electronic device, and a storage medium. A general modbus configuration file can be defined to improve the universality of the code.
[0004] In a first aspect, the embodiments provide a modbus data collection method, including: setting related parameters of a device to be collected in a modbus configuration file, the modbus configuration file including a system configuration file and a collection configuration file, the related parameters including a type, a communication address, data collection parameters, and data analysis parameters of the device to be collected; obtaining the system configuration file and the collection configuration file, and obtaining the type and the communication address of a device to be processed from the system configuration file; obtaining the data collection parameters and the data analysis parameters of the device to be collected from the collection configuration file according to the type of the device to be collected; creating a thread for the device to be collected according to the communication address, the data collection parameters, and the data analysis parameters of the device to be collected; collecting data of the device to be collected through the thread, and analyzing the data.
[0005] In a second aspect, the embodiments provide a storage medium having computer instructions stored thereon, the computer instructions being executed by a processor to implement the steps of the method of any one of the first aspect.
[0006] In a third aspect, the embodiments provide an electronic device having a processor and a memory, the memory having computer instructions stored therein, the computer instructions being executed by the processor to implement the steps of the method of any one of the first aspect.
[0007] One beneficial effect of the embodiment of the present disclosure is that when data is collected through the modbus protocol, the related parameters of the to-be-collected device can be set in the modbus configuration file, then the system configuration file of modbus including the system configuration file and the collection configuration file is acquired, the type and the communication address of the to-be-collected device are acquired from the system configuration file, the data collection parameter and the data analysis parameter of the to-be-collected device are acquired from the collection configuration file based on the type of the to-be-collected device, and the thread of the to-be-collected device is created according to the communication address, the data collection parameter and the analysis parameter of the to-be-collected device, so as to collect data and analyze. In this way, the related software of modbus only needs to develop the modbus configuration file including the related parameters of the system configuration and the collection configuration of the plurality of to-be-collected devices in the modbus system once, and then the data of the plurality of to-be-collected devices can be collected according to the configuration file. When the to-be-collected device in the modbus system changes, increases or decreases, or changes, the user only needs to increase or decrease the related parameters in the process of setting the parameters of the to-be-collected device, so as to continue to collect the data of the device through the developed software, without the need to develop the software and modify the code again, thereby improving the reusability of the code, improving the efficiency and reducing the cost.
[0008] Other features and advantages of the embodiments of the present disclosure will become clear from the following detailed description of exemplary embodiments of the present disclosure with reference to the drawings. BRIEF DESCRIPTION OF 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 data collection method of modbus of an embodiment of the present disclosure is shown.
[0011] Figure 2 A schematic diagram of a system configuration file of an embodiment of the present disclosure is shown.
[0012] Figure 3 A schematic diagram of a collection configuration file of an embodiment of the present disclosure is shown.
[0013] Figure 4 A collection flow chart of a plurality of collection periods of an embodiment of the present disclosure is shown.
[0014] Figure 5 A block diagram of an electronic device of 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, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of the invention.
[0016] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.
[0017] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.
[0018] In all the examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.
[0019] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.
[0020] like Figure 1 As shown in the figure, this application discloses a Modbus data acquisition method, which includes steps S11-S15.
[0021] Step S11: Set the relevant parameters of the device to be acquired in the Modbus configuration file. The Modbus configuration file includes the system configuration file and the acquisition configuration file. The relevant parameters include the type of the device to be acquired, the communication address, the data acquisition parameters, and the data parsing parameters.
[0022] In one example of this embodiment, the Modbus configuration file is a configuration file that defines various parameters of the devices to be acquired. Before obtaining the Modbus configuration file, the user can pre-configure the Modbus configuration file based on the actual devices to be processed. For example, the Modbus configuration file can set the number, name, type, communication address, and related acquisition and parsing parameters of the devices to be acquired. The Modbus configuration file includes a system configuration file and an acquisition configuration file. The system configuration file can be configured with parameters such as the number of devices to be acquired, the name, type, and communication address of each device.
[0023] In one example of the embodiment, the modbus configuration file is a configuration file defining 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 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 specifically set as shown in Figure 2 wherein dev_num=2, representing 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, representing that the name of device [device0] is dev1, TYPE=PCS0, representing that the type of device [device0] is PCS0, and ip=192.168.100.100, representing that the communication address of device [device0] is 192.168.100.100. For the parameters in device [device1], name=dev2, representing that the name of device [device1] is dev2, TYPE=PCS1, representing that the type of device [device1] is PCS1, and ip=192.168.100.101, representing that the communication address of device [device1] is 192.168.100.101. Before using modbus to collect data, the user can pre-configure the number, name, type, and ip address of the device to be collected in the system configuration file. In the case of changes in the device to be collected, only the configuration file needs to be modified to achieve data collection, improving the universality of the code.
[0025] In one example of the embodiment, the collection configuration file is configured with data collection parameters and data analysis parameters. The data collection parameters include the collection period, collection method, register address to be collected, and collection address length of each type of device to be collected; and the data analysis parameters include the offset of the first register address, the number of registers to be merged and analyzed, the data attribute, and the collection accuracy of each type of device to be collected.
[0026] In one example, the collection configuration file can be specifically set as shown in Figure 3As shown, this configuration file mainly consists of two parts: `datas` and `keys`. The parameters in the `datas` section are the data acquisition parameters for the device to be acquired. Different data acquisition parameters can be set for different types of devices. For example, the parameters in `TYPE PCS0` are the data acquisition parameters for the device of type `PCS0` in the system configuration file. Here, `period` represents the acquisition period; `period: 1000` means the acquisition period is 1000ms. `function` indicates the acquisition method for different devices. `adrrs` represents the register address to be acquired, where `adr` represents the register address of the device to be acquired, and `length` represents the length of that register address. For example, `addr: 0x0001, length: 1` means that the register address to be acquired is 0x0001, and the length of that address is 1, meaning only that address itself is acquired. `addr: 0x0002, length: 26` indicates that the first register address to be acquired is 0x0002, and the length is 26. This means data from register addresses 0x0002 to 0x0027 will be acquired, allowing for segmented acquisition of consecutive register addresses and improving acquisition efficiency. Furthermore, for the same type of acquisition device, multiple acquisition configurations can be set, specifically, different acquisition cycles and register addresses to be acquired can be configured.
[0027] In addition to the parameters mentioned above, the acquisition parameters can also include the name and sequence of the table to be stored after acquisition, as well as the slave address of the device to be acquired. For example, `table: TABLE1` indicates that the table name is TABLE1, `id: 1` indicates that the sequence of the table is 1, and `Slave_id: 100` represents that the slave address of the device to be acquired is 100.
[0028] like Figure 3 As shown, the parameters in the `keys` section are the data parsing parameters for the device to be acquired. Different data parsing parameters can be set for different types of devices. The parameters in `TYPE PCS0` are the data parsing parameters for the device to be acquired, which is of type `PCS0` in the system configuration file. Here, `start` represents the offset of the first register address of the device to be acquired, `len` represents the number of registers to be merged and parsed. For example, `len: 1` means that the data in the registers does not need to be merged and parsed, only parsed individually; `len: 2` means that the data in two registers needs to be merged and parsed together. `type` represents the data attribute; the attributes of the data in the registers may differ depending on the device. `scale` represents the data precision. Furthermore, for acquisition devices of the same type with multiple acquisition configurations, multiple corresponding parsing configurations can be set to parse the acquired data. When the device to be acquired changes, only the configuration file needs to be modified to achieve data parsing, improving the code's versatility.
[0029] In addition to the above parameters, the acquisition parameters can further include a meaning of a register address to be acquired, a change resolution parameter, a batch resolution parameter, and a big little endian configuration parameter. For example, colname”:POINTNAME1 indicates that the meaning of the register address to be acquired is POINTNAME1, so that it can be determined clearly that what data is acquired and resolved in subsequent processing. The change is a change resolution parameter, which is used to represent whether the device to be processed is configured to change resolution. The group is a batch resolution parameter, which can be adjusted when the user needs to perform batch resolution on the data of the register. Generally, it can be set to 0. The BiglittleEndian is a big little endian configuration parameter, which is used to represent whether the device to be acquired is configured in a big endian byte order or a little endian byte order, and corresponding processing can be performed during data resolution.
[0030] In one example, if the device to be acquired in the modbus system does not change, the data acquisition can also be directly performed in step S12 based on the previously set configuration file to directly perform data acquisition and resolution.
[0031] In step S12, the system configuration file and the acquisition configuration file are obtained, and the type and the communication address of the device to be processed are obtained from the system configuration file.
[0032] In step S13, the data acquisition parameters and the data resolution parameters of the device to be acquired are obtained from the acquisition configuration file according to the type of the device to be acquired.
[0033] After setting the related parameters of the device to be acquired in the modbus configuration file, the system configuration file and the acquisition configuration file can be obtained and read, the type and the corresponding communication address of each device to be processed are obtained in the system configuration file, and then the data acquisition parameters and the data resolution parameters of the corresponding type can be read from the acquisition configuration file according to the type of each device to be processed.
[0034] In step S14, a thread is created for the device to be acquired according to the communication address, the data acquisition parameters and the data resolution parameters of the device to be acquired.
[0035] In step S15, the data of the device to be acquired is acquired through the thread, and the data is resolved.
[0036] In one example of the embodiment, the thread is created for the device to be acquired according to the communication address, the data acquisition parameters and the data resolution parameters of the device to be acquired, including: writing the communication address, the data acquisition parameters and the data resolution parameters of the device to be acquired into a cache structure to obtain structure data of the device to be processed; and creating a thread for the device to be acquired according to the structure data.
[0037] In the embodiment, when writing the communication address, data collection parameter and data analysis parameter of the device to be collected into the cache structure, a plurality of types of cache structures can be used, for example, a map cache structure. After obtaining the communication address, data collection parameter and data analysis parameter of each device to be collected, the parameters of each device to be processed can be written into the map cache structure, and the map structure data of each device to be processed is obtained, so that the linux thread interface is called subsequently to start the collection thread of each device to be processed by using the map structure data, and the data of the device to be processed is collected and analyzed. Specifically, the connection with the device to be collected is established by using the communication address of the device to be collected, the thread is started, the data of the device to be collected is collected based on the data collection parameter, and the collected data of the device to be collected is analyzed based on the data analysis parameter.
[0038] When collecting data by using the modbus protocol, the related parameters of the device to be collected can be set in the modbus configuration file first, then the system configuration file of modbus including the system configuration file and the collection configuration file is obtained, the type and communication address of the device to be collected are obtained from the system configuration file, the data collection parameter and data analysis parameter of the device to be collected are obtained from the collection configuration file based on the type of the device to be collected, and the thread of the device to be collected is created based on the communication address, data collection parameter and analysis parameter of the device to be collected, so as to collect data and analyze. In this way, the related software of modbus only needs to develop the modbus configuration file including the related parameters of the system configuration and collection configuration of a plurality of devices to be collected in the modbus system once, and then the data of a plurality of devices to be collected can be collected according to the configuration file. When the devices to be collected in the modbus system change, increase or decrease, or change, the user only needs to increase or decrease the related parameters in the process of setting the parameters of the device to be collected, so as to continue collecting the data of the device by using the developed software, without the need to develop the software and modify the code again, thereby improving the reusability of the code, improving the efficiency and reducing the cost.
[0039] In one example of the embodiment, the data of the device to be collected is collected, including: in the case that the collection period of the device to be collected is one, the data of the device to be collected is collected based on the collection period; in the case that the device to be collected includes a plurality of collection periods, the collection time interval of the device to be collected is determined according to the plurality of collection periods, and the data of the device to be collected is collected according to the collection time interval.
[0040] In the embodiment, the collection period of the device to be collected can be set as one or more. If the collection period is set as one, the single-period collection can be performed by using a timer in a single collection thread. However, the timer can only time at a fixed time interval and cannot perform multiple-period collection in a thread. Therefore, the data of the device to be collected can be collected by determining the collection time delay.
[0041] In one example of the embodiment, in the case that the device to be collected includes multiple collection periods, the collection time interval of the device to be collected is determined according to the multiple collection periods, and the data of the device to be collected is collected according to the collection time interval, including: backing up the multiple collection periods and determining the least common multiple of the multiple collection periods; determining the related parameters and the collection time interval according to the multiple collection periods, and collecting the data of the device to be collected after the collection time interval; determining whether a first parameter in the related parameters is equal to the least common multiple, and initializing the multiple collection periods and the related parameters in the case that the first parameter is equal to the least common multiple, wherein the multiple collection periods are initialized by the backup, and the first parameter is the minimum value in the multiple collection periods; again performing the steps of determining the collection time interval and the related parameters, collecting the data of the device to be collected after the collection time interval, and determining whether the first parameter in the related parameters is equal to the least common multiple.
[0042] In one example of the embodiment, the related parameters and the collection time interval are determined according to the multiple collection periods, and the data of the device to be collected is collected after the collection time interval, including: determining the collection time interval and a first parameter, wherein the value of the first parameter is equal to the minimum value in the multiple collection periods, and the collection time interval is equal to the difference between the first parameter and a 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, determining whether a first period in the multiple collection periods is equal to the first parameter in sequence, wherein the first period is any collection period in the multiple collection periods; in the case that the first period is equal to the first parameter, collecting the data of the device to be collected, and updating the value of the first period and the second parameter, 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.
[0043] The specific flow is as follows Figure 4As shown, in one example, for example, a certain to-be-collected device includes two acquisition periods, period A and period B, 200 ms and 500 ms, respectively, at this time, the least common multiple of the two acquisition periods can be calculated to be 1000 ms, then the first parameter and the acquisition time interval are determined, the value of the first parameter is the minimum value in the plurality of acquisition periods, that is, 200 ms, the initial value of the second parameter is 0, and the value of the acquisition time interval is the difference between the first parameter and the second parameter, that is, 200 ms. After 200 ms, it can be determined in turn whether each period in the plurality of acquisition periods is equal to the first parameter, wherein period A is equal to the first parameter 200 ms, at this time, the data of the to-be-collected device in turn can be collected according to the address of the register in the configuration file, and the value of period A and the second parameter is updated, at this time, the updated period A is equal to the sum of the initial value of period A and the value of period A before updating, that is, 400 ms, and the second parameter is equal to the first parameter, that is, 200 ms. Then, it is determined whether the other period B 500 ms is equal to the first parameter 200 ms. Since the other period is not equal to the first parameter, the collection is not triggered. Then, it is determined whether the first parameter 200 ms is equal to the least common multiple, and in the case of not equal, the step of determining the acquisition time interval and the first parameter is executed again.
[0044] The first parameter and the acquisition time interval are determined again, at this time, the value of the first parameter is the minimum value in the plurality of acquisition periods, that is, 400 ms, and the acquisition time interval is the difference between the first parameter and the second parameter, that is, 400 ms-200 ms=200 ms, after 200 ms, it is continued to be determined in turn whether each period in the plurality of acquisition periods is equal to the first parameter 400 ms, wherein period A 400 ms is equal to the first parameter, and the collection is continued once and the period A and the second parameter are updated, the updated period A is 600 ms, and the second parameter is 400 ms. Then, it is determined whether period B is equal to the first parameter, and since the other period is not equal to the first parameter, the collection is not triggered. Then, it is determined whether the first parameter 400 ms is equal to the least common multiple, and in the case of not equal, the step of determining the acquisition time interval and the first parameter is executed again.
[0045] Again, the first parameter and the collection time interval are determined, where the value of the first parameter is the minimum value in the plurality of collection periods, i.e. 500 ms, and the collection time interval is the difference between the first parameter and the second parameter, i.e. 500-400=100 ms. After 100 ms, it is determined in turn whether each of the plurality of collection periods is equal to the first parameter 500 ms. Period B 500 ms is equal to the first parameter, and collection is performed once more and the period B and the second parameter are updated. The updated period B is the sum of the period B and the initial value of the period B, i.e. 1000 ms. The second parameter is equal to the first parameter, i.e. 500 ms. Then, it is determined whether the period A is equal to the first parameter. Since the other period is not equal to the first parameter, collection is not triggered. Then, it is determined whether the first parameter 500 ms is equal to the least common multiple. If not, the steps of determining the collection time interval and the first parameter are re-executed.
[0046] It should be noted that the register addresses collected by different collection periods can be different, and the specific collection addresses can be determined according to the parameters in the collection configuration file.
[0047] The intermediate process is similar to the foregoing process, and will not be described in detail. Finally, when the period A and the period B are both 1000 ms, the first parameter and the collection time interval are determined, where the value of the first parameter is the minimum value in the plurality of collection periods, i.e. 1000 ms, and the collection time interval is the difference between the first parameter and the second parameter, i.e. 1000-800=200 ms. After 200 ms, it is determined in turn whether each of the plurality of collection periods is equal to the first parameter 1000 ms. The period A and the period B are both 1000 ms and equal to the first parameter. At this time, collection can be performed once and the period A and the period B can be updated. At this time, the collection thread has passed 1000 ms, and has collected 5 times according to the period A and 2 times according to the period B, completing a cycle. Then, it is determined whether the first parameter 1000 ms is equal to the least common multiple. If yes, the plurality of collection periods and the related parameters are all initialized, and collection is performed again according to the multi-period strategy.
[0048] In one example, in the case where the first period is not equal to the first parameter, it is determined in turn whether other collection periods in the plurality of collection periods are equal to the first parameter, or the step of determining whether the first parameter in the related parameters is equal to the least common multiple is executed.
[0049] In one example, the operation performed when the first period is not equal to the first parameter can be determined according to whether there is another period in the plurality of collection periods that needs to be compared with the first parameter. For example, when the first period is the last period in the plurality of collection periods that needs to be compared with the first parameter, the operation performed when the first period is not equal to the first parameter can continue to determine whether the first parameter is equal to the least common multiple. When the first period is not the last period in the plurality of collection periods that needs to be compared with the first parameter, the operation performed when the first period is not equal to the first parameter can continue to determine whether another period in the plurality of collection periods is equal to the first parameter.
[0050] In one example, before the plurality of collection periods of the device to be collected, a period set composed of a plurality of periods can be backed up. In the process of obtaining the initial value or initialization of the period, the corresponding data can be obtained from the backed-up period set.
[0051] In this example, when the collection period of the device to be processed includes a plurality of periods, the data collection of the plurality of periods in the same collection thread can be realized by determining the collection time interval, and the thread use efficiency and performance can be improved.
[0052] In one example of the embodiment, the data analysis parameter further includes a change analysis parameter, which is used to represent whether the device to be processed is configured to change analysis. The data is analyzed, including: in the case that the device to be processed is configured to change analysis, the data that changes in the data of the device to be processed is analyzed; in the case that the device to be processed is not configured to change analysis, all the data is analyzed.
[0053] In one example of the embodiment, as shown in Figure 3 The change is a change analysis parameter, which is used to represent whether the device to be processed is configured to change analysis. For example, change: 1 can be set to change analysis, and change: 0 can be set to non-change analysis. When the device to be processed is configured to change analysis, the data collected in the current period of the device to be processed is compared with the data of the last period, and only the data that changes in the current period is analyzed. When the device to be processed is not configured to change analysis, all the data collected in the current period is analyzed.
[0054] In one example of the embodiment, after the data of the device to be collected is collected by the thread and the data is analyzed, the method further includes: writing the analyzed data of the device to be processed to the head of the processing queue, and reading the data from the tail of the processing queue for corresponding processing.
[0055] In the embodiment, after the data of the plurality of to-be-processed devices is acquired and parsed through the modbus protocol, a thread can be started, and the parsed data of each to-be-processed device is stored in a processing queue. The processing queue can be a queue, and the collected data of each to-be-processed device can be stored at the head of the queue and acquired from the tail to perform corresponding processing, for example, uploading to a server, storing locally, or processing the data through other devices or software. After the data at the tail is acquired, the data can be deleted from the tail to ensure that the data in the queue does not overflow.
[0056] The embodiment provides an electronic device 100, as shown in the figure, comprising a processor 101 and a memory 102. The memory 102 stores a computer program, which, when executed by the processor 101, implements each process of the above-mentioned modbus data acquisition method embodiment and achieves the same technical effect. To avoid repetition, details are not described here. Figure 5
[0057] The embodiment provides a storage medium, which stores computer instructions. When the computer instructions are executed by a processor, each process of the above-mentioned modbus data acquisition method embodiment is implemented, and the same technical effect is achieved. To avoid repetition, details are not described here.
[0058] Each embodiment in the present disclosure is described in a progressive manner, and the same or similar parts of each embodiment can be referred to each other. Each embodiment focuses on the difference 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 part of the method embodiment.
[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 recited in the claims can be performed in an order different than the order in which they are recited and still achieve desirable results. In addition, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order, to achieve the desired results. In some implementations, multitasking and parallel processing can be advantageous.
[0060] Embodiments of the present disclosure can be systems, methods, and / or computer program products. The computer program product can include a computer readable storage medium having computer readable program instructions loaded thereon for causing a processor to implement various aspects of embodiments of the present disclosure.
[0061] Computer readable storage media can be tangible storage media which can retain and store instructions for use by an instruction execution device. Computer readable storage media can be, for example, but is not limited to, an electronic 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 (a non-exhaustive list) of computer readable storage media include the following: a portable computer diskette, 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 disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire.
[0062] Computer readable program instructions described herein can be downloaded to respective computing / processing devices from a computer readable storage medium or to an external computer or external storage device via a network, for example, the Internet, a local area network, a wide area network and / or a wireless network. The network can comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and / or edge servers. A network adapter card or network interface in each computing / processing device receives computer readable program instructions from the network and forwards the computer readable program instructions for storage in a computer readable storage medium within the respective computing / processing device.
[0063] Computer readable program instructions for carrying out operations of embodiments of the present disclosure can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, or source or object code, in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++ or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer readable program instructions can execute entirely on a user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate array (FPGA), or programmable logic array (PLA) can execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of embodiments of the present disclosure.
[0064] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0065] These computer readable program instructions can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks. These computer readable program instructions can also be stored in a computer readable storage medium that can include random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other data storage device. When the computer readable program instructions are loaded into the computer and other programmable data processing apparatus, a series of operational steps are implemented that provide processes such that the computer or other programmable apparatus provide processes for implementing the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0066] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable data processing apparatus, or other device implement the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0067] The computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer implemented process, such that the instructions which execute on the computer, other programmable data processing apparatus, or other device implement the functions / acts specified in the flowchart and / or block diagram block or blocks.
[0068] Embodiments of the present disclosure have been described above, and the description is intended to be illustrative, and not restrictive, of the disclosed embodiments. Many modifications and variations of the described embodiments are possible, and all such modifications and variations are intended to be within the scope of the described embodiments. The description used herein is intended to best explain the principles of the various embodiments, the practical application, and the best mode of using the technology in the market, or to enable others skilled in the art to understand the various embodiments disclosed herein.
Claims
1. A Modbus data acquisition method, characterized in that, The method includes: In the Modbus configuration file, set the relevant parameters of the device to be acquired. The Modbus configuration file includes a system configuration file and an acquisition configuration file. The relevant parameters include the type of the device to be acquired, the communication address, the data acquisition parameters, and the data parsing parameters. Obtain the system configuration file and the acquisition configuration file, and obtain the type and communication address of the device to be acquired from the system configuration file; Based on the type of device to be collected, the data collection parameters and data parsing parameters of the device to be collected are obtained from the collection configuration file; A thread is created for the device to be collected based on its communication address, data collection parameters, and data parsing parameters. The thread collects data from the device to be collected and parses the data. The process of collecting data from the device to be collected via the thread includes: When the device to be collected includes multiple collection cycles, the multiple collection cycles are backed up, and the least common multiple of the multiple collection cycles is determined. Based on the multiple acquisition cycles, determine the relevant parameters of the acquisition cycle and the acquisition time interval of the device to be acquired, and acquire the data of the device to be acquired after the acquisition time interval has elapsed; Determine whether the first parameter in the relevant parameters of the acquisition period is equal to the least common multiple. If the first parameter is equal to the least common multiple, initialize the multiple acquisition periods and the relevant parameters of the acquisition period. The multiple acquisition periods are initialized through the backup, and the first parameter is the minimum value among the multiple acquisition periods. The steps of determining the relevant parameters of the acquisition period and the acquisition time interval of the device to be acquired are executed again, and after the acquisition time interval has elapsed, the data of the device to be acquired is acquired, and the first parameter in the relevant parameters of the acquisition period is determined to be equal to the least common multiple is also executed. The step of determining relevant parameters of the acquisition cycle and the acquisition time interval of the device to be acquired based on the multiple acquisition cycles, and acquiring data from the device to be acquired after the acquisition time interval has elapsed, includes: The acquisition time interval and the first parameter are determined, wherein the value of the first parameter is equal to the minimum value among the plurality of acquisition periods, the acquisition 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 elapsed, it is determined in turn whether the first period among the plurality of acquisition cycles is equal to the first parameter, wherein the first period is any one of the plurality of acquisition cycles; When the first period is equal to the first parameter, data is collected from the device to be 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.
2. The method according to claim 1, characterized in that, The data acquisition parameters include the acquisition cycle, acquisition method, register address to be acquired, and acquisition address length for each type of device to be acquired; The data parsing parameters include the offset of the first register address of each type of device to be acquired, the number of registers to be merged and parsed, data attributes, and acquisition accuracy.
3. The method according to claim 1, characterized in that, The step of creating a thread for the device to be acquired based on its communication address, data acquisition parameters, and data parsing parameters includes: Write the communication address, data acquisition parameters, and data parsing parameters of the device to be acquired into the cache structure to obtain the structural data of the device to be acquired. A thread is created for the device to be acquired based on the structure data.
4. The method according to claim 1, characterized in that, The data collected from the device to be collected via the thread includes: When the acquisition cycle of the device to be acquired is one, data from the device to be acquired is acquired based on the acquisition cycle.
5. The method according to claim 1, characterized in that, The method further includes: If the first period is not equal to the first parameter, continue to determine whether other acquisition periods among the plurality of acquisition periods are equal to the first parameter, or perform the step of determining whether the first parameter among the relevant parameters of the acquisition period is equal to the least common multiple.
6. The method according to claim 1, characterized in that, The data parsing parameters also include change parsing parameters, which are used to characterize whether the device to be collected is configured for change parsing. The parsing of the data includes: When the device to be collected is configured for change analysis, the data in the device to be collected that has changed is analyzed. If the device to be collected is not configured for change analysis, all the data will be analyzed.
7. The method according to claim 1, characterized in that, After collecting data from the device to be collected through the thread and parsing the data, the method further includes: The parsed data from the device to be collected is written to the head of the processing queue, and the data is read from the tail of the processing queue for corresponding processing.
8. A storage medium, characterized in that, It stores computer instructions that, when executed by a processor, implement the steps of the method described in any one of claims 1-7.
9. An electronic device, characterized in that, The device has a processor and a memory, the memory storing computer instructions that, when executed by the processor, implement the steps of the method according to any one of claims 1-7.
Citation Information
Patent Citations
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