Automatic addressing method, device and equipment based on RS-485 bus and medium

The automatic addressing method using RS-485 bus, which utilizes master station broadcast addressing instructions and CRC16 checksums to achieve automatic addressing of slave nodes, solves the problem of inefficiency in manual configuration in existing technologies, improves system deployment efficiency, and reduces labor costs.

CN121125689APending Publication Date: 2025-12-12SHANGHAI RUJING AUTOMATIC CONTROL SYST CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511141727.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-15
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

Existing technologies in RS-485 bus systems suffer from problems such as default station number conflicts, inefficient manual configuration, poor configuration fault tolerance, and insufficient system maintainability during the station number configuration process for slave nodes, resulting in low deployment efficiency and high labor costs for automated systems.

Method used

An automatic addressing method based on the RS-485 bus is adopted. The master station sends a broadcast addressing command to control the addressing register of the slave station to be set, and the CRC16 check code is used to ensure the integrity of the data frame, so as to realize the automatic addressing of the slave station.

Benefits of technology

It achieves automated addressing of slave nodes, eliminating manual node-by-node operation, dynamically adapting to changes in system scale, improving system deployment efficiency, and saving labor costs and debugging time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121125689A_ABST
    Figure CN121125689A_ABST
Patent Text Reader

Abstract

The invention provides an automatic addressing method and device based on an RS-485 bus, equipment and a medium. The method comprises the following steps: receiving a broadcast addressing instruction sent by a main station; the broadcast addressing instruction comprises a control command for setting an addressing register of the slave station to be 1; the slave station is in cascade connection with the master station through an RS-485 bus; performing a setting operation on an addressing register of the slave station based on the broadcast addressing instruction, and sending an automatic addressing instruction; and in response to the automatic addressing instruction, the slave station executes automatic addressing based on an addressing instruction data frame sent by the master station. According to the method, the register of the slave station is automatically set in a mode of supporting RS-485 broadcast, the addressing mode is automatic addressing, addressing of a plurality of slave station RS-485 bus systems can be effectively carried out, dependence on manual node-by-node operation is eliminated, system scale changes can be dynamically adapted, the automatic system deployment efficiency is relatively high, time and labor are saved in the implementation process, and the implementation efficiency is improved. And the labor cost and the debugging time are greatly saved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of automatic addressing, and relates to an automatic addressing method based on an RS-485 bus, in particular to an automatic addressing method based on an RS-485 bus, a device, equipment and a medium. BACKGROUND

[0002] In the field of industrial automation, especially in scenarios such as logistics conveying lines, a multi-slave node level system is often used to realize material transmission, sorting and collaborative control. Such a system is usually built based on bus communication technologies such as RS-485 and CAN, and uses a master-slave architecture to complete data interaction and instruction transmission between multiple nodes. Although such scenarios have relatively loose requirements for communication real-time performance and accuracy, their core feature is to connect a large number of slave nodes (such as motor drivers, sensors, actuators, etc.) to the master controller through cascading to form an integrated system of centralized control and distributed execution.

[0003] However, the prior art has significant bottlenecks in actual deployment and debugging, mainly in the station number configuration of the slave nodes:

[0004] Default station number conflict and inefficient manual configuration: The default station number of all slave nodes is usually set to the same value (for example, all station number 1) when they leave the factory. During system installation, each node needs to be assigned a unique station number through external devices such as physical buttons and handheld keyboards to prevent bus communication conflicts. This process requires the operator to physically access or manually input each node, especially in scenarios with a large number of nodes and a wide distribution range (such as long-distance conveying lines), which is time-consuming and labor-intensive, and has very low efficiency, severely restricting the deployment speed of the system.

[0005] Poor configuration fault tolerance and prone to errors: During the manual configuration process, if there is a station number duplication, omission or input error, it will directly cause bus communication abnormalities (such as incorrect response to instructions, data packet loss, etc.), which need to be rechecked and corrected, further increasing the debugging cycle and maintenance cost. In addition, when the system is expanded or the nodes are replaced later, the tedious station number reset process needs to be performed again, and the system is not maintainable and flexible enough.

[0006] High cost for large-scale applications: For large logistics systems (such as warehouse sorting lines and cross-region conveying networks), the cascading of hundreds or even thousands of nodes makes it difficult for traditional manual configuration methods to meet the requirements of installation efficiency and cost control of enterprises. Setting each node not only significantly increases labor input, but also may cause downtime due to operation errors, indirectly causing production losses.

[0007] Although the prior art attempts to simplify the configuration process by presetting the station number table, improving the design of the dial switch, etc., it still cannot get rid of the dependence on manual node-by-node operation, and cannot dynamically adapt to the change of the system scale, so the deployment efficiency of the automatic system is very low, the implementation process is time-consuming and labor-intensive, and for a huge system, it cannot reduce the labor cost of enterprises. SUMMARY

[0008] The present application provides an automatic addressing method, device, equipment and medium based on RS-485 bus, which is used to solve the problem that the addressing method in the prior art cannot get rid of the dependence on manual node-by-node operation when setting the slave station, and cannot dynamically adapt to the change of the system scale, thereby causing the deployment efficiency of the automatic system to be very low, the implementation process to be time-consuming and labor-intensive, and the labor cost of enterprises to be unable to be reduced.

[0009] In a first aspect, the present application provides an automatic addressing method based on RS-485 bus, which comprises: receiving a broadcast addressing instruction sent from a master station; the broadcast addressing instruction contains a control command for setting the addressing register of a slave station to 1; the slave station is cascaded with the master station through an RS-485 bus; performing a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issuing an automatic addressing instruction; in response to the automatic addressing instruction, the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station.

[0010] In an implementation form of the first aspect, performing a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issuing an automatic addressing instruction comprises: performing a set operation on the addressing register in the slave station controller based on the broadcast addressing instruction, and accumulating the number of received broadcast addressing instructions; when the slave station detects that the accumulated number of broadcast addressing instructions reaches a preset threshold, controlling the RS-485 bus communication output interface of the slave station to perform a disconnection operation, and issuing an automatic addressing instruction; the preset threshold is a configurable positive integer.

[0011] In an implementation form of the first aspect, when the slave station contains one slave station, the slave station performing automatic addressing based on the addressing instruction data frame sent by the master station comprises: receiving the addressing instruction data frame sent by the master station; setting the local communication address of the current slave station according to the addressing instruction data frame, and generating a communication address completion instruction; in response to the communication address completion instruction, controlling the addressing register of the current slave station to perform a set operation to 0; in response to the communication address completion instruction, controlling the RS-485 bus communication output interface of the current slave station to perform a closing operation; in response to the communication address completion instruction, controlling the current slave station to return an addressing instruction data frame with an incremented communication address; in response to the addressing instruction data frame with the incremented communication address, verifying the addressing state of the current slave station, and completing automatic addressing.

[0012] In an implementation form of the first aspect, when the slave stations include at least two slave stations, the slave stations performing automatic addressing based on the addressing instruction data frame sent by the master station comprises: receiving the addressing instruction data frame sent by the master station; setting a local communication address of a current slave station according to the addressing instruction data frame, and generating a communication address completion instruction; in response to the communication address completion instruction, controlling an addressing register of the current slave station to perform a set-to-zero operation; in response to the communication address completion instruction, controlling an RS-485 bus communication output interface of the current slave station to perform a closed operation to connect a next slave station; in response to the communication address completion instruction, controlling the current slave station to return an addressing instruction data frame with an incremented communication address; controlling the next slave station to perform automatic addressing according to the addressing instruction data frame with the incremented communication address; and performing automatic addressing on the remaining slave stations in turn until a last slave station completes automatic addressing.

[0013] In an implementation form of the first aspect, setting the local communication address of the current slave station according to the addressing instruction data frame comprises: obtaining a communication address data segment according to the addressing instruction data frame; and setting the communication address data segment as the local communication address of the current slave station.

[0014] In an implementation form of the first aspect, the addressing instruction data frame includes a first data segment, a second data segment, and a CRC16 check code; and the addressing instruction data frame satisfies the following conditions: the first data segment and the second data segment have the same content; and the addressing instruction data frame can pass the check of the CRC16 check code.

[0015] In an implementation form of the first aspect, the communication address increment is a step-by-step increment of 1 or a preset step increment.

[0016] In a second aspect, the application provides an automatic addressing device based on an RS-485 bus, which comprises: a master station configured to generate a broadcast addressing instruction and an addressing instruction data frame, and receive and analyze a response data frame returned by a slave station; the broadcast addressing instruction includes a control command for setting an automatic addressing register of the slave station to 1; at least one slave station, each slave station including a controller, an addressing register, an RS-485 bus communication output interface, and an RS-485 bus communication input interface; each slave station is connected to the master station in cascade through an RS-485 bus; wherein, under the control of the controller, the slave station receives the broadcast addressing instruction sent by the master station through the RS-485 bus communication input interface, performs a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issues an automatic addressing instruction; in response to the automatic addressing instruction, the slave station performs automatic addressing based on an addressing instruction data frame sent by the master station, and feeds back an addressing instruction data frame with an incremented communication address to the master station or a next slave station through the RS-485 bus communication output interface.

[0017] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory; the memory is configured to store a computer program; the processor is configured to execute the computer program stored in the memory, so that the electronic device executes the automatic addressing method based on the RS-485 bus as described above.

[0018] In a third aspect, the present application provides a computer readable storage medium, which stores a computer program, the program is executed by an electronic device to implement the automatic addressing method based on the RS-485 bus as described above.

[0019] As described above, the automatic addressing method, device, equipment and medium based on the RS-485 bus provided by the present application have the following beneficial effects:

[0020] The present application receives a broadcast addressing instruction sent from a master station; the broadcast addressing instruction contains a control command for setting an addressing register of a slave station to 1; the slave station is cascaded with the master station through an RS-485 bus; based on the broadcast addressing instruction, a set operation is performed on the addressing register of the slave station, and an automatic addressing instruction is issued; in response to the automatic addressing instruction, the slave station performs automatic addressing based on an addressing instruction data frame sent by the master station. The present application automatically sets the register of the slave station in the manner of supporting RS-485 broadcast, the addressing mode is automatic addressing, which can effectively perform addressing of the RS-485 bus system of multiple slave stations, and get rid of the dependence on manual node-by-node operation, can dynamically adapt to system size changes, and has high efficiency in automatic system deployment, saves time and labor in the implementation process, and greatly saves labor cost and debugging time. BRIEF DESCRIPTION OF DRAWINGS

[0021] Figure 1A A schematic diagram of a topology structure of a conventional master-slave station cascade is shown.

[0022] Figure 1B A schematic diagram of a topology structure of a conventional master-slave station cascade is shown.

[0023] Figure 2A A schematic diagram of the structure of an automatic addressing device is shown.

[0024] Figure 2B A schematic diagram of the structure of a slave station in Figure 2A is shown.

[0025] Figure 3 A schematic diagram of the flow of the automatic addressing method based on the RS-485 bus is shown.

[0026] Figure 4A flowchart showing the automatic addressing process of the slave station based on the addressing instruction data frame sent by the master station according to the embodiment of the present application.

[0027] Figure 5 A flowchart showing the automatic addressing process of the slave station based on the addressing instruction data frame sent by the master station according to another embodiment of the present application.

[0028] Figure 6 A structural diagram of the automatic addressing device based on RS-485 bus according to the embodiment of the present application.

[0029] Figure 7 A structural diagram of the automatic addressing device based on RS-485 bus according to another embodiment of the present application.

[0030] Figure 8 A structural diagram of the electronic device according to the embodiment of the present application.

[0031] Element number explanation

[0032] 300 Automatic addressing device based on RS-485 bus

[0033] 301 Master station

[0034] 302 Slave station

[0035] 3021 Controller

[0036] 3022 Addressing register

[0037] 3023 RS-485 bus communication input interface

[0038] 3024 RS-485 bus communication output interface

[0039] 400 Electronic device

[0040] 401 Processor

[0041] 402 Memory

[0042] S1-S3 Steps

[0043] S311-S316 Steps

[0044] S321-S327 Steps DETAILED DESCRIPTION

[0045] The following detailed description is presented to enable any person skilled in the art to make and use the application. Various modifications to the embodiments described herein will be readily apparent to those skilled in the art, and the generic principles defined herein can be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the claims.

[0046] It should be noted that the drawings provided in the following embodiments are only schematically illustrating the basic concept of the present application, and only the components related to the present application are shown in the drawings, rather than the number, shape and size of the components in actual implementation. The shape, number and ratio of the components in actual implementation can be arbitrarily changed, and the layout of the components can be more complex.

[0047] Figure 1A A schematic diagram of a topology of a conventional master-slave station cascade is shown. Figure 1B A schematic diagram of a topology of a conventional master-slave station cascade is shown. As shown in Figures 1A-1B The master station includes interface A and interface B, and each slave station includes interface A and interface B. The master station and the slave station 1, the slave station 2, …, the slave station N are sequentially cascaded in communication through the pin A and the pin B of RS-485, and are sequentially addressed to set the subsequent address, which is very low in efficiency, time-consuming and laborious in implementation process, and high in labor cost for a system including a large number of slave stations.

[0048] Figure 2A A schematic diagram of the structure of the automatic addressing device according to the embodiment of the present application is shown. Figure 2B A schematic diagram of the structure of the slave station in Figure 2A is shown. As shown in Figures 2A-2BAs shown, the automatic addressing device includes a master station and a plurality of slave stations (for example, slave station 1, slave station 2, …, slave station N), each slave station including a single-chip microcomputer master control MCU control system, an RS-485 bus communication input interface (IN), and an RS-485 bus communication output interface (OUT), wherein the RS-485 bus communication input interface is in a normally closed state, and the RS-485 bus communication output interface is in a controllable state. The cascading mode of the master station and each slave station is as follows: the master station is connected in communication with the pin A of the RS-485 bus communication input interface of the slave station 1 through the pin A of the RS-485, the master station is connected in communication with the pin B of the RS-485 bus communication input interface of the slave station 1 through the pin B of the RS-485, the RS-485 bus communication output interface A of the slave station 1 is connected in communication with the pin A of the RS-485 bus communication input interface of the slave station 2, the RS-485 bus communication output interface B of the slave station 1 is connected in communication with the pin B of the RS-485 bus communication input interface of the slave station 2, and the subsequent slave stations are sequentially cascaded, that is, the RS-485 bus communication input interface of each slave station is cascaded in communication with the previous slave station, and the RS-485 bus communication output interface of each slave station is cascaded in communication with the next slave station. In this way, the addressing instructions sent by the master station can be received, and automatic addressing of multiple nodes is sequentially performed, so that the actual production line application process becomes very simple and convenient, and the labor cost and debugging time are greatly saved.

[0049] In addition, the RS-485 bus communication output interface (OUT) is connected in series with an analog switch, and each slave station controls the on-off of the analog switch through its own MCU.

[0050] The following embodiments of the present application provide an automatic addressing method, device, equipment and medium based on an RS-485 bus, which solves the problem that the addressing method in the prior art cannot get rid of the dependence on manual node-by-node operation when setting slave stations, and cannot dynamically adapt to changes in system size, thereby causing the deployment efficiency of the automatic system to be very low, the implementation process to be time-consuming and labor-intensive, and the labor cost of enterprises to be unable to be reduced.

[0051] The automatic addressing method based on the RS-485 bus provided in the following embodiments of the present application can be implemented based on the automatic addressing device in Figure 2A and Figure 2B , but the automatic addressing device for implementing the automatic addressing method based on the RS-485 bus of the present application is not limited to the structure and function in Figures 2A-2B . Any improvement in structure and function can implement the automatic addressing method based on the RS-485 bus described in the embodiments of the present application.

[0052] The technical solutions in the embodiments of the present application will be described in detail below with reference to the drawings in the embodiments of the present application.

[0053] As Figure 3 shown in the drawings, the embodiment provides an automatic addressing method based on RS-485 bus, which comprises the following steps S1-S3.

[0054] Step S1, receiving a broadcast addressing instruction sent from a master station; the broadcast addressing instruction contains a control command for setting an addressing register of a slave station to 1; the slave station is cascaded with the master station through RS-485 bus.

[0055] In some embodiments, the master station sends a broadcast addressing instruction to the slave station in a broadcast manner, so that the slave station sets its own addressing register according to the broadcast addressing instruction, thereby performing subsequent automatic addressing.

[0056] In some embodiments, the slave station is cascaded with the master station through RS-485 bus. RS-485 bus has two ports, input and output, the input is connected to the previous slave station, and the output is connected to the next slave station; for example, the RS-485 bus communication input interface of slave station 1 is connected to the master station communication, the RS-485 bus communication output interface of slave station 1 is connected to the RS-485 bus communication input interface of slave station 2, the RS-485 bus communication output interface of slave station 2 is connected to the RS-485 bus communication input interface of slave station 3, the RS-485 bus communication output interface of slave station 3 is connected to the RS-485 bus communication input interface of slave station 4, and so on, until the last slave station node.

[0057] Step S2, performing a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issuing an automatic addressing instruction.

[0058] In some embodiments, the slave station performs a set operation on its own addressing register according to the broadcast addressing instruction, sets its own addressing register to 1, and issues an automatic addressing instruction. The automatic addressing instruction is an addressing register set completion instruction. The addressing register is located in the MCU controller of the slave station.

[0059] In an embodiment of the present application, performing a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issuing an automatic addressing instruction comprises the following steps S21-S22.

[0060] Step S21, performing a set operation on the addressing register in the slave station controller based on the broadcast addressing instruction, and accumulating the number of received broadcast addressing instructions;

[0061] Step S22: When the slave station detects that the cumulative number of broadcast addressing commands has reached a preset threshold, it controls the RS-485 bus communication output interface of the slave station to perform a disconnection operation and issues an automatic addressing command; the preset threshold is a configurable positive integer.

[0062] In some embodiments, the master station sends a broadcast addressing command to the slave station via broadcast. The slave station sets its own addressing register to 1 according to the broadcast addressing command and accumulates the number of received cumulative set commands (i.e., the number of broadcast addressing commands). When the slave station detects that the number of cumulative set commands has reached a preset threshold M, it disconnects its RS-485 bus communication output interface and issues an automatic addressing command. The preset threshold M is a configurable positive integer. The preset threshold M is set by the user; for example, M = 3, meaning that when the slave station receives the cumulative set command for the third time, it disconnects its RS-485 bus communication output interface and issues an automatic addressing command. The decision to disconnect the slave station's RS-485 bus communication output interface only when it receives the cumulative set command for the third time is primarily to prevent the slave station from missing this automatic addressing operation and thus avoiding automatic addressing errors.

[0063] Step S3: In response to the automatic addressing instruction, the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station.

[0064] In some embodiments, in response to the automatic addressing instruction, the master station sends an addressing instruction data frame to the slave station, and the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station.

[0065] like Figure 4 As shown, in one embodiment of this application, when the slave station includes one slave station, the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station, including the following steps S311 to S316.

[0066] Step S311: Receive the addressing instruction data frame sent by the master station.

[0067] In some embodiments, the addressing instruction data frame includes a first data segment, a second data segment, and a CRC16 check code; the addressing instruction data frame satisfies the following conditions: the first data segment and the second data segment have the same content; the addressing instruction data frame can pass the check of the CRC16 check code. For example, the addressing instruction data frame is 0x01+0x01+CRC16. The following conditions 1 and condition 2 are satisfied. Wherein, condition 1: the first data segment (0x01) and the second data segment (0x01) have the same content; condition 2: the addressing instruction data frame satisfies the data check format of CRC16.

[0068] It should be noted that the CRC16 check code is an error detection technology widely used in the fields of data communication and storage, which is used to ensure the integrity and accuracy of data transmission. CRC16 is a cyclic redundancy check code, which checks the data by polynomial division and generates a 16-bit check code. It can effectively detect errors in data transmission, such as single-bit error, double-bit error, and odd number of bits error.

[0069] Step S312, setting the local communication address of the current slave station according to the addressing instruction data frame, and generating a communication address completion instruction.

[0070] Step S313, in response to the communication address completion instruction, controlling the addressing register of the current slave station to perform a set-to-0 operation.

[0071] Step S314, in response to the communication address completion instruction, controlling the RS-485 bus communication output interface of the current slave station to perform a closed operation.

[0072] Step S315, in response to the communication address completion instruction, controlling the current slave station to return an addressing instruction data frame with an incremented communication address.

[0073] Step S316, in response to the addressing instruction data frame with the incremented communication address, verifying the addressing state of the current slave station, and completing the automatic addressing.

[0074] In some embodiments, when the slave station includes one slave station, the slave station receives an addressing instruction data frame (e.g., 0x01+0x01+CRC16) sent by the master station, takes the frame data 0x01, sets the local communication address (i.e., ID number) of the current slave station, and generates a communication address completion instruction. In response to the communication address completion instruction, the addressing register in the MCU controller of the current slave station is controlled to perform a set-to-0 operation, indicating that the current slave station completes automatic addressing, and the RS-485 bus communication output interface of the current slave station is controlled to perform a closed operation to connect the communication bus. After the slave station receives the local communication address, the current slave station is controlled to return an addressing instruction data frame with an incremented communication address, so as to verify the addressing state of the current slave station based on the addressing instruction data frame with the incremented communication address (0x02+0x02+CRC16), and complete automatic addressing.

[0075] As shown in FIG. 1, in an embodiment of the present application, when the slave station includes at least two slave stations, the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station, including the following steps S321-S327. Figure 5

[0076] Step S321, receiving the addressing instruction data frame sent by the master station.

[0077] Step S322, setting the local communication address of the current slave station according to the addressing instruction data frame, and generating a communication address completion instruction.

[0078] Step S323, in response to the communication address completion instruction, controlling the addressing register of the current slave station to perform a set-to-0 operation.

[0079] Step S324, in response to the communication address completion instruction, controlling the RS-485 bus communication output interface of the current slave station to perform a closed operation to connect the next slave station.

[0080] Step S325, in response to the communication address completion instruction, controlling the current slave station to return an addressing instruction data frame with an incremented communication address.

[0081] Step S326, controlling the next slave station to perform automatic addressing according to the addressing instruction data frame with the incremented communication address.

[0082] Step S327, sequentially performing automatic addressing on the remaining slave stations until the last slave station completes automatic addressing.

[0083] In an embodiment of the present application, setting the local communication address of the current slave station according to the addressing instruction data frame includes the following steps S331-S332.

[0084] Step S331, obtaining the communication address data segment according to the addressing instruction data frame;​

[0085] Step S332, setting the communication address data segment as the local communication address of the current slave station.

[0086] In an embodiment of the present application, the communication address is incremented by 1 or by a preset step size.

[0087] In some embodiments, when the slave stations include at least two slave stations, the master station issues an addressing instruction data frame to the first slave station, the first slave station sets the local communication address according to the addressing instruction data frame issued by the master station, turns on the RS-485 bus communication output interface of the local station after the local communication address is successfully set, connects the second slave station, increments the communication address, and issues an addressing instruction data frame with the incremented communication address to the second slave station, the second slave station repeats the automatic addressing steps of the first slave station until the last slave station successfully sets the local communication address, and the last slave station returns an addressing success data (i.e., a response data frame) to the master station, indicating that all slave stations have completed the automatic addressing process. The communication address is incremented by 1 as an example, but the present application is not limited thereto.

[0088] In the present embodiment, when the slave stations include at least two slave stations, for example, N slave stations, the automatic addressing process of the N slave stations includes the following steps S401 to S414.

[0089] Step S401, the master station sends a broadcast addressing instruction to the first slave station in a broadcast manner, and the first slave station automatically sets the addressing register of the local station to 1 according to the broadcast addressing instruction.

[0090] Step S402, the first slave station accumulates the number of received cumulative set instructions (i.e., the number of broadcast addressing instructions) until a preset threshold M is reached.

[0091] Step S403, when the slave station detects that the number of cumulative set instructions reaches the preset threshold M, the RS-485 bus communication output interface of the slave station is disconnected, and an automatic addressing instruction is issued. The automatic addressing instruction is a pre-set completion instruction of the first slave station, and the preset value includes all settings in steps S401 to S403. The preset threshold M is a configurable positive integer.

[0092] Step S404, the master station receives the automatic addressing instruction and sends an addressing instruction data frame (e.g., 0x01+0x01+CRC16) to the first slave station.

[0093] Condition 1: the first data segment and the second data segment have the same content;

[0094] Condition 2: the addressing instruction data frame satisfies the data check format of CRC16;

[0095] Step S405, the first slave station takes frame data 0x01 from the addressing instruction data frame (0x01+0x01+CRC16), and sets the frame data 0x01 as the communication address of the local station.

[0096] Step S406, after the setting of the communication address of the local station is completed, the first slave station indicates that the automatic addressing of the local station is completed, and controls the addressing register in the MCU of the local station to perform the operation of setting to 0, indicating that the automatic addressing is no longer performed.

[0097] Step S407, after the setting of the communication address of the local station is completed, the first slave station controls the RS-485 bus communication output interface of the local station to perform the operation of closing, so as to realize the automatic connection between the first slave station and the second slave station.

[0098] Step S408, after the first slave station receives the communication address of the local station, the first slave station generates a response data frame (for example, 0x02+0x02+CRC16) with an incremented communication address to the communication bus.

[0099] Step S409, when the first slave station closes the RS-485 bus communication output interface of the current slave station, the first slave station is automatically connected with the second slave station, and after the second slave station receives the response data frame (0x02+0x02+CRC16) with the incremented communication address sent by the first slave station, the step S404 is repeated.

[0100] Step S410, the second slave station sets the communication address of the local station according to the response data frame (for example, 0x02+0x02+CRC16) with the incremented communication address, that is, takes the frame data 0x02 and sets it as the communication address of the local station, and the step S405 is repeated.

[0101] Step S411, after the setting of the communication address of the local station is completed, the second slave station indicates that the automatic addressing of the local station is completed, and controls the addressing register in the MCU of the local station to perform the operation of setting to 0, indicating that the automatic addressing of the local station is no longer performed. The step S406 is repeated.

[0102] Step S412, after the setting of the communication address of the local station is completed, the second slave station controls the RS-485 bus communication output interface of the local station to perform the operation of closing, so as to realize the automatic connection between the second slave station and the third slave station. The step S407 is repeated.

[0103] Step S413, after the second slave station receives the communication address of the local station, the second slave station generates a response data frame (for example, 0x03+0x03+CRC16) with an incremented communication address to the communication bus.

[0104] Step S414, the slave station is sequentially cycled to execute the above-mentioned automatic addressing step until the Nth slave station is automatically connected with the N-1th slave station, and the final response data frame (i.e. (N+1)+(N+1)+CRC16) is generated to the communication bus, and the final response data frame (i.e. (N+1)+(N+1)+CRC16) is generated to the communication bus, and the communication bus is considered to end the addressing process after waiting for 1ms without refreshing data.

[0105] The application can effectively address the RS-485 bus system of multiple slave stations, and can dynamically adapt to the change of system scale, and has high efficiency in automatic system deployment, and can save time and labor in the implementation process, and can make the actual production line application process very simple and convenient, and greatly save the labor cost and the debugging time.

[0106] The protection scope of the automatic addressing method based on the RS-485 bus in the embodiment of the application is not limited to the step execution order listed in the embodiment, and any scheme realized by adding, reducing or replacing the steps of the prior art according to the principle of the application is included in the protection scope of the application.

[0107] The embodiment of the application further provides an automatic addressing system based on the RS-485 bus, which can realize the automatic addressing method based on the RS-485 bus in the application, but the implementation device of the automatic addressing method based on the RS-485 bus in the application includes but is not limited to the structure of the automatic addressing system based on the RS-485 bus listed in the embodiment, and any structure deformation and replacement of the prior art according to the principle of the application is included in the protection scope of the application.

[0108] As shown in FIG. 3, Figure 6 The embodiment provides an automatic addressing device based on the RS-485 bus, and the device 300 includes a master station 301 and at least one slave station 302.

[0109] The master station 301 is configured to generate a broadcast addressing instruction and an addressing instruction data frame, receive and analyze a response data frame returned by a slave station, and the broadcast addressing instruction contains a control command for setting the automatic addressing register of the slave station to 1.

[0110] The at least one slave station 302 includes a controller 3021, an addressing register 3022, an RS-485 bus communication input interface 3023 and an RS-485 bus communication output interface 3024, and each slave station is cascaded with the master station through the RS-485 bus.

[0111] The slave station receives a broadcast addressing instruction sent from the master station through the RS-485 bus communication input interface under the control of the controller, performs a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and sends an automatic addressing instruction; in response to the automatic addressing instruction, the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station, and feeds back an addressing instruction data frame with an incremented communication address to the master station or the next slave station through the RS-485 bus communication output interface.

[0112] Figure 7 A structure diagram of an automatic addressing device based on an RS-485 bus is shown as another embodiment of the present application. As shown in Figure 7 The device 300 includes a plurality of slave stations 302, i.e., a slave station 1, a slave station 2, …, and a slave station N. The master station and the slave station 1 are in cascade communication through an RS-485 bus, and the slave station 1, the slave station 2, …, and the slave station N are in cascade communication through the RS-485 bus in turn.

[0113] The slave station 1 receives a broadcast addressing instruction sent from the master station through the RS-485 bus communication input interface under the control of the controller, performs a set operation on the addressing register of the slave station 1 based on the broadcast addressing instruction, and sends an automatic addressing instruction; in response to the automatic addressing instruction, the slave station 1 performs automatic addressing based on the addressing instruction data frame sent by the master station, and feeds back an addressing instruction data frame with an incremented communication address to the slave station 2 through the RS-485 bus communication output interface, so that the slave station 2 performs an automatic addressing process through the addressing instruction data frame with an incremented communication address sent by the slave station 1. The remaining slave stations perform automatic addressing in turn until the last slave station N completes automatic addressing.

[0114] It should be noted that the functions or operations of the master station 301 and the at least one slave station 302, the controller 3021, the addressing register 3022, the RS-485 bus communication input interface 3023, and the RS-485 bus communication output interface 3024 in each slave station correspond to the steps in the automatic addressing method based on the RS-485 bus described above one by one, and thus will not be described here again.

[0115] In several embodiments provided in the present application, it should be understood that the disclosed system, device or method can be implemented in other manners. For example, the division of the above-described device embodiment is only a logical function division, and there can be another division manner for the actual implementation, for example, multiple physical devices or multiple physical modules can be combined or integrated into another system, or some characteristics can be ignored or not executed. In addition, the display or discussion of the mutual coupling or direct coupling or communication connection between the above-described relative elements can be implemented by using some interfaces, and the indirect coupling or communication connection between the above-described relative elements can be implemented in electrical, mechanical or other forms.

[0116] The modules / units described as separated components can or can not be physically separated, and the components shown as modules / units can or can not be physical modules, i.e., can be located in one place or distributed on multiple network units. Some or all of the modules / units can be selected according to actual needs to achieve the purposes of the embodiments of the present application. For example, the functional modules / units in the embodiments of the present application can be integrated into a processing module, or each module / unit can be physically separated, or two or more modules / units can be integrated into one module / unit.

[0117] Those of ordinary skill in the art should further appreciate that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software or a combination of both. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general terms in the above description. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. A skilled person can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0118] As shown in the Figure 8 embodiment, the electronic device 400 includes a processor 401 and a memory 402.

[0119] The memory 402 is configured to store a computer program.

[0120] The processor 401 is configured to execute the computer program stored in the memory 402, so that the electronic device 400 performs the automatic addressing method based on the RS-485 bus as described above.

[0121] The embodiments of the present application further provide a computer readable storage medium. Those skilled in the art can understand that all or part of the steps of the methods described in the above embodiments can be instructed by a program to complete the processor, and the program can be stored in a computer readable storage medium, and the storage medium is a non-transitory medium, for example, a random access memory, a read only memory, a flash memory, a hard disk, a solid state disk, a magnetic tape, a floppy disk, an optical disc and any combination thereof. The storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, a data center and the like, which includes one or more available media sets. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a digital video disc (DVD)) or a semiconductor medium (for example, a solid state disk (SSD)) and the like.

[0122] The embodiments of the present application can also provide a computer program product, which includes one or more computer instructions. When the computer instructions are loaded and executed on a computing device, all or part of the processes or functions described in the embodiments of the present application are generated. The computer instructions can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, the computer instructions can be transmitted from one website, computer or data center to another website, computer or data center through wired (for example, coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (for example, infrared, wireless, microwave and the like) mode.

[0123] When the computer program product is executed by a computer, the computer executes the method described in the foregoing method embodiments. The computer program product can be a software installation package, and when the foregoing method is needed, the computer program product can be downloaded and executed on the computer.

[0124] In summary, the automatic addressing method, device, equipment and medium based on RS-485 bus provided by the present application have the following beneficial effects:

[0125] The application receives a broadcast addressing instruction sent by a master station; the broadcast addressing instruction contains a control command for setting an addressing register of a slave station to 1; the slave station is cascaded with the master station through an RS-485 bus; a set operation is performed on the addressing register of the slave station based on the broadcast addressing instruction, and an automatic addressing instruction is sent; in response to the automatic addressing instruction, the slave station performs automatic addressing based on an addressing instruction data frame sent by the master station. The application automatically sets the register of the slave station in the manner of supporting RS-485 broadcast, the addressing manner is automatic addressing, and the addressing of the RS-485 bus system of multiple slave stations can be effectively performed, the dependence on manual node-by-node operation is eliminated, the system size change can be dynamically adapted, the automation system deployment efficiency is high, the implementation process saves time and labor, and the manpower cost and debugging time are greatly saved.

[0126] The description of the flow or structure corresponding to each of the above figures has its own emphasis, and the part not described in detail in a certain flow or structure can be referred to the related description of other flows or structures.

[0127] The above embodiments only exemplarily illustrate the principles and effects of the application, and are not used to limit the application. Any person skilled in the art can modify or change the above embodiments without departing from the spirit and scope of the application. Therefore, all equivalent modifications or changes completed by those skilled in the art without departing from the spirit and technical thought of the application should be covered by the claims of the application.

Claims

1. A method for automatic addressing based on RS-485 bus, characterized in that, The method comprises: receiving a broadcast addressing instruction sent from a master station; the broadcast addressing instruction comprises a control command for setting an addressing register of a slave station to 1; the slave station is cascaded with the master station through an RS-485 bus; performing a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issuing an automatic addressing instruction; in response to the automatic addressing instruction, the slave station performs automatic addressing based on an addressing instruction data frame sent by the master station.

2. The method of automatically addressing RS-485 bus-based devices of claim 1, wherein, performing a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issuing an automatic addressing instruction comprises: performing a set operation on the addressing register in the slave station controller based on the broadcast addressing instruction, and accumulating the number of received broadcast addressing instructions; when the slave station detects that the number of broadcast addressing instructions reaches a preset threshold, controlling the RS-485 bus communication output interface of the slave station to perform a disconnect operation, and issuing an automatic addressing instruction; the preset threshold is a configurable positive integer.

3. The method of automatically addressing RS-485 bus-based devices of claim 1, wherein, when the slave station comprises one slave station, the slave station performing automatic addressing based on the addressing instruction data frame sent by the master station comprises: receiving the addressing instruction data frame sent by the master station; setting a local communication address of the current slave station according to the addressing instruction data frame, and generating a communication address completion instruction; in response to the communication address completion instruction, controlling the addressing register of the current slave station to perform a set operation to 0; in response to the communication address completion instruction, controlling the RS-485 bus communication output interface of the current slave station to perform a close operation; in response to the communication address completion instruction, controlling the current slave station to return an addressing instruction data frame with an incremented communication address; in response to the addressing instruction data frame with the incremented communication address, verifying the addressing state of the current slave station, and completing automatic addressing.

4. The method of automatic addressing based on RS-485 bus according to claim 1, characterized in that, when the slave station comprises at least two slave stations, the slave station performing automatic addressing based on the addressing instruction data frame sent by the master station comprises: receiving the addressing instruction data frame sent by the master station; setting a local communication address of the current slave station according to the addressing instruction data frame, and generating a communication address completion instruction; in response to the communication address completion instruction, controlling the addressing register of the current slave station to perform a set operation to 0; in response to the communication address completion instruction, controlling the RS-485 bus communication output interface of the current slave station to perform a close operation to connect the next slave station; in response to the communication address completion instruction, controlling the current slave station to return an addressing instruction data frame with an incremented communication address; controlling the next slave station to perform automatic addressing according to the addressing instruction data frame with the incremented communication address; sequentially and circularly performing automatic addressing on the remaining slave stations until the last slave station completes automatic addressing.

5. The method of automatically addressing RS-485 bus based networks according to claim 3 or 4, characterized in that, setting a local communication address of the current slave station according to the addressing instruction data frame comprises: obtaining a communication address data segment according to the addressing instruction data frame; setting the communication address data segment as the local communication address of the current slave station.

6. The method of automatically addressing RS-485 bus based networks according to claim 3 or 4, characterized in that, The addressing instruction data frame comprises a first data segment, a second data segment, and a CRC16 check code; the addressing instruction data frame satisfies the following conditions: the first data segment and the second data segment have the same content; The addressing instruction data frame can pass the CRC16 check code check.

7. The method of automatically addressing RS-485 bus based networks as claimed in claim 3 or 4, wherein, The communication address is incremented by 1 or by a preset step.

8. An automatic addressing device based on RS-485 bus, characterized in that, The method comprises: a master station configured to generate a broadcast addressing instruction and an addressing instruction data frame, receive and parse a response data frame returned by a slave station; the broadcast addressing instruction contains a control command for setting an automatic addressing register of the slave station to 1; at least one slave station, each slave station comprising a controller, an addressing register, an RS-485 bus communication output interface and an RS-485 bus communication input interface; each slave station is cascaded with the master station through an RS-485 bus; wherein the slave station receives the broadcast addressing instruction sent by the master station through the RS-485 bus communication input interface under the control of the controller, performs a set operation on the addressing register of the slave station based on the broadcast addressing instruction, and issues an automatic addressing instruction; in response to the automatic addressing instruction, the slave station performs automatic addressing based on the addressing instruction data frame sent by the master station, and feeds back an addressing instruction data frame with an incremented communication address to the master station or the next slave station through the RS-485 bus communication output interface.

9. An electronic device, comprising: The electronic device comprises a processor and a memory; The memory is configured to store a computer program; The processor is configured to execute the computer program stored in the memory to enable the electronic device to perform the automatic addressing method based on the RS-485 bus as claimed in any one of claims 1 to 7.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the electronic device to implement the automatic addressing method based on the RS-485 bus as claimed in any one of claims 1 to 7.