Communication method and device based on RS-485, equipment and storage medium

By adopting RS-485 communication and CRC32 checksum in rail transit systems and designing a multi-frame structure, the problem of low data transmission reliability in rail transit is solved, and higher data transmission accuracy and reliability are achieved.

CN121664581APending Publication Date: 2026-03-13BEIJING SHIGAN XINGBANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-21
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

In rail transit control systems, the frame structure of the Modbus RTU protocol based on the GB/T 19582.1-2008 standard uses CRC16 checksum, which makes it difficult to guarantee the integrity of data in strong electromagnetic environments, resulting in low communication reliability.

Method used

The RS-485-based communication method is adopted, and a multi-frame communication frame structure and CRC32 check method are designed. The master station sends a polling command to the slave station, and the slave station constructs and sends back frame data. The frame structure includes frame header, source address, destination address, vehicle number flag, data length, life signal, time source, time validity flag, X vehicle data validity, command type, sequence number and CRC32 check.

Benefits of technology

It improves the reliability of communication between carriages in rail transit and the accuracy of data transmission, prevents data loss and congestion, and adapts to complex logic control commands.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121664581A_ABST
    Figure CN121664581A_ABST
Patent Text Reader

Abstract

The invention provides a communication method based on RS-485, which is used for realizing data communication between a master station and slave stations in rail transit, and comprises the following steps: the master station sends a polling command to each slave station; after each slave station receives the polling command sent by the master station, when each slave station determines that frame return data needs to be constructed at present according to the polling command, the frame return data is constructed and returned to the master station; the polling command and the frame returning data are constructed according to a preset frame structure, and the preset frame structure comprises a frame header (0x5AA5), a source address (1B), a destination address (1B), a vehicle number mark (1B), a data length (2B), a life signal (2B), a time source (2B), a time effective mark bit (2B), an X vehicle data effective (2B), a command type (2B), a serial number (2B), data (nB), CRC32 (4B) and a frame tail (0xAAAB). According to the invention, the communication frame structure with multiple frame bits is designed, so that multiple verification can be carried out during data receiving and transmitting detection, and the accuracy and reliability of data receiving and transmitting can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of rail transit communication technology, and in particular to a communication method, apparatus, device and storage medium based on RS-485. Background Technology

[0002] Currently, in rail transit control systems, the Modbus RTU protocol architecture based on the GB / T 19582.1-2008 standard is commonly used. The frame structure of its communication protocol layer mainly adopts the standard frame structure, namely "device address (1B) + function code (1B) + data field (nB) + CRC16 (2B)". The standard frame structure uses CRC16 for verification. CRC16 verification is difficult to guarantee the integrity of data in a strong electromagnetic environment, which leads to the problem of low reliability when performing data transmission and reception detection.

[0003] Therefore, how to improve the reliability of communication between carriages in rail transit has become an urgent problem to be solved by those skilled in the art. Summary of the Invention

[0004] In view of this, this application proposes a communication method, apparatus, device and storage medium based on RS-485, which can effectively improve the reliability of communication between carriages.

[0005] According to a first aspect of this application, an RS-485-based communication method is provided for realizing data communication between a master station and a slave station in rail transit, comprising: The master station sends a polling command to each of the slave stations; After receiving the polling command sent by the master station, each slave station determines whether it is necessary to construct back frame data based on the polling command. When each of the slave stations determines that the return frame data needs to be constructed, the return frame data is constructed, and the constructed return frame data is sent back to the master station to realize data communication between the master station and each of the slave stations; Currently, the number of slave stations that need to construct the return frame data is one; both the polling command and the return frame data are constructed according to a preset frame structure, and the preset frame structure includes: |Frame header (0x5AA5) |Source address (1B) |Destination address (1B) |Vehicle number identifier (1B) |Data length (2B) |Life signal (2B) |Time source (2B) |Time valid flag (2B) |X vehicle data valid (2B) |Command type (2B) |Serial number (2B) |Data (nB) |CRC32 (4B) |Frame tail (0xAAAB) |.

[0006] In one possible implementation, after each slave station receives a polling command from the master station, determining whether back frame data needs to be constructed based on the polling command includes: Each of the slave stations obtains the destination address and vehicle number identifier from the polling command; The destination address and the vehicle number flag are compared with the address and vehicle number of each slave station. When it is determined that the destination address and the vehicle number flag are consistent with the address and vehicle number of the current slave station, it is determined that the current slave station needs to construct return frame data.

[0007] In one possible implementation, when the slave station constructs the return frame data, it includes: The slave station currently obtains the command type from the polling command; Query the corresponding data based on the command type; The return frame data is constructed based on the command type and the data queried.

[0008] In one possible implementation, after the slave station sends the constructed return frame data to the master station, the process also includes the master station confirming whether it has received the return frame data.

[0009] In one possible implementation, when the master station confirms whether the return frame data has been received, it includes: When the master station confirms that it has received the return frame data, the master station performs normal delay processing. When the master station confirms that it has not received the return frame data, the master station performs a timeout delay processing operation.

[0010] In one possible implementation, when the master station performs delay processing, the delay processing is performed based on a preset time interval.

[0011] In one possible implementation, when the main station performs normal delay processing, it includes: The master station obtains the communication time with the current slave station; The master station calculates its delay time based on a preset time interval and the communication time consumption. The master station performs normal delay processing based on the delay time and then sends the next frame polling command.

[0012] According to a second aspect of this application, an RS-485-based communication device is provided for realizing data communication between a master station and a slave station in rail transit, comprising: A polling command sending module is used for the master station to send polling commands to the slave station; The frame data construction confirmation module is used for each slave station to determine whether frame data needs to be constructed based on the polling command sent by the master station after receiving the polling command from the master station. The frame data return module is used to construct the frame data when each of the slave stations determines that the frame data needs to be constructed, and to return the constructed frame data to the master station, so as to realize simplified data communication between the master station and each of the slave stations. Currently, the number of slave stations that need to construct the return frame data is one; both the polling command and the return frame data are constructed according to a preset frame structure, and the preset frame structure includes: |Frame header (0x5AA5) |Source address (1B) |Destination address (1B) |Vehicle number identifier (1B) |Data length (2B) |Life signal (2B) |Time source (2B) |Time valid flag (2B) |X vehicle data valid (2B) |Command type (2B) |Serial number (2B) |Data (nB) |CRC32 (4B) |Frame tail (0xAAAB) |.

[0013] According to a third aspect of this application, an RS-485-based communication device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the method described in the first aspect of this application.

[0014] According to a fourth aspect of this application, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions, when executed by a processor, implement the method described in the first aspect of this application.

[0015] This application provides an RS-485-based communication method for realizing data communication between a master station and slave stations in rail transit. The method includes: the master station sending a polling command to the slave stations; each slave station, upon receiving the polling command from the master station, confirming whether it needs to construct a return frame data; when each slave station determines that it needs to construct the return frame data, constructing the return frame data and sending the constructed return frame data back to the master station, thereby achieving simplified data communication between the master station and each slave station; wherein, the number of slave stations that need to construct the return frame data is one; both the polling command and the return frame data are constructed according to a preset frame structure, and the preset frame structure includes: |Frame header (0x5AA5) |Source address (1B) |Destination address (1B) |Train number identifier (1B) |Data length (2B) |Life signal (2B) |Time source (2B) |Time validity flag (2B) |Car X Data Valid (2B)|Command Type (2B)|Sequence Number (2B)|Data (nB)|CRC32 (4B)|Frame End (0xAAAB)|. This application designs a multi-frame structure for communication, enabling multiple verifications during data transmission and reception. Furthermore, the use of CRC32 verification effectively improves the accuracy and reliability of transmitted and received data, thus enhancing communication reliability between carriages in rail transit.

[0016] Other features and aspects of this application will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description

[0017] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this application together with the specification and serve to explain the principles of this application.

[0018] Figure 1 A flowchart illustrating an RS-485-based communication method according to an embodiment of this application is shown. Figure 2 A schematic diagram of an RS-485-based communication architecture according to an embodiment of this application is shown; Figure 3 A schematic block diagram illustrating an RS-485-based communication process according to an embodiment of this application is shown. Figure 4 A schematic block diagram illustrating a process for RS-485-based communication delay processing according to an embodiment of this application is shown. Figure 5 A schematic block diagram of an RS-485-based communication device according to an embodiment of this application is shown; Figure 6A schematic block diagram of an RS-485-based communication device according to an embodiment of this application is shown. Detailed Implementation

[0019] Various exemplary embodiments, features, and aspects of this application will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.

[0020] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.

[0021] Furthermore, to better illustrate this application, numerous specific details are provided in the following detailed embodiments. Those skilled in the art should understand that this application can be implemented without certain specific details. In some instances, methods, means, components, and circuits well-known to those skilled in the art have not been described in detail in order to highlight the main points of this application.

[0022] <Method Implementation> Figure 1 A flowchart illustrating an RS-485-based communication method according to an embodiment of this application is shown. Figure 2 This diagram illustrates the architecture of communication between the master station and slave station according to an embodiment of this application. Figure 1 As shown, this method is used to realize data communication between a master station and slave stations in rail transit. The method includes steps S1100-S1400: S1100, the master station sends a polling command to each slave station; S1200, after receiving the polling command from the master station, each slave station determines whether it needs to construct a return frame data based on the polling command; S1300, when each slave station determines that it needs to construct a return frame data, it constructs the return frame data and sends the constructed return frame data back to the master station to realize data communication between the master station and each slave station; wherein, the number of slave stations that need to construct return frame data is one; the polling command and the return frame data are both constructed according to a preset frame structure, and the preset frame structure includes: |Frame header (0x5AA5) |Source address (1B) |Destination address (1B) |Train number identifier (1B) |Data length (2B) |Life signal (2B) |Time source (2B) |Time validity flag (2B) |X vehicle data valid (2B)|Command type (2B)|Serial number (2B)|Data (nB)|CRC32 (4B)|Frame end (0xAAAB)|.

[0023] This application designs a multi-frame communication frame structure, enabling multiple verifications during data transmission and reception detection between the master and slave stations. Furthermore, the use of CRC32 verification effectively improves the accuracy and reliability of transmitted and received data, thus enhancing communication reliability between carriages in rail transit. Moreover, traditional frame structures rely on simple function codes for instruction operations, which are limited to relatively simple operations and cannot handle complex logic control instructions. This application uses command types for instruction operations, accommodating complex logic control instructions. Furthermore, while traditional frame structures use only 1B function codes, this application uses 2B command types, resulting in a frame structure containing more and more complex instruction operations compared to traditional structures.

[0024] In one possible implementation, both the polling command and the response frame data are set according to a preset frame structure. The preset frame structure is as follows: | Frame Header (0x5AA5) | Source Address (1B) | Destination Address (1B) | Vehicle Number Flag (1B) | Data Length (2B) | Life Signal (2B) | Time Source (2B) | Time Valid Flag (2B) | X Vehicle Data Valid (2B) | Command Type (2B) | Sequence Number (2B) | Data (nB) | CRC32 (4B) | Frame Trailer (0xAAAB) |. It should be noted that the source address refers to the address of the data sender, the destination address refers to the address of the data receiver, the vehicle number flag refers to the current sender's vehicle compartment number, and the data length is the length of data carried in the current data packet. The life signal is a cyclically increasing number, ranging from 0 to 65535, incrementing by 1 per second. When it reaches 65535, it is reset and starts counting again. The purpose is to indicate a program crash when the receiver (either a slave receiving polling commands from the master or the master receiving return frames from the slave) receives the same number (life signal) 10 consecutive times. When the number stops increasing, it indicates the program is dead. Time sources include server time and local time to ensure consistency. A time validity flag indicates whether the time is valid. "X vehicle data valid" is used to show the host computer that a particular vehicle's data is valid. The command type refers to the data type queried during the actual data query. The sequence number identifies the packet order and detects packet loss / out-of-order delivery. The data contains the specific content of the polling command or the specific data retrieved based on the polling command. The CRC32 field is a checksum field used to verify the integrity of the data packet.

[0025] It should be further noted that, see [link / reference] Figure 2As shown in this application, the master station and slave station communicate based on the RS-485 bus. The RS-485 bus operates in half-duplex mode, meaning it can only receive or send data at a time, not simultaneously. Therefore, data transmission and reception are achieved by switching the DE pins. Based on this, each carriage (master station or slave station) is connected to the bus in this application. During communication, each carriage is first numbered to identify its master and slave stations. The master station sends a polling command to the slave stations, and the slave stations respond with frame data upon receiving the command. It should be noted that the master station is any carriage in the rail transit system, and the slave stations are every other carriage except the master station.

[0026] It should also be noted that when this application implements data transmission and reception through switching of the DE pins, the switching of the DE pins is controlled by a pre-set switching program. The switching program is as follows: pthread_mutex_lock(&pUart->nSendLock); GpioWrite(nEnableIo, eGpioHigh); / / Send high-level data if(write(pUart->nDevFd,pBuf,nSize) != nSize) { ret = false; } fsync(pUart->nDevFd); / / Forcefully saves the information stored in the file descriptor from memory to disk. usleep(20 1000); pthread_mutex_unlock(&pUart->nSendLock); GpioWrite(nEnableIo, eGpioLow); / / Pull low to disable sending In other words, when communication begins, before the master station sends polling commands to each slave station, it first executes the aforementioned switching procedure to switch the DE pin, thus switching the RS-485 bus to the data transmission state. At this time, the master station writes polling commands to the bus based on the data transmission state and sends these commands to each slave station via the bus. Each slave station simply receives the polling commands transmitted by the bus. Specifically, after the DE pin switches to the data transmission state, the master station writes the polling commands to the bus via the DE pin and transmits them to each slave station via the bus, thereby enabling each slave station to receive the polling commands sent by the master station. It should be noted that, to avoid insufficient delay time after the DE pin switching, resulting in missing data packets, this application sets a delay time after the DE pin switching is completed to ensure the integrity of data transmission. That is, after the DE pin switches from the data receiving state to the data transmitting state, there is a pause delay period to ensure that data can be transmitted completely during this period. This prevents situations where large data packets are partially transmitted due to the lack of a delay time set for the DE pin, resulting in missing bytes in the data packet. The delay time can be determined based on the specific data packet transmission time and is not limited thereto. In this application, the delay time is preferably set to 20ms.

[0027] In one possible implementation method Figure 2 This illustration shows the communication architecture of each carriage in a rail transit system according to one embodiment of this application. In this architecture, there is one master station among the carriages of the train, and the remaining carriages are slave stations. See further details. Figure 2 As shown, to prevent communication disruption due to damage to the main station, this application designs a hot standby main station mechanism. Specifically, this application designates both the first and last carriages of the seven carriages as the main station. This allows for direct data communication to switch to the last carriage if the physical wiring in the first carriage is interrupted, thus not affecting the overall train communication. It should also be noted that... Figure 2 The communication architecture consists of carriages numbered 1-7 from left to right.

[0028] When communication begins, the master station first sends polling commands to each slave station. See [link to relevant documentation]. Figure 3 As shown, vehicle 1 (master station) sends a polling command to the RS-485 bus, and each slave station receives the polling command via the bus. Based on the received polling command, each slave station confirms whether it needs to construct a return frame data.

[0029] Before each slave station confirms whether it needs to construct a return frame data based on the received polling command, the process also includes each slave station determining whether the vehicle number flag in the polling command is vehicle 1. See [link to relevant documentation]. Figure 3As shown, after the master station issues a polling command, all carriages connected to the bus will receive the polling command. If the carriage number in the polling command is carriage 1 (i.e., the master station), a self-sending and self-receiving processing measure is required. In this case, there is no need to construct a return frame data. Therefore, each slave station needs to determine whether the current carriage matching the polling command is carriage 1. That is, after receiving the current polling command, each slave station determines whether it is carriage 1 based on the carriage number flag in the received polling command. If it is carriage 1, carriage 1 can directly query the corresponding data according to the polling command and store the queried data directly. If it is not carriage 1, then it is another slave station besides carriage 1. Each slave station needs to find the slave station that matches the current polling command, that is, to confirm whether each slave station needs to construct a return frame data.

[0030] In one possible implementation, when each slave station determines whether it needs to construct back frame data, the process includes: each slave station obtaining the destination address and vehicle number flag from the polling command; comparing the destination address and vehicle number flag with the address and vehicle number of each slave station; and determining that the destination address and vehicle number of the polling command are consistent with the address and vehicle number of the current slave station, thus determining that the current slave station needs to construct back frame data.

[0031] When it is confirmed that the current slave station needs to construct a return frame data, the process includes: the current slave station obtaining the command type from the received polling commands; querying the corresponding data based on the command type; and constructing the return frame data based on the command type and the queried data. After constructing the return frame data, the return frame data is transmitted back to the master station via the bus. After receiving the return frame data, the master station completes the communication between the master station and the current slave station and begins sending the next polling command.

[0032] It should be noted that, see Figure 3 As shown, after the current slave station sends the constructed return frame data to the master station, the process also includes an operation for the master station to confirm whether it has received the return frame data. Specifically, when the master station confirms whether it has received the return frame data, it checks whether a data packet has been received, and simultaneously uses the destination address and vehicle number flag of that data packet to confirm whether it has received the return frame data sent by the current slave station.

[0033] When the master station confirms that it has received the return frame data, it performs normal delay processing; when the master station confirms that it has not received the return frame data, it performs timeout delay processing.

[0034] Once the master station confirms receipt of the echo frame data sent by the slave station (i.e. Figure 3When Uartread receives data, it acquires the communication time consumed between the master station and the current slave station, and calculates the master station's delay time based on the preset time interval and the communication consumption time. The master station performs normal delay processing based on the delay time and then sends the next frame polling command. It should be noted that the master station performs delay processing based on the preset time interval. The preset time interval refers to the time window for communication between the master station and each slave station, and this time interval can be determined based on the total communication time between the master station and each slave station sequentially. For example, in the communication of a 7-car train, there are 7 cars communicating. If the total communication time is set to 1 second, the time interval can be 142 ms.

[0035] It should be noted that this application uses a high-precision external clock circuit for timing, and each carriage is equipped with such a circuit. Timing begins with a polling command issued by the master station, and the high-precision clock circuit at the master station keeps track until the master station receives a response frame. This allows for the determination of the communication time consumed between the master station and the current slave station. See also... Figure 4 As shown, the timer starts when the master station sends the polling command (Uartwrite sends polling data). Figure 4 (A microsecond timer is started in the master station). After the master station receives the return frame data from the slave station (i.e., Uartrecv receives data), the timer stops, and the time taken is the duration of the current communication between the slave and master stations. At this time, the master station subtracts the communication duration from the preset time interval, which is the delay time required by the master station after this round of communication. After the delay is completed, the master station sends the next frame polling command normally.

[0036] See Figure 3 As shown, when the master station does not receive a return frame data from the slave station (i.e., Uartread does not receive a return frame data), it will determine whether the current communication is with itself based on the current polling command (i.e., Figure 3 (Whether it is vehicle 1 or not), when it is confirmed that the current communication is being conducted by itself, the timeout delay processing time is one time interval (i.e., Figure 3 or Figure 4 (142ms in the original text) When it is confirmed that the current communication is with another slave station besides itself, a timeout delay of one polling time (i.e., the total communication time between the master station and each slave station) is applied. Figure 3 or Figure 4 (1000ms in the process). After the delay processing ends, the master station sends the next frame polling command.

[0037] It should also be noted that after all slave stations have finished communicating, the difference between the current communication time and the preset total time needs to be calculated and then a delay is applied before the communication between the current master station and each slave station is completed and the next round of polling frames is sent.

[0038] This application uses a 7-car metro train as an example to illustrate the specific communication process between the master station and each slave station. Specifically, when communicating with a 7-car metro train, there are 7 cars in total, and the entire train polling time can be set to 1 second, with a preset time interval of 142 ms. In other words, during actual communication, the communication time window between the master station and each slave station is 142 ms. Communication between the master station and the current slave station is completed within these 142 ms, and the polling process of all 7 cars is completed within 1 second (i.e., the master station communicates with each slave station sequentially).

[0039] In order to prevent the loss of data packet bytes due to insufficient DE pin switching delay time when obtaining the communication time between the master station and the current slave station, this embodiment sets a delay time of 20ms after the DE pin switches. After the delay ends, the DE pin switches from the transmitting state to the receiving state. At the same time, this embodiment also sets the variable time for the pin switching program execution to 7ms.

[0040] In one possible implementation, see [link to relevant documentation] Figure 2 As shown, during communication within a 7-car train, cars 1 and 7 are the master stations, with car 7 serving as the backup master station. In specific communication, the program switches the DE pin to transmit mode, sending the polling command from car 1 to the bus, which then transmits the polling command to cars 1-7. The slave station currently communicating with the master station is identified based on the destination address and car number in the polling command. In one possible implementation, the communication between the master and slave stations includes two operating conditions: one where the master station normally receives return frame data (in which case the master station experiences normal delay), and another where all received return frame data times out (in which case the master station experiences timeout delay).

[0041] In one possible implementation, when the master station normally receives the returned frame data and performs normal delay processing, the process includes: During initial communication, the master station first sends a polling command to vehicle 1. At this time, vehicle 1 is self-transmitting and self-receiving. That is, the master station sends the polling command to vehicle 1 and starts timing. Other slave stations do not respond when they receive the polling command. Vehicle 1 directly looks up the corresponding data according to the command type in the polling command and stores the found data directly. At this time, the communication of vehicle 1 is completed, and the timing ends. The difference between the communication time interval and the time elapsed obtained by timing is calculated, and normal delay processing is performed based on this difference. After the delay processing ends, the master station sequentially sends polling commands to vehicles 2-7.

[0042] During communication between vehicles 2 and 7, the master station sequentially sends polling commands to vehicles 2-7 to start timing. Each slave station receives the polling command. After receiving the polling command, vehicles 2-7 look up the corresponding data according to the command type in the polling command, construct a response frame, and send it to the master station. Once the master station receives this data, the timing ends. The delay time of the master station after successful communication between vehicles 2 and 7 is obtained by subtracting the elapsed time from the 142ms time interval. After the delay processing ends, all communication between vehicles 1-7 ends, and the current communication between the master station and each slave station ends. Specifically, after all vehicles 1 to 7 have completed communication, the total elapsed time of vehicles 1 to 7 needs to be calculated. This total elapsed time includes the communication elapsed time obtained from the timing of each vehicle, and the master station's delay time after communication with each vehicle ends. The redundancy delay time for this round of communication is obtained by calculating the difference between the preset total time and the total elapsed time of vehicles 1 to 7. After the master station performs delay processing based on this redundancy delay time, the next round of communication begins.

[0043] It should be noted here that the specific calculation process for the communication time between the master station and the current slave station includes: when a new polling begins, car 1 sends a polling command, and car 1 initiates communication. Car 1's communication does not require bus transmission; therefore, car 1 can directly query the corresponding data based on the polling command and store it directly. Although car 1's communication does not go through the bus, since rail transit communication is based on the RS485 bus and the communication method is broadcast, during car 1's self-transmission and self-reception, car 1's polling command and response frame data will be sent to other slave stations via the bus. Furthermore, the fixed communication time of the master station itself includes the pin switching delay. and the variable time of program execution. Since the bus is usually in data receiving mode, during the self-transmission and self-reception of vehicle 1, two pin switches are required to switch the bus from data receiving mode to transmitting mode. This allows vehicle 1's polling commands and response frame data to be sent to other slave stations via the bus, and the other slave stations receive vehicle 1's polling commands and response frame data. The total time taken by vehicle 1 can then be calculated. It can be expressed by the formula: in, This represents the total communication time for one vehicle. This indicates the 20ms delay time after the DE pin switches. This variable represents the execution time of the program that performs the DE pin switching.

[0044] After calculating the communication time of vehicle 1, and the time interval of vehicle 1 (communication time window is 142ms), the remaining time after the communication of vehicle 1 ends can be calculated, which can be expressed by the formula: in, This indicates the remaining time after the communication between vehicle 1 and vehicle 2 ends.

[0045] Based on the remaining time calculated, a delay is performed. After the delay is completed, the polling of car 1 ends. At this time, the time gap between car 1 and car 2 is entered, and car 1 (master station) communicates with cars 2-6 (slave stations) in sequence.

[0046] When communicating between vehicle 1 and vehicles 2-6 sequentially, the delay time for each vehicle only includes the delay time for switching the DE pin to the transmit state. In addition, the program execution time during the DE pin switching is also a variable. Based on this, the communication time for vehicles 2-6 can be calculated. It can be expressed by the formula: Where n represents the vehicle number.

[0047] Based on the communication time of each vehicle in steps 2-6, the remaining time for each vehicle in its time interval can be calculated, which can be expressed by the formula: After delaying each car, communication occurs only when car 7 is reached. Specifically, during car 7 communication, the total polling time for all cars is 1 second. To ensure the final polling time is 1 second, this application calculates the polling time for car 7 using the same method as for cars 2-6. Then, the total time for cars 1-6 is added to the polling time for car 7 to calculate the total polling time for cars 1-7. Subtracting the total polling time from 1 second gives the delay time required after the polling of car 7, thus ensuring that the polling time for each round is 1 second. This can be expressed by the formula: It should be noted that when vehicles 2-7 are communicating, the DE pin only needs to be switched once to directly send the polling command sent by the master station to the slave station. After the bus delay of 20ms, it switches to the receiving state. At this time, the return frame data constructed by the slave station only needs to be sent back to the master station through the bus.

[0048] In one possible implementation, all received frame data from the master station time out. The timeout delay processing includes: during initial communication, the master station sends a polling command to vehicle 1 and starts timing. If the master station does not receive frame data from vehicle 1, it continues timing until the communication time interval of vehicle 1 reaches 142ms, at which point the master station terminates its own communication and sends polling commands to vehicles 2-7 in sequence. If the master station does not receive frame data from vehicles 2-7, a delay of 1000ms is applied.

[0049] It should be noted here that the specific calculation process for the communication timeout between the master station and the current slave station includes: when all data received by vehicle 1 times out, all data is calculated based on the maximum time slot. At this time, when polling vehicle 1, the base time is 95ms, plus a 20ms delay time for sending data. And the 20ms delay time for pin switching when vehicle 1 sends its own return frame data. There is also the variable time for executing pin switching code. Therefore, the total travel time for one vehicle can be calculated. It can be expressed by the formula: It should be noted that when vehicle 1 times out of receiving data, the communication time interval for vehicle 1 is fixed at 142ms. Besides this fixed timeout, the remaining time is the specific delay time of the master station during vehicle 1 communication (i.e., the aforementioned base time). In practical applications, this means the time the master station waits for the returned frame data, excluding the fixed time during communication between the master station and vehicle 1, until the timer reaches 142ms, at which point the current communication between the master station and vehicle 1 ends.

[0050] It should also be noted that the program execution time is dynamically changing. That is, setting the program execution time to 7ms ensures the program will finish executing within the set time period. However, in actual applications, the actual execution time may be less than 7ms, meaning the aforementioned program execution time is dynamic. The base time is calculated based on the maximum execution time of 7ms. Therefore, to ensure the total communication time for vehicle 1 is 142ms, the delay time for communication between the master station and vehicle 1 also needs to be calculated. It can be expressed by the formula: Similarly, when polling vehicle 2, the master station reduces the pin switching delay by 20ms, plus the variable time for executing the code. The total travel time for the two vehicles can be calculated. It can be expressed by the formula: It should be noted that since the two vehicles only need to perform one pin switch, the calculated base time for the two vehicles is 115ms when the master station times out receiving the frame data from the two vehicles.

[0051] The time interval between the two vehicles is also 142ms. Based on this, the remaining time of the communication window between the two vehicles is calculated. And with a delay, it can be expressed by the formula: Similarly, the polling time calculation for wheels 3-6 is the same as the timeout calculation method for the master station and wheel 2. That is, when the master station communicates with wheels 3-6 sequentially, the base delay of the master station is 115ms for each communication interval, plus a 20ms delay for switching the data transmission pin. In addition, the program execution time is a variable. The total time taken for the main station to communicate with each of vehicles 3-6 in sequence can be calculated. It can be expressed by the formula: Where n represents the carriage number.

[0052] It should be noted that the communication time for each carriage is 142ms. The remaining time can be calculated based on the communication time and the communication time of each carriage. And it is delayed, which can be expressed by the formula: Finally, to ensure the entire polling cycle time is 1 second, the total time is calculated, and the remaining unused time is used for the 7-vehicle delay. This can be expressed by the formula: Considering the actual operating environment, vehicles 1-7 should operate under a mixture of timeout delays and normal delays; therefore, the formula for the actual operating delay time should be as follows: It should also be noted here that, see Figure 3As shown, each carriage is equipped with a communication fault determination counter and a communication fault cancellation counter. During each communication, both counters in the carriage communicating with the master station increment by 1. Specifically, during initial communication, both the communication fault determination counter and the communication fault cancellation counter of each slave station are 0. The master station sequentially sends polling commands. When a corresponding response frame is received, the current slave station checks if its own communication fault cancellation counter value is greater than a preset threshold (preferably 5). If the value of the communication fault cancellation counter is greater than 5, the slave station clears its communication fault determination counter to zero and simultaneously increments its own communication fault cancellation counter by 1. If the value of the communication fault cancellation counter is less than 5, the slave station directly increments both the communication fault determination counter and the communication fault cancellation counter by 1. When the master station receives the corresponding response frame, the communication indicator light of the currently communicating slave station flashes, indicating that the slave station's communication is normal.

[0053] When the master station does not receive the corresponding return frame data, the slave station currently communicating determines whether the value of the communication fault determination counter is greater than a preset threshold (preferably 10). When the slave station determines that the value of the communication fault determination counter is greater than 10, it clears the communication cancellation counter to zero. At this time, the communication indicator light stays on, indicating that the current slave station is experiencing a communication fault. When the slave station determines that the communication fault determination counter is not greater than 10, both the communication fault determination counter and the communication fault cancellation counter of the slave station are incremented by 1.

[0054] For example, the master station sends a polling command to vehicle 1. Vehicle 1 retrieves data according to the polling command and stores it directly. When the master station receives the data retrieved by vehicle 1, the value of vehicle 1's communication fault cancellation counter is 0, which is less than a preset threshold (preferably 5). Therefore, vehicle 1 increments its own communication fault cancellation counter by 1, and also increments its communication fault determination counter by 1. Waiting for the next communication with vehicle 1, if the master station does not receive a return frame data at this time, vehicle 1 determines that the value of its communication fault determination counter is less than 10. Therefore, both vehicle 1's communication fault determination counter and communication fault cancellation counter are incremented by 1.

[0055] In one possible implementation, this application also includes a host computer for monitoring the entire communication process and receiving polling commands sent by the master station and return frame data sent by each slave station carriage, so that the faulty equipment can be quickly located through the host computer when a communication failure occurs.

[0056] This application provides an RS-485 communication method for realizing data communication between a master station and slave stations in rail transit. The method includes: the master station sending a polling command to each slave station; each slave station, upon receiving the polling command from the master station, determining whether it needs to construct a return frame data; when each slave station determines that it needs to construct a return frame data, constructing the return frame data and sending the constructed return frame data back to the master station to realize data communication between the master station and each slave station; wherein, the number of slave stations that need to construct return frame data is one; both the polling command and the return frame data are obtained according to a preset frame structure, and the preset frame structure includes: | Frame header (0x5AA5) | Source address (1B) | Destination address (1B) | Vehicle number identifier (1B) | Data length (2B) | Life signal (2B) | Time source (2B) | Time validity flag (2B) | X vehicle data valid (2B) | Command type (2B) | Serial number (2B) | Data (nB) | CRC32 (4B) |Frame End (0xAAAB) |. This application designs a multi-frame-bit communication frame structure, enabling multiple verifications during data transmission and reception. Based on the CRC32 verification method used in this application, the accuracy and reliability of transmitted and received data can be effectively improved, thus enhancing communication reliability between carriages in rail transit. Furthermore, by setting time gaps for each master and slave station, this application ensures that each slave station is within its designated time gap during communication, avoiding data congestion caused by timeouts in current slave station communication. This also ensures that the bus is empty after the previous slave station's communication time has ended, allowing for smooth communication from the next slave station. Additionally, this application includes a delay time during DE pin switching, effectively ensuring the integrity of transmitted data and preventing data loss due to excessively short pin switching times.

[0057] <Device Embodiment> Figure 5 A schematic block diagram of an RS-485-based communication device according to an embodiment of this application is shown. Figure 5As shown, the device 100 is used to realize data communication between the master station and the slave station in rail transit, and the device 100 includes: a polling command sending module 110, a return frame data construction confirmation module 120, and a return frame data return transmission module 130. The system includes a polling command sending module 110, used by the master station to send polling commands to the slave stations; a return frame data construction confirmation module 120, used by each slave station to determine whether it needs to construct return frame data after receiving the polling command from the master station; and a return frame data transmission module 130, used to construct return frame data when each slave station determines that it needs to construct return frame data, and to transmit the constructed return frame data back to the master station, thereby achieving simplified data communication between the master station and each slave station. The number of slave stations that need to construct return frame data is one. Both the polling command and the return frame data are constructed according to a preset frame structure, which includes: | Frame header (0x5AA5) | Source address (1B) | Destination address (1B) | Vehicle number identifier (1B) | Data length (2B) | Life signal (2B) | Time source (2B) | Time validity flag (2B) | X vehicle data valid (2B) | Command type (2B) | Serial number (2B) | Data (nB) | CRC32(4B) |Frame tail(0xAAAB)|.

[0058] <Equipment Example> Figure 6 A schematic block diagram of an RS-485-based communication device according to an embodiment of this application is shown. Figure 6 As shown, the RS-485-based communication device 200 includes a processor 210 and a memory 220 for storing executable instructions of the processor 210. The processor 210 is configured to implement any of the aforementioned RS-485-based communication methods when executing the executable instructions.

[0059] It should be noted here that the number of processors 210 can be one or more. Furthermore, the RS-485-based communication device 200 in this embodiment may also include an input device 230 and an output device 240. The processors 210, memory 220, input device 230, and output device 240 can be connected via a bus or other means, which are not specifically limited here.

[0060] The memory 220, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and various modules, such as the program or module corresponding to the RS-485-based communication method in this application embodiment. The processor 210 executes various functional applications and data processing of the RS-485-based communication device 200 by running the software program or module stored in the memory 220.

[0061] Input device 230 can be used to receive input digital numbers or signals. These signals may include key signals related to user settings and function control of the device / terminal / server. Output device 240 may include a display device such as a screen.

[0062] <Storage Medium Examples> According to a fourth aspect of this application, a non-volatile computer-readable storage medium is also provided, on which computer program instructions are stored, which, when executed by processor 210, implement any of the preceding RS-485-based communication methods.

[0063] The various embodiments of this application have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical applications, or technological improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.

Claims

1. A communication method based on RS-485, characterized in that, Used to enable data communication between master and slave stations in rail transit, including: The master station sends a polling command to each of the slave stations; After receiving the polling command sent by the master station, each slave station determines whether it is necessary to construct back frame data based on the polling command. When each of the slave stations determines that the return frame data needs to be constructed, the return frame data is constructed, and the constructed return frame data is sent back to the master station to realize data communication between the master station and each of the slave stations; Currently, the number of slave stations that need to construct the return frame data is one; both the polling command and the return frame data are constructed according to a preset frame structure, and the preset frame structure includes: |Frame header (0x5AA5) |Source address (1B) |Destination address (1B) |Vehicle number identifier (1B) |Data length (2B) |Life signal (2B) |Time source (2B) |Time valid flag (2B) |X vehicle data valid (2B) |Command type (2B) |Serial number (2B) |Data (nB) |CRC32 (4B) |Frame tail (0xAAAB) |.

2. The RS-485-based communication method according to claim 1, characterized in that, After each slave station receives a polling command from the master station, when determining whether back frame data needs to be constructed based on the polling command, the process includes: Each of the slave stations obtains the destination address and vehicle number identifier from the polling command; The destination address and the vehicle number flag are compared with the address and vehicle number of each slave station. When it is determined that the destination address and the vehicle number flag are consistent with the address and vehicle number of the current slave station, it is determined that the current slave station needs to construct return frame data.

3. The RS-485-based communication method according to claim 2, characterized in that, When constructing the return frame data at the current slave station, the following is included: The slave station currently obtains the command type from the polling command; Query the corresponding data based on the command type; The return frame data is constructed based on the command type and the data queried.

4. The RS-485-based communication method according to claim 1, characterized in that, After the slave station sends the constructed return frame data to the master station, the process also includes the master station confirming whether it has received the return frame data.

5. The RS-485-based communication method according to claim 3, characterized in that, When the master station confirms whether it has received the return frame data, it includes: When the master station confirms that it has received the return frame data, the master station performs normal delay processing. When the master station confirms that it has not received the return frame data, the master station performs a timeout delay processing operation.

6. The RS-485-based communication method according to claim 4, characterized in that, When the main station performs delay processing, the delay processing is performed based on a preset time interval.

7. The RS-485-based communication method according to claim 5, characterized in that, When the main station performs normal delay processing, it includes: The master station obtains the communication time with the current slave station; The master station calculates its delay time based on a preset time interval and the communication time consumption. The master station performs normal delay processing based on the delay time and then sends the next frame polling command.

8. A communication device based on RS-485, characterized in that, Used to enable data communication between master and slave stations in rail transit, including: A polling command sending module is used for the master station to send polling commands to the slave station; The frame data construction confirmation module is used for each slave station to determine whether frame data needs to be constructed based on the polling command sent by the master station after receiving the polling command from the master station. The frame data return module is used to construct the frame data when each of the slave stations determines that the frame data needs to be constructed, and to return the constructed frame data to the master station, so as to realize simplified data communication between the master station and each of the slave stations. Currently, the number of slave stations that need to construct the return frame data is one; both the polling command and the return frame data are constructed according to a preset frame structure, and the preset frame structure includes: |Frame header (0x5AA5) |Source address (1B) |Destination address (1B) |Vehicle number identifier (1B) |Data length (2B) |Life signal (2B) |Time source (2B) |Time valid flag (2B) |X vehicle data valid (2B) |Command type (2B) |Serial number (2B) |Data (nB) |CRC32 (4B) |Frame tail (0xAAAB) |.

9. A communication device based on RS-485, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to implement the method of any one of claims 1 to 7 when executing the executable instructions.

10. A non-volatile computer-readable storage medium storing computer program instructions thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 7.