A data storage method, related device, equipment and readable storage medium
Patent Information
- Application Number
- CN202311456974.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-03
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2043-11-03
AI Technical Summary
[0003]本申请实施例提供一种数据存储方法、相关装置、设备以及可读存储介质,该方法解决了通过Modbus协议读取设备参数效率低的问题
Smart Images

Figure CN117539794B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data storage, and in particular to a data storage method, related apparatus, device, and readable storage medium. Background Technology
[0002] The Modbus communication protocol is a widely used communication protocol between industrial devices. Electronic devices using the Modbus protocol include multiple Modbus registers to store the device's parameters. Each Modbus register stores a Modbus address, and these addresses map to the storage space containing the device's parameters. Other electronic devices can read and / or write the parameters stored in the Modbus registers by accessing the Modbus address. Summary of the Invention
[0003] This application provides a data storage method, related apparatus, device, and readable storage medium, which solves the problem of low efficiency in reading device parameters via the Modbus protocol.
[0004] In a first aspect, embodiments of this application provide a data storage method, comprising: detecting whether a second Modbus address stored in a storage space mapped by M consecutive first Modbus addresses in a first register is within an address range, wherein the first Modbus address is an address in the address programming segment of the first register; if the second Modbus address is within the address range, determining whether the second Modbus address is a first target Modbus address, wherein the parameter stored in the storage space mapped by the first target Modbus address is greater than 1 bit; if so, deleting a third Modbus address from the storage space mapped by the first Modbus address, wherein the third Modbus address... The address is the second Modbus address stored in the next memory space of the memory space where the first target Modbus address is located; starting from the memory space mapped by the second target Modbus address, the third Modbus address is written sequentially into the memory space mapped by the first Modbus address. The second target Modbus address is the address following the last first Modbus address in the M consecutive first Modbus addresses; the parameters in the memory space mapped by the second Modbus address are written into the memory spaces mapped by the L consecutive fourth Modbus addresses. The fourth Modbus address is the address in the address implementation segment of the second register, and L is less than or equal to M.
[0005] In conjunction with the first aspect, in one possible implementation, before detecting whether the second Modbus address stored in the storage space mapped by M consecutive first Modbus addresses in the first register is within the address range, the method further includes: creating an address programming segment in the first register, the address programming segment including N first Modbus addresses, the storage space mapped by each first Modbus address being used to store the second Modbus address of the storage space where the parameter to be read by the second electronic device is located, N being greater than or equal to M; and sequentially writing the second Modbus address into the storage space mapped by the M consecutive first Modbus addresses in the address programming segment.
[0006] In conjunction with the first aspect, in one possible implementation, a second Modbus address that is not within the address range is deleted from the storage space mapped by the M first Modbus addresses.
[0007] In conjunction with the first aspect, in one possible implementation, before sequentially writing the second Modbus address into the memory space mapped by the M consecutive first Modbus addresses in the address programming segment, the method further includes: performing address offset processing on the second Modbus address according to the address offset algorithm of the register corresponding to each second Modbus address to obtain the offset second Modbus address; the offset second Modbus address corresponding to different registers is a Modbus address in a different address range, and the offset second Modbus address is the address to be written into the memory space mapped by the first Modbus address.
[0008] In conjunction with the first aspect, in one possible implementation, after writing the parameters in the storage space of the second Modbus address mapping into the storage space of L consecutive fourth Modbus address mappings, the method further includes: sending a fifth Modbus address to the second electronic device, wherein the fifth Modbus address is the starting Modbus address among the L consecutive fourth Modbus addresses.
[0009] In conjunction with the first aspect, in one possible implementation, after sending the fifth Modbus address to the second electronic device, the method further includes: if the register corresponding to the storage space mapped by the second Modbus address is a read / write register, detecting whether the target parameter in the storage space mapped by the fourth Modbus address has changed; if so, updating the parameter of the storage space mapped by the third target Modbus address based on the changed target parameter, wherein the third target Modbus address is the second Modbus address corresponding to the fourth target Modbus address.
[0010] Secondly, embodiments of this application provide a data storage device, which includes a first detection unit, a first judgment unit, a first deletion unit, a first writing unit, and a second writing unit; wherein:
[0011] The first detection unit is used to detect whether the second Modbus address stored in the storage space mapped by the M consecutive first Modbus addresses in the first register is within the address range;
[0012] The first judgment unit is used to determine whether the second Modbus address is the first target Modbus address;
[0013] The first deletion unit is used to delete the third Modbus address from the storage space mapped by the first Modbus address;
[0014] The first write unit is used to write the third Modbus address sequentially into the storage space mapped by the first Modbus address, starting from the storage space mapped by the second target Modbus address.
[0015] The second write unit is used to write the parameters in the storage space of the second Modbus address mapping into L consecutive storage spaces of the fourth Modbus address mapping.
[0016] In conjunction with the second aspect, in one possible implementation, the data storage device further includes a creation unit and a third writing unit; wherein:
[0017] Create a unit for creating an address programming segment in the first register;
[0018] The third write unit is used to sequentially write the second Modbus address into the memory space mapped by the M consecutive first Modbus addresses in the address programming segment.
[0019] In conjunction with the second aspect, in one possible implementation, the data storage device further includes a second deletion unit; wherein:
[0020] The second deletion unit is used to delete a second Modbus address that is not within the address range from the storage space mapped by the M first Modbus addresses.
[0021] In conjunction with the second aspect, in one possible implementation, the data storage device further includes an offset unit; wherein:
[0022] The offset unit is used to: perform address offset processing on the second Modbus address according to the address offset algorithm of the register corresponding to each second Modbus address, so as to obtain the offset second Modbus address; the offset second Modbus address corresponding to different registers is the Modbus address in different address ranges, and the offset second Modbus address is the address to be written into the memory space mapped by the first Modbus address.
[0023] In conjunction with the second aspect, in one possible implementation, the data storage device further includes a transmission unit; wherein:
[0024] The transmitting unit is used to send the fifth Modbus address to the second electronic device.
[0025] In conjunction with the second aspect, in one possible implementation, the data storage device further includes a second detection unit and an update unit; wherein:
[0026] The second detection unit is used to detect whether the target parameters in the storage space of the fourth Modbus address mapping have changed;
[0027] The update unit is used to update the parameters of the storage space mapped by the third target Modbus address based on the changed target parameters.
[0028] Thirdly, embodiments of this application provide a data storage device, which includes a memory, a communication module, and a processor;
[0029] The memory is used to store program code, and the processor is used to call the program code stored in the memory to execute the data storage method in the first aspect and its various possible implementations.
[0030] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the data storage method described in the first aspect and its various possible implementations.
[0031] Fifthly, embodiments of this application provide a computer program including instructions that, when executed by a computer, cause a data storage device to perform the data storage method described in the first aspect and its various possible implementations. Attached Figure Description
[0032] The accompanying drawings used in the embodiments of this application are described below.
[0033] Figure 1 This is an exemplary Modbus address mapping table provided in the embodiments of this application;
[0034] Figure 2 This is a flowchart of a data storage method provided in an embodiment of this application;
[0035] Figure 3 This is a second Modus address example table provided in the embodiments of this application;
[0036] Figure 4 This is a schematic diagram of the structure of a data storage device 40 provided in an embodiment of this application;
[0037] Figure 5 This is a schematic diagram of the structure of a data storage device 50 provided in an embodiment of this application. Detailed Implementation
[0038] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. The term "embodiment" as used herein means that a specific feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of this application. The appearance of this phrase in different places in the specification does not necessarily indicate the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0039] The terms "first," "second," "third," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects and not to describe a particular order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, it may include a series of steps or units, or optionally, steps or units not listed, or other steps or units inherent to these processes, methods, products, or devices.
[0040] The accompanying drawings show only the portions relevant to this application, not all of them. Before discussing exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts depict operations (or steps) as sequential processes, many of these operations may be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations may be rearranged. The process may be terminated when its operation is completed, but may also have additional steps not included in the drawings. The process may correspond to a method, function, procedure, subroutine, subprogram, etc.
[0041] The terms “component,” “module,” “system,” “unit,” etc., used in this specification are used to refer to computer-related entities, hardware, firmware, combinations of hardware and software, software, or software in execution. For example, a unit can be, but is not limited to, a process running on a processor, a processor, an object, an executable file, a thread of execution, a program, and / or distributed between two or more computers. Furthermore, these units can be executed from various computer-readable media on which various data structures are stored. Units can communicate, for example, via local and / or remote processes based on signals having one or more data packets (e.g., data from a second unit interacting with another unit between a local system, a distributed system, and / or a network; for example, the Internet interacting with other systems via signals).
[0042] The Modbus communication protocol is a widely used communication protocol between industrial devices. Electronic devices using the Modbus protocol include multiple Modbus registers to store the device's parameters. Each Modbus register stores a Modbus address, and these addresses map to the storage space containing the device's parameters. Other electronic devices can read and / or write the parameters stored in the Modbus registers by accessing the Modbus address.
[0043] The Modbus communication protocol defines four types of registers: input registers, discrete registers, holding registers, and coil registers. Input registers and discrete registers are read-only registers, meaning they can only read the parameters of the electronic device stored therein. Holding registers and coil registers are read-write registers, meaning they can read, write, or modify the parameters stored therein. Different types of Modbus registers have corresponding Modbus address mapping tables. Each Modbus register's address mapping table includes the relationship between the register's corresponding Modbus address and the device parameters stored in the memory space mapped to that address.
[0044] For example, such as Figure 1 The image shows the Modbus address mapping table of electronic device 100. As can be seen, the Modbus address mapping table mainly includes two parts: the Modbus address and the corresponding device parameters. Assuming... Figure 1 The Modbus address mapping table in the table is the Modbus address mapping table of the discrete registers of electronic device 100, which is... Figure 1It can be seen that this discrete register corresponds to 200 Modbus addresses. The memory space mapped to Modbus address 00001 stores the cumulative power-on duration data of electronic device 100 this time; the memory space mapped to Modbus address 00002 stores the power-on count data of electronic device 100; the memory space mapped to Modbus address 00003 stores the real-time engine temperature data of electronic device 100; and so on. The memory space mapped to Modbus address 00200 stores the engine operating status data of electronic device 100 (e.g., normal or abnormal). Other electronic devices (e.g., electronic device 200) must read the Modbus addresses of the Modbus registers in electronic device 100 according to the order of the Modbus addresses in the Modbus address mapping table if they want to read the Modbus addresses. For consecutive Modbus addresses in the Modbus address mapping table, electronic device 200 can acquire multiple Modbus addresses in one frame of data, provided that the maximum number of Modbus addresses read in a single operation (N) does not exceed this limit. This allows access to the Modbus address mapping storage space and the acquisition of parameters within that storage space. If the Modbus addresses to be read by electronic device 200 are not consecutive in the Modbus address mapping table, and the number of Modbus addresses between them is less than or equal to N-2, then electronic device 200 can sequentially read these two Modbus addresses and the addresses between them in the address mapping table according to their address order. If the number of Modbus addresses between them is greater than N-2, then electronic device 200 needs to read the Modbus addresses multiple times, requiring multiple frames of data to acquire the addresses to be read.
[0045] For example, suppose the maximum number of Modbus addresses that electronic device 200 can read at one time is 50, and suppose electronic device 200 wants to read the above... Figure 1 The numbers 00001~00005, 00015~00020, 00056~00060, 00120~00130, and 00145~00150 are listed above. Therefore, electronic device 200 can first proceed according to the above... Figure 1 In the Modbus address mapping table, Modbus addresses 00001 to 00020 are read sequentially (Modbus addresses 00006 to 00014 are addresses not needed by electronic device 200 and can be discarded after reading); electronic device 200 can then proceed in the same manner a second time. Figure 1The Modbus addresses in the Modbus address mapping table are read sequentially from 00056 to 00060; the electronic device 200 can then proceed in the same manner for the third time. Figure 1 The Modbus addresses in the Modbus address mapping table are read sequentially from 00120 to 00130; electronic device 200 can follow the above procedure for the fourth time. Figure 1 The Modbus addresses in the Modbus address mapping table are read sequentially from 00145 to 00150. Each time the electronic device 200 reads an address from the Modbus address mapping table, it needs to read one frame of data. The electronic device 200 needs four times to read these 35 Modbus addresses, therefore requiring four frames of data. When the electronic device 200 subsequently reads parameters based on these four frames, it also needs to read them four times. However, the number of Modbus addresses read by the electronic device 200 is 35, which is less than the maximum number of Modbus addresses that can be read in a single operation (50). The fact that the electronic device 200 needs to read the Modbus addresses and parameters four times significantly reduces the efficiency of reading Modbus addresses and parameters.
[0046] Especially in the industrial field, electronic devices read parameters from other electronic devices in a relatively fixed manner. If an electronic device uses too many data frames to read Modbus addresses and parameters each time it reads parameters, it may cause delays in reading the device parameters. If the delay is too long, it may cause the device to interrupt its tasks.
[0047] Therefore, to address the problem of excessive parameter reading by electronic device 200 from electronic device 100, this application provides a data storage method. This method includes: creating an address programming segment in the first Modbus register of electronic device 100, where the memory space mapped by the address programming segment stores the Modbus address corresponding to the parameter to be read by electronic device 200. Then, the Modbus address corresponding to the parameter to be read by electronic device 200 is written into the memory space mapped by the address programming segment, resulting in a Modbus address set. If the Modbus address in the Modbus set passes verification, the parameter in the memory space mapped by the verified Modbus address is written into the memory space mapped by the address implementation segment of the second register of electronic device 100. Thus, when electronic device 200 needs to read parameters from electronic device 100, electronic device 100 can obtain the parameters simply by sending a first Modbus address to electronic device 200, allowing electronic device 200 to access the corresponding memory space based on the first Modbus address. The first Modbus address is the starting Modbus address of the parameter to be read by electronic device 200 in the address implementation segment.
[0048] The following describes the flow of a data storage method provided in an embodiment of this application, with reference to the accompanying drawings. Please refer to... Figure 2 , Figure 2 This is a flowchart of a data storage method provided in an embodiment of this application. The specific process is as follows:
[0049] S201: Create an address programming segment in the first register. The address programming segment includes N first Modbus addresses. The storage space mapped by each first Modbus address is used to store the second Modbus address of the storage space where the parameter to be read by the second electronic device is located. The first register is a register of the first electronic device.
[0050] Specifically, the first register is a Modbus register that can be read and written in the first electronic device, and the first electronic device can be the one described above. Figure 1 The electronic device 100 in the embodiment. Since different Modbus registers in the first electronic device have corresponding Modbus address mapping tables, as described above... Figure 1As described in the embodiment, when other electronic devices read parameters stored in the corresponding Modbus register of the first electronic device via the Modbus communication protocol, they must read them according to the Modbus address order in the Modbus address mapping table of the Modbus register. Furthermore, there is an upper limit to the number of Modbus addresses that an electronic device can read at one time. If the number of Modbus addresses read by the electronic device is less than or equal to the upper limit, and the interval between the Modbus addresses read by the electronic device in different Modbus registers or in the Modbus address mapping table is greater than or equal to the upper limit, then the electronic device may need to use multiple frames of data to obtain the Modbus address, and consequently, it may also need to use multiple frames of data to obtain the parameters stored in the Modbus address mapping space. This would significantly reduce the efficiency of the electronic device in reading parameters.
[0051] Therefore, a dedicated address implementation segment can be allocated in the Modbus register of the first electronic device to store parameters to be read by other electronic devices. First, the Modbus address of the storage space containing the parameter to be read needs to be obtained and stored in the dedicated storage space. Therefore, an address programming segment can be created in the first register, including N first Modbus addresses. The storage space mapped by the first Modbus addresses is used to store the Modbus address of the storage space containing the parameter to be read, i.e., the second Modbus address. Here, N can be the sum of the number of Modbus addresses in the storage spaces of all Modbus registers storing parameters in the first electronic device, or the sum of the number of Modbus addresses corresponding to the storage spaces of input registers and discrete registers storing parameters in the first electronic device, or the sum of the number of Modbus addresses in the storage spaces of holding registers and coil registers storing parameters in the first electronic device. This embodiment of the application does not limit this.
[0052] S202: Write the second Modbus address sequentially into the storage space mapped by the M consecutive first Modbus addresses in the address programming segment. The second Modbus address is the Modbus address corresponding to the storage space where the M parameters to be read by the second electronic device are located.
[0053] Specifically, after determining the M parameters to be read by the second electronic device from the first electronic device, the Modbus addresses (second Modbus addresses) corresponding to these M parameters can be sequentially written into the memory space mapped by the M consecutive first Modbus addresses in the address programming segment. Here, the second electronic device is the device that reads the parameters from the first electronic device. For example, the second electronic device can be as described above. Figure 1Electronic device 200 in the embodiment.
[0054] S203: Determine whether each of the second Modbus addresses is within the address range.
[0055] Optionally, after writing the M second Modbus addresses corresponding to the parameters into the memory space mapped by the M consecutive first Modbus addresses in the address programming segment, these M second Modbus addresses can be checked to determine whether they are within the address range. Specifically, this can be done by determining the type of the Modbus register corresponding to the programmable address segment, obtaining all Modbus addresses of that Modbus register, and thus obtaining the first address range. If a second Modbus address is within the first address range, it is determined that the second Modbus address is within the address range; otherwise, it is determined that the second Modbus address is not within the address range.
[0056] For example, assuming the memory space mapped to the first Modbus address of the address programming segment in the first register is used to store the addresses of discrete registers and / or input registers, all Modbus addresses of the discrete registers and input registers can be obtained. Assuming the minimum Modbus address of the discrete register is 000001 and the maximum Modbus address is 000400, then the first address range of the discrete register can be determined as [000001, 000400]; the minimum Modbus address of the input register is 000500 and the maximum Modbus address is 000800, then the first address range of the input register can be determined as [000500, 000800]. Then, it can be determined whether each second Modbus address is within the first address range [000001, 000400] or whether it is within the first address range [000500, 000800]. If a second Modbus address is not within either the first address range [000001, 000400] or the first address range [000500, 000800], then it is determined that the second Modbus address is not within the address range.
[0057] In some possible implementations, the Modbus addresses of different Modbus registers may overlap completely or partially. Therefore, before writing the Modbus address into the memory space mapped by the first Modbus address, the Modbus address to be written can be offset using the corresponding Modbus address offset algorithm based on the register to which the Modbus address to be written belongs, thus obtaining the offset Modbus address, which is the second Modbus address. For example, if the Modbus address ranges of the discrete register and the input register are [000200, 000600] and [000500, 000800] respectively, it can be seen that the Modbus addresses of the discrete register and the input register partially overlap (the overlapping part is 000500~00600). Therefore, for discrete registers, before writing all or part of their Modbus address into the memory space mapped by the first Modbus address, the Modbus address offset algorithm for that discrete register can be used to offset the Modbus address to be written to the range of 001000 to 001400. For input registers, before writing all or part of their Modbus address into the memory space mapped by the first Modbus address, the Modbus address offset algorithm for that input register can be used to offset the Modbus address to be written to the range of 001600 to 001900. In this way, the calculated second Modbus address of the discrete register and the second Modbus address of the input register are in different address ranges, thus avoiding the problem of overlapping Modbus addresses of different registers. This avoids the problem of the second electronic device not knowing which register to read data from due to multiple identical second Modbus addresses. Then, the address range of the register can be processed by the Modbus offset algorithm corresponding to that register to obtain the offset address range, which is the address range. Determine whether the second Modbus address is within the address range after the offset.
[0058] S204: Clear the second Modbus address that is not within the stated address range.
[0059] Specifically, if there is a second Modbus address that is not within the address range among these M second Modbus addresses, then the Modbus address that is not within the address range will be cleared.
[0060] In some embodiments, after a second Modbus address that is no longer in the address range is removed from the storage space, the storage space can be marked to indicate that the reason the storage space is currently empty is that a Modbus address that is no longer in the address range has been removed.
[0061] S205: Determine whether the first target Modbus address exists in the second Modbus address, and the parameter stored in the storage space mapped by the first target Modbus address is greater than 1 bit.
[0062] Specifically, the Modbus address mapping table in the Modbus register includes not only the Modbus address and the meaning of the corresponding parameter, but also the magnitude (in bits) of that parameter. The magnitude of the parameter corresponding to the second Modbus address can be viewed through the Modbus address mapping table of the register corresponding to the second Modbus address. If the parameter is greater than 1 bit, then the second Modbus address corresponding to that parameter is determined to be the first target Modbus address.
[0063] S206: If a first target Modbus address exists in the second Modbus address, the second Modbus address in the next storage space after the first target Modbus address in the address-programmed segment-mapped storage space is determined as the third Modbus address.
[0064] Specifically, if a first target Modbus address exists in the second Modbus address, the second Modbus address in the next memory space after the first target Modbus address in the memory space mapped by the address segment is determined as the third Modbus address. Then, the size of the parameters of the memory space mapped by the third Modbus address can be obtained.
[0065] S207: Delete the third Modbus address in the storage space mapped by the address programming segment in sequence.
[0066] Specifically, since some parameters are 2 bits in size, the storage space mapped to each Modbus address can only store 1 bit of the parameter. Therefore, storing a 2-bit parameter requires two storage spaces. This may result in a difference between the number of storage spaces for the parameter corresponding to the second Modbus address and the number of storage spaces for the second Modbus address itself. When writing the parameter corresponding to the second Modbus address into contiguous storage spaces in the register, if the number of storage spaces for the parameter and the second Modbus address differs, the available number of storage spaces for the parameter will be inconsistent with the available number of storage spaces in the address programming segment. Therefore, when the existence of the first target Modbus address is detected, the second Modbus address in the next storage space storing the first target Modbus address can be identified as the third Modbus address, and the third Modbus address in the storage space mapped to the address programming segment can be deleted. This way, the storage space previously storing the third Modbus address can be identified as the storage space corresponding to the first target Modbus address; that is, one first target Modbus address occupies two storage spaces. In this way, it is ensured that the amount of storage space occupied by the first target Modbus address is the same as the amount of storage space occupied by the parameters stored in the storage space mapped by the first target Modbus address.
[0067] S208: Starting from the storage space mapped by the second target Modbus address, write the third Modbus address into the storage space mapped by the address programming segment in sequence. The second target Modbus address is the address following the last Modbus address in the M consecutive first Modbus addresses.
[0068] Specifically, based on the size of the parameters stored in the storage space mapped by the third Modbus address, starting from the storage space mapped by the second target Modbus address, the third Modbus address is written into the storage space mapped by the address programming segment in sequence. The second target Modbus address is the last Modbus address among the M first Modbus addresses.
[0069] For example, Figure 3 This is a second Modus address example table provided in the embodiments of this application. Figure 3There are 10 second Modbus addresses, numbered 00010 to 00020. Assume the parameters stored in the memory spaces mapped to addresses 00011, 00012, and 00016 are 2 bits in size, while the parameters stored in the memory spaces mapped to other addresses are 1 bit in size. Then, 00011, 00012, and 00016 are determined as target Modbus addresses, and 00012, 00014, and 00016 are determined as third Modbus addresses. The addresses 00012, 00014, and 00016 can be deleted from the memory spaces mapped to addresses 12, 14, and 16, and 00012, 00014, and 00016 can be stored in the memory spaces mapped to address 21 (the second target Modbus address), address 22, and address 23, respectively.
[0070] S209: Obtain the parameters in the storage space mapped by the second Modbus address according to the second Modbus address.
[0071] Specifically, the storage space corresponding to the second Modbus address can be accessed based on the second Modbus address, and then the parameters stored in that storage space can be read.
[0072] In some embodiments, if the second Modbus address is an address processed by the address offset algorithm, the second Modbus address can be restored to the address before offset processing based on the inverse algorithm of the address offset algorithm. Then, the memory space mapped to it can be accessed according to the address before offset processing, and the parameters in the memory space can be obtained.
[0073] S210: Write the read parameters into the storage space of L consecutive fourth Modbus address mappings in the address implementation segment. The address implementation segment consists of multiple fourth Modbus addresses created in the second register. The storage space of the fourth Modbus address mappings in the address implementation segment is used to store the parameters in the storage space of the second Modbus address mapping.
[0074] Specifically, after obtaining L parameters from the storage space of the second Modbus address mapping, the read parameters can be written into L consecutive storage spaces of the fourth Modbus address mapping in the address implementation segment. Here, L is the number of second Modbus addresses, and L is less than or equal to M.
[0075] Through the above Figure 2In the embodiment, when the second electronic device needs to read / write parameters, the first electronic device only needs to send the first of the L fourth Modbus addresses to the second electronic device. The second electronic device can then obtain the read / write parameters starting from the storage space mapped by the first fourth Modbus address, according to the number of parameters to be read.
[0076] In some embodiments, when the register corresponding to the storage space mapped by the second Modbus address is a read / write register (e.g., a coil register, a holding register, etc.), after the second electronic device modifies the parameters in the storage space mapped by the fourth Modbus address by accessing the fourth Modbus address, the first electronic device can first obtain the second Modbus address corresponding to the fourth Modbus address. Then, it updates the parameters in the storage space mapped by the second Modbus address (if the second Modbus address is a Modbus address obtained after address offset processing, then it is the storage space mapped by the Modbus address before address offset processing) according to the modified parameters.
[0077] The methods of the embodiments of this application have been described in detail above. The related devices, equipment, computer-readable storage media, and computer programs of the embodiments of this application are described below.
[0078] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of a data storage device 40 provided in an embodiment of this application. The data storage device 40 may include a first detection unit 401, a first judgment unit 402, a first deletion unit 403, a first writing unit 404, and a second writing unit 405; wherein:
[0079] The first detection unit 401 is used to detect whether the second Modbus address stored in the storage space mapped by the M consecutive first Modbus addresses in the first register is within the address range;
[0080] The first judgment unit 402 is used to determine whether the second Modbus address is the first target Modbus address;
[0081] The first deletion unit 403 is used to delete the third Modbus address from the storage space mapped by the first Modbus address;
[0082] The first writing unit 404 is used to write the third Modbus address sequentially into the storage space mapped by the first Modbus address, starting from the storage space mapped by the second target Modbus address.
[0083] The second write unit 405 is used to write the parameters in the storage space of the second Modbus address mapping into L consecutive storage spaces of the fourth Modbus address mapping.
[0084] In one possible implementation, the data storage device 40 further includes a creation unit and a third writing unit; wherein:
[0085] Create a unit for creating an address programming segment in the first register;
[0086] The third write unit is used to sequentially write the second Modbus address into the memory space mapped by the M consecutive first Modbus addresses in the address programming segment.
[0087] In one possible implementation, the data storage device 40 further includes a second deletion unit; wherein:
[0088] The second deletion unit is used to delete a second Modbus address that is not within the address range from the storage space mapped by the M first Modbus addresses.
[0089] In one possible implementation, the data storage device 40 further includes an offset unit; wherein:
[0090] The offset unit is used to: perform address offset processing on the second Modbus address according to the address offset algorithm of the register corresponding to each second Modbus address, so as to obtain the offset second Modbus address; the offset second Modbus address corresponding to different registers is the Modbus address in different address ranges, and the offset second Modbus address is the address to be written into the memory space mapped by the first Modbus address.
[0091] In one possible implementation, the data storage device 40 further includes a transmission unit; wherein:
[0092] The transmitting unit is used to send the fifth Modbus address to the second electronic device.
[0093] In one possible implementation, the data storage device 40 further includes a second detection unit and an update unit; wherein:
[0094] The second detection unit is used to detect whether the target parameters in the storage space of the fourth Modbus address mapping have changed;
[0095] The update unit is used to update the parameters of the storage space mapped by the third target Modbus address based on the changed target parameters.
[0096] Please see Figure 5 , Figure 5This is a schematic diagram of the structure of a data storage device 50 provided in an embodiment of this application. The data storage device 50 may include a memory 501, a communication module 502, and a processor 503; wherein, the detailed description of each unit is as follows:
[0097] Memory 501 is used to store program code.
[0098] Processor 503 is used to call program code stored in memory to perform the following steps:
[0099] Check if the second Modbus address stored in the memory space mapped by the M consecutive first Modbus addresses in the first register is within the address range. The first Modbus address is the address in the address programming segment of the first register. If the second Modbus address is within the address range, determine if the second Modbus address is the first target Modbus address. The parameter stored in the memory space mapped by the first target Modbus address is greater than 1 bit. If so, delete the third Modbus address from the memory space mapped by the first Modbus address. The third Modbus address is the second Modbus address stored in the next memory space after the memory space where the first target Modbus address is located. Starting from the memory space mapped by the second target Modbus address, write the third Modbus address sequentially into the memory space mapped by the first Modbus address. The second target Modbus address is the address after the last first Modbus address in the M consecutive first Modbus addresses. Write the parameter in the memory space mapped by the second Modbus address into the memory space mapped by the L consecutive fourth Modbus addresses. The fourth Modbus address is the address in the address implementation segment of the second register, where L is less than or equal to M.
[0100] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0101] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0102] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0103] An address programming segment is created in the first register. The address programming segment includes N first Modbus addresses. The storage space mapped by each first Modbus address is used to store the second Modbus address of the storage space where the parameter to be read by the second electronic device is located. N is greater than or equal to M. The second Modbus addresses are written sequentially into the storage spaces mapped by the M consecutive first Modbus addresses in the address programming segment.
[0104] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0105] In the memory spaces mapped by the M first Modbus addresses, delete the second Modbus addresses that are not within the address range.
[0106] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0107] The second Modbus address is offset according to the address offset algorithm of the register corresponding to each second Modbus address to obtain the offset second Modbus address; the offset second Modbus address corresponding to different registers is the Modbus address in different address ranges, and the offset second Modbus address is the address to be written into the memory space mapped by the first Modbus address.
[0108] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0109] The fifth Modbus address is sent to the second electronic device through the communication module 502. The fifth Modbus address is the starting Modbus address among the L consecutive fourth Modbus addresses.
[0110] In one possible implementation, processor 503 is used to invoke program code stored in memory to perform the following steps:
[0111] If the register corresponding to the storage space mapped by the second Modbus address is a read / write register, check whether the target parameter in the storage space mapped by the fourth Modbus address has changed; if so, update the parameter of the storage space mapped by the third target Modbus address based on the changed target parameter, and the third target Modbus address is the second Modbus address corresponding to the fourth target Modbus address.
[0112] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the data storage method described in the above embodiments and their various possible implementations.
[0113] This application provides a computer program that includes instructions that, when executed by a computer, enable a data storage device to perform the processes executed by the data storage device in the above embodiments and their various possible implementations.
[0114] It should be noted that the memory in the above embodiments can be read-only memory (ROM) or other types of static storage devices capable of storing static information and instructions, random access memory (RAM) or other types of dynamic storage devices capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. The memory can exist independently and be connected to the processor via a bus. The memory can also be integrated with the processor.
[0115] The processor in the above embodiments may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the above scheme program.
[0116] For the foregoing method embodiments, in order to simplify the description, they are all expressed as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps may be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0117] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of the units described above is merely a logical functional division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0118] The units described above as separate components may or may not be physically separate. Similarly, the components shown as units may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0119] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The aforementioned integrated unit can be implemented in hardware or as a software functional unit.
[0120] If the aforementioned integrated units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in software form. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which can be a personal computer, server, or network device, specifically a processor in the computer device) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium may include various media capable of storing program code, such as a USB flash drive, portable hard drive, magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM).
[0121] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A data storage method, characterized in that, include: Detect whether the second Modbus address stored in the memory space mapped by M consecutive first Modbus addresses in the first register is within the address range, where the first Modbus address is the address in the address programming segment of the first register; If the second Modbus address is within the address range, determine whether the second Modbus address is the first target Modbus address, and the parameter stored in the storage space mapped by the first target Modbus address is greater than 1 bit; If so, delete the third Modbus address in the storage space mapped by the first Modbus address. The third Modbus address is the second Modbus address stored in the next storage space of the storage space where the first target Modbus address is located. Starting from the storage space mapped by the second target Modbus address, the third Modbus address is written sequentially into the storage space mapped by the first Modbus address. The second target Modbus address is the address following the last first Modbus address among the M consecutive first Modbus addresses. The parameters in the storage space mapped by the second Modbus address are written into the storage spaces mapped by the fourth Modbus address L consecutively. The fourth Modbus address is the address in the address implementation segment of the second register, and L is less than or equal to M.
2. The method as described in claim 1, characterized in that, Before detecting whether the second Modbus address stored in the memory space mapped by the M consecutive first Modbus addresses in the first register is within the address range, the method further includes: An address programming segment is created in the first register, which includes N first Modbus addresses. The storage space mapped by each first Modbus address is used to store the second Modbus address of the storage space where the parameter to be read by the second electronic device is located. The N is greater than or equal to the M. The second Modbus address is sequentially written into the memory space mapped by the M consecutive first Modbus addresses in the address programming segment.
3. The method as described in claim 1, characterized in that, In the storage space mapped by the M first Modbus addresses, delete the second Modbus address that is not within the address range.
4. The method as described in claim 2, characterized in that, Before sequentially writing the second Modbus address into the memory space mapped by the M consecutive first Modbus addresses of the address programming segment, the method further includes: The second Modbus address is offset according to the address offset algorithm of the register corresponding to each second Modbus address to obtain the offset second Modbus address; the offset second Modbus address corresponding to different registers is the Modbus address in different address ranges, and the offset second Modbus address is the address to be written into the memory space mapped by the first Modbus address.
5. The method according to any one of claims 1-4, characterized in that, After writing the parameters from the second Modbus address mapping storage space into L consecutive fourth Modbus address mapping storage spaces, the method further includes: Send a fifth Modbus address to the second electronic device, wherein the fifth Modbus address is the starting Modbus address among the L consecutive fourth Modbus addresses.
6. The method as described in claim 5, characterized in that, After sending the fifth Modbus address to the second electronic device, the method further includes: If the register corresponding to the storage space mapped by the second Modbus address is a read / write register, check whether the parameters in the storage space mapped by the fourth Modbus address have changed. If so, the parameters of the storage space mapped to the third target Modbus address are updated based on the changed parameters, wherein the third target Modbus address is the second Modbus address corresponding to the fourth Modbus address.
7. A data storage device, characterized in that, It includes a unit that performs the data storage method as described in any one of claims 1-6.
8. A data storage device, characterized in that, include: Memory and processor, wherein: The memory is used to store computer programs, the computer programs including program instructions; The processor is used to invoke the program instructions to cause the data storage device to perform the method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Modbus address remapping method used for electric quantity module
CN104407983A
Address transformation cache control method and device, equipment and medium
CN115658564A