Control method and control equipment of parallel operation system and storage medium
By introducing random codes and random delays into the RS485 parallel system, the system's automatic master-slave switching and automatic allocation of virtual parallel address are realized, which solves the disadvantages of manual intervention in the prior art, improves convenience and reduces labor costs.
Patent Information
- Application Number
- CN202411999338.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2044-12-31
AI Technical Summary
In the prior art, manual intervention is required to realize master-slave switching in the RS485 parallel system, which is not convenient enough, especially in systems that have been installed or systems installed in remote areas.
By introducing random codes and random delays into the RS485 parallel system, controllers can automatically be in the parallel state, judge the host identity by themselves, and automatically assign virtual parallel addresses to realize automatic switching and communication between master and slave.
The automatic master-slave switching of the RS485 parallel system and the automatic allocation of virtual parallel address are realized, which reduces labor costs, improves convenience, and avoids the need for manual address reconfiguration.
Smart Images

Figure CN119945978A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of parallel systems, and in particular to a control method, a control device and a storage medium for a parallel system. Background Art
[0002] RS485 parallel system is a common multi-machine communication system, which is usually used to connect multiple devices to achieve data communication and linkage control. In such a system, there are mainly two roles: master and slave. In actual operation, the master may not work properly, such as errors in the host control logic, communication failures, etc. This host abnormality will cause the system to not operate normally, and it is necessary to switch the master and slave again.
[0003] At present, the common method of master-slave switching is to implement it through manual intervention, and the hardware dial code of the communication address is set on the device to assign the slave address. The manual allocation method is not convenient enough, which requires personnel to operate on site in real time, which is inconvenient for systems that have been installed or installed in remote areas. Summary of the invention
[0004] The technical problem to be solved by the embodiments of the present invention is to provide a control method, a control device and a storage medium for a parallel system, so as to solve the problem that manual intervention is required in the prior art to realize the switching between the master and slave machines, which is not convenient enough.
[0005] The present invention discloses a control method for a parallel system, which is applied to an RS485 parallel system. The RS485 parallel system includes a plurality of controllers connected in pairs for communication;
[0006] The control method of the parallel system includes:
[0007] The current controller receives the parallel control instruction and transmits the control instruction to the controllers connected to it, so that all the controllers are in a parallel state;
[0008] Obtaining its own random code and random delay, and based on the random delay being in a waiting state, determining whether a first control instruction sent by any other controller is received in the waiting state;
[0009] If not, the controller itself is used as the host, and the other controllers of the RS485 parallel system are used as slaves, and the first control instruction is sent to all the slaves;
[0010] receiving a slave instruction sent by the slave in response to the first control instruction, the slave instruction including a random code of the slave;
[0011] In response to the slave instruction, assigning a virtual parallel address to the slave from an address list, and sending a response instruction to the slave, wherein the response instruction includes the virtual parallel address;
[0012] Acquire the total number of currently connected slaves, set a sending cycle based on the total number, and send a second control instruction to all the slaves according to the sending cycle; the second control instruction includes relevant information of all the slaves, and the relevant information includes the virtual parallel address of the slave;
[0013] A slave data instruction sent by each slave according to its own random delay in response to the second control instruction is received.
[0014] Optionally, the step of receiving a slave data instruction sent by each slave according to its own random delay in response to the control instruction includes:
[0015] When at least one slave fails to send the slave data instruction in response to the second control instruction for a preset number of consecutive times, treating the at least one slave as a disconnected slave;
[0016] The relevant information of the offline slave is deleted, the control instruction is updated, and all the slaves send the updated control instruction.
[0017] Optionally, after the step of determining whether the first control instruction sent by the remaining controllers is received in the waiting state, the following steps are included:
[0018] If yes, the controller sending the first control instruction is used as the host, and in response to the first control instruction sent by the host, the slave instruction including the random code of the slave instruction is sent to the host, and the response instruction sent by the host in response to the slave instruction is received;
[0019] The second control instruction sent by the host is received, and in response to the second control instruction, the slave data of the host is acquired to generate a slave data instruction, and the slave data instruction is sent according to its own random delay.
[0020] Optionally, the control method of the parallel system further includes:
[0021] When the host fails, judging whether it can serve as a new host based on its own virtual parallel address;
[0022] If yes, then change its own virtual parallel address to the default host address;
[0023] A new third control instruction is generated based on the second control instruction received previously, and the third control instruction is sent to the remaining slaves in the RS485 parallel system.
[0024] Optionally, when the current controller is a host, the control method of the parallel system further includes:
[0025] Determine whether its current working status meets the host requirements;
[0026] If not, after receiving the third control instruction sent by the new host, the slave of the new host responds to the third control instruction and sends a slave data instruction according to its own random delay.
[0027] Optionally, when the current controller needs to access a successfully built target parallel system, the control method of the parallel system further includes:
[0028] receiving a second control instruction sent by a current host in the target parallel system, and acting as a current slave of the current host based on the second control instruction;
[0029] Obtaining the random code and the random delay of the current master, generating a current slave instruction based on the random code, and sending the current slave instruction to the current master,
[0030] Receive a current virtual parallel address allocated by the current master based on the current slave instruction.
[0031] Optionally, the step of allocating a virtual parallel address for the slave from an address list in response to the slave instruction comprises:
[0032] Determine whether the random code in the slave instruction is the same as the random code of other slaves. If not, execute the step of allocating a virtual parallel address for the slave from an address list in response to the slave instruction.
[0033] Optionally, the step of receiving a parallel control instruction includes:
[0034] Receive the parallel control instruction input by the user, or receive the parallel control instruction forwarded by any of the other controllers.
[0035] The present invention also discloses a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor executes the steps of the method described above.
[0036] The present invention also discloses a control device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above method.
[0037] Compared with the prior art, the control method of the parallel system provided by the embodiment of the present invention has the beneficial effect that: since the control machines in the parallel system are connected in pairs, any controller can communicate with other remaining controllers. Each controller obtains its own random code and random delay, and the random delay is used to control the delay of the corresponding controller sending instructions to avoid communication congestion and data confusion caused by multiple controllers sending instructions at the same time. The random code is used to apply for a virtual parallel address for the controller as a slave to ensure that there is no conflict between the virtual parallel addresses of each slave, and the virtual parallel addresses of each slave can be automatically allocated without manual setting by the user. Communication between the host and the slave is realized based on the virtual parallel address. When the master and slave switch, communication can be carried out based on the previously allocated virtual parallel address. There is no need to manually reallocate the address, and the system can continue to work normally, which greatly reduces the labor cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The scheme of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments, in which:
[0039] Figure 1 is a flow chart of a first embodiment of a control method for a parallel system provided by the present invention;
[0040] Figure 2 is a flow chart of a second embodiment of a control method for a parallel system provided by the present invention;
[0041] Figure 3 is a flow chart of a third embodiment of a control method for a parallel system provided by the present invention;
[0042] Figure 4 It is a flow chart of a fourth embodiment of the control method of the parallel system provided by the present invention. DETAILED DESCRIPTION
[0043] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. Now, in conjunction with the accompanying drawings, the preferred embodiments of the present invention are described in detail.
[0044] See also Figure 1 , Figure 11 is a flow chart of a first embodiment of a control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention is applied to an RS485 parallel system, which is generally used to connect multiple devices to realize data communication and linkage control. There are two roles in an RS485 parallel system: a host and a slave. The host is responsible for controlling and managing the entire system, while the slave is responsible for executing instructions issued by the host and reporting data to the host. The host needs to be able to identify each slave and communicate effectively with it. The control method for a parallel system provided by the present invention can be implemented based on the MODBUS protocol. The MODBUS protocol is a commonly used industrial communication protocol for transmitting data in an automation system. The MODBUS protocol is based on a master-slave architecture, which includes a master station (host) and multiple slave stations (slaves). The master station is responsible for initiating a communication request, and the slave station responds to the request of the master station. The MODBUS protocol can communicate through different physical media such as serial communication (such as RS-485) or Ethernet. The MODBUS protocol defines a set of communication rules, including the structure of a data frame, function codes, register addresses, etc. Through these rules, the master station can request data from the slave station, send control commands, etc.
[0045] The control method of the parallel system provided by the present invention comprises the following steps:
[0046] S101: The current controller receives a parallel control instruction and transmits the control instruction to a connected controller.
[0047] In a specific implementation scenario, the RS485 parallel system includes multiple controllers that are connected in pairs. When the host has not yet been determined, the status of each controller is the same. The user can randomly select one from multiple controllers to input a control instruction, and the control instruction is used to indicate that each controller is in parallel mode. After receiving the control instruction input by the user, the controller not only puts itself in parallel mode according to the control instruction, but also transmits the control instruction to the RS485 bus. The controllers in the RS485 parallel system all belong to the same RS485 bus. Therefore, the remaining controllers in the RS485 parallel system can receive the control instruction and are in standby mode according to the control instruction. As a result, all controllers in the RS485 parallel system are in parallel mode.
[0048] S102: Obtain its own random code and random delay, and based on the random delay being in a waiting state, determine whether a first control instruction sent by other controllers is received in the waiting state; if not, execute step S103.
[0049] In a specific implementation scenario, after each controller is in parallel state, it obtains its own random code and random delay. Take controller A as an example, controller A can be any controller in the RS485 parallel system. Controller A can obtain random codes and random delays according to a preset algorithm. For example, all controllers can obtain random codes and random delays in ascending order based on their current device addresses, so that the controllers in the RS485 parallel system operate more orderly in data communication and control, while ensuring that each controller has a unique random code and delay to avoid conflicts and confusion.
[0050] In this implementation scenario, the random code can be a number or a combination of numbers or a combination of numbers and letters randomly selected from a set of numbers and / or a combination of numbers and letters, and the random delay can be a duration randomly selected from a range of durations.
[0051] After all controllers have obtained their own random codes and random durations, controller A determines whether it can serve as the host in the RS485 parallel system. If controller A's own random duration is the shortest, controller A will serve as the host in the RS485 parallel system. Specifically, controller A is in a waiting state according to its own random duration, or it can be said that it starts counting down based on the random duration. Before the countdown ends, controller A is in a waiting state. In the waiting state, it is constantly monitored whether the first control information sent by any other controller in the RS485 parallel system is received. If the first control information is not received in the waiting state, it can be considered that its own random duration is the shortest, and controller A can serve as the host. If the first control message sent by the other controllers is received in the waiting state, the random duration of the other controllers is the shortest, and the other controllers can serve as the host, and controller A serves as the slave of the host.
[0052] S103: Taking itself as the host and the other controllers of the RS485 parallel system as slaves, a first control instruction is sent to all the slaves.
[0053] In a specific implementation scenario, when controller A does not receive the first control instruction sent by the other controllers in the waiting state, it determines that it can act as the host, sets its own working mode to the host mode, and sends the first control instruction to the other controllers of the RS485 parallel system. After receiving the first control instruction, the other controllers will act as slaves of controller A, and their working modes will be set to the slave mode.
[0054] S104: Receive a slave instruction sent by the slave in response to the first control instruction, where the slave instruction includes a random code of the slave.
[0055] In a specific implementation scenario, taking any one of the other controllers, such as controller B, as an example, after setting itself to slave mode, controller B sends a slave instruction to controller A, and the slave instruction includes a random code of controller B. When sending the slave instruction, it can be based on the random delay of controller B. After receiving the first control instruction, the slave instruction can be issued after delaying for a period of time corresponding to the random delay. In this way, when there are multiple slaves in the RS485 parallel system, since their respective random delays are not equal, there will be no data transmission conflicts and confusion, thereby ensuring orderly data communication.
[0056] S105: In response to the slave instruction, a virtual parallel address is allocated to the slave from the address list, and a response instruction is sent to the slave, where the response instruction includes the virtual parallel address.
[0057] In a specific implementation scenario, an address list is preset, and the host (controller A) receives a slave instruction sent by the slave (controller B), and in response to the slave instruction, allocates a virtual parallel address to (controller B) from the address list, which can be selected randomly from the address list, or selected from the address list in the order in which the slave instructions are received. A response instruction is sent to the slave (controller B), and the response instruction includes the virtual parallel address assigned to the slave (controller B).
[0058] When the host (controller A) receives the slave instructions from all slaves, it will assign each slave its corresponding virtual parallel address. At the same time, the host (controller A) will be able to obtain the random code of each slave. Therefore, the host (controller A) can store the random code and virtual parallel address of each slave in correspondence to reflect the corresponding relationship between the two.
[0059] The host (controller A) sends a response command to the slave (controller B), completing the data binding between the host (controller A) and the slave (controller B). After the slave (controller B) receives the response command, the host (controller A) can communicate with the slave (controller B) based on the virtual parallel address of the slave (controller B) instead of the actual device address of the slave (controller B).
[0060] In other implementation scenarios, after the host (controller A) receives the slave instructions from all slaves, it stores the random codes of all slaves and determines whether there are at least two identical random codes. If so, no virtual parallel address is assigned to the slaves with the same random code, and no response instruction is sent.
[0061] In other implementation scenarios, after the host (controller A) receives a slave instruction sent by a slave (controller B), it may compare the random code of the slave (controller B) with the random codes of other slaves received previously. If the random code of the slave (controller B) is consistent with the random code received previously, the virtual parallel address will not be assigned to the slave (controller B) and no response instruction will be sent.
[0062] In other implementation scenarios, the slave (controller B) may fail to receive a response instruction. This may be due to a failure in the communication link between the slave (controller B) and the host (controller A). The slave (controller B) can send a slave instruction again to obtain a response instruction sent by the host (controller A). If the response instruction is not received after sending the slave instruction for multiple consecutive times, it can be assumed that the slave is currently offline and stop sending the slave instruction. Further, an alarm prompt and other information can be sent to remind the user to troubleshoot the problem in a timely manner.
[0063] In other implementation scenarios, the situation where the slave (controller B) fails to receive the response instruction may also be caused by the fact that the random code of the slave (controller B) is the same as the random code of other slaves. Therefore, the slave (controller B) that has not received the response instruction can re-execute the steps of obtaining its own random code and random delay in S102, obtain a new random code and random delay, and then send a new slave instruction to the host (controller A) according to the new random code to obtain the response instruction sent by the host (controller A).
[0064] S106: Acquire the total number of currently connected slaves, set a sending cycle based on the total number, and send a second control instruction to all slaves according to the sending cycle.
[0065] In a specific implementation scenario, after the host (controller A) sends a response instruction to the corresponding slave based on each received slave instruction, it is considered that these slaves are currently online and connected to the host (controller A). The host (controller A) counts the number of all slaves that have sent response instructions as the total number of currently connected slaves, and sets the sending cycle based on the total number. If the host sends instructions frequently and there are a large number of slaves, it may cause network congestion and affect the stability and efficiency of communication. Therefore, setting the sending cycle based on the total number can avoid this situation. In addition, regularly sending control instructions may consume a lot of energy, especially when there are a large number of slaves. By adjusting the sending cycle according to the number of slaves, energy can be saved and the service life of the system can be extended.
[0066] The second control instruction is sent to all slaves according to the sending cycle. The second control instruction is used to obtain and notify each slave to report its own slave data to the host. The slave data usually includes the current status of the slave, operating parameters, sensor data, equipment health status, fault information, instruction execution results and other information.
[0067] In one implementation scenario, the second control instruction includes relevant information of each slave. The relevant information includes the virtual parallel address of each slave. Further, the relevant information also includes slave data reported by each slave. Specifically, after the second control instruction is sent in the previous cycle, the slave data reported by the slave is received, and the slave data is added to the second control instruction, and the second control instruction with the slave data added is sent to the slave in the next cycle.
[0068] S107: receiving a slave data instruction sent by each slave according to its own random delay in response to the second control instruction.
[0069] In a specific implementation scenario, after receiving the second control instruction, the slave (controller B) will respond to the second control instruction, collect its own slave data, generate a slave data instruction, and send the slave data instruction to the host (controller A). When sending the slave data instruction, it will issue the slave data instruction after the random delay after receiving the second control instruction based on its own random delay. This can avoid data transmission conflicts and data confusion when all slaves need to send slave data instructions, and can make data transmission more evenly distributed on the timeline, reduce the system load, and improve the stability and reliability of the system.
[0070] In other implementation scenarios, the slave (controller B) may also have problems such as work failure, or the communication link between the slave (controller B) and the host (controller A) may fail, which will cause the slave (controller B) to be unable to receive instructions sent by the host (controller A), or the slave (controller B) cannot send instructions to the host (controller A), then the host (controller A) will not be able to receive the slave data instructions of the slave (controller B). If the slave (controller B) has been offline, the host (controller A) does not need to continue to send instructions to the slave (controller B), avoiding the waste of communication resources and avoiding communication confusion.
[0071] If the host (controller A) fails to receive the slave data instruction from the slave (controller B) for several consecutive times (for example, 2 times or 3 times), the slave (controller B) may be regarded as an offline slave, and the relevant information of the offline slave may be deleted, and the relevant information may include the virtual parallel address of the slave (controller B) and may also include the random code of the slave (controller B). After deleting the relevant information, a new second control instruction is generated based on the deleted relevant information.
[0072] The new second control instruction is sent to all slaves in the RS485 parallel system. After receiving the new second control instruction, all slaves will synchronously remove the relevant information of the offline slave (controller B) and only save the relevant information of other slaves that work normally.
[0073] In this way, each normally working slave in the RS485 parallel system can synchronously remove the relevant information of the offline slave, avoiding operations on the offline slaves and ensuring the stability of the system. Normally working slaves can quickly adapt to the new system status and will not be affected by the offline slaves, ensuring the normal operation of the system.
[0074] Furthermore, if the slave (controller B) is only temporarily faulty, resulting in the failure to successfully send the slave data instruction, it will also receive a new second control instruction after the subsequent fault is repaired. The slave (controller B) detects that the new control instruction no longer includes its own relevant information, and can then learn that it has been regarded as a disconnected slave by the host (controller A), and can send a slave instruction to the host (controller A) again. The slave instruction includes a random code of the slave (controller B), so that the host (controller A) responds to the slave instruction and reallocates a virtual parallel address for the slave (controller B) from the address list. The reallocated virtual parallel address can be the original virtual parallel address of the slave (controller B) or a newly allocated virtual parallel address.
[0075] After the host (controller A) reallocates the virtual parallel address for the slave (controller B), it adds the relevant information of the slave (controller B) to the second control instruction, and sends the added control instruction to each slave in the RS485 parallel system according to the preset sending cycle. In this way, after all slaves receive the new second control instruction, they will synchronize the relevant information of the newly added slave (controller B), so that the slave (controller B) can be reconnected to the RS485 parallel system.
[0076] In this way, each slave in the RS485 parallel system can obtain relevant information of all slaves in the system through the second control instruction. Once the host fails and cannot perform the host work, any slave in normal working state can take over as the new host and control the operation of the entire system based on the relevant information that has been obtained. There is no need to re-perform the addressing operation. The new host can directly take over the work of the host and continue to send control instructions to other slaves. In this way, even if the host fails, the RS485 parallel system can still continue to work normally, thereby ensuring the continuity and stability of the work, which is of great significance for scenarios requiring high reliability and uninterrupted operation.
[0077] It can be seen from the above description that in this embodiment, since the control machines in the parallel system are connected in pairs, any controller can communicate with other remaining controllers. Each controller obtains its own random code and random delay. The random delay is used to control the delay of the corresponding controller sending instructions to avoid communication congestion and data confusion caused by multiple controllers sending instructions at the same time. The random code is used to apply for a virtual parallel address for the controller as a slave to ensure that there is no conflict between the virtual parallel addresses of each slave, and the virtual parallel addresses of each slave can be automatically allocated without manual setting by the user. Communication between the host and the slave is realized based on the virtual parallel address. When the master and slave switch, communication can be carried out based on the previously allocated virtual parallel address. There is no need to manually reallocate the address, and the system can continue to work normally, greatly reducing the labor cost.
[0078] See also Figure 2 , Figure 2 1 is a flow chart of a second embodiment of a control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention comprises the following steps:
[0079] S201: The current controller receives a parallel control instruction and transmits the control instruction to the controller connected to it.
[0080] S202: Obtain its own random code and random delay, and based on the random delay being in a waiting state, determine whether a first control instruction sent by any other controller is received in the waiting state, and if so, execute step S203.
[0081] In a specific implementation scenario, steps S210 - S201 are substantially consistent with steps S101 - S102 of the first embodiment of the control method for the parallel system provided by the present invention, and are not described in detail herein.
[0082] S203: Sending a slave instruction including its own random code to the host in response to the first control instruction sent by the host, and receiving a response instruction sent by the host in response to the slave instruction.
[0083] In a specific implementation scenario, a controller B is used as an example for explanation, and the controller B can be any controller in the RS485 parallel system. When the controller B receives the first control instruction sent by other controllers (for example, the controller A) in the waiting state, the controller B cannot act as a master, but can only act as a slave of the controller A.
[0084] After receiving the first control instruction sent by controller A, controller B will act as a slave of controller A according to the first control instruction. Controller A needs to assign a corresponding virtual parallel address to each slave to achieve master-slave binding of controllers A and B. In order to ensure the uniqueness of each virtual parallel address, controller B will send its own random code to controller A. For example, controller B sends a slave instruction to controller A, and the slave instruction includes the random code of controller B.
[0085] After verifying the uniqueness of the random code of controller B, controller A will assign a unique virtual parallel address to controller B, and include the virtual parallel address in the response instruction and send it to controller B. Thus, controller B acts as a slave of the host (controller A) and communicates with the host (controller A) through the virtual parallel address.
[0086] S204: receiving a second control instruction sent by the host, acquiring its own slave data to generate a slave data instruction in response to the second control instruction, and sending the slave data instruction according to its own random delay.
[0087] In a specific implementation scenario, the host (controller A) needs to obtain the information of each slave to manage the entire RS485 parallel system, and the host (controller A) sends a second control instruction to all slaves. The second control instruction is used to obtain and notify each slave to report its own slave data to the host. After receiving the second control instruction, the slave (controller B) collects the corresponding slave data and generates a slave data instruction according to the collected slave data. In addition to the slave data, the slave data instruction may also include a random code and / or a virtual parallel address of the slave (controller B) so that the host (controller A) can correctly parse the slave data of the slave (controller B).
[0088] From the above description, it can be seen that in this embodiment, when the controller acts as a slave, it sends a slave instruction including its own random code to the host, and receives the virtual parallel address sent by the host in response to the slave instruction, so as to realize automatic allocation of virtual parallel addresses of each slave without manual setting by the user, and realize communication between the host and the slave based on the virtual parallel address. When the master and slave are switched, communication can be carried out based on the previously allocated virtual parallel address. There is no need to manually reallocate the address, and the system can continue to work normally, which greatly reduces labor costs and improves convenience.
[0089] See also Figure 3 , Figure 3 1 is a flow chart of a third embodiment of a control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention comprises the following steps:
[0090] S301: When a host fails, it determines whether it can serve as a new host based on its own virtual parallel address; if so, execute step S302.
[0091] In a specific implementation scenario, if the slave finds that the host fails to send the second control instruction according to the cycle, it can be considered that the host fails, or the host can detect whether it fails through some self-detection mechanism. When the host fails, it cannot assume the host responsibilities in the RS485 parallel system. In order to ensure the normal operation of the RS485 parallel system, it is necessary to select one from all the slaves as the new host to inherit the host responsibilities. The failed host can continue to work as a slave of the new host, or it may be disconnected due to serious failure.
[0092] Each slave detects its own working status, for example, it can judge each working ability through preset evaluation criteria to determine whether it can perform the work of the master. If it cannot bear the work of the master, it cannot serve as the master. If its own working status meets the working requirements of the master, it determines whether it can serve as the new master based on its own virtual parallel address. Specifically, it determines whether the value of its own virtual parallel address is the smallest among the virtual parallel addresses of all slaves. If so, it can serve as the new master. If not, it serves as the slave of the new master and continues to work.
[0093] S302: Modify its own virtual parallel address to the preset host address.
[0094] In a specific implementation scenario, the slave with the smallest virtual parallel address, assuming it is controller B, will be used as the new master, and the virtual parallel address of the new master (controller B) will be modified to the preset master address, which is smaller than all virtual parallel addresses in the address list, for example, 1. This ensures that after the master is replaced, the new master (controller B) can immediately take over the control of the entire system, and can also avoid conflicts with other virtual parallel addresses. This ensures that each controller in the system has a unique virtual parallel address to avoid communication confusion and errors. In other implementation scenarios, the preset host address can also be other values, which are set by the user according to actual application requirements.
[0095] S303: Generate a new third control instruction based on the previously received second control instruction, and send the third control instruction to the remaining slaves in the parallel system.
[0096] In a specific implementation scenario, when the new host (controller B) is a slave of the original host (controller A), it receives a second control instruction sent by the original host (controller A), and the second control instruction includes relevant information of each slave, including information such as the virtual parallel address of the slave. Therefore, the new host (controller B) can remove the part related to itself (controller B) based on the relevant information of each slave in the second control instruction received before, generate a third control instruction including relevant information of the remaining slaves, and send the third control instruction to the remaining slaves in the RS485 parallel system. As a result, other slaves in the RS485 parallel system can collect their own slave data based on the received third control instruction, generate corresponding slave data instructions and send them to the new host (controller B).
[0097] In other implementation scenarios, the original host (controller A) can determine whether its current working state meets the host requirements. If so, the original host (controller A) continues to work as the host in the RS485 parallel system. If not, the original host (controller A) no longer works as the host. When a new host (controller B) is selected from the current slaves, the original host (controller A) can work as a slave of the new host (controller B).
[0098] Specifically, when the original host (controller A) is used as a slave (controller A), it is still connected to the new host (controller B). After receiving the third control instruction sent by the new host (controller B), the steps S202-S203 in the second embodiment of the control method of the parallel system provided by the present invention will be executed to obtain the virtual parallel address assigned to it by the new host (controller B). After obtaining its own virtual parallel address, when the slave (controller A) receives the third control instruction sent by the new host (controller B) again, it will collect its own slave data and send the slave data instruction to the new host (controller B) based on its own random delay. In this way, the entire RS485 parallel system can continue to work normally without being affected by the switching of the host.
[0099] From the above description, it can be seen that in this embodiment, when a master machine fails, the slave machine can select a new master machine based on the virtual parallel address, and the new master machine can obtain the relevant information of all slave machines through the second control instruction sent by the original master machine, and thus obtain the virtual parallel address of each slave machine. After becoming the new master machine, it can communicate with the slave machine according to these known virtual parallel addresses. There is no need to manually reallocate the address, and the system can continue to work normally, which greatly reduces labor costs and improves convenience.
[0100] See also Figure 4 , Figure 4 1 is a flow chart of a fourth embodiment of a control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention comprises the following steps:
[0101] S401: Receive a second control instruction sent by the current master in the target parallel system, and serve as a current slave of the current master based on the control instruction.
[0102] In a specific implementation scenario, the current controller is a newly added controller and needs to be added to the target parallel system. Assuming that the host in the target parallel system is controller A and the current controller is controller C, when controller C is connected to the target parallel system, when controller A sends the second control instruction to all slaves in the target control system, since the second control instruction is sent through the bus, controller C can also receive the second control instruction. After controller C receives the second control instruction, it indicates that controller C can know that the current host is controller A and has established a communication connection with the host (controller A), and controller C can serve as a slave of the host (controller A).
[0103] S402: Obtain its own random code and random delay, generate a current slave instruction based on the random code, and send the current slave instruction to the current host.
[0104] In a specific implementation scenario, the controller C obtains its own random code and random delay, and the specific acquisition steps are consistent with the steps of obtaining the random code and random delay in the above text, which will not be repeated here. The current slave instruction is generated, and the current slave instruction includes the random code of the controller C.
[0105] S403: Receive the current virtual parallel address allocated by the current host based on the current slave instruction.
[0106] In a specific implementation scenario, after the host (controller A) receives the random code from controller C, it determines whether the random code is a unique random code. If so, a current virtual parallel address can be assigned to controller C according to a preset address list. In this way, the master-slave binding of controller C and the host (controller A) is realized, and controller C works as a slave of the host (controller A).
[0107] It can be understood that when the host (controller A) sends the second control instruction again, the relevant information of the controller C will be added to the second control instruction.
[0108] From the above description, it can be seen that in this embodiment, when there are other controllers that need to be added to the target parallel system, the host communicates with the controller alone and adds it as a slave, which does not affect the communication between the host and other current slaves, does not require the participation of other current slaves, and does not affect the normal operation of the target parallel system.
[0109] The present invention also provides a control device, the control device comprising a processor and a memory. The processor is coupled to the memory. The memory stores a computer program, and the processor executes the computer program when working to implement the above method. The detailed steps can be found above and will not be repeated here.
[0110] The present invention also provides a computer-readable storage medium. The computer-readable storage medium stores at least one computer program, which is used to be executed by a processor to implement the above method. The detailed steps can be referred to above and will not be repeated here. In one embodiment, the computer-readable storage medium can be a storage chip, a hard disk, or a mobile hard disk or a USB flash drive, an optical disk, or other readable and writable storage tools in a terminal, or a server, etc.
[0111] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0112] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0113] It should be understood that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. For those skilled in the art, the technical solutions described in the above embodiments can be modified, or some of the technical features therein can be replaced by equivalents; and all these modifications and replacements should fall within the scope of protection of the claims attached to the present invention.
Claims
1. A control method for a parallel system, characterized in that: Applicable to RS485 parallel system, the RS485 parallel system includes a plurality of controllers connected in pairs for communication; The control method of the parallel system includes: The current controller receives the parallel control instruction and transmits the control instruction to the controllers connected to it, so that all the controllers are in a parallel state; Obtaining its own random code and random delay, and based on the random delay being in a waiting state, determining whether a first control instruction sent by any other controller is received in the waiting state; If not, the controller takes itself as the host, takes all the other controllers of the RS485 parallel system as slaves, and sends the first control instruction to all the slaves; receiving a slave instruction sent by a slave, wherein the slave instruction includes a random code of the slave; In response to the slave instruction, assigning a virtual parallel address to the slave from an address list, and sending a response instruction to the slave, wherein the response instruction includes the virtual parallel address; Acquire the total number of currently connected slaves, set a sending cycle based on the total number, and send a second control instruction to all the slaves according to the sending cycle; the second control instruction includes relevant information of all the slaves, and the relevant information includes the virtual parallel address of the slave; A slave data instruction sent by each slave according to its own random delay in response to the second control instruction is received.
2. The control method of the parallel system according to claim 1, characterized in that: The step of receiving a slave data instruction sent by each slave according to its own random delay in response to the control instruction comprises: When at least one slave fails to send the slave data instruction in response to the second control instruction for a preset number of consecutive times, treating the at least one slave as a disconnected slave; The relevant information of the offline slave is deleted, the control instruction is updated, and all the slaves send the updated control instruction.
3. The control method of the parallel system according to claim 1, characterized in that: After the step of determining whether the first control instruction sent by the remaining controllers is received in the waiting state, the method further comprises: If yes, the controller sending the first control instruction is used as the host, and in response to the first control instruction sent by the host, the slave instruction including the random code of the slave instruction is sent to the host, and the response instruction sent by the host in response to the slave instruction is received; The second control instruction sent by the host is received, and in response to the second control instruction, the slave data of the host is acquired to generate a slave data instruction, and the slave data instruction is sent according to its own random delay.
4. The control method of the parallel system according to claim 3, characterized in that: The control method of the parallel system also includes: When the host fails, judging whether it can serve as a new host based on its own virtual parallel address; If yes, then change its own virtual parallel address to the default host address; A new third control instruction is generated based on the second control instruction received previously, and the third control instruction is sent to the remaining slaves in the RS485 parallel system.
5. The control method of the parallel system according to claim 4, characterized in that: When the current controller is the host, the control method of the parallel system further includes: Determine whether its current working status meets the host requirements; If not, after receiving the third control instruction sent by the new host, the slave of the new host responds to the third control instruction and sends a slave data instruction according to its own random delay.
6. The control method of the parallel system according to claim 1, characterized in that: When the current controller needs to access a successfully built target parallel system, the control method of the parallel system further includes: receiving a second control instruction sent by a current host in the target parallel system, and acting as a current slave of the current host based on the second control instruction; Obtaining the random code and the random delay of the current master, generating a current slave instruction based on the random code, and sending the current slave instruction to the current master, Receive a current virtual parallel address allocated by the current master based on the current slave instruction.
7. The control method of the parallel system according to claims 1-6, characterized in that: The step of allocating a virtual parallel address for the slave from an address list in response to the slave instruction comprises: Determine whether the random code in the slave instruction is the same as the random code of other slaves. If not, execute the step of allocating a virtual parallel address for the slave from an address list in response to the slave instruction.
8. The control method of the parallel system according to any one of claims 1 to 6, characterized in that: The step of receiving the parallel control instruction includes: Receive the parallel control instruction input by the user, or receive the parallel control instruction forwarded by any of the remaining controllers.
9. A computer-readable storage medium, characterized in that: A computer program is stored, and when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 8.
10. A control device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Ad-hoc network method and device based on RS485 communication, computer equipment and medium
CN115442333A
Slave address automatic allocation method based on CAN bus communication
CN116527638A
Multi-device master-slave competition method and device, storage medium and electronic device
CN117675531A
Intelligent capacitor automatic networking system and method
CN118631785A
Master-slave control maneuvering micro-grid host autonomous distribution method and system
CN119182174A