RS485 communication method capable of avoiding bus conflict, host and slave

By detecting the bus idle state and actively reporting data, the problems of bus conflict, low efficiency and poor real-time performance in RS485 communication are solved, efficient and real-time data transmission is achieved, and data redundancy and delay are reduced.

CN119088554APending Publication Date: 2024-12-06HAILIN ENERGY TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411152692.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

There are problems in existing RS485 communications such as bus conflict, low efficiency, poor real-time performance, data redundancy and data update delay, especially when the number of slaves is large, it affects system performance.

Method used

By detecting whether the bus is idle between the master and slave, sending instructions that prohibit the use of the bus, ensuring that the bus application is successful before data transmission is carried out, and the bus is released after use, and actively reporting data is used to reduce polling and data redundancy.

Benefits of technology

It effectively avoids bus conflicts, improves communication efficiency and real-timeness, reduces host load and data transmission delays, and optimizes the timeliness and accuracy of slave data reporting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088554A_ABST
    Figure CN119088554A_ABST
Patent Text Reader

Abstract

The invention discloses an RS485 communication method capable of avoiding bus conflicts, a host and slaves, and the method comprises the steps: detecting whether a bus is idle or not when a bus application instruction of the slaves is received or a control instruction needs to be actively issued, if the bus is busy, continuing detection until the bus is idle, and issuing an instruction for prohibiting the use of the bus to a plurality of slaves connected with the host; the bus application instruction is uploaded to the host after the slave detects that the bus is idle when the slave needs to actively report data; after the instruction of prohibiting the use of the bus is issued, waiting for a set time to detect whether the bus is idle again, and if the bus is idle, sending a control instruction to the slave sending the bus application instruction or sending the control instruction to the specified slave; receiving a slave response; whether the bus application instructions sent by all the slaves are processed or not is judged, or whether the control instructions needing to be actively issued are processed or not is judged, and if yes, a bus release command is sent to the multiple slaves. According to the invention, the communication efficiency and the real-time performance are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of electronic technology, and in particular to an RS485 communication method, a host and a slave capable of avoiding bus conflicts. Background Art

[0002] RS485 communication is a widely used serial communication protocol in the fields of industrial automation, building automation, etc. It allows multiple devices to be connected on one bus to achieve multi-point communication. However, RS485 usually works in half-duplex mode, which means that at any given time, the device either sends data or receives data, but not at the same time. If two devices send data at the same time, bus conflicts may occur, resulting in data transmission failure.

[0003] To avoid bus conflicts, most existing technologies use the master-slave mode and polling method, that is, the host sends query instructions to each slave in turn, and the slave responds with data after receiving a specific instruction. This ensures that only one device on the bus sends data at the same time, avoiding bus conflicts. Although the polling method effectively avoids conflicts in RS485 communication, it also has the following shortcomings:

[0004] 1) Inefficiency: The host needs to send a large number of query instructions to each slave in turn, increasing the bus load and the host MCU resource usage.

[0005] 2) Poor real-time performance: The host needs to wait for the slave to respond. If the slave does not respond in time, it may cause the bus connection to time out.

[0006] 3) Data redundancy: The data contained in all requests reported by the slaves include data that has not changed for a long time, resulting in data redundancy.

[0007] 4) Data update delay: The slaves that are not polled cannot report data in time, resulting in delays in updating the slave data. Especially when there are a large number of slaves, the data update delay is relatively large. Summary of the invention

[0008] Based on this, in order to solve the above technical problems, an RS485 communication method, a host and a slave which can avoid bus conflicts are provided to solve the problems of low efficiency, poor real-time performance, received data redundancy and data update delay in the prior art.

[0009] In the first aspect, a RS485 communication bus conflict resolution method is applied to a host in a communication system, wherein the communication system includes multiple slaves, a communication bus and a host, and the multiple slaves are connected to the host via the communication bus; the method includes:

[0010] Step S1: when receiving a bus application instruction from a slave or when actively sending a control instruction, detecting whether the bus is idle, if the bus is busy, continuing to detect until the bus is idle, and sending instructions prohibiting the use of the bus to multiple slaves connected to the host; the bus application instruction is uploaded to the host after the slave detects that the bus is idle when it needs to actively report data;

[0011] Step S2: after issuing the instruction to prohibit the use of the bus, wait for the first set time to detect again whether the bus is idle, if it is idle, send a control instruction to the slave that sent the bus application instruction or send a control instruction to the designated slave;

[0012] Step S3: receiving a response from the slave;

[0013] Step S4: Determine whether the bus application instructions sent by all slaves have been processed, or whether the control instructions that need to be actively sent have been processed. If so, send a bus release command to multiple slaves connected to the host.

[0014] In the above scheme, optionally, the waiting for the first set time is to detect again whether the bus is idle, and if it is not idle, an instruction to prohibit the use of the bus is re-issued to the multiple slaves connected to the host, and step S2 is repeated;

[0015] If the instructions for prohibiting the use of the bus are issued to multiple slaves connected to the host for multiple times in succession, and the bus is detected to be in a non-idle state again after waiting for the first set time, a fault is reported.

[0016] In the above solution, optionally, the first set time is the time required for the current network to transmit 3 bytes.

[0017] In the above solution, optionally, if no response from the designated slave is received within a certain period of time after sending the control instruction to the designated slave, the control instruction is sent to the designated slave again.

[0018] In a second aspect, an RS485 communication method for avoiding bus conflicts is applied to a first slave in a communication system, wherein the communication system comprises a plurality of second slaves, a first slave, a communication bus and a host; the first slave and the second slave are connected to the host via the communication bus; the method comprises:

[0019] Step S1: When the first slave needs to actively report data, it detects whether the bus is idle. If it is idle, it sends a bus application instruction to the host; if the first slave does not need to actively report data, it directly executes step S2;

[0020] Step S2: receiving a command from the host to prohibit the use of the bus; the command to prohibit the use of the bus is issued by the host to the first slave and multiple second slaves after the host detects that the bus is idle after receiving the bus application command sent by the first slave or when it needs to actively issue a control command to the first slave;

[0021] Step S3: receiving a control instruction sent by the host; the control instruction is sent to the first slave after the host sends an instruction to prohibit the use of the bus and waits for a first set time to detect that the bus is idle again;

[0022] Step S4: Return a response to the host;

[0023] Step S5: accept the release bus command issued by the host to adjust the state to a state capable of applying for the bus; the release bus command is issued by the host after determining that the bus application instructions sent by the first slave and all second slaves have been processed, or the control instructions that need to be actively issued have been processed.

[0024] In the above solution, optionally, when the first slave needs to actively report data, it detects whether the bus is idle. If not, it detects whether the bus is idle again after a second set time interval until it is detected that the bus is idle.

[0025] In the above solution, further optionally, the first set time and the second set time are the time required for the current network to transmit 3 bytes.

[0026] In the above scheme, further optionally, the time required to transmit 3 bytes under the current network is calculated according to the serial communication baud rate, the number of data bits, the number of start bits, and the number of stop bits, specifically by the following formula:

[0027]

[0028] In a third aspect, a host comprises a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the steps of an RS485 communication method capable of avoiding bus conflicts as described in the first aspect when executing the computer program.

[0029] In a fourth aspect, a slave device stores a computer program thereon, wherein when the computer program is executed by a processor, the steps of the RS485 communication method capable of avoiding bus conflicts described in the second aspect are implemented.

[0030] This application has at least the following beneficial effects:

[0031] This application requires that both the host and the slave detect whether the bus is idle before using the bus. In addition, the slave needs to wait for the host's approval, the host notifies each slave, and the host releases the bus after using the bus, thereby effectively avoiding bus conflicts. When the slave is active when the data changes, it does not need to wait for the host's polling, and actively applies for a bus application instruction from the host. The host issues an instruction to prohibit the use of the bus to all slaves until the slave's data is received; thereby improving communication efficiency and real-time performance. When the host needs to issue a control command, it issues an instruction to prohibit the use of the bus to all slaves, and after receiving the data after issuing the control command, it releases the right to use the bus. Therefore, when the slave needs to report data, it reports it instead of polling. Each polling reports this data, thereby reducing data redundancy, transmitting only necessary information, and effectively reducing the host load, improving the overall performance of the system; when the slave needs to report data, it can automatically apply for reporting, without waiting for the host's inquiry, thereby optimizing the data transmission process, reducing data transmission delay, and improving the timeliness and accuracy of slave data reporting. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 A flow chart of an RS485 communication method for avoiding bus conflicts provided by an embodiment of the present application;

[0033] Figure 2 A topological diagram of the communication relationship between the host and the slave is provided for one embodiment of the present application;

[0034] Figure 3 A communication state diagram of a master and a slave when slave data is reported is provided for one embodiment of the present application;

[0035] Figure 4 The communication status of the master and slave machines when the host sends a control command provided in one embodiment of the present application;

[0036] Figure 5 A flowchart for applying for a bus for a slave provided in one embodiment of the present application;

[0037] Figure 6 A diagram of bus operation status and bus instruction conversion status when a slave actively reports data provided by an embodiment of the present application;

[0038] Figure 7 A diagram of the bus operation status and bus instruction change status when the host actively sends control instructions is provided for an embodiment of the present application. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0040] At present, RS485 communication usually adopts polling mode, which is incapable of handling large-scale equipment. Its high load, low efficiency and data update delay are becoming more and more prominent. In view of this situation, the present invention proposes an innovative RS485 communication bus conflict solution method. By designing a set of efficient and intelligent communication protocols, the bus conflict problem is completely solved, and efficient coordination of multi-point communication is achieved, which brings new solutions and unlimited possibilities to the fields of industrial automation and building automation.

[0041] In one embodiment, Figure 1 As shown, a RS485 communication method capable of avoiding bus conflicts is provided, which is applied to a host in a communication system, wherein the communication system comprises a plurality of slaves, a communication bus and a host, wherein the plurality of slaves are connected to the host via the communication bus; Figure 2 As shown, it is a communication topology diagram between the host and the slave. The method comprises:

[0042] Step S1: When a bus application instruction is received from a slave or a control instruction needs to be actively issued, detect whether the bus is idle. If the bus is busy, continue to detect until the bus is idle, and then issue an instruction prohibiting the use of the bus to multiple slaves connected to the host; the bus application instruction is uploaded to the host after the slave detects that the bus is idle when it needs to actively report data.

[0043] In step S1, generally speaking, there are two situations in which the host issues an instruction prohibiting the use of the bus. The first situation is that the slave needs to actively report data. After sending a bus application instruction to the host, the host issues an instruction prohibiting the use of the bus to all slaves. The second situation is that the host needs to issue a control instruction to the slave, so it issues an instruction prohibiting the use of the bus. Here, the host may actively need the slave to report data, or it may mainly need the slave to perform a certain action.

[0044] Step S2: after issuing the instruction to prohibit the use of the bus, wait for the first set time to detect again whether the bus is idle, if it is idle, send a control instruction to the slave that sent the bus application instruction or send a control instruction to a designated slave.

[0045] In step S2, if the slave needs to actively report data, the control instruction sent by the host to the slave that sends the bus application instruction is a control instruction for reporting data, requiring the slave to report data. If the host actively sends a control command to the slave, according to the needs of the host, if the slave needs to report data, the control instruction sent is a control instruction for reporting data, and if the slave needs to perform an action, the control instruction sent is a control instruction for executing the action.

[0046] Step S3: Receive a slave response.

[0047] In step S3, if the host actively sends a control instruction requiring the slave to act, what is received is the response of the slave completing the action. If the host actively sends a control instruction requiring the slave to upload data, the received response is the data uploaded by the slave. If the slave needs to actively report data, and the control command sent by the host is a control command for uploading data, the received response is the data uploaded by the slave.

[0048] Step S4: Determine whether the bus application instructions sent by all slaves have been processed, or whether the control instructions that need to be actively sent have been processed. If so, send a bus release command to multiple slaves connected to the host.

[0049] In step S4, after the slave sends a bus application instruction to the host, in the process of issuing a prohibition on the use of the bus, it may receive multiple bus application instructions sent by the slaves, so the host needs to process them one by one, wait for all the processing to be completed, and then release the bus. And when the host actively needs to issue a control instruction, if there is more than one control instruction, it needs to send the control instructions in sequence and get the response of the slave before releasing the bus.

[0050] This application solves the bus conflict problem by adding additional protocols. In order to minimize the data transmission time, the instruction length is defined to be relatively small. The specific protocols are shown in the following table:

[0051] Table 1

[0052] Frame Field Frame data length Remark Frame Header 0xAA 0xA5 2 Frame header flag address 0x01 1 Slave address 1-100

[0053] Table 2

[0054]

[0055] Table 3

[0056] Frame Field Frame data length Remark Frame Header 0xAA 0xA5 2 Frame header flag Function code 0XFA 1 Release bus

[0057] Among them, Table 1 is the slave bus application instruction, Table 2 is the host's response to the slave bus application instruction, and Table 3 is the host's bus release instruction.

[0058] like Figure 3 The figure shows the communication status of the master and slave when the slave has data to report. The specific communication process is as follows:

[0059] 1) The slave detects whether the bus is idle, and sends a bus request instruction (0xAA 0xA5 address) to apply for the bus when it is idle.

[0060] 2) After receiving the bus request from the slave, the host checks whether the bus is idle. If it is idle, it sends a command to prohibit the use of the bus (0xAA 0xA5 0xFF) to notify each device on the bus that a device wants to use the bus now and does not need to apply for the bus again.

[0061] 3) The host delays 3Bytes of data transmission time and checks whether the bus is idle again. If it is idle, it means that 0xAA0xA5 0xFF was sent successfully, and the host status switches from "idle" to "sending command". If it is not idle, the host sends 0xAA0xA5 0xFF again. If it fails for three consecutive times, the host reports a fault.

[0062] 4) After the slave receives 0xAA 0xA5 0xFF, the state switches from "idle" to "waiting for instruction". If no bus application response is received within the timeout period, the slave continues to send bus applications in the "idle" state after a delay.

[0063] 5) The host sends a report data control command (0xAA 0xA5 address) to notify the slave to report data, and the status switches from "sending command" to "waiting for data".

[0064] 6) After the slave receives the address 0xAA0xA5, the state switches from "waiting for instructions" to "sending data" and reports the data. After sending the data, the state switches from "sending data" to "waiting for instructions".

[0065] 7) After the host receives the data reported by the slave or the reception times out, the state switches from "waiting for data" to "sending instructions". If multiple slaves have applied for the bus, the host sends the address 0xAA 0xA5 to the next slave to notify it to report data. After all the applied slaves have reported data, the host sends 0xAA 0xA5 0xFA to release the bus, and the state switches from "sending instructions" to "idle".

[0066] 8) After the slave receives the 0xA5 0xFA bus release command, the state switches from "waiting for command" to "idle". If the slave does not receive any command within the timeout period, the state also switches from "waiting for command" to "idle".

[0067] like Figure 4 As shown in the figure, when the host needs to actively send control commands (actively collect data), the communication status of the master and slave machines is as follows:

[0068] 1) The host detects whether the bus is idle. When it is idle, it sends a command to prohibit the use of the bus (0xAA0xA50xFF) to notify each device on the bus that a device wants to use the bus now and does not apply for the bus again.

[0069] 2) The host delays 3Bytes of data transmission time to check whether the bus is idle again. If it is idle, it means that 0xAA0xA5 0xFF has been sent successfully, and the host status switches from "idle" to "sending command". If it is not idle, the host sends 0xAA0xA5 0xFF again. If it fails for three consecutive times, the host reports a fault.

[0070] 3) After the slave receives 0xAA 0xA5 0xFF, the state switches from "idle" to "waiting for instruction".

[0071] 4) The host sends a control command and the status switches from "sending command" to "waiting for data".

[0072] 5) After the slave receives the command, the state switches from "waiting for command" to "sending data". After sending the data, the state switches from "sending data" to "waiting for command".

[0073] 6) After the host receives a response from the slave or the reception times out, the status switches from "waiting for data" to "sending instructions". If there are multiple control instructions to be sent, the host sends the next control instruction. After all instructions are sent, the host sends 0xAA 0xA5 0xFA to release the bus, and the status switches from "sending instructions" to "idle". If no response is received after the timeout, the control instruction is re-sent. If no response is received for more than 3 times, a fault is reported.

[0074] 7) After the slave receives the 0xAA 0xA5 0xFA bus release command, the state switches from "waiting for command" to "idle". If the slave does not receive any command within the timeout period, the state also switches from "waiting for command" to "idle".

[0075] During the communication process of this application, whether the host sends a control command or the slave reports data, the first thing to do is to ensure that the bus application is successful. After the bus application is successful, other devices will no longer send commands, so that conflicts are not likely to occur when sending formal data. Before applying for the bus, it is necessary to check whether the bus is idle to increase the probability of successful bus application. After the bus application command is sent, it is necessary to check whether the bus is idle again to ensure that there is no data conflict on the bus when the bus application is made.

[0076] like Figure 5The figure shows the process when the slave applies for the bus. In RS485 communication, DMA interrupt mode is used to receive data, and the data received by DMA is placed in the receiving buffer. When there is data to be sent, the bus use right is applied for first. When applying for the bus, first determine whether the current bus is idle by checking whether there is data in the receiving buffer. If there is data in the receiving buffer, it indicates that the bus is busy. If there is no data in the receiving buffer, it indicates that the bus is idle. When the bus is busy, delay time and check the receiving buffer again. When the bus is idle, send the bus application instruction. After the instruction is sent, delay time and check whether there is data in the receiving buffer again. If there is no data, it means that the bus application instruction is sent successfully. If there is data in the receiving buffer, it indicates that other devices are also applying for the bus during data transmission. The bus application fails and re-apply.

[0077] The delay time is the time it takes to send the bus request instruction, that is, the time it takes to send 3 bytes of data. The time is calculated based on the serial communication baud rate, the number of data bits, the number of start bits, and the number of stop bits. The calculation formula is as follows:

[0078]

[0079] In the above RS485 communication method that can avoid bus conflicts, both the host and the slave need to detect whether the bus is idle before using the bus. In addition, the slave needs to wait for the host's approval, and the host needs to notify each slave, and release the bus after using the bus, thereby effectively avoiding bus conflicts. When the slave is active when the data changes, it does not need to wait for the host's polling, and actively applies for the bus application instruction from the host. The host issues an instruction to prohibit the use of the bus to all slaves until the slave's data is received; thereby improving communication efficiency and real-time performance. When the host needs to issue a control command, it issues an instruction to prohibit the use of the bus to all slaves, and releases the right to use the bus after receiving the data after issuing the control command. Therefore, the slave reports data when it needs to, instead of taking a polling approach. The data is reported each time polling occurs, thereby reducing data redundancy, transmitting only necessary information, and effectively reducing the host load, thereby improving the overall performance of the system; when the slave needs to report data, it can automatically apply for reporting without waiting for the host's inquiry, thereby optimizing the data transmission process, reducing data transmission delays, and improving the timeliness and accuracy of slave data reporting.

[0080] In one embodiment, the control instruction is sent to the designated slave, and if no response from the slave is received within a certain period of time, the control instruction is sent to the designated slave again.

[0081] In this embodiment, generally speaking, if the host actively sends a control instruction to the slave and does not receive a response from the slave within a certain period of time, it will resend the control instruction to the slave.

[0082] In one embodiment, a RS485 communication method capable of avoiding bus conflicts is provided, which is applied to a first slave in a communication system, wherein the communication system comprises a plurality of second slaves, a first slave, a communication bus and a host; the first slave and the second slave are connected to the host via the communication bus; the method comprises:

[0083] Step S1: When the first slave needs to actively report data, it detects whether the bus is idle. If it is idle, it sends a bus application instruction to the host; if the first slave does not need to actively report data, it directly executes step S2;

[0084] Step S2: receiving a command from the host to prohibit the use of the bus; the command to prohibit the use of the bus is issued by the host to the first slave and multiple second slaves after the host receives a bus application command from the first slave or needs to actively issue a control command to the first slave and detects that the bus is idle;

[0085] Step S3: receiving a control instruction sent by the host; the control instruction is sent to the first slave after the host sends an instruction to prohibit the use of the bus and waits for a first set time to detect that the bus is idle again;

[0086] Step S4: Return a response to the host;

[0087] Step S5: accept the release bus command issued by the host to adjust the state to a state capable of applying for the bus; the release bus command is issued by the host after determining that the bus application instructions sent by the first slave and all second slaves have been processed, or the control instructions that need to be actively issued have been processed.

[0088] The host and slave communication state machine has two states in operation, one is the bus operation state, and the other is the bus command state. The bus operation state is divided into three states: idle (IDLE), data transmission (SEND), and data reception (RECV). The bus command has four types: default (MIN), control command (CTRL), bus request command (REQ), and bus release command (FREE).

[0089] like Figure 6 The figure shows the bus operation status and bus instruction conversion status when the slave actively reports data. The specific process is as follows:

[0090] 1) When powered on, both the slave and the host are in IDLE state.

[0091] 2) When the slave has data to report, it sends a bus application instruction. After the transmission is successful, the bus operation state switches from IDLE (idle) to RECV (data reception) state, and the bus instruction state switches from MIN (default) to REQ (bus application instruction). If the transmission is not successful, it will reapply in the IDLE (idle) state.

[0092] 3) After the host receives the bus request command from the slave, the bus operation state switches from IDLE (idle) to SEND (data sending) state, and the bus command state switches from MIN (default) to REQ (bus request command).

[0093] 4) After the host sends the bus approval command in the SEND (data sending) state, the bus operation state switches from SEND (data sending) to RECV (data receiving), and the bus command state remains unchanged.

[0094] 5) After the slave receives the host bus approval command in the RECV (data reception) state, the bus operation state switches from RECV (data reception) to SEND (data transmission), and the bus command state remains unchanged.

[0095] 6) The slave reports data in the SEND state, the bus operation state switches from SEND (data sending) to RECV (data receiving), and the bus command state switches from REQ (bus request command) to FREE (bus release command).

[0096] 7) After the host receives the data reported by the slave in the RECV (data reception) state, the bus operation state switches from RECV (data reception) to SEND (data transmission), and the bus command state switches from REQ (bus application command) to FREE (bus release command).

[0097] 8) After the host sends a bus release command in the SEND (data sending) state, the bus operation state switches from SEND (data sending) to IDLE (idle), and the bus command state switches from FREE (bus release command) to MIN (default).

[0098] 9) After the slave receives the bus release command in the RECV (data reception) state, the bus operation state switches from RECV (data reception) to IDLE (idle), and the bus command state switches from FREE (bus release command) to MIN (default).

[0099] like Figure 7 The figure shows the bus operation status and bus command conversion status when the host actively sends control commands. The specific process is as follows:

[0100] 1) When powered on, both the master and slave are in IDLE state.

[0101] 2) When the host sends a control instruction, it sends a bus application instruction. After the transmission is successful, the bus operation state switches from IDLE (idle) to SEND (data transmission), and the bus instruction state switches from MIN (default) to CTRL (control instruction). If the transmission is not successful, it will be re-applied in the IDLE (idle) state.

[0102] 3) After the slave receives the bus request command from the host, the bus operation state switches from IDLE (idle) to RECV (data reception), and the bus command state switches from MIN (default) to CTRL (control command).

[0103] 4) After the host sends the control quasi-instruction in the SEND (data sending) state, the bus operation state switches from SEND (data sending) to RECV (data receiving), and the bus instruction state remains unchanged.

[0104] 5) After the slave receives the control instruction in the RECV (data reception) state, the bus operation state switches from RECV (data reception) to SEND (data transmission), and the bus instruction state remains unchanged.

[0105] 6) The slave sends a host control command response in the SEND (data sending) state, the bus operation state switches from SEND (data sending) to RECV (data receiving), and the bus command state switches from CTRL (control command) to FREE (bus release command).

[0106] 7) After the host receives the response from the slave in the RECV (data reception) state, the bus operation state switches from RECV (data reception) to SEND (data transmission), and the bus command state switches from CTRL (control command) to FREE (bus release command).

[0107] 8) The host sends a bus release command in the SEND (data sending) state, the bus operation state switches from SEND (data sending) to IDLE (idle), and the bus command state switches from FREE (bus release command) to MIN (default).

[0108] 9) After the slave receives the bus release command in the RECV (data reception) state, the bus operation state switches from RECV (data reception) to IDLE (idle), and the bus command state switches from FREE (bus release command) to MIN (default).

[0109] The present invention solves the bus conflict problem by adding an additional communication protocol, and the slave actively reports when the data changes, thereby reducing the burden on the host, improving communication efficiency and the real-time performance of data update, and has the following advantages:

[0110] 1) Reduce host load and improve overall system performance.

[0111] 2) Optimize the data transmission process and reduce data transmission delay.

[0112] 3) Reduce data redundancy and transmit only necessary information.

[0113] 4) Improve the timeliness and accuracy of slave data reporting.

[0114] In one embodiment, a host is provided, which may be a terminal, and includes a processor, a memory, a communication interface, a display screen, and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, an operator network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the above-mentioned RS485 communication bus conflict resolution method is implemented. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covered on the display screen, or a key, a trackball or a touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.

[0115] In one embodiment, a slave machine is further provided, including a memory and a processor, wherein the memory stores a computer program, and the computer program is stored thereon, and relates to all or part of the processes in the above-mentioned embodiment method.

[0116] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0117] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0118] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. An RS485 communication method for avoiding bus conflicts, applied to a main frame in a communication system, wherein the communication system comprises a plurality of slaves, a communication bus and a main frame, wherein the plurality of slaves are connected to the main frame via the communication bus; It is characterized in that The method comprises: Step S1: when receiving a bus application instruction from a slave or when actively sending a control instruction, detecting whether the bus is idle, if the bus is busy, continuing to detect until the bus is idle, and sending instructions prohibiting the use of the bus to multiple slaves connected to the host; the bus application instruction is uploaded to the host after the slave detects that the bus is idle when it needs to actively report data; Step S2: after issuing the instruction to prohibit the use of the bus, wait for the first set time to detect again whether the bus is idle, if it is idle, send a control instruction to the slave that sent the bus application instruction or send a control instruction to the designated slave; Step S3: receiving a response from the slave; Step S4: Determine whether the bus application instructions sent by all slaves have been processed, or whether the control instructions that need to be actively sent have been processed. If so, send a bus release command to multiple slaves connected to the host.

2. The RS485 communication method according to claim 1 that can avoid bus conflicts, It is characterized in that The waiting time is the first set time to detect again whether the bus is idle, if it is not idle, re-issuing instructions to prohibit the use of the bus to the multiple slaves connected to the host, and repeating step S2; If the instructions for prohibiting the use of the bus are issued to multiple slaves connected to the host for multiple times in succession, and the bus is detected to be in a non-idle state again after waiting for the first set time, a fault is reported.

3. The RS485 communication method according to claim 1 that can avoid bus conflicts, It is characterized in that The first set time is the time required for the current network to transmit 3 bytes.

4. The RS485 communication method for avoiding bus conflicts according to claim 1, It is characterized in that The control instruction is sent to the designated slave, and if no response is received from the slave within a certain period of time, the control instruction is sent to the designated slave again.

5. An RS485 communication method for avoiding bus conflicts, applied to a first slave in a communication system, wherein the communication system comprises a plurality of second slaves, a first slave, a communication bus and a host; the first slave and the second slave are connected to the host via the communication bus; It is characterized in that The method comprises: Step S1: When the first slave needs to actively report data, it detects whether the bus is idle. If it is idle, it sends a bus application instruction to the host; if the first slave does not need to actively report data, it directly executes step S2; Step S2: receiving a command from the host to prohibit the use of the bus; the command to prohibit the use of the bus is issued by the host to the first slave and multiple second slaves after the host receives a bus application command from the first slave or needs to actively issue a control command to the first slave and detects that the bus is idle; Step S3: receiving a control instruction sent by the host; the control instruction is sent to the first slave after the host sends an instruction to prohibit the use of the bus and waits for a first set time to detect that the bus is idle again; Step S4: Return a response to the host; Step S5: accept the release bus command issued by the host to adjust the state to a state capable of applying for the bus; the release bus command is issued by the host after determining that the bus application instructions sent by the first slave and all second slaves have been processed, or the control instructions that need to be actively issued have been processed.

6. The RS485 communication method for avoiding bus conflicts according to claim 5, It is characterized in that When the first slave needs to actively report data, it detects whether the bus is idle. If not, it detects whether the bus is idle again after a second set time interval until it is detected that the bus is idle.

7. The RS485 communication method for avoiding bus conflicts according to claim 6, It is characterized in that The first set time and the second set time are the time required for the current network to transmit 3 bytes.

8. The RS485 communication method for avoiding bus conflicts according to claim 7, It is characterized in that The time required to transmit 3 bytes under the current network is calculated according to the serial communication baud rate, the number of data bits, the number of start bits, and the number of stop bits, specifically by the following formula:

9. A host comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.

10. A slave having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 5 to 8 are implemented.

Citation Information

Cited By

  • Multi-host communication method and device applied to RS485 bus

    CN121455870A