Master-slave communication method, electronic equipment and storage medium

By exchanging flag bits between the master and slave devices in the RS485 bus system, the problem of command frame conflict with the current process is resolved, enabling timely response and reducing response latency, thereby improving the efficiency and accuracy of the communication system.

CN121125392AActive Publication Date: 2025-12-12DELIXI GROUP INSTRUMENT CO LTD

Patent Information

Application Number
CN202511640782.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-11
Publication Date
2025-12-12
Estimated Expiration
2045-11-11

AI Technical Summary

Technical Problem

In RS485 bus systems used in industrial automation, if the host or slave device is executing other processes when it receives a command frame, it will cause a conflict between the command frame and the current process, resulting in a response delay.

Method used

When the host receives a command frame, it sends a flag bit to interrupt the current process of the target slave according to the preset conditions of the command. Before sending the command frame, the host reminds the slave to prepare. After receiving the flag bit, the slave interrupts its current process to execute the command frame first. The host also interrupts its process before receiving the response frame from the slave and forwards the response frame in a timely manner.

Benefits of technology

By interrupting processes in advance and responding promptly, conflicts between command frames and the current process are avoided, response latency is reduced, and the efficiency and accuracy of the communication system are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121125392A_ABST
    Figure CN121125392A_ABST
Patent Text Reader

Abstract

The invention provides a master-slave communication method, electronic equipment and a storage medium, and relates to the technical field of communication. The method comprises the steps that when a host receives a command frame sent by an upper computer for a target slave and determines that a command symbol in the command frame meets a first preset condition, a first flag bit is sent to the target slave, the first flag bit is used for indicating that the host is about to send the command frame, the target slave interrupts a current process, and the host sends the command frame to the target slave, the target slave executes the command frame, so that the conflict between the command frame and the current process is avoided, the target slave can immediately execute the command frame without queuing and waiting, the command frame is responded in time, and the response delay is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to a master-slave communication method, electronic device, and storage medium. Background Technology

[0002] In medium- and long-distance communication within industrial automation, the RS485 bus system has been widely adopted due to its advantages such as simple hardware design, flexible control, and low cost. In typical engineering deployments, RS485-based communication systems can employ a master-slave architecture, where one master connects to multiple slave devices, each with a unique communication address. Data exchange between the master and slave devices is achieved through addressing.

[0003] Currently, when the host computer communicates with the host or slave device, the host computer sends a command frame to the host, and the host executes and responds to the command frame; or, the host computer sends a command frame to the slave device through the host, and the slave device executes and responds to the command frame.

[0004] However, if the host or slave receives a command frame while executing another process, a conflict may occur between the command frame and the current process, resulting in a response delay. Summary of the Invention

[0005] This application provides a master-slave communication method, electronic device, and storage medium to solve the problem that if the master or slave receives a command frame while executing other processes, a conflict may occur between the command frame and the current process, resulting in response delay, thereby achieving the goal of reducing response delay.

[0006] In a first aspect, this application provides a master-slave communication method applied to a master in a master-slave communication system, the master-slave communication system comprising a master and multiple slaves, the method comprising: When the host receives a command frame for the target slave from the host computer and determines that the command character in the command frame meets the first preset condition, the host sends a first flag bit to the target slave to cause the target slave to interrupt the current process; the first flag bit is used to indicate that the host is about to send the command frame. The host sends the command frame to the target slave device so that the target slave device executes the command frame.

[0007] In one possible design, the method further includes: The host receives a second flag bit sent by the target slave device, the second flag bit being sent by the target slave device after generating a response frame according to the command frame; the second flag bit is used to indicate that the target slave device is about to send the response frame. The host interrupts the current process; The host receives the response frame sent by the target slave and sends the response frame to the host computer.

[0008] In one possible design, the method further includes: When the host receives a command frame for the target slave from the host computer and determines that the command character in the command frame meets the second preset condition, the host sends the command frame to the target slave. The host receives the third flag bit sent by the target slave and sends the third flag bit to the host computer; the third flag bit is sent by the target slave while continuing to execute the current process and storing the command frame; the third flag bit is used to indicate that the target slave is busy, so that the host computer stops sending other command frames.

[0009] In one possible design, the first preset condition includes: the command character indicates that the command frame is an operation command frame; or, the command character indicates that the command frame is a read command frame and all data identifiers in the command character belong to a preset list; The second preset condition includes: the command character indicates that the command frame is a read-type command frame and the data identifiers in the command character do not belong to the preset list.

[0010] In one possible design, the method further includes: When the host receives a command frame sent by the host computer, it interrupts the current process. The host executes the command frame; The host generates a response frame based on the command frame; The host computer sends the response frame to the host computer.

[0011] Using the method provided in the first aspect, when the host receives a command frame from the host computer targeting the target slave and determines that the command symbol in the command frame meets the first preset condition, it sends a first flag bit to the target slave. This allows the host to know that the command frame needs to be executed first, and to notify the target slave in advance via the first flag bit to prepare to receive the command frame. The target slave interrupts its current process, allowing it to interrupt its current process before the command frame arrives, ensuring timely response to high-priority command frames and avoiding conflicts between command frames and the current process, thus preventing response delays. When the host sends the command frame to the target slave, the target slave executes it. Since the target slave has already interrupted its current process, meaning resources have been released, the target slave can execute the command frame immediately without queuing, achieving timely response to the command frame and reducing response latency.

[0012] Secondly, this application provides a master-slave communication method applied to a slave device in a master-slave communication system, wherein the master-slave communication system includes a master device and multiple slave devices, and the method includes: The target slave device receives a first flag bit sent by the host; the first flag bit is sent by the host when it receives a command frame for the target slave device sent by the host computer and determines that the command character in the command frame meets a first preset condition; the first flag bit is used to indicate that the host is about to send the command frame. The target slave device interrupts the current process; The target slave device receives and executes the command frames sent by the host.

[0013] In one possible design, the method further includes: The target slave device generates a response frame based on the command frame; The target slave device sends a second flag bit to the host device, causing the host device to interrupt the current process; the second flag bit is used to indicate that the target slave device is about to send the response frame. The target slave device sends the response frame to the host device, so that the host device sends the response frame to the host computer.

[0014] In one possible design, the method further includes: The target slave device receives the command frame sent by the host computer when it receives the command frame for the target slave device sent by the host computer, and determines that the command character in the command frame meets the second preset condition; The target slave device continues to execute the current process and stores the command frame; The target slave device sends a third flag bit to the host device, so that the host device sends the third flag bit to the host computer; the third flag bit is used to indicate that the target slave device is busy, so that the host computer stops sending other command frames.

[0015] The beneficial effects of the methods provided in the second aspect and the various possible designs of the second aspect can be found in the first aspect and the various possible designs of the first aspect, and will not be repeated here.

[0016] Thirdly, this application provides a master-slave communication device, comprising: a module for performing the methods described in the first aspect and any possible design of the first aspect.

[0017] Fourthly, this application provides a master-slave communication device, comprising: a module for performing the methods described in the second aspect and any possible design of the second aspect.

[0018] Fifthly, this application provides an electronic device including a first processor, which, when executing a computer-executable program or instructions in a memory, implements a master-slave communication method as described in the first and second aspects and any of the possible designs of the first and second aspects.

[0019] In a sixth aspect, this application provides an electronic device including at least one memory and at least one second processor. The memory stores a computer-executable program or instructions, and the second processor, when executing the computer-executable program or instructions, implements a master-slave communication method as described in the first and second aspects and any of the possible designs of the first and second aspects.

[0020] In a seventh aspect, this application provides a computer-readable storage medium storing a computer-executable program or instructions, which, when executed by a processor, implement a master-slave communication method as described in the first and second aspects and any of the possible designs of the first and second aspects.

[0021] Eighthly, this application provides a computer program product comprising: execution instructions stored in a readable storage medium, at least one processor of an electronic device being able to read the execution instructions from the readable storage medium, and the at least one processor executing the execution instructions causing the electronic device to implement a master-slave communication method as described in the first to second aspects and any of the possible designs of the first to second aspects.

[0022] The above description is merely an overview of the technical solutions of the embodiments of this application. In order to better understand the technical means of the embodiments of this application and to implement them in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the embodiments of this application more obvious and understandable, specific implementation methods of this application are described below. Attached Figure Description

[0023] Figure 1 This is a schematic diagram of a master-slave communication system provided in an embodiment of this application.

[0024] Figure 2 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 1 .

[0025] Figure 3 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 2 .

[0026] Figure 4 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 3 .

[0027] Figure 5Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 4 .

[0028] Figure 6 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 1 .

[0029] Figure 7 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 2 .

[0030] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 1 .

[0031] Figure 9 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 2 . Detailed Implementation

[0032] In this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c alone can mean: a alone, b alone, c alone, a combination of a and b, a combination of a and c, a combination of b and c, or a, b, and c, where a, b, and c can be single or multiple. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0033] The terms “center,” “longitudinal,” “lateral,” “up,” “down,” “left,” “right,” “front,” and “rear,” etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0034] The terms "connected" and "connected" should be interpreted broadly. For example, in circuit structures, "connected" or "connected" can refer not only to physical connections but also to electrical or signal connections. This could be a direct connection (physical connection) or an indirect connection via at least one intermediate component, as long as the circuit is connected. It could also refer to the internal connection between two components. Similarly, a signal connection can refer to a connection via a circuit or a medium, such as radio waves. Those skilled in the art will understand the specific meaning of these terms in this application based on the specific circumstances.

[0035] For example, this application provides a master-slave communication method, electronic device, and storage medium. Before sending a command frame to a target slave device, the master device sends a first flag bit to the target slave device when the command symbol in the command frame meets a first preset condition. This causes the target slave device to interrupt its current process, and the master device then sends the command frame. Therefore, when the target slave device receives a command frame, it can prioritize executing the command frame to respond promptly, thereby avoiding process conflicts and reducing response latency.

[0036] The master-slave communication method provided in this application is executed by an electronic device, or by a master-slave communication device in an electronic device.

[0037] Electronic devices can be the master or slave in a master-slave communication system. The master or slave can be an electricity meter, capacitor, or circuit breaker, etc.

[0038] Electronic devices can also include servers, desktop computers, mobile phones, tablets, laptops, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, etc.

[0039] The master-slave communication device can be implemented through a combination of software and / or hardware. For example, the master-slave communication device can be a transceiver chip. Alternatively, the master-slave communication device can be an application (APP), a webpage, or a public account, etc.

[0040] To simplify the explanation, the embodiments of this application are illustrated using the example of a host and a slave device.

[0041] Below, in conjunction with Figure 1 The master-slave communication system provided in the embodiments of this application will be described.

[0042] Please see Figure 1 , Figure 1 This is a schematic diagram of a master-slave communication system provided in one embodiment of this application. Figure 1As shown, the master-slave communication system of this application may include: a master 11 and multiple slaves 12.

[0043] in, Figure 1 This illustration is based on the example of 3 slave devices 12. This application does not limit the number of slave devices 12.

[0044] The host 11 can be an energy meter or capacitor, and the slave 12 can also be an energy meter or capacitor.

[0045] In a master-slave communication system, slave device 12 can also be configured as a master device, and this application does not impose any restrictions on this.

[0046] The host 11 is connected to multiple slave devices 12 for communication.

[0047] Multiple slave devices 12 can also communicate with each other. Figure 1 Not shown in the image.

[0048] For example, the host 11 and the slave 12 can be directly or indirectly connected via wired or wireless communication. Each slave 12 can also be directly or indirectly connected via wired or wireless communication.

[0049] Wired communication methods can include coaxial cable, fiber optic cable, and digital subscriber line (DSL). Wireless communication methods can include Bluetooth, infrared, Wi-Fi, and microwave.

[0050] In some specific examples, the host 11 and multiple slaves 12 can communicate via the ModBus communication protocol based on the RS485 bus.

[0051] In some specific examples, the host 11 and multiple slave devices 12 are equipped with RJ45 (registered jack 45) interfaces. The host 11 and the multiple slave devices 12 can communicate with each other through the RJ45 interfaces according to the RS-485 protocol.

[0052] The following embodiments of this application will be used to illustrate the concept of having Figure 1 Taking the master-slave communication system with the structure shown as an example, combined with Figures 2 to 5 This application provides a detailed description of the master-slave communication method.

[0053] Please see Figure 2 , Figure 2 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 1 .like Figure 2 As shown, the method includes: S101, The host computer sends a command frame to the host computer.

[0054] Correspondingly, the host computer receives command frames sent by the host computer.

[0055] The host computer can be a desktop computer, mobile phone, tablet computer, industrial control computer, or server, etc.

[0056] The command frame is a data packet encapsulated according to a preset format. The command frame includes a frame header, destination address, command character, data packet, and checksum.

[0057] The frame header is used by the receiver to identify the start position of the command frame.

[0058] The destination address is used to identify the destination of the command frame. In a master-slave communication system, the master and each slave have a unique address. When the master receives a command frame, it can determine the destination of the command frame based on the destination address.

[0059] The command symbol is used to indicate the type of command frame.

[0060] For example, in a master-slave communication system that is an electricity meter system, the command frame types can include operation command frames and read command frames. Operation command frames are used for example to control the electricity meter to close or open, write the purchased electricity amount or amount, and issue low electricity warnings. Read command frames are used for example to read the current current, electricity amount, energy, and voltage.

[0061] Furthermore, when the command frame is a read-type command frame, the command also includes a data identifier field, which is used to indicate the data type to be read.

[0062] For example, when the command frame is an operation command frame, the command symbol can be 0x01. When the command frame is a read command frame, the current data identifier can be 0x11, the quantity data identifier can be 0x12, the energy data identifier can be 0x13, the voltage data identifier can be 0x14, and the command symbol can be 0x02 0x11, 0x02 0x12, 0x02 0x13, or 0x02 0x14.

[0063] Among them, 0x02 0x11 indicates that the command frame is a read-type command frame and the data type read is current; 0x02 0x12 indicates that the command frame is a read-type command frame and the data type read is electrical energy; 0x02 0x13 indicates that the command frame is a read-type command frame and the data type read is electrical energy; 0x02 0x14 indicates that the command frame is a read-type command frame and the data type read is voltage.

[0064] The data packet contains specific parameters related to the command.

[0065] The checksum is used to verify the integrity of the command frame. For example, the checksum can be a cyclic redundancy check (CRC) code.

[0066] Based on this, the host computer can control the master computer through command frames or control the target slave computer to execute command frames through the master computer.

[0067] S102. When the host receives a command frame for the target slave from the host computer and determines that the command symbol in the command frame meets the first preset condition, the host sends a first flag bit to the target slave.

[0068] Correspondingly, the target slave receives the first flag bit sent by the host; the first flag bit is sent by the host when it receives a command frame for the target slave sent by the host computer and determines that the command character in the command frame meets the first preset condition.

[0069] After receiving a command frame, the host can determine whether the command frame is for the target slave device or for the host based on the destination address in the command frame. Specifically, if the destination address is the host's address, the host determines that the command frame is for the host; if the destination address is the slave device's address, the host determines that the command frame is for the target slave device.

[0070] In this context, the target slave is one of the multiple slaves in the master-slave communication system, that is, the slave indicated by the target address in the command frame.

[0071] For example, a master-slave communication system includes one master and three slaves. The master address is 0x00, and the slave addresses are 0x01, 0x02, and 0x03. The command frame A received by the master is shown in Table 1 below: Table 1

[0072] In Table 1, the target address 0x01 is the slave address, and the master can determine that the command frame is a command frame for the target slave with address 0x01.

[0073] Based on this, the host can first distinguish command frames for different devices, so that when the command frame is a command frame for the target slave, it can forward the command frame to the target slave in a timely manner.

[0074] In the command frame, the command symbol is used to indicate the type of command frame.

[0075] Different types of command frames have different execution priorities. Based on this, a first preset condition and a second preset condition can be set according to the execution priority of different types of command frames. Command frames that meet the first preset condition are command frames that need to be executed first, and command frames that meet the second preset condition are command frames that do not need to be executed first.

[0076] For example, when the master-slave communication system is an electricity meter system: For operational command frames, if the target slave device executes its current process before responding to the command frame, it may cause frame loss, frame errors, and slow response, which may lead to system abnormalities and serious consequences.

[0077] For read-type command frames, there are different execution priorities depending on the type of data.

[0078] For example, when a command frame indicates that voltage needs to be read, the host computer may need to determine whether the energy meter is faulty based on the voltage. If the target slave device executes its current process before responding to the command frame, it may result in a slow response and failure to identify the fault in a timely manner. Therefore, it needs to be executed first. When a command frame indicates that power needs to be read, the host computer may only need to query the current power level for power statistics, and the real-time requirement is not high. Therefore, it does not need to be executed first.

[0079] Therefore, all operational command frames require a real-time response from the target slave device and should be executed first; the execution priority of read command frames depends on the type of data being read.

[0080] In some examples, the first and second preset conditions can be as follows: The first preset conditions include: the command symbol indicates that the command frame is an operation command frame; or, the command symbol indicates that the command frame is a read command frame and all the data identifiers in the command symbol belong to the preset list.

[0081] The second preset condition includes: the command character indicates that the command frame is a read-type command frame and the data identifiers in the command character do not belong to the preset list.

[0082] The preset list indicates which data identifiers should be executed first when the command frame is a read-type command frame. For example, the preset list includes: current and voltage. That is, when the command indicates that the command frame is a read-type command frame and the data identifier in the command is current or voltage, this command frame should be executed first.

[0083] Based on the example in Table 1 above, if 0x01 represents an operation command frame and 0x02 represents a read command frame, the data identifier for current is 0x11, the data identifier for electrical quantity is 0x12, the data identifier for electrical energy is 0x13, and the data identifier for voltage is 0x14. In Table 1, the command symbol for command frame A is 0x02 0x14, and the host can determine that command frame A is a read command frame. Furthermore, since the data identifier in the command symbol is 0x14, the host can determine that the data type indicated by command frame A is voltage. If the preset list includes current and voltage, the host determines that the command symbol in command frame A satisfies the first preset condition.

[0084] Based on this, when the host receives a command frame sent by the host computer for the target slave and determines that the command symbol in the command frame meets the first preset condition, the host can know that the command frame needs to be executed first. The host can send the first flag bit to the target slave in order to notify the target slave in advance to prepare to receive the command frame.

[0085] The first flag bit is used to indicate that the host is about to send a command frame. The first flag bit can be a message frame, or it can be a hardware interrupt signal, such as a first pin being pulled low. This application does not limit the form of the first flag bit.

[0086] Therefore, when the target slave receives the first flag, it can know that it needs to execute the command frame sent by the master first, thus enabling it to respond to the command frame in a timely manner.

[0087] S103, The target slave interrupts the current process.

[0088] The current process of the target slave device is, for example, a data acquisition process, a regular calculation process, or a status reporting process.

[0089] Upon receiving the first flag, the target slave device learns that the master is about to send a command frame. This allows the target slave device to interrupt its current process, release resources, and execute the command frame promptly.

[0090] Based on this, the target slave device can interrupt the current process before the command frame arrives, thereby ensuring that it can respond to high-priority command frames in a timely manner, avoiding conflicts between command frames and the current process, and thus avoiding response delays.

[0091] For example, when the first flag is a hardware interrupt signal, the target slave device will trigger an interrupt when it detects that the first pin is pulled low, interrupting the current process. The target slave device can save the execution state of the current process to memory so that it can resume the current process after executing the command frame.

[0092] S104, The host sends a command frame to the target slave.

[0093] Correspondingly, the target slave device receives the command frame.

[0094] It should be noted that S103 and S104 have no specific order. The target slave device can interrupt the current process first, and the master device can send the command frame first. The only requirement is that the target slave device can execute the command frame first upon receiving it. This application does not restrict the execution order of S103 and S104. Figure 2 The diagram shows a scenario where the target slave interrupts the current process of the master before sending a command frame.

[0095] S105, Target slave executes command frame.

[0096] Since the target slave has interrupted its current process, meaning the resources have been released, the target slave can immediately execute the command frame without queuing, thus achieving timely response to the command frame and reducing response latency.

[0097] In this embodiment, the host computer sends a command frame to the master computer. Upon receiving the command frame from the host computer for the target slave computer and determining that the command symbol in the command frame meets a first preset condition, the master computer sends a first flag bit to the target slave computer. This allows the master computer to know that the command frame needs to be executed first, and to notify the target slave computer in advance via the first flag bit to prepare to receive the command frame. The target slave computer interrupts its current process, allowing it to interrupt its current process before the command frame arrives, ensuring timely response to high-priority command frames and avoiding conflicts between command frames and the current process, thus preventing response delays. When the master computer sends the command frame to the target slave computer, the target slave computer executes the command frame. Since the target slave computer has interrupted its current process, meaning resources have been released, it can execute the command frame immediately without queuing, achieving timely response to the command frame and reducing response delays.

[0098] Furthermore, if the command frame conflicts with the current process, it will cause excessive pressure on master-slave communication. Based on the embodiments of this application, hierarchical response to command frames can be implemented, which can reduce the pressure on master-slave communication.

[0099] Based on the above exemplary description, after S105, the master-slave communication method further includes the following S106 to S1010.

[0100] Please see Figure 3 , Figure 3 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 2 .like Figure 3 As shown, after S105, the master-slave communication method also includes: S106. The target slave device generates a response frame based on the command frame.

[0101] After executing the command frame, the target slave device will generate a response frame based on the execution result. The format of the response frame is similar to that of the command frame. The response frame may include a frame header, destination address, data packet, and checksum. The destination address is the host's address. The execution result can be encapsulated in the data packet.

[0102] For example, when the command frame is command frame A as shown in Table 1, the response frame can be as shown in Table 2 below: Table 2

[0103] Based on this, the target slave device can use response frames to report the execution status of command frames to the host or upper computer.

[0104] S107. The target slave sends the second flag bit to the master.

[0105] Since the target slave device does not know whether the master device is executing a process, it can send a second flag to the master device before sending a response frame, so as to notify the master device in advance that it needs to be ready to receive the response frame.

[0106] The second flag bit is used to indicate that the target slave device is about to send a response frame. The second flag bit can be a message frame, or it can be a hardware interrupt signal, such as a second pin being pulled low. This application does not limit the form of the second flag bit.

[0107] Therefore, when the host receives the second flag, it can know that it needs to prioritize receiving the response frame sent by the target slave, and thus forward the response frame to the host computer in a timely manner.

[0108] S108, The host interrupts the current process.

[0109] The current process of the host machine may include processing data from other slave machines or communicating with the host computer.

[0110] After receiving the second flag, the host knows that the target slave is about to send a response frame. The host can then interrupt the current process, release resources, and forward the response frame to the host computer in a timely manner.

[0111] Based on this, the host can interrupt the current process before the response frame arrives, thereby ensuring that the response frame can be forwarded to the host computer in a timely manner, avoiding conflict between the response frame and the current process, and thus avoiding response delay.

[0112] For example, when the second flag is a hardware interrupt signal, the host will trigger an interrupt when it detects that the second pin is pulled low, interrupting the current process. The host can save the execution state of the current process to memory so that it can resume the current process after forwarding the response frame to the host computer.

[0113] S109. The target slave device sends a response frame to the master device.

[0114] Correspondingly, the host receives the response frame sent by the target slave.

[0115] It should be noted that S108 and S109 have no specific order. The host can interrupt the current process first, and the target slave can send the response frame first, as long as the host can send the command frame to the host computer first when it receives the response frame. This application does not restrict the execution order of S108 and S109. Figure 3 The diagram shows a scenario where the host first interrupts the current process, targets the slave, and then sends a response frame.

[0116] S1010, The host sends a response frame to the host computer.

[0117] Correspondingly, the host computer receives the response frame sent by the host.

[0118] Since the host has interrupted the current process, meaning the resources have been released, the host can immediately send a response frame to the host computer without queuing, thus enabling timely transmission of the response frame and allowing the host computer to receive the response frame promptly, thereby reducing response latency.

[0119] Based on this, before sending a command frame, the host sends a first flag to the target slave. Upon receiving the first flag, the target slave interrupts its current process, thus enabling it to execute the command frame promptly upon receipt, avoiding conflicts between the command frame and the process, and thereby shortening the response time. Before receiving a response frame and sending it to the host, the target slave sends a second flag to the host. Upon receiving the second flag, the host interrupts its current process, thus enabling it to forward the response frame to the host computer promptly upon receipt, avoiding conflicts between the response frame and the process, and further shortening the response time.

[0120] Based on the above exemplary description, after S101, when the host receives a command frame for the target slave device sent by the host computer, and determines that the command symbol in the command frame satisfies the second preset condition, the host can proceed as follows: Figure 4 The command frame is sent to the target slave device in the manner shown.

[0121] Please see Figure 4 , Figure 4 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 3 .like Figure 4 As shown, when the host receives a command frame from the host computer targeting the slave device, and determines that the command symbol in the command frame satisfies the second preset condition, the master-slave communication method further includes: S201. When the host receives a command frame for the target slave from the host computer and determines that the command symbol in the command frame meets the second preset condition, the host sends a command frame to the target slave.

[0122] Correspondingly, the target slave receives the command frame sent by the master when the command symbol in the determination command frame meets the second preset condition.

[0123] As described in S102, when the host determines that the command symbol in the command frame meets the second preset condition, it can know that the command frame does not need to be executed first. In other words, the target slave does not need to interrupt its own process, and the host can directly send the command frame to the target slave.

[0124] S202. The target slave device continues to execute the current process and stores the command frame.

[0125] After receiving a command frame, the target slave device can continue executing the current process. The target slave device can first store the command frame, for example, by storing the command frame in a buffer, and wait for the current process to finish executing before retrieving the command frame from the buffer and executing the command frame.

[0126] S203, The target slave sends the third flag bit to the master.

[0127] Correspondingly, the host receives the third flag bit sent by the target slave.

[0128] Since the target slave device has not yet executed the command frame, it can send a third flag to the host device to inform the host or upper computer that the target slave device is busy.

[0129] The third flag bit is used to indicate that the target slave device is busy. The third flag bit can be a message frame, or it can be a hardware busy signal, such as a third pin being pulled low. This application does not limit the form of the third flag bit.

[0130] Therefore, when the host receives the third flag, it can know that the target slave is busy, so as to promptly report back to the host computer.

[0131] It should be noted that S202 and S203 have no specific order. The target slave device can execute S202 first and then S203, or S203 first and then S202, or both simultaneously. That is, the target slave device can send the third flag bit first, or store the command frame first, or send the third flag bit to the master device while storing the command frame. This application does not restrict the execution order of S202 and S203. Figure 4 The diagram shows the case where the command frame is stored first and then the third flag bit is sent.

[0132] S204. The host computer sends the third flag bit to the host computer.

[0133] Correspondingly, the host computer receives the third flag bit sent by the host computer.

[0134] S205, The host computer stops sending other command frames.

[0135] When the host computer receives the third flag, it can determine that the target slave device is busy and can stop sending other command frames, thereby reducing the pressure on master-slave communication. After the target slave device finishes executing its current process, it executes the command frame and receives the response frame, then sends the response frame to the host computer through the host. When the host computer receives the response frame, it resumes sending other command frames. Specifically, after the target slave device finishes executing its current process and the command frame, it can send the response frame in accordance with the methods in S106 to S1010; this application does not impose any restrictions on this.

[0136] If the host computer periodically sends command frames, it needs to receive a response frame before sending the next period's command frames. Based on this, the host computer stops sending other command frames. When the host computer receives the response frame, it resumes sending other command frames, thus avoiding frame loss and frame errors and ensuring the accuracy of master-slave communication.

[0137] Based on this, the host can perform different processing when it determines that the command symbol in the command frame meets the first or second preset condition, thereby achieving hierarchical response for different types of command frames. When the first preset condition is met, the first flag bit is used to prompt the target slave to interrupt the current process and prioritize the processing of the command frame, reducing response latency. When the second preset condition is met, the command frame is sent directly, and the third flag bit is used to prompt the host to wait and stop sending other command frames, reducing the pressure on master-slave communication.

[0138] Based on the above exemplary description, after S101, when the host receives a command frame sent by the host computer, the host can execute the following: Figure 5 The method shown.

[0139] Please see Figure 5 , Figure 5 Signaling interaction of a master-slave communication method provided in an embodiment of this application Figure 4 .like Figure 5 As shown, when the host receives a command frame sent by the host computer, the master-slave communication method also includes: S301. When the host receives a command frame sent by the host computer, it interrupts the current process.

[0140] If the host determines that the command frame sent by the host computer is a command frame for the host, the host can directly interrupt the current process in order to execute the command frame in a timely manner.

[0141] S302, Host executes command frame.

[0142] S303, The host generates a response frame based on the command frame.

[0143] S304. The host computer sends a response frame to the host computer.

[0144] Based on this, the host can prioritize executing command frames and send response frames in a timely manner, so that the host computer can receive the response frames in a timely manner, thereby reducing response latency.

[0145] In addition, the host can also use a method similar to that described in S102 to first determine the priority of the command frame, decide whether to execute the current process to store the command frame first, or interrupt the current process to execute the command frame first, thereby further reducing the response latency.

[0146] For example, this application also provides a master-slave communication device.

[0147] Please see Figure 6 , Figure 6 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 1 .

[0148] like Figure 6 As shown, the first master-slave communication device 100 can exist independently or be integrated into other devices. It can communicate with the slave device mentioned above to implement the operation corresponding to the master in any of the above method embodiments.

[0149] The first master-slave communication device 100 may include a first transceiver unit 101. The first transceiver unit 101 may also be referred to as a communication interface or a communication unit. The first transceiver unit 101 can implement the corresponding communication functions in the foregoing method embodiments.

[0150] Optionally, the first master-slave communication device 100 may further include a processing unit, which can read instructions and / or data from the storage unit and perform data processing so that the first master-slave communication device 100 implements the aforementioned method embodiment.

[0151] Optionally, the first master-slave communication device 100 may further include a storage unit, which can be used to store instructions and / or data.

[0152] The first master-slave communication device 100 can be used to perform the actions performed by the host in the method embodiments described above. The first master-slave communication device 100 can be a host or a component configurable on the host.

[0153] Optionally, the first transceiver unit 101 may include a sending unit and a receiving unit. The sending unit is used to perform the sending operation in the foregoing method embodiments. The receiving unit is used to perform the receiving operation in the foregoing method embodiments.

[0154] It should be noted that the first master-slave communication device 100 may include a transmitting unit but not a receiving unit. Alternatively, the first master-slave communication device 100 may include a receiving unit but not a transmitting unit. Specifically, it depends on whether the above-described scheme executed by the first master-slave communication device 100 includes both transmitting and receiving actions.

[0155] As an example, the first master-slave communication device 100 is used to perform the aforementioned... Figures 2 to 5 The actions performed by the host in the illustrated embodiment.

[0156] The first master-slave communication device 100 may include: a first transceiver unit 101.

[0157] The first transceiver unit 101 is used to send a first flag bit to the target slave device when it receives a command frame sent by the host computer for the target slave device and determines that the command symbol in the command frame meets the first preset condition, so as to cause the target slave device to interrupt the current process; the first flag bit is used to indicate that the host computer is about to send a command frame. Send a command frame to the target slave device so that the target slave device executes the command frame.

[0158] It should be understood that the corresponding processes performed by each unit have been described in detail in the above method embodiments, and will not be repeated here for the sake of brevity.

[0159] In some examples, the first master-slave communication device 100 further includes a processing unit.

[0160] The first transceiver unit 101 is also used to receive a second flag bit sent by the target slave device. The second flag bit is sent by the target slave device after generating a response frame according to the command frame. The second flag bit is used to indicate that the target slave device is about to send a response frame. A processing unit used to interrupt the current process; The first transceiver unit 101 is also used to receive the response frame sent by the target slave device and send the response frame to the host computer.

[0161] In some examples, the first transceiver unit 101 is further configured to send a command frame to the target slave device when it receives a command frame sent by the host computer for the target slave device and determines that the command symbol in the command frame meets the second preset condition. The system receives the third flag bit sent by the target slave device and sends the third flag bit to the host computer. The third flag bit is sent by the target slave device while continuing to execute the current process and storing the command frame. The third flag bit is used to indicate that the target slave device is busy so that the host computer stops sending other command frames.

[0162] In some examples, the first preset condition includes: the command symbol indicates that the command frame is an operation command frame; or, the command symbol indicates that the command frame is a read command frame and all the data identifiers in the command symbol belong to the preset list; The second preset condition includes: the command character indicates that the command frame is a read-type command frame and the data identifiers in the command character do not belong to the preset list.

[0163] In some examples, the first master-slave communication device 100 further includes a processing unit.

[0164] The processing unit is used to interrupt the current process, execute the command frame, and generate a response frame based on the command frame when it receives a command frame for the host computer. The first transceiver unit 101 is also used to send response frames to the host computer.

[0165] For example, this application also provides a master-slave communication device.

[0166] Please see Figure 7 , Figure 7 A schematic diagram of the structure of a master-slave communication device provided in an embodiment of this application. Figure 2 .

[0167] like Figure 7 As shown, the second master-slave communication device 200 can exist independently or be integrated into other devices. It can communicate with the master mentioned above to implement the operation corresponding to the slave device in any of the above method embodiments.

[0168] The second master-slave communication device 200 may include a second transceiver unit 201 and a processing unit 202. The second transceiver unit 201 may also be referred to as a communication interface or communication unit. The processing unit 202 may read instructions and / or data from the storage unit to enable the second master-slave communication device 200 to implement the aforementioned method embodiment. The second transceiver unit 201 may implement the corresponding communication function, and the processing unit 202 may perform data processing.

[0169] Optionally, the second master-slave communication device 200 may further include a storage unit, which can be used to store instructions and / or data.

[0170] The second master-slave communication device 200 can be used to execute the actions performed by the slave device in the aforementioned method embodiments. The second master-slave communication device 200 can be a slave device or a component configurable on the slave device.

[0171] Optionally, the second transceiver unit 201 may include a sending unit and a receiving unit. The sending unit is used to perform the sending operation in the foregoing method embodiments. The receiving unit is used to perform the receiving operation in the foregoing method embodiments.

[0172] It should be noted that the second master-slave communication device 200 may include a transmitting unit but not a receiving unit. Alternatively, the second master-slave communication device 200 may include a receiving unit but not a transmitting unit. Specifically, it depends on whether the above-described scheme executed by the second master-slave communication device 200 includes both transmitting and receiving actions.

[0173] As an example, the second master-slave communication device 200 is used to perform the aforementioned... Figures 2 to 5 The actions performed by the slave device in the illustrated embodiment.

[0174] The second master-slave communication device 200 may include a second transceiver unit 201 and a processing unit 202.

[0175] The second transceiver unit 201 is used to receive a first flag bit sent by the host; the first flag bit is sent by the host when it receives a command frame for the target slave device sent by the host computer and determines that the command character in the command frame meets the first preset condition; the first flag bit is used to indicate that the host is about to send a command frame. Processing unit 202 is used to interrupt the current process; The second transceiver unit 201 is used to receive command frames sent by the host. Processing unit 202 is used to execute command frames.

[0176] In some examples, processing unit 202 is also used to generate a response frame based on the command frame; The second transceiver unit 201 is also used to send a second flag bit to the host so that the host can interrupt the current process; the second flag bit is used to indicate that the target slave is about to send a response frame; and to send a response frame to the host so that the host can send a response frame to the host computer.

[0177] In some examples, the second master-slave communication device 200 also includes a storage unit.

[0178] The second transceiver unit 201 is also used to receive a command frame sent by the host computer for the target slave when it receives a command frame sent by the host computer and determines that the command symbol in the command frame meets the second preset condition. Processing unit 202 is also used to continue executing the current process; Storage unit, used to store command frames; The second transceiver unit 201 is also used to send a third flag bit to the host so that the host sends the third flag bit to the host computer; the third flag bit is used to indicate that the target slave is busy so that the host computer stops sending other command frames.

[0179] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 1 .like Figure 8 As shown, the electronic device may include a first processor 301, which, when executing a computer-executable program or instruction in the memory, implements the master-slave communication method in the above method embodiment.

[0180] The electronic device can be used to perform the various steps and / or processes corresponding to the electronic devices in the above method embodiments.

[0181] Figure 9 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 2 .like Figure 9 As shown, the electronic device may include a second processor 401 and a memory 402. The memory 402 stores a computer program. When the second processor 401 executes the computer program, it implements the master-slave communication method in the above method embodiment.

[0182] The electronic device can be used to perform the various steps and / or processes corresponding to the electronic devices in the above method embodiments.

[0183] The electronic device of this application can be used to execute the technical solutions of the method embodiments described above. Its implementation principle and technical effects are similar. The operations implemented by each module can be further referred to the relevant descriptions of the method embodiments, which will not be repeated here. The modules here can also be replaced by components or circuits.

[0184] This application can divide electronic devices into functional modules based on the above method examples. For example, each function can be divided into its own functional module, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in the embodiments of this application is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0185] Another embodiment of this application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the master-slave communication method described in the above method embodiments.

[0186] This application also provides a program product including executable instructions stored in a computer-readable storage medium. At least one processor of an electronic device can read the executable instructions from the computer-readable storage medium, and the execution of the executable instructions by the at least one processor causes the electronic device to implement the master-slave communication method described in the above method embodiments.

[0187] This application also provides a chip that is connected to a memory, or a chip that integrates a memory, wherein when a software program stored in the memory is executed, the master-slave communication method described in the above method embodiments is implemented.

[0188] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.

[0189] Those skilled in the art will understand that although some embodiments herein include certain features included in other embodiments, combinations of features from different embodiments are intended to be within the scope of this application and form different embodiments. For example, in the claims, any of the claimed embodiments can be used in any combination.

[0190] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A master-slave communication method, characterized in that, A host applied in a master-slave communication system, the master-slave communication system comprising a host and multiple slaves, the method comprising: When the host receives a command frame for the target slave from the host computer and determines that the command character in the command frame meets the first preset condition, the host sends a first flag bit to the target slave to cause the target slave to interrupt the current process; the first flag bit is used to indicate that the host is about to send the command frame. The host sends the command frame to the target slave device so that the target slave device executes the command frame.

2. The method according to claim 1, characterized in that, The method further includes: The host receives a second flag bit sent by the target slave device, the second flag bit being sent by the target slave device after generating a response frame according to the command frame; the second flag bit is used to indicate that the target slave device is about to send the response frame. The host interrupts the current process; The host receives the response frame sent by the target slave and sends the response frame to the host computer.

3. The method according to claim 1 or 2, characterized in that, The method further includes: When the host receives a command frame for the target slave from the host computer and determines that the command character in the command frame meets the second preset condition, the host sends the command frame to the target slave. The host receives the third flag bit sent by the target slave and sends the third flag bit to the host computer; the third flag bit is sent by the target slave while continuing to execute the current process and storing the command frame; the third flag bit is used to indicate that the target slave is busy, so that the host computer stops sending other command frames.

4. The method according to claim 3, characterized in that, The first preset condition includes: the command character indicates that the command frame is an operation command frame; or, the command character indicates that the command frame is a read command frame and all data identifiers in the command character belong to a preset list; The second preset condition includes: the command character indicates that the command frame is a read-type command frame and the data identifiers in the command character do not belong to the preset list.

5. The method according to claim 1, characterized in that, The method further includes: When the host receives a command frame sent by the host computer, it interrupts the current process. The host executes the command frame; The host generates a response frame based on the command frame; The host computer sends the response frame to the host computer.

6. A master-slave communication method, characterized in that, A slave device applied in a master-slave communication system, wherein the master-slave communication system includes a master and multiple slave devices, the method comprising: The target slave device receives a first flag bit sent by the host; the first flag bit is sent by the host when it receives a command frame for the target slave device sent by the host computer and determines that the command character in the command frame meets a first preset condition; the first flag bit is used to indicate that the host is about to send the command frame. The target slave device interrupts the current process; The target slave device receives and executes the command frames sent by the host.

7. The method according to claim 6, characterized in that, The method further includes: The target slave device generates a response frame based on the command frame; The target slave device sends a second flag bit to the host device, causing the host device to interrupt the current process; the second flag bit is used to indicate that the target slave device is about to send the response frame. The target slave device sends the response frame to the host device, so that the host device sends the response frame to the host computer.

8. The method according to claim 6 or 7, characterized in that, The method further includes: The target slave device receives the command frame sent by the host computer when it receives the command frame for the target slave device sent by the host computer, and determines that the command character in the command frame meets the second preset condition; The target slave device continues to execute the current process and stores the command frame; The target slave device sends a third flag bit to the host device, so that the host device sends the third flag bit to the host computer; the third flag bit is used to indicate that the target slave device is busy, so that the host computer stops sending other command frames.

9. An electronic device, characterized in that, include: First processor; The first processor is configured to execute a computer-executable program or instructions in the memory, causing the electronic device to perform the master-slave communication method according to any one of claims 1-5 or 6-8.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer-executable program or instructions, the computer-executable program or instructions being configured to perform the master-slave communication method according to any one of claims 1-5 or 6-8.

Citation Information

Patent Citations

  • Data transmission method for master equipment and slave equipment

    CN103685578A

  • Quality of service based arbitrations optimized for enterprise solid state drives

    CN110674059A

  • SPI-based master-slave communication method and device

    CN112817886A

  • Task scheduling for distributed data processing

    CN115362434A

  • Control method and device

    CN116708193A

Cited By

  • Master-slave communication method, electronic equipment and storage medium

    CN122027466A

  • Master-slave communication method, electronic device, and storage medium

    CN122027466B