Communication method and system of master station and slave station, terminal equipment and storage medium

By using the RS485 bus for master-slave communication in the field of industrial control and realizing automatic configuration of slaves, the problem of difficult communication distance and transmission efficiency of serial bus expansion methods is solved, and efficient communication and automated configuration is achieved.

CN119030818APending Publication Date: 2024-11-26FUJIAN RAYNEN TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411030718.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

In the field of industrial control, it is difficult to take into account both communication distance and transmission efficiency.

Method used

The RS485 bus is used to communicate between master and slave stations, and the master station configures the slave station's network communication address and controls the slave station to enter the operation mode to realize automatic automatic configuration of master and slave stations.

Benefits of technology

It not only ensures a long communication distance, but also achieves a high transmission efficiency and improves configuration efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119030818A_ABST
    Figure CN119030818A_ABST
Patent Text Reader

Abstract

The invention is suitable for the technical field of communication, and provides a communication method and system of a master station and a slave station, terminal equipment and a storage medium. The system comprises a master station and one or more slave stations, the master station communicates with the slave stations through an RS485 bus, and the method comprises the following steps: the master station configures network communication addresses of the slave stations; after the communication address of the slave station is configured, the master station controls the slave station to enter an operation mode; and after the slave station enters the operation mode, the master station performs communication control on the slave station. According to the embodiment of the invention, the master station communicates with the slave station through the RS485 bus, so that a relatively long communication distance can be ensured, and relatively high transmission efficiency can be realized. Meanwhile, the master station configures the network communication address of the slave station and controls the slave station to enter the operation mode, so that automatic configuration of the master station and the slave station can be realized, and the configuration efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of communication technology, and in particular, relates to a communication method, system, terminal device and storage medium for a master-slave station. Background Art

[0002] In the field of industrial control, with the development of automation and intelligence, the number of control points that the control system needs to access and control is increasing, and the number of control points that the controller needs to provide is also increasing. In related technologies, more control points can be obtained by expanding the control module, for example, serial bus expansion methods such as SPI bus, I2C bus, UART, free LVDS bus, CAN, Ethernet, etc. can be used. However, the above serial bus expansion methods are difficult to take into account both communication distance and transmission efficiency. Summary of the invention

[0003] The embodiments of the present application provide a master-slave station communication method, system, terminal device and storage medium, which can solve the problem in the related art that the serial bus expansion method is difficult to take into account both communication distance and transmission efficiency.

[0004] In a first aspect, an embodiment of the present application provides a communication method between a master and a slave station, the method being applied to a communication system of a master and a slave station, the system comprising: a master station, one or more slave stations, the master station and the slave station communicating via an RS485 bus, the method comprising:

[0005] The master station configures the network communication address of the slave station;

[0006] After configuring the communication address of the slave station, the master station controls the slave station to enter the operation mode;

[0007] After the slave station enters the operation mode, the master station performs communication control on the slave station.

[0008] In a second aspect, an embodiment of the present application provides a master-slave station communication system, comprising: a master station, one or more slave stations, wherein the master station communicates with the slave stations via an RS485 bus, and the master station is used to:

[0009] Configuring the network communication address of the slave station;

[0010] After configuring the communication address of the slave station, controlling the slave station to enter the operation mode;

[0011] After the slave station enters the operation mode, communication control is performed on the slave station.

[0012] In a third aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned master-slave station communication method when executing the computer program.

[0013] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned master-slave station communication method are implemented.

[0014] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the above-mentioned master-slave station communication method.

[0015] Compared with the prior art, the embodiment of the present application has the following beneficial effects: the embodiment of the present application uses RS485 bus communication between the master station and the slave station, which can ensure a longer communication distance and achieve higher transmission efficiency. At the same time, the master station configures the network communication address of the slave station and controls the slave station to enter the operation mode, which can realize automatic configuration of the master and slave stations and improve the configuration efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art 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 creative labor.

[0017] Figure 1 It is a schematic diagram of the implementation flow of a master-slave station communication method provided in an embodiment of the present application;

[0018] Figure 2 It is a schematic diagram of a communication system of a master-slave station provided in an embodiment of the present application;

[0019] Figure 3 It is a schematic diagram of the structure of the terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work are protected by the present application.

[0021] It should be noted that the terms "include", "comprises" and "have" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, terminal, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices. In the claims, specification and drawings of the present application, relational terms such as "first" and "second" are merely used to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such real-time relationship or order between these entities / operations / objects.

[0022] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0023] In the field of industrial control, with the development of automation and intelligence, the number of control points that the control system needs to access and control is increasing, and the number of control points that the controller needs to provide is also increasing. In related technologies, more control points can be obtained by expanding the control module, for example, serial bus expansion methods such as SPI bus, I2C bus, UART, free LVDS bus, CAN, Ethernet, etc. can be used. However, the above serial bus expansion methods are difficult to take into account both communication distance and transmission efficiency.

[0024] In view of this, the embodiment of the present application communicates between the master station and the slave station through the RS485 bus, which can not only ensure a longer communication distance, but also achieve a higher transmission efficiency. At the same time, the master station configures the network communication address of the slave station and controls the slave station to enter the operation mode, which can realize automatic configuration of the master and slave stations, thereby improving the configuration efficiency.

[0025] In order to illustrate the technical solution of the present application, a specific embodiment is provided below for illustration.

[0026] Figure 1 A schematic diagram of the implementation flow of a master-slave station communication method provided in an embodiment of the present application is shown. The method can be applied to a master-slave station communication system. The system may include: a master station, one or more slave stations, and the master station and the slave stations communicate via an RS485 bus.

[0027] It is important to understand that the master-slave communication system is a distributed control system architecture that includes a master and one or more slaves. The master is responsible for coordinating and controlling the entire system, which can be a PLC host or a remote IO coupler. The slave performs the tasks assigned by the master or responds to the master's request.

[0028] RS485 bus is a standard that defines the electrical characteristics of drivers and receivers in a balanced digital multi-point system. The standard is defined by the Telecommunications Industry Association and the Electronics Industry Alliance. It has high data transmission rate and good anti-interference performance, allowing up to 32 devices to be connected on a twisted pair and maintaining high-speed data transmission rate within a distance of 1000 meters.

[0029] Specifically, the master-slave station communication method may include the following steps S101 to S103.

[0030] Step S101, the master station configures the network communication address of the slave station.

[0031] Among them, the network communication address is a unique address used to identify the slave station so that other devices can accurately send and receive data.

[0032] In the implementation mode of the present application, when the system is started or initialized, the master station can send configuration instructions to the slave station via the RS485 bus. These configuration instructions can include the unique network communication address of the slave station, and after receiving the configuration instructions, the slave station can save the network communication address in its own memory.

[0033] Step S102, after configuring the communication address of the slave station, the master station controls the slave station to enter the operation mode.

[0034] In the implementation mode of the present application, after the slave successfully configures the network communication address, the master can send a command to enter the operation mode. After receiving the command, the slave can switch its internal state to the operation mode and be ready to execute the task sent by the master or respond to the request of the master.

[0035] Step S103, after the slave station enters the operation mode, the master station performs communication control on the slave station.

[0036] In the implementation mode of the present application, after the slave station enters the operation mode, the master station can send various control instructions to the slave station via the RS485 bus. Specifically, the control instructions may include data reading, writing, device status query, parameter setting, etc. After the slave station receives the instruction, it can perform corresponding operations according to the content of the instruction, and return the result to the master station via the RS485 bus.

[0037] Compared with the prior art, the embodiment of the present application has the following beneficial effects: the embodiment of the present application uses RS485 bus communication between the master station and the slave station, which can ensure a longer communication distance and achieve higher transmission efficiency. At the same time, the master station configures the network communication address of the slave station and controls the slave station to enter the operation mode, which can realize automatic configuration of the master and slave stations and improve the configuration efficiency.

[0038] like Figure 2 As shown, in some embodiments of the present application, the master station includes a master station data communication interface and a master station status control interface, the slave station includes a first slave station, a second slave station and an Nth slave station, N is greater than 2, each slave station includes a slave station data communication interface and a slave station status control interface, and the slave station status control interface includes a slave station status control input interface and a slave station status control output interface.

[0039] Among them, the master station data communication interface is the interface used by the master station to transmit data with the slave station, usually used to send control instructions, read data, etc. The master station status control interface is the interface used by the master station to perform certain status controls on the slave station, such as start, stop, reset, etc. The slave station data communication interface corresponds to the master station data communication interface, and the slave station data communication interface is used for data transmission between the slave station and the master station. The slave station status control interface corresponds to the master station status control interface, and the slave station status control interface allows the master station or other slave stations of the slave station to perform status control on the slave station. The slave station status control input interface is used to receive status control instructions from the master station or other slave stations. The slave station status control output interface is used to forward the status control instructions of the slave station to the next slave station. The first slave station is directly connected to the master station through the status control interface. The second slave station is directly connected to the first slave station through the status control interface, and so on.

[0040] The above master station and slave station communicate via RS485 bus, including the following steps:

[0041] The data communication interface of the master station communicates with the data communication interface of each slave station via the RS485 bus.

[0042] In the implementation manner of the present application, the data communication interface of the master station communicates in series with the data communication interface of each slave station via the RS485 bus, that is, a data communication link is established between the master station and the slave station, allowing bidirectional data transmission.

[0043] In some specific implementations of the present application, the master station and the slave station communicate via an RS485 bus, and further include steps S401 to S403.

[0044] Step S401, the master station state control interface communicates with the slave station state control input interface of the first slave station via the RS485 bus.

[0045] Step S402: The slave state control output interface of the first slave station communicates with the slave state control input interface of the second slave station via the RS485 bus.

[0046] Step S403: the slave state control output interface of the second slave station communicates with the slave state control input interface of the Nth slave station via the RS485 bus.

[0047] In the implementation mode of the present application, the master station can not only transmit data with the slave station, but also directly control the state of the first slave station through the state control interface. After the first slave station receives the state control instruction of the master station, it not only executes it itself, but also forwards the instruction to the next slave station (i.e., the second slave station) through its state control output interface. Similarly, the second slave station will also forward the instruction to the third slave station, and so on, until the Nth slave station, thereby forming a state control instruction chain between slave stations.

[0048] Specifically, Figure 2 As shown, the communication system of the master-slave station includes: a master station and a slave station, wherein the slave station includes a first slave station (I / O module (1)), a second slave station (I / O module (2)), and an Nth slave station (I / O module (n)). The master station includes a master station data communication interface (RS485-DP) and a master station state control interface (RS485-CP). Each slave station specifically includes a slave station state control input interface (RS485-CPI) and a slave station state control output interface (RS485-CPO). The communication interface RS485-DP of the master station and the RS485-DP communication interfaces of the I / O modules (1), (2) and (n) are connected via an RS485 bus; the communication interface RS485-CP of the master station and the communication interface RS485-CPI of the I / O module (1) are connected via an RS485 bus; the communication interface RS485-CPO of the I / O module (1) and the communication interface RS485-CPI of the I / O module (2) are connected via an RS485 bus; the communication interface RS485-CPO of the I / O module (2) and the communication interface RS485-CPI of the I / O module (n) are connected via an RS485 bus.

[0049] In some specific implementations of the present application, the master station configures the network communication address of the slave station, which may specifically include steps S501 to S505.

[0050] Step S501: the master station sends a first address configuration instruction to the slave station, and counts the number of the slave stations as one.

[0051] The first address configuration instruction is an initial instruction sent by the master station to the slave station to configure its network communication address. This instruction contains the address information to be configured for the slave station and possible configuration parameters. The number of slave stations is the number of slave station devices in the system, which is used by the master station to track the number of slave stations with configured addresses.

[0052] In an implementation manner of the present application, during the initialization configuration process, the master station may send a configuration instruction including the first address information to the slave station, and count the number of the slave stations as one.

[0053] Step S502, the slave station that has completed the address configuration forwards the first address configuration instruction to the next slave station in sequence, until there is a slave station that has not completed the address configuration, then the slave station sets the address information carried in the first address configuration instruction as its own address, and returns the first execution result through the corresponding slave station status control input interface.

[0054] In the implementation mode of the present application, the slave station receiving the instruction checks whether the address has been configured. If not, it sets the address information in the instruction to its own address and returns the execution result to the master station through the slave station status control input interface. If the address has been configured, it forwards the instruction to the next slave station.

[0055] Step S503, after receiving the first execution result, the master station sends a second address configuration instruction to the slave station, and counts the number of the slave stations as two.

[0056] In the implementation manner of the present application, after receiving the execution result of the first slave station, the master station knows that the address of the slave station has been configured, so it sends a second address configuration instruction and counts the number of slave stations as two.

[0057] Step S504, the slave station that has completed the address configuration forwards the second address configuration instruction to the next slave station in sequence, until there is a slave station that has not completed the address configuration, then the slave station sets the address information carried in the second address configuration instruction as its own address, and returns the second execution result through the corresponding slave station status control input interface.

[0058] Step S505, after receiving the second execution result, the master station sends the Nth address configuration instruction to the slave station, and counts the number of slave stations as N, and so on, until all slave stations complete the address configuration.

[0059] In an implementation manner of the present application, the master station may repeat the above process until all slave stations have received and set their own addresses.

[0060] The specific implementation steps are as follows:

[0061] 1) The master station sends the slave station address configuration command ADDR1_CFG to the I / O module (1) through the communication interface RS485-CP, and counts the number of I / O modules to 1. After receiving ADDR1_CFG, the I / O module (1) determines whether it has already been configured with an address:

[0062] ① If yes, forward the ADDR1_CFG command through the RS485_CPO communication interface.

[0063] ② If not, set the address information carried in ADDR1_CFG as its own address, and then return the execution result of the address configuration instruction ADDR1_CFG to the master station through the RS485_CPI port.

[0064] 2) After the master station receives the address configuration instruction execution result feedback from the I / O module (1) through the communication interface RS485-CP, it determines whether the instruction execution is successful:

[0065] ① If it fails, resend the ADDR1_CFG command. If it fails to succeed after 3 resends, it is considered a system failure, and the resending is stopped and an alarm is issued.

[0066] ② If successful, the slave address configuration command ADDR2_CFG is sent to the I / O module (1) through the state control communication interface RS485-CP, and the number of I / O modules is counted as 2. Since the I / O module (1) itself has been configured with an address, the I / O module (1) will forward the AADR2_CFG command through the RS485_CPO communication interface. After receiving ADDR2_CFG, the I / O module (2) determines whether it has been configured with an address:

[0067] ① If yes, forward the ADDR2_CFG command through the RS485_CPO communication interface.

[0068] ② If not, the address information carried in ADDR2_CFG is set as its own address, and then the execution result of the address configuration instruction ADDR2_CFG is returned to the I / O module (1) through RS485_CPI. After the RS485_CPO of the I / O module (1) receives the execution result of the address configuration instruction ADDR2_CFG returned by the I / O module (2), it is forwarded to the master station through RS485_CPI.

[0069] 3) After receiving the execution result feedback of the address configuration instruction ADDR2_CFG of the I / O module (2) through the status control communication interface RS485-CP, the master station determines whether the instruction execution is OK:

[0070] ① If it fails, resend the ADDR2_CFG command. If it fails to succeed after 3 resends, it is considered a system failure, and the resend is stopped and an alarm is issued.

[0071] ② If successful, the slave address configuration instruction ADDRn_CFG is sent to the I / O module (1) through the status control communication interface RS485-CP, and the number of I / O modules is counted as n. Since the I / O module (1) itself has been configured with an address, the ADDRn_CFG instruction is forwarded to the I / O module (2) through the RS485_CPO communication interface. Since the I / O module (2) itself has been configured with an address, the ADDRn_CFG instruction is forwarded to the I / O module (n) through the RS485_CPO communication interface. After receiving ADDRn_CFG, the I / O module (n) determines whether it has been configured with an address:

[0072] ① If yes, forward the ADDRn_CFG command through the RS485_CPO communication interface.

[0073] ② If not, the address information carried in ADDRn_CFG is set as its own address, and then the execution result of the address configuration instruction ADDR2_CFG is returned to the I / O module (2) through RS485_CPI. After the RS485_CPO of the I / O module (2) receives the execution result of the address configuration instruction ADDR2_CFG returned by the I / O module (n), it forwards it to the I / O module (1) through RS485_CPI. After the RS485_CPO of the I / O module (1) receives the execution result of the address configuration instruction ADDR2_CFG returned by the I / O module (2), it forwards it to the master station through RS485_CPI.

[0074] In the implementation mode of the present application, by forwarding configuration instructions between slave stations, each slave station immediately checks whether the address has been configured after receiving the configuration instruction, thereby avoiding repeated configuration of the already configured slave station, thereby reducing the configuration error rate. In addition, this method does not depend on a specific number of slave stations and can be easily expanded to a system containing more slave stations. Simply increase the number of configuration instructions and the upper limit of the counter.

[0075] In some specific implementations of the present application, the master station controls the slave station to enter the operation mode, which may specifically include step S601 and step S602.

[0076] Step S601: the master station sends a start instruction to all slave stations through the master station status control interface.

[0077] Among them, the startup command is a control command used to instruct the slave to enter the running state. The startup mode is the state of the slave after receiving the startup command. At this time, the slave will prepare to transmit data or perform corresponding tasks. The heartbeat message is a message sent by the slave to the master regularly to notify the master that the slave is currently active and confirm the connectivity of the communication link.

[0078] In an implementation manner of the present application, the master station may send a startup instruction to all slave stations through the master station status control interface to notify all slave stations to start running.

[0079] Step S602: All slave stations enter the startup mode after receiving the startup instruction, and return corresponding heartbeat messages to the previous slave station in turn until the master station receives the heartbeat messages from all slave stations.

[0080] In the implementation mode of the present application, when the slave station receives the startup instruction, it will enter the startup mode and prepare to start running or perform the corresponding task. After the slave station enters the startup mode, the corresponding heartbeat message will be returned to the previous slave station (i.e. the slave station before it) in sequence. The sending of the heartbeat message is to confirm that the slave station has successfully entered the startup mode, and the communication link between the master station and the adjacent slave station is unobstructed. The master station will wait for and receive the heartbeat messages returned by all slave stations. After the master station receives the heartbeat message from the slave station, it can be confirmed that all slave stations have successfully entered the startup mode, and the entire system is ready for data transmission or other tasks.

[0081] Specifically, after the communication network address is configured, the master station sends the slave station start instruction DEV_START to all slave stations via the RS485_CP port. After receiving DEV_START, the I / O module (1) enters the operation mode and returns the heartbeat message (DEV_TICK) to the master station; then the DEV_START instruction is forwarded via RS485_CPO, and after receiving DEV_START, the I / O module (2) enters the operation mode and returns the heartbeat message (DEV_TICK) to the I / O module (1); then the DEV_START instruction is forwarded via RS485_CPO, and after receiving DEV_START, the I / O module (n) enters the operation mode and returns the heartbeat message (DEV_TICK) to the I / O module (2); then the whole system enters the normal working stage. The master station maintains the operation status of each I / O module through the received heartbeat message (DEV_TICK).

[0082] The implementation method of the present application requires the slave station to return a heartbeat message to the master station, so that the master station can confirm that each slave station has successfully received the startup instruction and entered the startup mode. This helps to ensure the stable operation of the entire system and helps to promptly discover and resolve communication failures, thereby enhancing the reliability and stability of the entire system. Through a unified startup instruction and heartbeat message mechanism, the system configuration and management process can also be simplified, reducing maintenance costs.

[0083] In some implementations of the present application, the master station performs communication control on the slave station, which may further include step S701 and step S702.

[0084] Step S701: the master station sends a data read / write instruction to the slave station.

[0085] Among them, the data read and write instructions are instructions sent by the master station to the slave station, which are used to read or write data on the slave station.

[0086] In an implementation manner of the present application, the master station may send a data read / write instruction to the slave station to request the slave station to perform a corresponding data read / write operation.

[0087] Step S702, if the master station has not received a reply message returned by any slave station according to the read / write instruction, the master station directly skips the slave station that failed to read / write data, and sends a read / write instruction to the next slave station of the slave station that failed to read / write data, until the master station receives reply messages returned by all slave stations that read / write data normally.

[0088] The reply message refers to the slave station receiving the data read and write instruction from the master station, executing the corresponding operation according to the instruction, and returning the operation result to the master station in the form of a message.

[0089] In the implementation manner of the present application, the master station may wait for a reply message from the slave station. If the master station does not receive a reply message from any slave station, it indicates that the slave station has failed to read or write data. At this time, the master station may skip the slave stations that have failed to read or write data, and continue to send data read or write instructions to the next slave station.

[0090] Specifically, the master station performs communication control on the slave station, including:

[0091] 1) The master station wants to read the data of the I / O expansion module (1). It will first determine whether the I / O module (1) is working properly:

[0092] ①If it is abnormal, skip the slave station and execute the next instruction.

[0093] ② If normal, send the slave remote data read instruction DEV_RD (ADDR1), and then wait for the slave remote I / O expansion module (1) to reply with the message DEV_RD_RTN (ADDR1). If the correct reply message is received within the specified time, the slave data is read successfully and the operation is marked as successful DEV_RD_OK, otherwise it is judged as a failure to read the data.

[0094] 2) The master station wants to write data to the I / O expansion module (1). The master station first determines whether the I / O module (1) is working normally:

[0095] ①If it is abnormal, skip the slave station and execute the next instruction.

[0096] ② If normal, send the slave remote data write command DEV_WR (ADDR1), and then wait for the slave remote I / O expansion module (1) to reply with the message DEV_WR_RTN (ADDR1). If the correct reply message is received within the specified time, the slave data is read successfully and the operation is marked as successful DEV_WR_OK, otherwise it is judged as a failure to write data.

[0097] The implementation method of the present application ensures that the master station will not be completely interrupted during the data reading and writing process due to the failure of a slave station, thereby improving the efficiency and fault tolerance of communication. At the same time, it also provides the master station with an opportunity to identify and handle the faulty slave station.

[0098] In some specific embodiments of the present application, the above-mentioned master station directly skips the slave station that fails to read or write data, and sends read or write instructions to the next slave station of the slave station that fails to read or write data, until the master station receives reply messages returned by all slave stations that read or write data normally. The above-mentioned method may also include steps S801 and S802.

[0099] Step S801, the master station resends a preset number of data read and write instructions to the slave station that fails to read or write data.

[0100] In an implementation manner of the present application, for a slave station that fails to read or write data, the master station will resend the data read or write instruction a preset number of times.

[0101] Step S802: If the master station does not receive a reply message returned by the slave station that fails to read or write data according to the read or write instruction, the master station executes the system alarm strategy.

[0102] In the implementation mode of the present application, the master station waits for the reply messages from the slave stations again. If the master station still does not receive the reply messages from the slave stations after a preset number of retries, the master station will execute the system alarm strategy. Specifically, it may include sending an alarm message to the operator, recording an error log, automatically restarting the system, and other measures.

[0103] It should be understood that in the related art, regarding the processing of the master station's failure to read and write data from the slave station, the commonly used processing methods in the related art are to retry a certain number of times after the data reading or writing fails. If it is still unsuccessful, the slave station is skipped to continue the subsequent reading and writing operations of the slave station. This method will cause the subsequent operation of the slave station to be poor in real time due to the retry of an error in a slave station. In order to solve this problem, the implementation method of the present application does not retry the operation after the data reading or writing fails, but only sends a message of data reading failure or writing failure to the corresponding slave station, and then continues the subsequent reading or writing operation of the slave station, and waits for all slave stations to read or write The operation is completed and then retry the failed slave station, retrying a round if there is still a failure, then retry again, if there is still a failure, the system alarms. The implementation method of the present application resends instructions and alarm strategies, and the master station can repair or isolate the faulty slave station to a certain extent to ensure the overall stable operation of the system. At the same time, it also provides clear fault information for system administrators to facilitate their troubleshooting and repair.

[0104] Figure 2 The structure diagram of a master-slave station communication system provided in an embodiment of the present application is shown. The master-slave station communication system includes: a master station and one or more slave stations. The master station and the slave stations communicate via an RS485 bus. The master station is used to:

[0105] Configure the network communication address of the slave station;

[0106] After configuring the communication address of the slave station, control the slave station to enter the running mode;

[0107] After the slave enters the running mode, the communication of the slave is controlled.

[0108] Compared with the prior art, the embodiment of the present application has the following beneficial effects: the embodiment of the present application uses RS485 bus communication between the master station and the slave station, which can ensure a longer communication distance and achieve higher transmission efficiency. At the same time, the master station configures the network communication address of the slave station and controls the slave station to enter the operation mode, which can realize automatic configuration of the master and slave stations and improve the configuration efficiency.

[0109] It is understandable that the above-mentioned master station or slave station can also be used to execute the implementation method corresponding to the above-mentioned method, which will not be repeated here.

[0110] like Figure 3FIG. 1 is a schematic diagram of a terminal device provided in an embodiment of the present application. It is understandable that the terminal device 3 may be a master station or a slave station, or may be a device including both a master station and a slave station. The terminal device 3 may include: a processor 301, a memory 302, and a computer program 303 stored in the memory 302 and executable on the processor 301, such as a communication program of a master-slave station. When the processor 301 executes the computer program 303, the steps in the above-mentioned communication method embodiments of each master-slave station are implemented, such as Figure 1 Steps S101 to S103 are shown.

[0111] The computer program may be divided into one or more modules / units, which are stored in the memory 302 and executed by the processor 301 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the terminal device.

[0112] The terminal device may include, but is not limited to, a processor 301 and a memory 302. Those skilled in the art will appreciate that Figure 3 It is only an example of a terminal device and does not constitute a limitation of the terminal device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access equipment, buses, etc.

[0113] The processor 301 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0114] The memory 302 may be an internal storage unit of the terminal device, such as a hard disk or memory of the terminal device. The memory 302 may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device. Further, the memory 302 may also include both an internal storage unit of the terminal device and an external storage device. The memory 302 is used to store the computer program and other programs and data required by the terminal device. The memory 302 may also be used to temporarily store data that has been output or is to be output.

[0115] It should be noted that, for the convenience and brevity of description, the structure of the above-mentioned terminal device can also refer to the specific description of the structure in the method embodiment, which will not be repeated here.

[0116] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0117] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned master-slave station communication method can be implemented.

[0118] An embodiment of the present application provides a computer program product. When the computer program product is run on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned master-slave station communication method when executing the computer program product.

[0119] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0120] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0121] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0122] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0123] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0124] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0125] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A master-slave communication method, It is characterized in that The method is applied to a master-slave station communication system, the system comprising: a master station and one or more slave stations, the master station and the slave stations communicate via an RS485 bus, the method comprising: The master station configures the network communication address of the slave station; After configuring the communication address of the slave station, the master station controls the slave station to enter the operation mode; After the slave station enters the operation mode, the master station performs communication control on the slave station.

2. The master-slave communication method as claimed in claim 1, It is characterized in that The master station includes a master station data communication interface and a master station state control interface, the slave station includes a first slave station, a second slave station and an Nth slave station, N is greater than 2, each of the slave stations includes a slave station data communication interface and a slave station state control interface, and the slave station state control interface includes a slave station state control input interface and a slave station state control output interface; The master station communicates with the slave station via RS485 bus, including: The master station data communication interface communicates with each of the slave station data communication interfaces via the RS485 bus.

3. The master-slave communication method as claimed in claim 2, It is characterized in that The master station communicates with the slave station via an RS485 bus, and further comprises: The master station state control interface communicates with the slave station state control input interface of the first slave station via the RS485 bus; The slave state control output interface of the first slave station communicates with the slave state control input interface of the second slave station via the RS485 bus; The slave state control output interface of the second slave station communicates with the slave state control input interface of the Nth slave station via the RS485 bus.

4. The communication method of the master-slave station as claimed in claim 3, It is characterized in that The master station configures the network communication address of the slave station, including: The master station sends a first address configuration instruction to the slave station, and counts the number of the slave stations as one; The slave station that has completed the address configuration forwards the first address configuration instruction to the next slave station in sequence, until there is a slave station that has not completed the address configuration, then the slave station sets the address information carried in the first address configuration instruction as its own address, and returns the first execution result through the corresponding slave station state control input interface; After receiving the first execution result, the master station sends a second address configuration instruction to the slave station, and counts the number of the slave stations as two; The slave station that has completed the address configuration forwards the second address configuration instruction to the next slave station in sequence, until there is a slave station that has not completed the address configuration, then the slave station sets the address information carried in the second address configuration instruction as its own address, and returns the second execution result through the corresponding slave station state control input interface; After receiving the second execution result, the master station sends the Nth address configuration instruction to the slave station, and counts the number of slave stations as N, and so on, until all the slave stations complete the address configuration.

5. The master-slave communication method as claimed in claim 3, It is characterized in that The master station controls the slave station to enter a running mode, including: The master station sends a start instruction to all the slave stations through the master station status control interface; After receiving the startup instruction, all the slave stations enter the startup mode and return corresponding heartbeat messages to the previous slave station in turn until the master station receives the heartbeat messages from all the slave stations.

6. The master-slave communication method as claimed in claim 3, It is characterized in that The master station performs communication control on the slave station, including: The master station sends a data read and write instruction to the slave station; If the master station does not receive a reply message returned by any of the slave stations according to the read / write instruction, the master station directly skips the slave station that failed to read / write data, and sends the read / write instruction to the next slave station after the slave station that failed to read / write data, until the master station receives reply messages returned by all slave stations that read / write data normally.

7. The master-slave communication method as claimed in claim 6, It is characterized in that The master station directly skips the slave station that fails to read or write data, and sends the read or write instruction to the next slave station of the slave station that fails to read or write data, until the master station receives reply messages returned by all slave stations that read or write data normally, the method further includes: The master station resends the data read and write instructions a preset number of times to the slave station that fails to read or write data; If the master station does not receive the reply message returned by the slave station that fails to read or write data according to the read or write instruction, the master station executes the system alarm strategy.

8. A master-slave communication system, It is characterized in that include: A master station and one or more slave stations, wherein the master station and the slave stations communicate via an RS485 bus, and the master station is used for: Configuring the network communication address of the slave station; After configuring the communication address of the slave station, controlling the slave station to enter the operation mode; After the slave station enters the operation mode, communication control is performed on the slave station.

9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the master-slave station communication method as claimed in any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the steps of the master-slave station communication method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Method for automatically configuring RS485 communication parameters and electronic equipment

    CN120074973A

  • Interaction method and device between master station equipment and slave station equipment, centralized controller, building management system and storage medium

    CN120785680A