Disclosure of Invention
One of the technical problems to be solved by the invention is how to realize that an RS485 bus architecture meets the requirement of a train control network on safety.
In order to solve the above technical problem, an embodiment of the present application first provides a communication system based on an RS485 bus, which is applied to a train control network and includes a first main control board, a second main control board, and a plurality of IO gateway boards; the first main control board and the second main control board are connected with each other through two mutually independent RS485 buses respectively; and the IO gateway boards are connected with the two RS485 buses.
Preferably, the IO gateway board includes a slave device and a hot standby slave device, and each RS485 bus is connected to a plurality of slave devices and a plurality of hot standby slave devices.
Preferably, the two main control boards and the plurality of IO gateways adopt master-slave response interactive communication.
The embodiment of the invention also discloses a communication method based on the RS485 bus, which is applied to the communication system, and the communication method comprises the following steps:
setting the first main control board as a main device and the second main control board as a hot standby main device, or setting the second main control board as a main device and the first main control board as a hot standby main device;
the first main control board and the second main control board are powered on, and whether the first main control board and the second main control board are main equipment or not is judged respectively;
the main control board as the main equipment carries out bus initialization and slave equipment scanning;
after initialization is completed, judging whether the current main control board is a main device or not, and if the current main control board is the main device, judging whether a communication fault exists in the current RS485 bus used by the main device or not;
if the current RS485 bus used by the main equipment has communication faults, the current RS485 bus used by the main equipment is switched to another RS485 bus, and if the current RS485 bus used by the main equipment has no communication faults, the step of sending a data request frame to a plurality of IO gateway boards by the main equipment is carried out;
the method comprises the steps that a main device sends a data request frame to a plurality of IO gateway boards;
the method comprises the steps that a master device receives data response frames of a plurality of IO gateway boards;
judging whether the data response frame is overtime or not according to the data response frame, if so, the data response frame is invalid, and if not, the data response frame is valid;
and returning to the step of judging whether the current main control board is the main equipment or not.
Preferably, the communication method further includes:
if the current main control board is not the main equipment, judging whether the current main control board monitors the communication abnormity of the main equipment;
if the current main control board monitors that the communication of the main equipment is abnormal, the current main control board is used as the main equipment, and if the communication of the main equipment is not abnormal, the current main control board is kept as the hot standby main equipment and receives data response frames of a plurality of IO gateway boards;
the method comprises the steps that a main device sends a data request frame to a plurality of IO gateway boards;
the method comprises the steps that a master device receives data response frames of a plurality of IO gateway boards;
judging whether the data response frame is overtime or not according to the data response frame, if so, the data response frame is invalid, and if not, the data response frame is valid;
and returning to the step of judging whether the current main control board is the main equipment or not.
Preferably, the communication method further includes:
electrifying a plurality of IO gateway boards, confirming the identities of slave equipment and hot standby slave equipment included in the IO gateway boards, and distributing corresponding communication IDs according to the identities;
receiving a request frame sent by a master device;
judging whether the ID of the receiving equipment of the request frame is consistent with the communication ID of the current equipment, if so, judging whether the current equipment is slave equipment, and if not, returning to the step of receiving the request frame sent by the master equipment;
if the current equipment is the slave equipment, judging whether the request frame is an initialization and equipment discovery frame;
if the request frame is an initialization and device discovery frame, sending an initialization response frame;
if the request frame is not the initialization and equipment discovery frame, judging whether the request frame is a data request frame;
if the request frame is a data request frame, sending a data response frame;
and if the request frame is not the data request frame, returning to the step of receiving the request frame sent by the master device.
Preferably, the communication method further includes:
if the current equipment is not the slave equipment, judging whether the hot standby slave equipment monitors communication abnormity of the slave equipment;
if the hot standby slave device monitors that the slave device is abnormal in communication, the hot standby slave device is changed into the slave device, whether the request frame is an initialization and device discovery frame or not is judged, and if the hot standby slave device does not monitor that the slave device is abnormal in communication, the hot standby slave device keeps the identity unchanged and returns to the step of receiving the request frame sent by the master device;
if the request frame is an initialization and device discovery frame, sending an initialization response frame;
if the request frame is not the initialization and equipment discovery frame, judging whether the request frame is a data request frame;
if the request frame is a data request frame, sending a data response frame;
and if the request frame is not the data request frame, returning to the step of receiving the request frame sent by the master device.
Preferably, the structure of the frame includes a start byte, a header, a data area, and a check area.
Preferably, the frame header is composed of 7 bytes, each byte indicating a frame type, a transmitting device ID, a receiving device ID, a frame sequence number, a time stamp, a mandatory acknowledgement group, and a data section data length, respectively.
Preferably, the slave device sets a timestamp of the response frame before transmitting the response frame, and the response frame includes an initialization response frame and a data response frame.
Compared with the prior art, one or more embodiments in the above scheme can have the following advantages or beneficial effects:
a communication system based on an RS485 bus is applied to a train control network and comprises a first main control board, a second main control board and a plurality of IO gateway boards; the first main control board and the second main control board are connected with each other through two mutually independent RS485 buses respectively, the first main control board and the second main control board can be connected through any one RS485 bus, and channel redundancy is realized by utilizing the two RS485 buses; a plurality of IO gateway boards all with two RS485 bus connections, a plurality of IO gateway boards can realize data interaction through any RS485 bus and first main control board and second main control board.
By utilizing the redundancy technology, when one RS485 bus is abnormal, the first main control board and the second main control board can also realize data interaction with a plurality of IO gateway boards through another RS485 bus, the breakdown of the whole train control network system caused by the abnormality of a single device or a single line is avoided, and the requirements of the train control network on the safety and the reliability of data transmission can be met.
Additional advantages, objects, and features of the invention will be set forth in part in the description which follows and in part will become apparent to those having ordinary skill in the art upon examination of the following or may be learned from practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Detailed Description
The following detailed description of the embodiments of the present invention will be provided with reference to the accompanying drawings and examples, so that how to apply the technical means to solve the technical problems and achieve the corresponding technical effects can be fully understood and implemented. The embodiments and the features of the embodiments can be combined without conflict, and the technical solutions formed are all within the scope of the present invention.
One of the technical problems to be solved by the embodiments of the present invention is: how to realize the RS485 bus architecture meets the requirement of a train control network on safety. In order to solve the above problem, an embodiment of the present invention provides a communication system based on an RS485 bus, which is applied to a train control network, and includes a first main control board, a second main control board, and a plurality of IO gateway boards; the first main control board and the second main control board are connected with each other through two mutually independent RS485 buses respectively, the first main control board and the second main control board can be connected through any one RS485 bus, channel redundancy is realized by utilizing the two RS485 buses, and the abnormality of the whole train control network system caused by the abnormal communication of a single RS485 bus channel can be avoided; a plurality of IO gateway boards all with two RS485 bus connections, a plurality of IO gateway boards can realize data interaction through any RS485 bus and first main control board and second main control board.
By utilizing the redundancy technology, when one RS485 bus is abnormal, the first main control board and the second main control board can also realize data interaction with a plurality of IO gateway boards through another RS485 bus, the breakdown of the whole train control network system caused by the abnormality of a single device or a single line is avoided, and the requirements of the train control network on the safety and the reliability of data transmission can be met.
The invention is further illustrated by the following specific examples.
As shown in fig. 1, a communication system based on an RS485 bus is applied to a train control network, and includes a first main control board, a second main control board, and a plurality of IO gateway boards; the first main control board and the second main control board are connected with each other through two mutually independent RS485 buses respectively, the first main control board and the second main control board can be connected through any one RS485 bus, and channel redundancy is realized by utilizing the two RS485 buses; a plurality of IO gateway boards all with two RS485 bus connections, a plurality of IO gateway boards can realize data interaction through any RS485 bus and first main control board and second main control board.
Further, the IO gateway board comprises a slave device and a hot standby slave device, and each RS485 bus is connected with the plurality of slave devices and the plurality of hot standby slave devices. Each IO network management board comprises a slave device and a hot standby slave device respectively.
The two RS485 buses are called a first RS485 bus and a second RS485 bus. The first main control board and the second main control board realize data interaction with the slave devices and the hot standby slave devices of the plurality of IO gateway boards through the first RS485 bus, or the first main control board and the second main control board realize data interaction with the hot standby slave devices and the hot standby slave devices of the plurality of IO gateway boards through the second RS485 bus. Namely, the slave device and the hot standby slave device of the IO gateway board may perform data interaction with the first main control board and the second main control board through the first RS485 bus or the second RS485 bus.
Each IO gateway board comprises slave equipment and hot standby slave equipment, so that equipment redundancy can be realized, and if the slave equipment of a certain IO gateway board fails, data interaction with the first main control board and the second main control board can be realized through the hot standby slave equipment of the IO gateway board through an RS485 bus.
Compare in traditional communication system based on RS485 bus, in the scheme of this application, realize the main equipment redundancy through setting up two main control boards, realize the channel redundancy through setting up two RS485 buses, IO gateway board includes that slave unit and heat are equipped with slave unit and realize that the slave unit is redundant. The redundancy of the main equipment and the redundancy of the slave equipment enable the communication system based on the RS485 bus to have a redundancy switching function, the problem of communication interruption caused by single equipment failure can be effectively solved, and the stability and the reliability of the communication system are improved. The channel redundancy enables the main control board and the IO gateway board to be connected with two mutually independent RS485 buses in the communication system based on the RS485 buses, the channel diagnosis and switching functions are achieved, the serious consequence that the whole train control network system is abnormal due to single channel faults can be avoided, and the safety and the reliability are higher.
According to the communication system based on the RS485 bus, the two main control boards and the plurality of IO gateways adopt master-slave response interactive communication, namely, the main control boards send request frames to the IO gateway boards, and the IO gateway boards send response frames to the main control boards after receiving the request frames. The main control board and the IO gateway board realize data interaction through a communication frame mode of a request frame and a response frame, and can avoid bus collision and improve the safety and the real-time performance of transmission.
The embodiment of the invention also discloses a communication method based on the RS485 bus, which is applied to the communication system. In the above communication system, each device has a unique device address, which is represented by a communication ID, and occupies 1 byte. The device address may be assigned by software in the train control network in the following manner. For example, the first master control board and the second master control board correspond to different communication IDs, such as 0x51 and 0x52, respectively. Each IO gateway board comprises a slave device and a hot standby slave device, communication IDs are sequentially allocated to the slave devices and the hot standby slave devices of the plurality of IO gateway boards according to the sequence of the IO gateway boards, the communication ID of the slave device of the first IO gateway board is 0xA0, the communication ID of the hot standby slave device of the first IO gateway board is 0xA1, the communication ID of the slave device of the second IO gateway board is 0xA2, the communication ID of the hot standby slave device of the second IO gateway board is 0xA3, and so on.
When the equipment address is detected, if the bit4-bit7 of the equipment address is 0x5, the current equipment is represented as a main control board, if the bit4-bit7 of the equipment address is 0xA, the current equipment is represented as an IO gateway board, and if the bit-bit7 is other values, the current equipment is represented as an illegal value. The numbers of the slave devices and the hot standby slave devices in the master control board or the IO gateway board are represented by bits 0 to bit3 of the device addresses, and priorities can be set according to the numbers, for example, the smaller the number is, the higher the priority is.
As can be seen from the communication IDs set above, the priority of the first main control board with the communication ID of 0x51 is higher than that of the second main control board with the communication ID of 0x52, the first main control board is a main device, and the second main control board is a hot standby main device; the slave of the first IO gateway board with the communication ID 0xA0 has higher priority than the hot standby slave of the first IO gateway board with the communication ID 0xA 1. Under normal conditions, the equipment with high priority carries out data communication, the equipment with low priority monitors the communication state of the equipment with high priority, and when the equipment with high priority fails in communication, the equipment with low priority carries out data communication, thereby realizing redundancy switching.
In the two RS485 buses, the priority of the first RS485 bus is higher than that of the second RS485 bus, data communication is carried out on the first RS485 bus under the default condition, data interaction between the main control board and the IO gateway board is completed, when the first RS485 bus is abnormal, the second RS485 bus is switched to carry out data communication, and data interaction between the main control board and the IO gateway board is completed.
The main control board and the IO gateway board perform data interaction and utilize a communication frame mode, and the frame structure comprises a starting byte, a frame header, a data area and a verification area. The structures of the communication frames are sequentially arranged, as shown in fig. 2, FrameStart is a start byte, and occupies 1 byte, and a fixed value is 0x 7E; the FrameHead is a frame header and is composed of 7 bytes, and each byte respectively indicates a frame type, a sending device ID, a receiving device ID, a frame sequence number, a timestamp, a forced response group and a data area data length; DATA is a DATA area, and the DATA length supports 0-255 bytes; FCS is a check area, and occupies 2 bytes. The data area adopts CRC-16 check mode, which can check the data of the frame head and the data area.
Specifically, the function of the frame header is as follows:
referring to fig. 3, with the structure of the communication frame, in the communication system based on the RS485 bus, the communication method based on the RS485 bus includes:
s1, setting the first main control board as a main device and the second main control board as a hot standby main device, or setting the second main control board as a main device and the first main control board as a hot standby main device;
generally, the first main control board is set as a master device, that is: and setting the first main control board as a communication ID with a smaller number.
S2, electrifying the first main control board and the second main control board, and respectively judging whether the first main control board and the second main control board are main devices;
and determining the identity of the first main control board and the second main control board through power-on self-test, namely determining whether the first main control board and the second main control board are the main equipment or the hot standby main equipment. Generally, the first main control board is used as a main device, and the second main control board is used as a hot standby main device.
S3, the main control board as the main device carries out bus initialization and slave device scanning;
generally, a first main control board performs bus initialization and slave device scanning, the first main control board sends an initialization and device discovery frame to an IO gateway board, a slave device of the IO gateway board responds according to the initialization and device discovery frame, a timestamp is set in a frame header of an initialization response frame, and the initialization response frame with the timestamp set is sent to the first main control board.
S4, after the initialization is finished, judging whether the current main control board is a main device;
s51, if the current master control board is the master device, judging whether the current RS485 bus used by the master device has communication fault;
and judging whether the current RS485 bus used by the master device has communication faults or not is realized by utilizing the periodic diagnosis of the current master control board.
S61, if the current RS485 bus used by the main device has communication fault, the current RS485 bus used by the main device is switched to another RS485 bus, the main device uses the another RS485 bus to perform data interaction with the IO gateway board, and if the current RS485 bus used by the main device has no communication fault, the step (S7) of sending a data request frame to a plurality of IO gateway boards by the main device is carried out;
through channel diagnosis and switching, the serious consequence that the fault of a single channel causes the abnormity of the whole train control network system can be avoided, and the method has stronger safety and reliability.
S7, the master device sends a data request frame to a plurality of IO gateway boards;
the master device periodically transmits a data request frame.
S8, the master device receives data response frames of a plurality of IO gateway boards;
s9, judging whether overtime exists according to the data response frame;
and judging whether the time is overtime or not according to the time stamp in the frame header of the data response frame.
S10, if time out, the data response frame is invalid;
s11, if not overtime, the data response frame is valid;
returning to the step of judging whether the current main control board is the main device (S4).
Further, referring to fig. 3, the communication method further includes:
s52, if the current main control board is not the main device, judging whether the current main control board monitors the communication abnormity of the main device;
if the current main control board is not the main device, the current main control board is a hot standby main device, and the communication state of the main device is periodically monitored by using the hot standby main device.
S62, if the current main control board monitors that the communication of the main equipment is abnormal, the current main control board is used as the main equipment, the current main control board used as the main equipment performs data interaction with the IO gateway board, and if the communication of the main equipment is not monitored by the current main control board, the current main control board is kept as the hot standby main equipment, monitors the communication state of the main equipment and receives data response frames of a plurality of IO gateway boards;
the redundant setting of main control board can effectively solve the problem that single equipment failure leads to communication interruption, and improves the stability and reliability of the train control network system.
S7, the master device sends a data request frame to a plurality of IO gateway boards;
the master device periodically transmits a data request frame.
S8, the master device receives data response frames of a plurality of IO gateway boards;
s9, judging whether overtime exists according to the data response frame;
and judging whether the time is overtime or not according to the time stamp in the frame header of the data response frame.
S10, if time out, the data response frame is invalid;
s11, if not overtime, the data response frame is valid;
returning to the step of judging whether the current main control board is the main device (S4).
Further, referring to fig. 4, the RS485 bus based communication method further includes:
s21, electrifying a plurality of IO gateway boards, confirming the identities of slave equipment and hot standby slave equipment included in the IO gateway boards, and distributing corresponding communication IDs according to the identities;
after the plurality of IO gateway boards are powered on, the identities of the IO gateway boards are determined through external hardware signals, whether the devices are slave devices or hot standby slave devices is determined, and corresponding communication IDs are allocated according to the identities, and the above embodiments can be referred to for setting of the communication IDs.
S22, receiving a request frame sent by the master device;
the slave device periodically waits to receive a request frame from the master device.
S23, judging whether the receiving device ID of the request frame is consistent with the communication ID of the current device;
s24, if it is consistent, it is judged whether the current device is the slave device, if not, it returns to the step of receiving the request frame sent by the master device (S22);
s25, if the current device is the slave device, judging whether the request frame is the initialization and device discovery frame;
and judging whether the frame is an initialization and equipment discovery frame or not according to the frame type of the frame head of the request frame.
S26, if the request frame is the initialization and equipment discovery frame, the initialization response frame is sent;
s27, if the request frame is not the initialization and device discovery frame, judging whether the request frame is a data request frame;
and judging whether the frame is a data request frame or not according to the frame type of the frame header of the request frame.
S28, if the request frame is a data request frame, sending a data response frame;
if the request frame is not a data request frame, the step of receiving the request frame sent by the master device is returned (S22).
Further, referring to fig. 4, the RS485 bus based communication method includes:
s251, if the current equipment is not the slave equipment, judging whether the hot standby slave equipment monitors the communication abnormality of the slave equipment;
the hot standby slave device periodically monitors the communication status of the slave device.
S252, if the hot standby slave device monitors that the communication of the slave device is abnormal, the hot standby slave device is changed into the slave device and is used as the slave device to judge whether the request frame is an initialization and device discovery frame (S25), if the hot standby slave device does not monitor that the communication of the slave device is abnormal, the hot standby slave device keeps the identity unchanged and returns to the step of receiving the request frame sent by the master device (S22);
the IO gateway board is provided with the slave equipment and the hot standby slave equipment in a redundant mode, so that the problem of communication interruption caused by single equipment failure can be effectively solved, and the stability and reliability of the train control network system are improved.
S26, if the request frame is the initialization and equipment discovery frame, the initialization response frame is sent;
s27, if the request frame is not the initialization and device discovery frame, judging whether the request frame is a data request frame;
and judging whether the frame is a data request frame or not according to the frame type of the frame header of the request frame.
S28, if the request frame is a data request frame, sending a data response frame;
if the request frame is not a data request frame, the step of receiving the request frame sent by the master device is returned (S22).
In the above embodiment, the slave device sets the time stamp of the response frame before transmitting the response frame, which includes the initialization response frame and the data response frame. By setting the timestamp, bus collision can be avoided, and the transmission safety and real-time performance are improved.
With the communication system and method based on the RS485 bus of the above embodiment, the following performance parameters can be achieved:
the above description is only a preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.