A control method, control device, and storage medium of a parallel system
By introducing random codes and random delay mechanisms into the RS485 parallel system, the master and slave devices are automatically determined and virtual addresses are assigned. This solves the problem of inconvenience in manual master-slave switching in existing technologies, realizes system automation and stability, and reduces labor costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SRNE SOLAR CO LTD
- Filing Date
- 2024-12-31
- Publication Date
- 2026-04-21
AI Technical Summary
In existing RS485 parallel systems, when the master unit malfunctions, manual intervention is required to switch the master and slave units, which is inconvenient, especially in systems that have already been installed or are located in remote areas.
By using random codes and random delay mechanisms between controllers, the master and slave devices are automatically determined, enabling automatic allocation of virtual parallel addresses, ensuring smooth communication, and eliminating the need for manual address reconfiguration during master-slave switching.
The system automates the master-slave switching operation of the RS485 parallel system, reducing labor costs, improving system stability and convenience, and ensuring smooth communication and normal system operation.
Smart Images

Figure CN119945978B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of parallel system technology, and in particular to a control method, control device and storage medium for a parallel system. Background Technology
[0002] RS485 parallel systems are common multi-device communication systems, typically used to connect multiple devices for data communication and coordinated control. In such systems, there are two main roles: master and slave. In actual operation, the master may malfunction, such as due to errors in its control logic or communication failures. Such master failures will cause the system to malfunction, requiring a master-slave switchover.
[0003] Currently, the typical method for master-slave switching is through manual intervention, using hardware DIP switches on the device to assign slave addresses. This manual method is inconvenient, requiring personnel to be on-site in real-time, which is undesirable for already installed systems or systems located 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, control device and storage medium for a parallel system, so as to solve the problem that the master-slave switching in the prior art is not convenient enough.
[0005] This invention discloses a control method for a parallel system, applied to an RS485 parallel system, wherein the RS485 parallel system includes multiple controllers that are connected in pairs for communication.
[0006] The control method for the parallel system includes:
[0007] The current controller receives the parallel operation control command and transmits the control command to the controllers connected to it, so that all the controllers are in parallel operation state;
[0008] The system obtains its own random code and random delay. Based on the random delay being in a waiting state, it determines whether it has received a first control command from any other controller while in the waiting state.
[0009] If not, then it will act as the master, with the other controllers of the RS485 parallel system as slaves, and send the first control command to all slaves;
[0010] Receive a slave instruction sent by the slave device in response to the first control instruction, wherein the slave instruction includes the random code of the slave device;
[0011] 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, the response instruction including the virtual parallel address;
[0012] Obtain the total number of currently connected slave devices, set a transmission period based on the total number, and send a second control instruction to all the slave devices according to the transmission period; the second control instruction includes relevant information of all the slave devices, including the virtual parallel address of the slave device;
[0013] Receive slave data commands sent by each slave in response to the second control command according to its own random delay.
[0014] Optionally, the step of receiving a slave data instruction sent by each slave in response to the control instruction according to its own random delay includes:
[0015] If at least one slave device fails to respond to the second control command and send the slave data command for a preset number of consecutive times, the at least one slave device will be designated as a disconnected slave device.
[0016] Delete the relevant information of the offline slave device, update the control command, and all slave devices send the updated control command.
[0017] Optionally, after determining whether a first control command sent by the other controllers has been received during the waiting state, the process includes:
[0018] If so, the controller that sends the first control command will be the master, and in response to the first control command sent by the master, the slave command including its own random code will be sent to the master, and the response command sent by the master in response to the slave command will be received.
[0019] The system receives the second control command sent by the host, and in response to the second control command, obtains its own slave data, generates a slave data command, and sends the slave data command according to its own random delay.
[0020] Optionally, the control method of the parallel system further includes:
[0021] When the host fails, it determines whether it can act as a new host based on its own virtual parallel address.
[0022] If so, then change its own virtual parallel address to the default host address;
[0023] A new third control command is generated based on the previously received second control command, and the third control command is sent to the other slave devices in the RS485 parallel system.
[0024] Optionally, when the current controller is the master, the control method of the parallel system further includes:
[0025] Determine whether your current working status meets the host requirements;
[0026] If not, after receiving the third control command sent by the new host, the slave device, acting as the slave of the new host, responds to the third control command and sends slave data commands according to its own random delay.
[0027] Optionally, when the current controller needs to connect to a target parallel system that has already been successfully assembled, the control method of the parallel system further includes:
[0028] Receive a second control command sent by the current master in the target parallel system, and act as the current slave of the current master based on the second control command;
[0029] The system obtains its own random code and random delay, generates a current slave instruction based on the random code, and sends the current slave instruction to the current host.
[0030] Receive the current virtual parallel address allocated by the current host based on the current slave instruction.
[0031] Optionally, the step of allocating a virtual parallel address to the slave from the address list in response to the slave instruction includes:
[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 to the slave from the address list in response to the slave instruction.
[0033] Optionally, the step of receiving the parallel control command includes:
[0034] The system can receive the parallel control command input by the number of users, or receive the parallel control command forwarded by any of the other controllers.
[0035] The present invention also discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform 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 performs the steps of the method described above.
[0037] Compared with the prior art, the beneficial effects of the control method for the parallel system provided in this invention are as follows: Since the controllers in the parallel system are connected in pairs, any controller can communicate with the 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, avoiding communication congestion and data corruption caused by multiple controllers sending instructions simultaneously. The random code is used to apply for a virtual parallel address for the controller acting as a slave, ensuring that there is no conflict between the virtual parallel addresses of each slave, and enabling automatic allocation of virtual parallel addresses for each slave without manual user configuration. Communication between the master and slave is achieved based on the virtual parallel address. When switching between master and slave, communication can be carried out based on the previously allocated virtual parallel address without manual address readjustment, and the system can continue to work normally, greatly reducing labor costs. Attached Figure Description
[0038] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. In the accompanying drawings:
[0039] Figure 1 This is a flowchart illustrating the first embodiment of the control method for the parallel system provided by the present invention;
[0040] Figure 2 This is a flowchart illustrating a second embodiment of the control method for a parallel system provided by the present invention;
[0041] Figure 3 This is a flowchart illustrating the third embodiment of the control method for the parallel system provided by the present invention;
[0042] Figure 4 This is a flowchart illustrating the fourth embodiment of the control method for the parallel system provided by the present invention. Detailed Implementation
[0043] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. The preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0044] Please see Figure 1 , Figure 1It is a schematic flowchart of the first embodiment of the control method for the parallel connection system provided by the present invention. The control method for the parallel connection system provided by the present invention is applied to the RS485 parallel connection system. The RS485 parallel connection system is usually used to connect multiple devices to achieve data communication and linkage control. There are two roles in the RS485 parallel connection system: the host and the slave. The host is responsible for controlling and managing the entire system, while the slave is responsible for executing the 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 the parallel connection 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 communication requests, while the slave stations respond to the requests of the master station. The MODBUS protocol can communicate through different physical media such as serial communication (e.g., RS-485) or Ethernet. The MODBUS protocol defines a set of communication rules, including the structure of data frames, function codes, register addresses, etc. Through these rules, the master station can request data from the slave stations, send control commands, etc.
[0045] The control method for the parallel connection system provided by the present invention includes the following steps:
[0046] S101: The current controller receives the parallel connection control instruction and transmits the control instruction to the connected controller.
[0047] In a specific implementation scenario, the RS485 parallel connection system includes multiple controllers that are pairwise communicatively connected. When the host has not been determined, the status of each controller is the same. The user can randomly select one of the multiple controllers to input a control instruction, and the control instruction is used to indicate that each controller is in the parallel connection mode. After receiving the control instruction input by the user, in addition to the controller itself being in the parallel connection mode according to the control instruction, it also transmits the control instruction to the RS485 bus. The controllers in the RS485 parallel connection system all belong to the same RS485 bus. Therefore, the remaining controllers in the RS485 parallel connection system can all receive the control instruction and be in the standby state according to the control instruction. Thus, all the controllers in the RS485 parallel connection system are in the parallel connection state.
[0048] S102: Obtain its own random code and random delay, wait based on the random delay, and determine whether a first control instruction sent by the remaining controllers is received during the waiting state; if not, execute step S103.
[0049] In a specific implementation scenario, after each controller enters parallel operation, it acquires its own random code and random delay. Taking controller A as an example, controller A can be any controller in the RS485 parallel system. Controller A can acquire the random code and random delay according to a preset algorithm. For example, all controllers can acquire the random code and random delay sequentially in ascending order based on their current device address. This ensures more orderly operation of the controllers in the RS485 parallel system in terms of data communication and control, while also ensuring that each controller has a unique random code and delay, avoiding conflicts and confusion.
[0050] In this implementation scenario, the random code can be a number or combination of numbers or a combination of numbers and letters randomly selected from a set of numbers and / or combinations of numbers and / or combinations of numbers and letters, and the random delay can be a duration randomly selected within a time range.
[0051] After all controllers have obtained their own random codes and random durations, controller A determines whether it can act as the master in the RS485 parallel system. If controller A has the shortest random duration, then controller A will act as the master in the RS485 parallel system. Specifically, controller A is in a waiting state based on its own random duration; in other words, it starts counting down based on the random duration, and remains in a waiting state until the countdown ends. In the waiting state, it constantly monitors whether it receives the first control message from any other controller in the RS485 parallel system. If it does not receive the first control message in the waiting state, it can be considered that its random duration is the shortest, and controller A can act as the master. If it receives the first control message from another controller in the waiting state, then that other controller has the shortest random duration and can act as the master, with controller A acting as the slave of the master.
[0052] S103: It acts as the master, with the other controllers in the RS485 parallel system as slaves, and sends the first control command to all slaves.
[0053] In a specific implementation scenario, when controller A does not receive the first control command from other controllers while in a waiting state, it determines that it can act as the master, sets its own working mode to master mode, and sends the first control command to the other controllers in the RS485 parallel system. After receiving the first control command, the other controllers will act as slaves of controller A, and their working mode will be set to slave mode.
[0054] S104: Receive a slave instruction sent by the slave in response to the first control instruction, the slave instruction including the slave's random code.
[0055] In a specific implementation scenario, taking any one of the other controllers, such as controller B, as an example, after controller B sets itself to slave mode, it sends a slave command to controller A. This slave command includes controller B's random code. When sending the slave command, controller B can delay the first control command for the corresponding random delay duration based on its random delay. In this way, when there are multiple slaves in the RS485 parallel system, since their random delays are not equal, there will be no data transmission conflicts or chaos, ensuring the orderly progress of data communication.
[0056] S105: In response to the slave instruction, allocate a virtual parallel address to the slave from the address list, and send a response instruction to the slave, which includes the virtual parallel address.
[0057] In a specific implementation scenario, a pre-defined address list is provided. When the master (controller A) receives a slave instruction from the slave (controller B), it allocates a virtual parallel address to (controller B) from the address list in response to the slave instruction. This can be done by randomly selecting an address from the address list or by selecting from the address list in the order in which the slave instructions were received. The master then sends a response instruction to the slave (controller B), which includes the virtual parallel address allocated to the slave (controller B).
[0058] Once the host (controller A) receives slave commands from all slave devices, it will assign a corresponding virtual parallel address to each slave device. At the same time, the host (controller A) will be able to obtain the random code of each slave device. Therefore, the host (controller A) can store the random code and virtual parallel address of each slave device to reflect the correspondence between the two.
[0059] When the master (controller A) sends a response command to the slave (controller B), the data binding between the master (controller A) and the slave (controller B) is completed. Upon receiving this response command, the slave (controller B) can subsequently communicate with the slave (controller B) based on the slave's virtual parallel address, rather than through the slave's actual device address.
[0060] In other implementation scenarios, after the host (controller A) receives slave commands from all slaves, it stores the random codes of all slaves and determines whether there are at least two identical random codes. If so, it does not assign virtual parallel addresses to slaves with the same random codes, nor does it send response commands.
[0061] In other implementation scenarios, after the host (controller A) receives a slave instruction from a slave (controller B), it compares the random code of the slave (controller B) with the random codes of other slaves it has previously received. If the random code of the slave (controller B) is consistent with the previously received random codes, then no virtual parallel address is assigned to the slave (controller B), and no response instruction is sent.
[0062] In other implementation scenarios, the slave device (controller B) may fail to receive a response command. This could be due to a communication link failure between the slave device (controller B) and the master device (controller A). The slave device (controller B) can resend the slave command to obtain a response command from the master device (controller A). If no response command is received after multiple consecutive slave command resentments, the device can be assumed to be offline and resuming slave command resentment. Further steps can be taken, such as sending alarm messages, to remind the user to troubleshoot the problem promptly.
[0063] In other implementation scenarios, the failure of the slave device (controller B) to receive a response command may also be due to the slave device (controller B) having the same random code as other slave devices. Therefore, the slave device (controller B) that has not received a response command can re-execute the step 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 command to the master device (controller A) according to the new random code to obtain the response command sent by the master device (controller A).
[0064] S106: Obtain the total number of currently connected slave devices, set the transmission period based on the total number, and send the second control command to all slave devices according to the transmission period.
[0065] In a specific implementation scenario, the host (controller A) considers these slave devices to be online and connected to the host (controller A) after sending a response command to the corresponding slave device for each received slave command. The host (controller A) counts the number of slave devices that have sent response commands, which is taken as the total number of currently connected slave devices, and sets the transmission period based on this total number. If the host sends commands frequently with a large number of slave devices, it may lead to network congestion, affecting the stability and efficiency of communication. Therefore, setting the transmission period based on the total number can avoid this situation. In addition, periodically sending control commands can consume a lot of energy, especially when there are many slave devices. By adjusting the transmission period according to the number of slave devices, energy can be saved and the system's lifespan can be extended.
[0066] According to the sending cycle, the second control command is sent to all slave devices. The second control command is used to obtain and notify each slave device to report its own slave data to the master device. The slave data usually includes the current status of the slave device, operating parameters, sensor data, device health status, fault information, command execution results and other information.
[0067] In one implementation scenario, the second control command includes relevant information for each slave device. This information includes the virtual parallel address of each slave device. Furthermore, it also includes slave data reported by each slave device. Specifically, if slave data reported by a slave device is received after the second control command is sent in the previous cycle, this slave data is added to the second control command, and in the next cycle, the second control command with the added slave data is sent to the slave device.
[0068] S107: Receive slave data commands sent by each slave in response to the second control command according to its own random delay.
[0069] In a specific implementation scenario, after receiving the second control command, the slave device (controller B) will respond by collecting its own slave data, generating a slave data command, and sending the slave data command to the master device (controller A). When sending the slave data command, it will send the slave data command after receiving the second control command at a random delay, based on its own random delay. This can avoid data transmission conflicts and data chaos when all slave devices need to send slave data commands. It can also make data transmission more evenly distributed on the time axis, reduce the system load, and improve the stability and reliability of the system.
[0070] In other implementation scenarios, the slave device (controller B) may also experience malfunctions, or the communication link between the slave device (controller B) and the master device (controller A) may fail. This could cause the slave device (controller B) to be unable to receive commands from the master device (controller A), or the slave device (controller B) to be unable to send commands to the master device (controller A). In such cases, the master device (controller A) will not be able to receive slave data commands from the slave device (controller B). If the slave device (controller B) has gone offline, the master device (controller A) does not need to continue sending commands to the slave device (controller B), thus avoiding waste of communication resources and preventing communication chaos.
[0071] If the master controller (controller A) fails to receive slave data commands from the slave device (controller B) for several consecutive times (e.g., 2 or 3 times), it can treat the slave device (controller B) as a disconnected slave device and delete its relevant information. This information includes the virtual parallel address of the slave device (controller B) and may also include the random code of the slave device (controller B). After deleting the relevant information, a new second control command is generated based on the deleted information.
[0072] The new second control command is sent to all slave devices in the RS485 parallel system. After receiving the new second control command, all slave devices will synchronously remove the relevant information of the offline slave device (controller B) and only save the relevant information of other normally working slave devices.
[0073] In this way, each normally functioning slave device in the RS485 parallel system can synchronously remove the relevant information of the offline slave device, avoiding operation on the offline slave device and ensuring the stability of the system. Normally functioning slave devices can quickly adapt to the new system state and will not be affected by the offline slave device, ensuring the normal operation of the system.
[0074] Furthermore, if the slave device (controller B) experiences only a temporary malfunction, resulting in the failure to successfully send slave data commands, it will receive a new second control command after the malfunction is resolved. If the slave device (controller B) detects that the new control command no longer includes its own information, it can determine that it has been designated as a disconnected slave by the master device (controller A). It can then send a slave command to the master device (controller A), which includes the slave device's (controller B's) random code. This causes the master device (controller A) to respond to the slave command by reassigning a virtual parallel address to the slave device (controller B) from its address list. This reassigned virtual parallel address can be either the slave device's (controller B's) original virtual parallel address or a newly assigned virtual parallel address.
[0075] After the host (controller A) reallocates a virtual parallel address to the slave (controller B), it adds the relevant information of the slave (controller B) to the second control command. The added control command is then sent to each slave in the RS485 parallel system according to a preset sending cycle. In this way, after all slaves receive the new second control command, they will synchronously add the relevant information of the slave (controller B), so that the slave (controller B) can reconnect to the RS485 parallel system.
[0076] In this way, each slave device in the RS485 parallel system can obtain relevant information from all slave devices in the system through the second control command. If the master device fails and cannot perform its function, any slave device in normal working order can take over as the new master, controlling the entire system based on the acquired information. There is no need to re-execute addressing operations; the new master can directly take over the master's work and continue sending control commands to other slave devices. Thus, even if the master fails, the RS485 parallel system can continue to operate normally, ensuring continuity and stability. This is of great significance for scenarios requiring high reliability and uninterrupted operation.
[0077] As described above, in this embodiment, since the controllers in the parallel system are connected in pairs, any controller can communicate with the 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, avoiding communication congestion and data corruption caused by multiple controllers sending instructions simultaneously. The random code is used to apply for virtual parallel addresses for the controllers acting as slaves, ensuring that there are no conflicts between the virtual parallel addresses of each slave and enabling automatic allocation of virtual parallel addresses for each slave without manual user configuration. Communication between the master and slave is achieved based on the virtual parallel addresses. When switching between master and slave, communication can be carried out based on the previously allocated virtual parallel addresses without manual address readjustment, allowing the system to continue to operate normally and greatly reducing labor costs.
[0078] Please see Figure 2 , Figure 2 This is a flowchart illustrating a second embodiment of the control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention includes the following steps:
[0079] S201: The current controller receives the parallel control command and transmits the control command to the controller connected to it.
[0080] S202: Obtain its own random code and random delay. Based on the random delay, it is in a waiting state. Determine whether it has received a first control command from any other controller while in the waiting state. If so, proceed to step S203.
[0081] In a specific implementation scenario, steps S210-S201 are basically the same as steps S101-S102 of the first embodiment of the control method for the parallel system provided by the present invention, and will not be described again here.
[0082] S203: In response to the first control command sent by the host, the slave command, which includes its own random code, is sent to the host, and the slave command is received in response to the host's response to the slave command.
[0083] In a specific implementation scenario, let's take controller B as an example. Controller B can be any controller in an RS485 parallel system. If controller B receives the first control command from another controller (e.g., controller A) while in a waiting state, then controller B cannot act as the master; it can only act as a slave of controller A.
[0084] After receiving the first control command from controller A, controller B will act as a slave of controller A according to the first control command. Controller A needs to assign a corresponding virtual parallel address to each slave to achieve master-slave binding between controller A and controller B. To ensure the uniqueness of each virtual parallel address, controller B will send its own random code to controller A. For example, when controller B sends a slave command to controller A, the slave command includes controller B's random code.
[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 send the virtual parallel address to controller B in the response instruction. Thus, controller B acts as a slave of the master (controller A) and communicates with the master (controller A) through the virtual parallel address.
[0086] S204: Receive the second control command sent by the host, and in response to the second control command, obtain its own slave data, generate a slave data command, and send the slave data command according to its own random delay.
[0087] In a specific implementation scenario, the host (controller A) needs to acquire information from each slave device to manage the entire RS485 parallel system. The host (controller A) sends a second control command to all slave devices. This second control command is used to instruct each slave device to report its slave data to the host. After receiving the second control command, the slave device (controller B) collects the corresponding slave data and generates a slave data instruction. Besides the slave data itself, the slave data instruction may also include the slave device's (controller B's) random code and / or virtual parallel address, enabling the host (controller A) to correctly parse the slave data from the slave device (controller B).
[0088] As described above, in this embodiment, when the controller acts as a slave, it sends a slave command including its own random code to the master and receives the virtual parallel address sent by the master in response to the slave command. This enables automatic allocation of virtual parallel addresses for each slave without requiring manual user configuration. Communication between the master and slave is achieved based on the virtual parallel address. When switching between master and slave, communication can be conducted based on the previously allocated virtual parallel address without the need for manual address readjustment. The system can continue to operate normally, greatly reducing labor costs and improving convenience.
[0089] Please see Figure 3 , Figure 3 This is a flowchart illustrating the third embodiment of the control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention includes the following steps:
[0090] S301: When the host fails, determine whether it can act as a new host based on its own virtual parallel address; if so, proceed to step S302.
[0091] In a specific implementation scenario, if a slave device detects that the master device has failed to send the second control command according to the cycle, it can be considered that the master device has failed. Alternatively, the master device can detect its own failure through some self-detection mechanisms. When the master device fails, it cannot assume the master responsibilities in the RS485 parallel system. To ensure the normal operation of the RS485 parallel system, one of the slave devices needs to be selected as the new master device to inherit the master responsibilities. The failed master device can continue to work as a slave device of the new master device, or it may go offline due to a severe failure.
[0092] Each slave device monitors its own operational status. For example, it can evaluate its various capabilities using preset criteria to determine whether it can perform the tasks of a master device. If it cannot handle the master's tasks, it cannot act as a master. If its operational status meets the master's requirements, it determines whether it can become a new master based on its own virtual parallel address. Specifically, it checks whether its virtual parallel address is the smallest among all slave devices. If it is, it can become a new master; otherwise, it continues to work as a slave of the new master.
[0093] S302: Modify its own virtual parallel address to the default host address.
[0094] In a specific implementation scenario, the slave device with the smallest virtual parallel address, assuming it's controller B, will become the new master. The virtual parallel address of the new master (controller B) will be modified to a preset master address, which is less than all virtual parallel addresses in the address list, for example, 1. This ensures that after a master replacement, the new master (controller B) can immediately take over control of the entire system and avoids conflicts with other virtual parallel addresses. This also ensures that each controller in the system has a unique virtual parallel address, preventing communication chaos and errors. In other implementation scenarios, the preset master address can also be other values, set by the user according to actual application requirements.
[0095] S303: Generate a new third control command based on the previously received second control command, and send the third control command to the other slave machines in the parallel system.
[0096] In a specific implementation scenario, when the new master (controller B) acts as a slave of the original master (controller A), it receives a second control command from the original master (controller A). This second control command includes relevant information about each slave, such as the slave's virtual parallel address. Therefore, the new master (controller B) can, based on the relevant information about each slave in the previously received second control command, remove the parts related to itself (controller B) and generate a third control command that includes the relevant information of the remaining slaves. This third control command is then sent to the remaining slaves in the RS485 parallel system. Consequently, the other slaves in the RS485 parallel system can collect their own slave data based on the received third control command and generate corresponding slave data commands to send to the new master (controller B).
[0097] In other implementation scenarios, the original master (controller A) can determine whether its current working state meets the master requirements. If so, the original master (controller A) continues to work as the master in the RS485 parallel system; otherwise, the original master (controller A) ceases to be the master. When a new master (controller B) is selected from the current slaves, the original master (controller A) can work as a slave of the new master (controller B).
[0098] Specifically, when the original host (controller A) becomes a slave (controller A), it remains connected to the new host (controller B). Upon receiving the third control command from the new host (controller B), it executes steps S202-S203 as described in the second embodiment of the control method for the parallel system provided by this invention 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 command from the new host (controller B) again, it collects its own slave data and sends slave data commands to the new host (controller B) based on its own random delay. In this way, the entire RS485 parallel system can continue to operate normally without being affected by the switch of hosts.
[0099] As described above, in this embodiment, when the master fails, the slave can select a new master based on the virtual parallel address. The new master can obtain the relevant information of all slaves through the second control command sent by the original master. Therefore, it can obtain the virtual parallel address of each slave. After becoming the new master, it can communicate with the slaves based on these known virtual parallel addresses. The system can continue to work normally without manual reconfiguration of addresses, which greatly reduces labor costs and improves convenience.
[0100] Please see Figure 4 , Figure 4 This is a flowchart illustrating the fourth embodiment of the control method for a parallel system provided by the present invention. The control method for a parallel system provided by the present invention includes the following steps:
[0101] S401: Receives the second control command sent by the current master in the target parallel system, and acts as the current slave of the current master based on the control command.
[0102] In a specific implementation scenario, the current controller is a newly added controller that needs to be joined to the target parallel system. Assuming the master controller in the target parallel system is controller A, and the current controller is controller C, when controller C joins the target parallel system, and controller A sends a second control command to all slave controllers in the target control system, controller C can also receive the second control command because it is sent via the bus. Upon receiving the second control command, controller C recognizes that the current master controller is controller A and has established a communication connection with it. Controller C can then act as a slave controller of the master controller (controller A).
[0103] S402: Obtain its own random code and random delay, generate the current slave instruction based on the random code, and send the current slave instruction to the current master.
[0104] In a specific implementation scenario, controller C obtains its own random code and random delay. The specific steps for obtaining the random code and random delay are the same as those described above, and will not be repeated here. The current slave instruction is generated, which includes the random code of 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 the controller C, it determines whether the random code is a unique random code. If so, it can assign a current virtual parallel address to the controller C according to the preset address list. This realizes the master-slave binding between the controller C and the host (controller A), and the controller C works as a slave of the host (controller A).
[0107] Understandably, when the host (controller A) sends the second control command again, it will add relevant information about controller C to the second control command.
[0108] As described above, in this embodiment, when other controllers need to be added to the target parallel system, the host communicates with the controller alone and adds it as a slave. This does not affect the communication between the host and other current slaves, nor does it 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, which includes a processor and a memory. The processor is coupled to the memory. The memory stores a computer program, which the processor executes during operation to implement the method described above. Detailed steps are described 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 executed by a processor to implement the above-described method. Detailed steps are described above and will not be repeated here. In one embodiment, the computer-readable storage medium may be a storage chip in a terminal, a hard disk, or other readable and writable storage tools such as a portable hard disk, USB flash drive, or optical disc, or it may be a server, etc.
[0111] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0112] The technical features of the above embodiments can be combined in any way. For the sake of brevity, 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, and are not intended to limit them. Those skilled in the art can modify the technical solutions described in the above embodiments, or make equivalent substitutions for some of the technical features; and all such modifications and substitutions should fall within the protection scope of the appended claims of the present invention.
Claims
1. A control method for a parallel system, characterized in that, Applied to RS485 parallel systems, the RS485 parallel systems include multiple controllers that are connected in pairs for communication. The control method for the parallel system includes: The current controller receives the parallel operation control command and transmits the control command to the controllers connected to it, so that all the controllers are in parallel operation state; Each controller acquires its own random code and random delay. Each controller has a unique random code and delay. Based on the random delay, the controller is in a waiting state and determines whether it receives a first control command from any other controller while in the waiting state. If not, then the system will act as the master, with all the remaining controllers of the RS485 parallel system acting as slaves, and will send the first control command to all the slaves. Receive slave instructions sent by the slave device, wherein the slave instructions include the random code of the slave device; 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, the response instruction including the virtual parallel address; Obtain the total number of currently connected slave devices, set a transmission period based on the total number, and send a second control instruction to all the slave devices according to the transmission period; the second control instruction includes relevant information of all the slave devices, including the virtual parallel address of the slave device; Receive slave data commands sent by each slave in response to the second control command according to its own random delay; If so, the controller that sends the first control command will be the master, and in response to the first control command sent by the master, the slave command including its own random code will be sent to the master, and the response command sent by the master in response to the slave command will be received. The system receives the second control command sent by the host, and in response to the second control command, obtains its own slave data, generates a slave data command, and sends the slave data command according to its own random delay. When the host fails, it determines whether it can act as a new host based on its own virtual parallel address. If so, then change its own virtual parallel address to the default host address; A new third control command is generated based on the previously received second control command, and the third control command is sent to the other slave devices in the RS485 parallel system.
2. The control method for a parallel system according to claim 1, characterized in that, The step of receiving slave data commands sent by each slave in response to the control command according to its own random delay includes: If at least one slave device fails to respond to the second control command and send the slave data command for a preset number of consecutive times, the at least one slave device will be designated as a disconnected slave device. Delete the relevant information of the offline slave device, update the control command, and all slave devices send the updated control command.
3. The control method for a parallel system according to claim 1, characterized in that, The control method for the parallel system further includes: When the host fails, it determines whether it can act as a new host based on its own virtual parallel address. If so, then change its own virtual parallel address to the default host address; A new third control command is generated based on the previously received second control command, and the third control command is sent to the other slave devices in the RS485 parallel system.
4. The control method for a parallel system according to claim 1, characterized in that, When the current controller is the master, the control method of the parallel system further includes: Determine whether your current working status meets the host requirements; If not, after receiving the third control command sent by the new host, the slave device, acting as the slave of the new host, responds to the third control command and sends slave data commands according to its own random delay.
5. The control method for a parallel system according to claim 1, characterized in that, When the current controller needs to connect to a target parallel system that has already been successfully assembled, the control method for the parallel system further includes: Receive a second control command sent by the current master in the target parallel system, and act as the current slave of the current master based on the second control command; The system obtains its own random code and random delay, generates a current slave instruction based on the random code, and sends the current slave instruction to the current host. Receive the current virtual parallel address allocated by the current host based on the current slave instruction.
6. The control method for a parallel system according to claims 1-5, characterized in that, The step of allocating a virtual parallel address to the slave from the address list in response to the slave instruction includes: 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 to the slave from the address list in response to the slave instruction.
7. The control method for a parallel system according to any one of claims 1-5, characterized in that, The step of receiving the parallel operation control command includes: The system can receive the parallel operation control command input by the number of users, or receive the parallel operation control command forwarded by any of the other controllers.
8. A computer-readable storage medium, characterized in that, The system stores a computer program that, when executed by a processor, causes the processor to perform the steps of the method as described in any one of claims 1 to 6.
9. A control device, characterized in that, It includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Intelligent capacitor automatic networking system and method
CN118631785A