Address allocation method and device, electronic equipment and storage medium

Through the broadcast address allocation information and polling and query request methods, slave devices in the Modbus network automatically allocate unique slave addresses, solving the problem of address conflicts and manual modification time-consuming, and improving the efficiency and success rate of address allocation.

CN119629152APending Publication Date: 2025-03-14SOLAR POWER NETWORK TECHNOLOGY (ZHEJIANG) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411649899.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

In the Modbus network, the slave addresses initialized by multiple slave devices may be the same or conflicting, resulting in communication conflicts and data confusion. The prior art requires manual modification of the slave address, which takes a long time and is less efficient.

Method used

By broadcasting address allocation information containing the protocol address in the preset range, the device to be allocated is allocated, and a query request for device information is sent to the protocol address in the preset range in accordance with the preset polling rules, the number of devices with successful address allocation is determined until all devices to be allocated are successfully allocated to the protocol address.

Benefits of technology

It improves the efficiency and success rate of address allocation, reduces the need to manually modify slave addresses, ensures that each slave device has a unique slave address, and avoids communication conflicts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119629152A_ABST
    Figure CN119629152A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of communication, and provides an address allocation method and device, electronic equipment and a storage medium, and the method comprises the steps: broadcasting address allocation information which comprises a protocol address in a preset range; sending a query request of the equipment information to a protocol address in a preset range according to a preset polling rule; based on response information corresponding to the query request, determining the number of devices with successfully allocated addresses; and if the number of the devices is smaller than that of the to-be-allocated devices, returning to execute the broadcast address allocation information. According to the method, whether the address is successfully allocated or not is determined by circularly broadcasting the address allocation information and polling the protocol addresses in the preset range in each cycle period, so that the address allocation efficiency and success rate are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to an address allocation method, device, electronic device and storage medium. Background Art

[0002] The Modbus communication protocol is a communication protocol based on a master-slave architecture, which defines the format and content of data transmission between master and slave devices. In a Modbus network, each slave device should have a unique slave address to identify the slave device. The host device can identify the slave device through the slave address and communicate with the slave device.

[0003] In the related art, a slave device usually initializes a slave address when it leaves the factory. However, in an application scenario where a host device communicates with multiple slave devices used in parallel, the slave addresses initialized by different slave devices may be the same or conflict. In order to ensure that multiple slave devices can communicate normally, the slave addresses initialized by the slave devices need to be manually modified to ensure the uniqueness of the slave addresses of each slave device. This method of setting slave addresses for slave devices is time-consuming and inefficient. Summary of the invention

[0004] In view of this, the present application provides an address allocation method, device, electronic device and storage medium to solve the problem of low address allocation efficiency in the related art.

[0005] A first aspect of an embodiment of the present application provides an address allocation method, which includes: broadcasting address allocation information, wherein the address allocation information includes a preset range of protocol addresses; sending a query request for device information to the protocol addresses within the preset range according to a preset polling rule; determining the number of devices with successfully allocated addresses based on the response information corresponding to the query request; if the number of devices is less than the number of devices to be allocated, returning to execute the broadcast address allocation information.

[0006] In some embodiments, determining the number of devices with successfully allocated addresses based on the response information corresponding to the query request includes: parsing the response information to obtain an initial serial number; if the initial serial number meets preset requirements and the protocol address corresponding to the initial serial number is a valid address, determining the device to be allocated that feeds back the response information as the target device, determining the initial serial number as the device serial number of the target device, and determining the protocol address corresponding to the device serial number as the target protocol address; determining the number of devices based on the number of target protocol addresses and the number of protocol addresses recorded in the first address list.

[0007] In some embodiments, the method further includes: if the protocol address corresponding to the initial serial number matches the protocol address recorded in the first address list, determining that the protocol address corresponding to the initial serial number is an invalid address; if the protocol address corresponding to the initial serial number does not match the protocol address in the first address list, determining that the protocol address corresponding to the initial serial number is a valid address.

[0008] In some embodiments, the method further includes: updating the device serial number and the corresponding target protocol address to the first address list.

[0009] In some embodiments, after determining the initial serial number as the device serial number and using the protocol address corresponding to the device serial number as the target protocol address, the method further includes: broadcasting the device serial number and the corresponding target protocol address of the target device, instructing the target device to write the target protocol address into a preset memory.

[0010] In some embodiments, after broadcasting the device serial number and the corresponding target protocol address, the method further includes: sending an exit allocation instruction to the target device to instruct the target device to stop responding to the address allocation information.

[0011] In some embodiments, the method further includes: responding to an allocation instruction for the continuous address of the device to be allocated, if the target protocol address is obtained for the first time, comparing the target protocol address with the initial address of the continuous address; if the target protocol address is consistent with the initial address, updating the target protocol address and the corresponding device serial number to a second address list; if the target protocol address is not obtained for the first time, obtaining the last address from the continuous addresses recorded in the second address list; if the target protocol address has a continuation relationship with the last address, updating the target protocol address and the corresponding device serial number to the second address list.

[0012] A second aspect of an embodiment of the present application provides an address allocation device, which includes: a broadcast module for broadcasting address allocation information, wherein the address allocation information includes a preset range of protocol addresses; a polling module for sending a query request for device information to the protocol address within the preset range according to a preset polling rule; a determination module for determining the number of devices to which addresses have been successfully allocated based on response information corresponding to the query request; and a judgment module for returning to execute the broadcast address allocation information if the number of devices is less than the number of devices to be allocated.

[0013] A third aspect of an embodiment of the present application provides an electronic device, comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor implements the above-mentioned address allocation method when executing the computer-readable instructions.

[0014] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions implement the above-mentioned address allocation method when executed by a processor.

[0015] In the address allocation method provided in the embodiment of the present application, the address is allocated to the device to be allocated by broadcasting the address allocation information containing the protocol address in the preset range. After broadcasting the address allocation information, according to the preset polling rule, a query request for device information is sent to the protocol address in the preset range. If the protocol address is successfully allocated, the response information of the target device corresponding to the protocol address to the query request will be received. If the protocol address is not successfully allocated, there is no target device corresponding to the protocol address, and the response information to the query request cannot be received. Therefore, the number of devices to which the address is successfully allocated can be determined based on the response information corresponding to the query request. In order to ensure that all devices to be allocated are allocated to the protocol address, the number of devices can be compared with the number of devices to be allocated. If the number of devices is less than the number of devices to be allocated, the broadcast address allocation information can be returned to execute until the number of devices is equal to the number of devices to be allocated. This method determines whether the address is successfully allocated by cyclically broadcasting the address allocation information and polling the protocol address in the preset range in each cycle, thereby improving the efficiency and success rate of address allocation. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0017] Figure 1 This is an application scenario diagram of the address allocation method provided in an embodiment of the present application.

[0018] Figure 2 It is a flowchart for implementing the address allocation method provided in the embodiment of the present application.

[0019] Figure 3 It is a data interaction diagram of the address allocation method provided in an embodiment of the present application.

[0020] Figure 4 It is a structural diagram of the address allocation device provided in an embodiment of the present application.

[0021] Figure 5 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0023] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way.

[0024] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by technicians in the technical field in this application. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. It should be understood that, unless otherwise specified in this application, " / " means or. For example, A / B can represent A or B. "And / or" in this application is only a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. "At least one" means one or more. "Multiple" means two or more than two. For example, at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c, a, b and c seven situations.

[0025] The communication network based on the Modbus communication protocol is a master-slave network. In the Modbus communication network, the command / response communication method is adopted. The master device sends a request, and the slave device responds to the request and sends back data or status information. The Modbus communication protocol supports multiple communication methods, such as Remote Terminal Unit (RTU) mode, Transmission Control Protocol / Internet Protocol (TCP / IP), etc.

[0026] For example, in a multi-machine parallel inverter system, the Energy Management System (EMS) can communicate with the inverter based on the Modbus communication protocol (such as the Modbus-RTU communication protocol) to achieve operations such as data acquisition, power control, and parameter setting. The inverter is equipped with a communication interface (such as RS-485, Ethernet communication interface, etc.) for connecting to the EMS or other external devices. These communication interfaces can support the communication protocol used to communicate with the EMS, such as the Modbus communication protocol. In the process of EMS and the inverter communicating based on the Modbus communication protocol, the inverter needs to be configured with a unique slave address. The EMS can address and communicate with the corresponding inverter through the slave address corresponding to the inverter. Ensuring that each inverter is configured with a unique slave address in the parallel system can avoid communication conflicts and data confusion, and ensure the accuracy of EMS's identification and control of the inverter and the normal communication between multiple parallel inverters.

[0027] In the related art, a slave address is usually initialized when each inverter leaves the factory. When multiple inverters are used in parallel, the slave addresses initialized by different inverters may be the same or conflict. Therefore, in the parallel system, it is usually necessary to manually modify these initialized slave addresses to ensure uniqueness. This method of setting the slave address is time-consuming and inefficient.

[0028] In order to solve the above problems, the present application provides an address allocation method, which improves the efficiency and success rate of address allocation by cyclically broadcasting address allocation information and polling protocol addresses within a preset range in each cycle to determine whether the address is allocated successfully.

[0029] See also Figure 1 As shown in FIG. 1 , an application scenario diagram of the address allocation method provided in an embodiment of the present application is shown. Figure 1 As shown, the electronic device 100 is connected to the devices 1 to N to be allocated via a network, where N is an integer greater than 0.

[0030] In the process of implementing address allocation for devices 1 to N to be allocated, the electronic device broadcasts address allocation information, wherein the address allocation information includes a preset range of protocol addresses. The device to be allocated receives the broadcasted address allocation information, parses the address allocation information, obtains a preset range of protocol addresses, randomly obtains an address from the preset range of protocol addresses, and modifies the slave address initialized in the device to be allocated to the address. The electronic device sends a query request for device information to the protocol address within the preset range according to the preset polling rule. Based on the response information of the query request, it can be determined whether the device to be allocated is successfully allocated with a protocol address, and by counting the number of devices that are successfully allocated with a protocol address, the number of devices that are successfully allocated with an address can be determined. The electronic device compares the number of devices that are successfully allocated with an address with the number of devices to be allocated. If the number of devices that are successfully allocated with an address is less than the number of devices to be allocated, it indicates that the address of a device to be allocated is not successfully allocated. In this case, the electronic device returns to execute the broadcast information until all devices to be allocated are successfully allocated with a protocol address. The electronic device can exit the loop and end the address allocation. Using this method, the efficiency and success rate of address allocation can be effectively improved.

[0031] In some embodiments, the network includes but is not limited to a wired communication network and a wireless communication network.

[0032] In some embodiments, the electronic device may be a control device, such as one or more devices of a control system (such as an EMS). For the convenience of the following description, the embodiment of the present application takes the electronic device as an independent device, and the electronic device communicates with the devices 1 to N to be allocated based on the Modbus communication protocol to implement the control and management of the devices 1 to N to be allocated. For example, the electronic device is a control device in an EMS, and the devices 1 to N to be allocated are multiple inverters connected in parallel.

[0033] Figure 1 The scenarios shown are only illustrative examples, and the address allocation method provided in this application can also be applied in other scenarios. For example, in some scenarios, it can include a terminal device or a host computer, an electronic device 100, and devices 1 to N to be allocated; in some scenarios, other types of devices can also be included. In summary, the embodiments of this application do not limit the specific application scenarios of the address allocation method.

[0034] See also Figure 2 The figure is a flowchart of the implementation of the address allocation method provided in the embodiment of the present application. The method is applied to electronic devices. The embodiment of the present application is applied to the method in Figure 1 The electronic device 100 in FIG. 1 is used as an example for explanation. The method includes the following steps. S11: Broadcast address allocation information, where the address allocation information includes a protocol address in a preset range.

[0035] In some embodiments, the protocol address represents a unique identification code or address identifier assigned to the device to be assigned under the communication protocol framework based on which the electronic device communicates with the device to be assigned, and is used to uniquely identify the device to be assigned in the network or communication link. For example, if the electronic device communicates with the device to be assigned based on the Modbus protocol, the protocol address is a Modbus address or slave address that can be assigned to the device to be assigned.

[0036] In some embodiments, the specific address of the protocol address in the preset range can be customized. Taking the electronic device communicating with the device to be allocated based on the Modbus protocol as an example, in the Modbus network, the address range of the slave device is usually 0 to address 247. Among them, address 0 is used as a broadcast address for sending broadcast instructions to all slave devices on the network, and the available slave address range is address 1-address 247, then the protocol address in the preset range can be selected from address 1-address 247, for example, it can be set to address 1 to address 20. For the specific address setting of the protocol address in the preset range, the embodiment of the present application is not limited.

[0037] In some embodiments, to ensure that all devices to be allocated are allocated protocol addresses, the electronic device can determine the number of protocol addresses that can be allocated according to the number of devices to be allocated, and set the number of protocol addresses within a preset range so that the number of protocol addresses within the preset range can cover the number of devices to be allocated. For example, if the number of devices to be allocated is 10, the number of protocol addresses that can be allocated can be set to 20.

[0038] In some embodiments, the address allocation information can be expressed in the form of an address allocation instruction. The electronic device sends a broadcast address allocation instruction to set an allocation protocol address for the device to be allocated. The device to be allocated can monitor instructions or data packets on the communication link between the electronic device. When receiving the address allocation instruction, the device to be allocated can parse the address allocation instruction, obtain a preset range of protocol addresses, and respond to the address allocation instruction, randomly select any protocol address from the preset range of protocol addresses, and modify the slave address initialized in the device to be allocated to the any protocol address.

[0039] In some embodiments, if the number of protocol addresses in the preset range is set to be the same as the number of devices to be assigned, it will be easy for different devices to be assigned to select the same protocol address, resulting in address duplication. In the subsequent verification of the device to which the address has been successfully assigned, it is easy for a query request for the same protocol address to receive multiple response information, resulting in data conflicts and even confusion on the communication link, which can easily lead to a longer time-consuming address allocation and affect the efficiency of address allocation.

[0040] In order to solve the above problem, the electronic device can set the number of protocol addresses in the preset range to be greater than the number of devices to be allocated, so as to reduce the probability of duplication of protocol addresses selected by different devices to be allocated, thereby saving the time of address allocation and improving the efficiency of address allocation. For example, the electronic device can set the number of protocol addresses in the preset range to be twice or more than the number of devices to be allocated. The embodiment of the present application does not limit the specific setting of the number of protocol addresses in the preset range.

[0041] In some embodiments, in a scenario where communication is performed based on the Modbus communication protocol, the method of triggering address allocation can be that when the device to be allocated is first connected to the Modbus communication network where the electronic device is located, a unique Modbus address needs to be allocated to the device to be allocated. This Modbus address will serve as the identity of the device to be allocated in the Modbus communication network for subsequent communication and data exchange.

[0042] In other embodiments, the method of triggering address allocation may also be other methods, which are not limited by the embodiments of the present application.

[0043] In some embodiments, the electronic device may also be connected to a terminal device for communication. A user may set a preset range of protocol addresses through the terminal device, and the terminal device encapsulates the preset range of protocol addresses into an address setting instruction and sends it to the electronic device. The electronic device responds to the address setting instruction, and the preset range of protocol addresses may be obtained by parsing the address setting instruction. The electronic device generates address allocation information according to the preset range of protocol addresses.

[0044] In other embodiments, the electronic device can determine the number of protocol addresses in a preset range that need to be set based on the determined number of devices to be allocated, and then select protocol addresses that meet the quantity requirements from the available protocol addresses, determine the protocol addresses in the preset range, and generate address allocation information based on the protocol addresses in the preset range.

[0045] In other embodiments, the electronic device may generate the address allocation information in other ways. The embodiment of the present application does not limit the way of generating the address allocation information.

[0046] In some embodiments, the electronic device can send the address allocation information in the form of a data packet to all devices to be allocated through the communication interface and the network topology. In the process of broadcasting the address allocation information, the electronic device can use a designated broadcast address or broadcast identifier to identify these data packets.

[0047] In some embodiments, in order to ensure the security of the communication process, security authentication may be performed between the electronic device and the device to be distributed, such as identity verification, data encryption, etc., to prevent unauthorized access and data leakage.

[0048] S12: According to a preset polling rule, a query request for device information is sent to a protocol address within a preset range. In some embodiments, the preset polling rule indicates the order and timing of the electronic device sending query requests to the protocol address. For example, the preset polling rule can be set so that the electronic device sends query requests for device information to the protocol addresses within the preset range in a fixed order (for example, in ascending or descending order of the protocol addresses within the preset range, or in a specified priority order, etc.). Alternatively, the preset polling rule can be set to polling based on time sequence, for example, the electronic device sends a query request for device information to the protocol address at fixed time intervals (such as every second, every millisecond, etc.). Or the preset polling rule can be set to send query requests for device information to the protocol addresses within the preset range in a fixed order and time sequence. The specific settings of the preset polling rules are not limited in the embodiments of the present application.

[0049] In some embodiments, the device information includes information that can be used to uniquely identify the device to be allocated, such as a device serial number (SN) and the like.

[0050] In some embodiments, the query request indicates a request for querying device information of the device to be allocated. The request frame of the query request may include information such as a protocol address, a function code, data, and a check code.

[0051] In some embodiments, the electronic device allocates a protocol address to the device to be allocated by broadcasting address allocation information. However, the device to be allocated may not receive the broadcast address allocation information due to network failure, security software settings, etc., or receive the address allocation information, but due to reasons such as device failure of the device to be allocated, the device to be allocated is not successfully allocated to the protocol address. Therefore, in order to ensure that all devices to be allocated are successfully allocated to the protocol address, and each device to be allocated is allocated to a unique protocol address, the electronic device can send a query request for device information to the protocol address within a preset range according to the preset polling rule. If the protocol address is successfully allocated to the device to be allocated, the electronic device sends a query request to the protocol address, and the corresponding device to be allocated will respond to the query request and return a response information containing the device information of the device to be allocated. Therefore, the electronic device can determine the number of devices to which the address is successfully allocated based on the response information corresponding to the query request, and determine whether to take measures based on the number of devices to which the address is successfully allocated, such as cyclically broadcasting the address allocation information, to ensure that all devices to be allocated are allocated to the protocol address and ensure the success rate of address allocation.

[0052] In some embodiments, since the device information is used to uniquely identify the device to be assigned, the electronic device determines the number of devices to which addresses have been successfully assigned by requesting the device information of the device to be assigned based on the protocol address, thereby ensuring the success rate of assigning addresses to the devices to be assigned while ensuring the uniqueness of the assigned addresses.

[0053] In some embodiments, the device to be assigned can monitor messages on the communication link. When the device to be assigned is successfully assigned to a protocol address, when it monitors request information that matches the protocol address corresponding to the device to be assigned, such as a query request sent by an electronic device, the device to be assigned can respond to the query request and return the response information to the electronic device that sent the query request.

[0054] S13: Determine the number of devices to which addresses are successfully allocated based on the response information corresponding to the query request.

[0055] In some embodiments, if the protocol address is successfully assigned to the device to be assigned, the device to be assigned can respond to the query request sent by the electronic device to the protocol address, obtain the device information of the device to be assigned, and package the device information to generate response information, and feed the response information back to the electronic device. At this time, the response information can include the protocol address assigned to the device to be assigned, the data information requested by the electronic device, such as the device information of the device to be assigned. Therefore, the electronic device can determine the number of devices to which the address is successfully assigned by analyzing the response information corresponding to the query request.

[0056] In some embodiments of the present application, the electronic device determines the number of devices to which addresses have been successfully allocated based on the response information corresponding to the query request, including: parsing the response information to obtain an initial serial number; if the initial serial number meets preset requirements and the protocol address corresponding to the initial serial number is a valid address, determining the device to be allocated that feeds back the response information as the target device, determining the initial serial number as the device serial number of the target device, and determining the protocol address corresponding to the device serial number as the target protocol address; determining the number of devices based on the number of target protocol addresses and the number of protocol addresses recorded in the first address list.

[0057] In some embodiments, the initial serial number is the serial number of the device that returns the response information in response to the query request. The preset requirements include that the initial serial number meets the requirements of uniqueness and consistency, and the composition, format, rules, etc. of the initial serial number meet the specifications. The specific settings of the preset requirements are not limited in the embodiments of the present application.

[0058] In some embodiments, the effective address represents a protocol address that uniquely identifies a device (eg, a device to be assigned), the target device represents a device to be assigned to which the address is successfully assigned, and the target protocol address represents a unique protocol address that is successfully assigned to the device to be assigned.

[0059] In some embodiments, the first address list stores device information (eg, device serial number) and corresponding unique protocol address of the device to be assigned to which the address is successfully assigned.

[0060] In some embodiments, the device serial number of the device to be allocated is unique and can uniquely identify the device to be allocated, and is used to verify the identity of the device to be allocated or to determine whether the device to be allocated has the authority to participate in a specified operation or communication. Therefore, determining the accuracy of the device serial number of the device to be allocated is crucial to verifying the identity of the device to be allocated.

[0061] After receiving the response information corresponding to the query request, the electronic device can parse the response information. If the initial serial number of the device that fed back the response information is obtained, the electronic device can determine whether the device performs identity authentication by judging whether the initial serial number meets the preset requirements, and determine whether the device is a device to be allocated. If it is determined whether the initial serial number meets the preset requirements, the electronic device can determine that the device is a device to be allocated, and the initial serial number is the device serial number of the device to be allocated.

[0062] In some embodiments, if the initial serial number meets the preset requirements, the electronic device can determine that the device corresponding to the initial serial number is a device to be allocated, and the device to be allocated is allocated to a protocol address. However, since the electronic device broadcasts a preset range of protocol addresses, it is possible that multiple devices to be allocated obtain the same protocol address, or that the device to be allocated is allocated to an already allocated protocol address, resulting in different addresses of devices to be allocated being repeated. Therefore, after determining that the initial serial number meets the preset requirements, the electronic device also needs to determine whether the protocol address corresponding to the initial serial number is a valid address. If the protocol address corresponding to the initial serial number is a valid address, it indicates that the protocol address uniquely identifies the device to be allocated corresponding to the initial serial number. At this time, the electronic device can determine that the device to be allocated is successfully allocated to a unique protocol address, and the address of the device to be allocated is successfully allocated, and the device to be allocated can be determined as a target device, the initial serial number is determined as the device serial number of the target device, and the unique protocol address to which the allocation device is successfully allocated is determined as the target protocol address.

[0063] In some embodiments, the electronic device may determine the total number of devices to which the current address is successfully allocated based on the number of target devices and the number of devices to be allocated to which the addresses are successfully allocated recorded in the first address list.

[0064] In some embodiments, since the target protocol address is a unique address identifier of the target device, the first address list stores unique protocol addresses of devices to be assigned whose addresses have been successfully assigned. Therefore, the electronic device can determine the number of target devices by counting the number of target protocol addresses, and determine the number of devices to be assigned whose addresses have been successfully assigned by determining the number of unique protocol addresses recorded in the first address list.

[0065] In other embodiments, if the query request is not successfully executed, the device to be allocated may also return response information corresponding to the query request. In this case, the response information may be an error prompt information to notify the electronic device that the query request is not successfully executed.

[0066] In some embodiments, if the response information received by the electronic device is an error prompt information or the electronic device does not receive the response information corresponding to the query request, the electronic device may regard the protocol address corresponding to the query request as a protocol address that has not been successfully allocated.

[0067] In some embodiments of the present application, if the protocol address corresponding to the initial serial number matches the protocol address recorded in the first address list, the protocol address corresponding to the initial serial number is determined to be an invalid address; if the protocol address corresponding to the initial serial number does not match the protocol address in the first address list, the protocol address corresponding to the initial serial number is determined to be a valid address.

[0068] In some embodiments, the first address list stores device information (e.g., device serial number) and corresponding unique protocol address of the device to be assigned to which the address is successfully assigned. To ensure the uniqueness of the protocol address, avoid address duplication, and avoid repeated recording of the same protocol address in the first address list, which leads to waste of resources, the electronic device can determine whether the protocol address corresponding to the initial serial number is a valid address by matching the protocol address corresponding to the initial serial number with the protocol address recorded in the first address list.

[0069] In some embodiments, if the protocol address corresponding to the initial serial number does not match the protocol address in the first address list, it indicates that the protocol address corresponding to the initial serial number is different from the protocol address in the first address list, and the electronic device can determine that the protocol address corresponding to the initial serial number is a valid address. If the protocol address corresponding to the initial serial number matches the protocol address recorded in the first address list, it indicates that the protocol address corresponding to the initial serial number is repeated with the protocol address in the first address list, and the electronic device can determine that the protocol address corresponding to the initial serial number is an invalid address.

[0070] In other embodiments, the method of determining that the protocol address corresponding to the initial serial number is an invalid address also includes: if the electronic device obtains multiple initial serial numbers in response to the query request corresponding to any protocol address, then the electronic device can determine that any protocol address may be assigned to multiple devices to be assigned, and the electronic device can determine any protocol address as an invalid address.

[0071] In other embodiments, the electronic device may also determine valid addresses and invalid addresses by other means, which is not limited by the embodiments of the present application.

[0072] In some embodiments of the present application, the electronic device may update the device serial number of the target device and the corresponding target protocol address to the first address list to ensure the uniqueness of the protocol address and facilitate operations such as addressing and communication with the target device.

[0073] In some embodiments, after updating the device serial number and the corresponding target protocol address of the target device to the first address list, the electronic device can determine the number of devices with successfully assigned addresses by determining the number of all protocol addresses stored in the first address list.

[0074] In some embodiments of the present application, after the initial serial number is determined as the device serial number and the protocol address corresponding to the device serial number is used as the target protocol address, the electronic device can also broadcast the device serial number and the corresponding target protocol address of the target device, instructing the target device to write the target protocol address into a preset memory.

[0075] In some embodiments, the preset memory may be an electrically erasable programmable read-only memory (EEPROM), etc. The embodiments of the present application do not limit the specific type of the preset memory.

[0076] In some embodiments, the target device monitors the device serial number and the corresponding target protocol address broadcast by the electronic device, and can compare the device serial number of the target device with the device serial number in the broadcast information. If the device serial number of the target device is consistent with the device serial number in the broadcast information, the target device can write the target protocol address into a preset memory. If the device serial number of the target device is inconsistent with the device serial number in the broadcast information, the target device does not process the broadcast information.

[0077] In some embodiments of the present application, after broadcasting the device serial number and the corresponding target protocol address, the electronic device may also send an exit allocation instruction to the target device to instruct the target device to stop responding to the address allocation information.

[0078] In some embodiments, since the device to be allocated an address successfully may need to respond to the address allocation information broadcast by the electronic device again in a subsequent cycle, which increases the time required for address allocation, wastes resources, and affects the efficiency of address allocation, after broadcasting the device serial number and the corresponding target protocol address, the electronic device may also send an exit allocation instruction to the target device, instructing the target device to stop responding to the address allocation information.

[0079] In the embodiment of the present application, the electronic device makes the entire allocation process efficient and orderly through an automated allocation and exit mechanism, thereby avoiding duplicate allocation and waste of resources.

[0080] S14: Determine whether the number of devices is less than the number of devices to be allocated.

[0081] In some embodiments, the number of devices indicates the number of devices to which addresses are successfully assigned. The electronic device can determine whether all the devices to be assigned are successfully assigned protocol addresses by comparing the number of devices to which addresses are successfully assigned with the number of devices to be assigned.

[0082] S15: If the number of devices is greater than or equal to the number of devices to be allocated, it is determined that the allocation is successful.

[0083] In some embodiments, if it is determined that the number of successfully allocated addresses is the same as the number of devices to be allocated, it indicates that the electronic device can determine that all devices to be allocated are successfully allocated to the protocol addresses.

[0084] In some embodiments, after the electronic device determines that all devices to be allocated are successfully allocated to protocol addresses, it can end the address allocation and record the device information of the devices to be allocated and the corresponding successfully allocated protocol addresses to provide a basis for subsequent identification and communication of the devices to be allocated.

[0085] In some embodiments of the present application, if the number of devices is less than the number of devices to be allocated, the broadcast address allocation information is returned.

[0086] In some embodiments, if the number of devices to which addresses are successfully allocated is less than the number of devices to be allocated, it indicates that there are devices to be allocated that have not been allocated a protocol address or have not been successfully allocated a unique protocol address. In this case, the electronic device can return to perform broadcast address allocation information to ensure that all devices to be allocated are successfully allocated a unique protocol address.

[0087] In some other embodiments of the present application, the electronic device can also preset the number of cycles in advance. In this case, if the number of devices with successful address allocation is less than the number of devices to be allocated, the electronic device can further determine whether the preset number of cycles is reached. If the number of cycles is reached, the electronic device can determine that the address allocation fails (or there are devices to be allocated that have not been successfully allocated unique protocol addresses). If the number of cycles is not reached, the electronic device can return to execute the broadcast address allocation information. If the address allocation fails, the electronic device can generate a prompt message to prompt the user that there are devices to be allocated that have not been successfully allocated unique protocol addresses. In some embodiments, the prompt message can include information about the devices with successful address allocation and the corresponding protocol addresses, etc. The form of the prompt message includes but is not limited to pop-up windows, text messages, emails, etc. The specific content and form of the prompt message are not limited in the embodiments of the present application.

[0088] In the embodiments of the present application, through multiple broadcasts and polling queries, the high success rate and accuracy of device address allocation are ensured, and the possibility of allocation failure is reduced.

[0089] As an example, please refer to Figure 3 , Figure 3 which shows the data interaction schematic diagram of the address allocation method provided by the embodiments of the present application. As Figure 3 shown, the energy management system communicates with multiple parallel inverters based on the Modbus-RTU protocol. The energy management system allocates Modbus addresses to multiple parallel inverters through multiple broadcasts and polling queries. As Figure 3 shown, n represents the number of multiple parallel inverters; m represents the number of devices with successful address allocation; i represents the number of protocol addresses polled; k represents the number of devices with successful address allocation; j represents the number of devices with successfully written addresses. The initial values of m, i, j, and k are 0. In this embodiment, the number of protocol addresses in the preset range is taken as 2n. During the process of address allocation by the energy management system, if the number of devices with successful address allocation is less than the number of multiple parallel inverters (m < n), the energy management system broadcasts an automatic allocation instruction, and multiple parallel inverters monitor the broadcast automatic allocation instruction and enter the address allocation state. Then the energy management system broadcasts the information containing the protocol addresses in the preset range. The inverter obtains the protocol addresses in the preset range, can randomly select any protocol address from the protocol addresses in the preset range, and modify the initialized slave address in the inverter to the any protocol address.

[0090] The energy management system polls 2n protocol addresses in sequence according to the preset polling rules, sends a query request to the protocol address, and queries the device serial number of the inverter. The inverter responds to the query request and returns a response message containing the device serial number. The energy management system parses the response message, obtains the device serial number and the protocol address corresponding to the response message, and if it is determined that the device serial number is correct (for example, it meets the preset requirements) and the corresponding protocol address is a valid address (for example, it has not been assigned), the energy management system can determine that the protocol address is successfully assigned to the inverter. The energy management system can record the device serial number and the corresponding protocol address of the inverter, and accumulate the number of devices with successful address assignment (such as m++, k++). For the inverter with a successful address assignment, the electronic device can broadcast the device serial number and the corresponding protocol address of the inverter, instruct the corresponding inverter to write the corresponding protocol address into a preset memory (for example, EEPROM) and exit the address assignment. The inverter receives the broadcasted device serial number and the corresponding protocol address, and can compare the broadcasted device serial number with its own device serial number. If the broadcasted device serial number is consistent with its own device serial number, the corresponding inverter can write the protocol address corresponding to the broadcasted device serial number into the preset memory (such as EEPROM) and exit the address allocation mode. If the broadcasted device serial number is inconsistent with its own device serial number, the inverter can wait for the next round of address allocation until all inverters are successfully allocated a unique protocol address.

[0091] In other embodiments of the present application, the electronic device responds to an allocation instruction for a continuous address of a device to be allocated. If the target protocol address is obtained for the first time, the initial address of the continuous address of the target protocol address is compared. If the target protocol address is consistent with the initial address, the target protocol address and the corresponding device serial number are updated to the second address list; if the target protocol address is not obtained for the first time, the last address is obtained from the continuous addresses recorded in the second address list; if the target protocol address and the last address have a continuation relationship, the target protocol address and the corresponding device serial number are updated to the second address list.

[0092] In some embodiments, the continuous addresses represent addresses arranged in sequence, for example, address 1, address 2, address 3, address 4, and address 5 are continuous addresses. The allocation instruction may include information specifying all addresses of the continuous addresses to be allocated, or only information including initial addresses of the continuous addresses. The initial address may be represented as the first address or the last address of the continuous addresses arranged in sequence (e.g., ascending or descending order).

[0093] In some embodiments, the target protocol address indicates successful allocation to the device to be allocated and is a unique protocol address of the device to be allocated.

[0094] In some embodiments, after receiving the allocation instruction for the continuous addresses of the device to be allocated, when the electronic device first determines the device to be allocated whose address is successfully allocated, the protocol address corresponding to the device to be allocated can be determined as the target protocol address obtained for the first time. After the device to be allocated whose address is successfully allocated is determined for the first time, the protocol address corresponding to the device to be allocated whose address is successfully allocated again determined by the electronic device is the target protocol address not obtained for the first time.

[0095] In some embodiments, the second address list stores successfully allocated consecutive addresses and corresponding device information of the devices to be allocated.

[0096] In some embodiments, the electronic device may arrange the protocol addresses in the second address list in sequence, and use the most recently updated boundary address in the sequence as the last address.

[0097] In some embodiments, the electronic device can determine a preset range of protocol addresses based on the allocation instruction for the continuous addresses of the devices to be allocated and the number of devices to be allocated, so that the preset range of protocol addresses includes all addresses in the continuous addresses. In order to reduce the probability of duplication of protocol addresses selected by different devices to be allocated, thereby saving the time for address allocation and improving the efficiency of address allocation, the electronic device sets the number of protocol addresses in the preset range to be greater than the number of devices to be allocated.

[0098] In some embodiments, in response to an instruction to allocate consecutive addresses of devices to be allocated, the electronic device needs to allocate addresses of the devices to be allocated so that the devices to be allocated are successfully allocated unique protocol addresses, and all devices to be allocated that are successfully allocated unique protocol addresses are arranged in order.

[0099] In some embodiments, when an allocation instruction for a continuous address of a device to be allocated is received, if the electronic device obtains the target protocol address for the first time, the initial address of the continuous address can be obtained, and the target protocol address obtained for the first time can be compared with the initial address. If the target protocol address is consistent with the initial address, the target protocol address and the corresponding device serial number are updated to the second address list. To ensure address continuity, if it is not the first time to obtain the target protocol address, the electronic device can obtain the last address from the continuous addresses recorded in the second address list. If it is not the first time to obtain the target protocol address, the target protocol address and the corresponding device serial number are updated to the second address list.

[0100] In other embodiments, the continuous address allocation instruction may also only include instruction information instructing the electronic device to allocate continuous addresses, without specifying the address range of the continuous addresses or the initial address of the continuous addresses. At this time, in response to the allocation instruction for the continuous addresses of the device to be allocated, if the electronic device obtains the target protocol address, it compares the target protocol address with the protocol address in the second address list. If the target protocol address has a connection relationship with the protocol address in the second address list, the electronic device may update the target protocol address to the second address list. It can be understood that when the second address list is empty, in response to the allocation instruction for the continuous addresses of the device to be allocated, the electronic device may update the target protocol address obtained for the first time to the second address list.

[0101] In the address allocation method provided in the embodiment of the present application, an address is allocated to the device to be allocated by broadcasting address allocation information containing a preset range of protocol addresses. After broadcasting the address allocation information, according to the preset polling rule, a query request for device information is sent to the protocol address within the preset range. If the protocol address is successfully allocated, the response information of the target device corresponding to the protocol address to the query request will be received. If the protocol address is not successfully allocated, there is no target device corresponding to the protocol address, and the response information to the query request cannot be received. Therefore, the number of devices to which the address is successfully allocated can be determined based on the response information corresponding to the query request. In order to ensure that all devices to be allocated are allocated to the protocol address, the number of devices can be compared with the number of devices to be allocated. If the number of devices is less than the number of devices to be allocated, the broadcast address allocation information can be returned to execute until the number of devices is equal to the number of devices to be allocated. This method improves the efficiency and success rate of address allocation by cyclically broadcasting address allocation information and polling the protocol address within the preset range in each cycle.

[0102] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0103] See also Figure 4 , Figure 4 The structure diagram of the address allocation device provided in the embodiment of the present application is shown, which can implement the details of the address allocation method in the above embodiment and achieve the same effect. Figure 5As shown, the address allocation device 10 can be applied to an electronic device with a data processing function, and the address allocation device 10 includes: a broadcast module 11, which is used to broadcast address allocation information, and the address allocation information includes a preset range of protocol addresses; a polling module 12, which is used to send a query request for device information to a protocol address within a preset range according to a preset polling rule; a determination module 13, which is used to determine the number of devices to which addresses are successfully allocated based on the response information corresponding to the query request; and a judgment module 14, which is used to return to execute the broadcast address allocation information if the number of devices is less than the number of devices to be allocated.

[0104] For the specific definition of the address allocation device 10, please refer to the definition of the address allocation method above, which will not be repeated here. The various modules in the above-mentioned address allocation device 10 can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the electronic device in the form of hardware, or can be stored in the memory of the electronic device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0105] See also Figure 5 , Figure 5 The diagram is a schematic diagram of the structure of an electronic device provided by an embodiment of the present application. The network where the electronic device 100 is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.

[0106] like Figure 5 As shown, the electronic device 100 includes a communication module 101, a memory 102, a processor 103, an input / output interface 104 and a bus 105. The processor 103 is coupled to the communication module 101, the memory 102 and the input / output interface 104 through the bus 105. The communication module 101 may be a wireless communication module or a mobile communication module. The wireless communication module may provide wireless communication solutions including wireless local area networks (WLAN) (e.g., wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., applied to the electronic device 100. The mobile communication module may provide wireless communication solutions including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The memory 102 may include one or more random access memories (RAM) and one or more non-volatile memories (NVM). The random access memory can be directly read and written by the processor 103, and can be used to store executable programs (such as machine instructions) of the operating system or other running programs, and can also be used to store user and application data. The random access memory may include static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM, for example, the fifth generation DDR SDRAM is generally called DDR5 SDRAM), etc. The non-volatile memory may also store executable programs and user and application data, etc., and may be loaded into the random access memory in advance for direct reading and writing by the processor 103. The non-volatile memory may include a disk storage device and a flash memory. The memory 102 is used to store one or more computer programs. The one or more computer programs are configured to be executed by the processor 103. The one or more computer programs include multiple instructions, and when the multiple instructions are executed by the processor 103, the address allocation method executed on the electronic device 100 can be implemented. In other embodiments, the electronic device 100 further includes an external memory interface for connecting to an external memory to expand the storage capacity of the electronic device 100 . The processor 103 may include one or more processing units, for example, the processor 103 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors. The processor 103 provides computing and control capabilities. For example, the processor 103 is used to execute a computer program stored in the memory 102 to implement the above-mentioned address allocation method. The input / output interface 104 is used to provide a channel for user input or output. For example, the input / output interface 104 can be used to connect various input and output devices, such as a mouse, keyboard, touch device, display screen, etc., so that the user can enter information or visualize information. The bus 105 is at least used to provide a channel for mutual communication among the communication module 101 , the memory 102 , the processor 103 , and the input / output interface 104 in the electronic device 100 . It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0107] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. The computer program includes program instructions. The method implemented when the program instructions are executed can refer to the address allocation method in the above-mentioned embodiments of the present application. The computer-readable storage medium may be an internal memory of the electronic device described in the above embodiment, such as a hard disk or memory of the electronic device. The computer-readable storage medium may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Furthermore, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the electronic device, etc.

[0108] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present application and are not intended to limit it. Although the present application has been described in detail with reference to the preferred embodiments, a person of ordinary skill in the art should understand that the technical solution of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present application.

Claims

1. An address allocation method, characterized in that: The address allocation method comprises: Broadcasting address allocation information, wherein the address allocation information includes a protocol address within a preset range; According to a preset polling rule, a query request for device information is sent to the protocol address within the preset range; Determine the number of devices with successfully assigned addresses based on the response information corresponding to the query request; If the number of devices is less than the number of devices to be allocated, return to execute the broadcast address allocation information.

2. The address allocation method according to claim 1, characterized in that: The determining, based on the response information corresponding to the query request, the number of devices with successfully allocated addresses includes: Parse the response information to obtain an initial sequence number; If the initial serial number meets the preset requirements and the protocol address corresponding to the initial serial number is a valid address, the device to be allocated that feeds back the response information is determined as the target device, the initial serial number is determined as the device serial number of the target device, and the protocol address corresponding to the device serial number is determined as the target protocol address; The number of devices is determined according to the number of the target protocol addresses and the number of protocol addresses recorded in the first address list.

3. The address allocation method according to claim 2, characterized in that: The method further comprises: If the protocol address corresponding to the initial serial number matches the protocol address recorded in the first address list, determining that the protocol address corresponding to the initial serial number is an invalid address; If the protocol address corresponding to the initial sequence number does not match the protocol address in the first address list, it is determined that the protocol address corresponding to the initial sequence number is a valid address.

4. The address allocation method according to claim 2, characterized in that: The method further comprises: The device serial number and the corresponding target protocol address are updated to the first address list.

5. The address allocation method according to claim 2, characterized in that: After determining the initial serial number as the device serial number and using the protocol address corresponding to the device serial number as the target protocol address, the method further includes: The device serial number of the target device and the corresponding target protocol address are broadcasted, and the target device is instructed to write the target protocol address into a preset memory.

6. The address allocation method according to claim 5, characterized in that: After broadcasting the device serial number and the corresponding target protocol address, the method further includes: Sending an exit allocation instruction to the target device to instruct the target device to stop responding to the address allocation information.

7. The address allocation method according to claim 2, characterized in that: The method further comprises: In response to an allocation instruction for the continuous address of the device to be allocated, if the target protocol address is obtained for the first time, compare the target protocol address with the initial address of the continuous address, and if the target protocol address is consistent with the initial address, update the target protocol address and the corresponding device serial number to the second address list; If the target protocol address is not obtained for the first time, obtaining the last address from the continuous addresses recorded in the second address list; If the target protocol address has a continuous relationship with the tail address, the target protocol address and the corresponding device serial number are updated to the second address list.

8. An address allocation device, characterized in that: The device comprises: A broadcast module, used for broadcasting address allocation information, wherein the address allocation information includes a protocol address within a preset range; A polling module, configured to send a query request for device information to the protocol address within the preset range according to a preset polling rule; A determination module, configured to determine the number of devices to which addresses are successfully allocated based on response information corresponding to the query request; The judgment module is used to return and execute the broadcast address allocation information if the number of the devices is less than the number of the devices to be allocated.

9. An electronic device, characterized in that: The method comprises a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the computer-readable instructions, when executed by the processor, implement the address allocation method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the address allocation method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Automatic fan Modbus address allocation method and system

    CN121603478A