Disclosure of Invention
Aiming at the defects that in the prior art, when 2 or more hosts need to be connected with each device simultaneously in the system, data errors can be caused and communication can not be completed due to the fact that a plurality of hosts send signals to a communication bus simultaneously, the invention provides an on-line switching system for RS485 communication, and aims to solve the technical problems.
The invention provides an on-line switching system for RS485 communication, which comprises: the system comprises a central processing module, a power supply module, a voltage conversion module, a communication module and a plurality of RS485 communication channels, wherein each communication channel comprises an RS485 communication unit, a protection unit and an RS485 repeater; the central processing module is connected to a plurality of external master terminal devices through the communication module, the central processing module is connected to external slave terminal devices through the RS485 repeater, the protection unit and the RS485 communication unit in sequence, and the central processing module, the RS485 repeater and the RS485 communication unit are all connected to the power supply module through the voltage conversion module;
the RS485 communication unit comprises an RS485 communication A line, an RS485 communication B line, a resistor R1, a gas discharge tube TV1, a thermistor PTC2, a transient suppression diode TVS1, a transient suppression diode TVS2, a transient suppression diode TVS3 and a double-path common mode filter T1;
the first end of the gas discharge tube TV1 is connected to the first end of external slave end equipment through an RS485 communication A line, the second end of the gas discharge tube TV1 is connected to the second end of the external slave end equipment through an RS485 communication B line, a resistor R1 is connected between the RS485 communication A line and the RS485 communication B line, the first end of the gas discharge tube TV1 is connected to the first end of a transient suppression diode TVS1 through a thermistor PTC1, the second end of the transient suppression diode TVS1 is grounded, the second end of the gas discharge tube TV1 is connected to the first end of a transient suppression diode TVS3 through a thermistor PTC2, the second end of the transient suppression diode TVS3 is grounded, the first end of the transient suppression diode TVS1 is also connected to the first end of a double-circuit common mode filter T1, the first end of the double-circuit common mode filter T1 is also connected to the second end of the double-circuit common mode filter T1, a transient suppression diode TVS2 is connected between the first end of the double-circuit common mode filter T1 and the second end of the double-circuit common mode filter T1, and the second end of the double-circuit common mode filter T1 is connected to the first end of the TVS1 and the first end of the double-circuit common mode protection unit.
The technical scheme is that the protection unit comprises an isolation chip U1, a resistor R2, a resistor R3, a capacitor C1 and an optocoupler;
the first pin of the isolation chip U1 is connected to the fourth end of the double-circuit common mode filter T1 through a resistor R2, the second pin of the isolation chip U1 is also connected to the fourth end of the double-circuit common mode filter T1, the third pin of the isolation chip U1 is connected to the third end of the double-circuit common mode filter T1, the third pin of the isolation chip U1 is grounded through a resistor R3, the fourth pin of the isolation chip U1 is grounded, the first end of the capacitor C1 is grounded, the second end of the capacitor C1 is grounded, and the fifth pin, the sixth pin, the seventh pin and the eighth pin of the isolation chip U1 are all connected to the RS485 repeater through optocoupler devices.
The technical scheme is further that the isolation chip U1 is an isolation chip with the model number of TDH541S 485H.
According to the technical scheme, the RS485 repeater is further connected with a debugging unit, the debugging unit comprises a first dial switch and a second dial switch, the first dial switch and the second dial switch are both connected to the RS485 repeater, the first dial switch is used for setting the baud rate of external main terminal equipment, and the baud rate of external slave terminal equipment of the second dial switch is set.
The technical scheme further comprises that the voltage conversion module comprises a 3.3V voltage conversion unit and a 5V voltage conversion unit, the central processing module and the RS485 repeater are connected to the power supply module through the 3.3V voltage conversion unit, and the RS485 communication unit is connected to the power supply module through the 5V voltage conversion unit.
Further still, the communication module of the present technical solution includes a 4G communication unit, a LORA communication unit, and an HPLC communication unit.
The intelligent power distribution network system has the beneficial effects that the intelligent power distribution network system is used for data acquisition and information interaction between various power distribution side terminals (main terminals) and various downlink equipment (auxiliary terminals) so as to meet the requirements of the construction of a novel power system and an intelligent power distribution network; the baud rate conversion can be carried out in the communication process, and the serial port communication with different baud rates can be realized according to different baud rates generated by switching different receiving and transmitting states; when the main end has the wireless communication conditions of 4G, LORA and the like or the wired communication transmission conditions of the power carrier, the RS485 communication can be realized through the conversion of the central processing module; finally, the invention can also select and switch the communication channel, thereby preventing the problem that the communication cannot be completed due to data errors caused by the fact that a plurality of hosts send signals to the communication bus simultaneously.
In addition, the invention has reliable design principle, simple structure and very wide application prospect.
Detailed Description
In order to make the technical solution of the present invention better understood by those skilled in the art, the technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
The following explains key terms appearing in the present invention.
MCU, microcontroller Unit, the micro-control unit, also known as a single chip microcomputer (Single Chip Microcomputer) or a single chip microcomputer, is to properly reduce the frequency and specification of the CPU (Central Process Unit, CPU), integrate peripheral interfaces such as memory (memory), counter (Timer), USB, A/D conversion, UART, PLC, DMA, etc., and even LCD driving circuits on a single chip to form a chip-level computer, and perform different combination control for different application occasions. Such as mobile phones, PC periphery, remote controllers, automotive electronics, industrial stepper motors, control of robotic arms, etc., can see the shadow of the MCU.
FPGA, field-Programmable Gate Array, a Field programmable gate array, is a product of further development on the basis of programmable devices such as PAL, GAL, CPLD. The programmable device is used as a semi-custom circuit in the field of Application Specific Integrated Circuits (ASICs), which not only solves the defect of custom circuits, but also overcomes the defect of limited gate circuits of the original programmable device.
The Long, which is called Long Range in its entirety, is a wireless digital communication Modulation technique of a physical layer, which is called a spread spectrum continuous frequency Modulation (Chirp Modulation) technique. The method is characterized in that the method is farther than other wireless modes in transmission under the same power consumption, the unification of low power consumption and long distance is realized, and the radio frequency communication distance is enlarged by 3-5 times compared with the traditional wireless communication under the same power consumption.
HPLC is a high-speed power line carrier, also known as a broadband power line carrier, which is a broadband power line carrier technology that performs data transmission on a voltage power line. The broadband power line carrier communication network uses a power line as a communication medium to realize convergence, transmission and interaction of power consumption information of a low-voltage power user. The broadband power line carrier mainly adopts an Orthogonal Frequency Division Multiplexing (OFDM) technology, and the frequency band is 2MHz-12MHz. Compared with the traditional low-speed narrow-band power line carrier technology, the HPLC technology has large bandwidth and high transmission rate, and can meet the higher requirements of the low-speed narrow-band power line carrier communication.
In this embodiment, the RS485 communication online switching system may be divided into a plurality of functional modules according to the functions performed by the system, as shown in fig. 1. The functional module may include: the central processing module 110, the power module 120, the voltage conversion module 130, the communication module 140, and a plurality of RS485 communication channels, each of which includes an RS485 communication unit 151, a guard unit 152, and an RS485 repeater 153. In the present embodiment, the functions of the respective modules will be described in detail in the following embodiments.
The external master terminal equipment comprises a plurality of public transformer area acquisition equipment and systems such as an intelligent transformer area fusion terminal, an intelligent power distribution terminal and a power distribution scheduling system, and n downlink equipment which are correspondingly acquired can be used as external slave terminal equipment for RS485 communication and can be a plurality of distributed new energy sources such as a photovoltaic inverter and a charging pile. The original communication modes of the master end and the slave end can comprise a wireless mode such as 4G, LORA and micropower wireless mode and a wired mode such as a power line carrier. In order to ensure the flexibility, expandability and rapid iteration performance of the system, the whole system comprises a central processing module 110, a power module 120, a voltage conversion module 130, a communication module 140 and a plurality of RS485 communication channels, wherein each communication channel comprises an RS485 communication unit 151, a protection unit 152 and an RS485 repeater 153; specifically, the central processing module is connected to a plurality of external master terminal devices through the communication module, the central processing module is connected to external slave terminal devices through the RS485 repeater, the protection unit and the RS485 communication unit in sequence, and the central processing module, the RS485 repeater and the RS485 communication unit are connected to the power supply module through the voltage conversion module. The communication module comprises a 4G communication unit, a LORA communication unit and an HPLC communication unit.
One end of the power supply module is connected with a 220V external power supply, and the other end of the power supply module is connected to each functional module through the voltage conversion module to supply power to the functional module; the voltage conversion module comprises a 3.3V voltage conversion unit and a 5V voltage conversion unit, the central processing module and the RS485 repeater are connected to the power supply module through the 3.3V voltage conversion unit, and the RS485 communication unit is connected to the power supply module through the 5V voltage conversion unit.
As shown in fig. 2, the RS485 communication unit includes an RS485 communication a line, an RS485 communication B line, a resistor R1, a gas discharge tube TV1, a thermistor PTC2, a transient suppression diode TVs1, a transient suppression diode TVs2, a transient suppression diode TVs3, and a two-way common mode filter T1; the first end of the gas discharge tube TV1 is connected to the first end of external slave end equipment through an RS485 communication A line, the second end of the gas discharge tube TV1 is connected to the second end of the external slave end equipment through an RS485 communication B line, a resistor R1 is connected between the RS485 communication A line and the RS485 communication B line, the first end of the gas discharge tube TV1 is connected to the first end of a transient suppression diode TVS1 through a thermistor PTC1, the second end of the transient suppression diode TVS1 is grounded, the second end of the gas discharge tube TV1 is connected to the first end of a transient suppression diode TVS3 through a thermistor PTC2, the second end of the transient suppression diode TVS3 is grounded, the first end of the transient suppression diode TVS1 is also connected to the first end of a double-circuit common mode filter T1, the first end of the double-circuit common mode filter T1 is also connected to the second end of the double-circuit common mode filter T1, a transient suppression diode TVS2 is connected between the first end of the double-circuit common mode filter T1 and the second end of the double-circuit common mode filter T1, and the second end of the double-circuit common mode filter T1 is connected to the first end of the TVS1 and the first end of the double-circuit common mode protection unit.
As shown in fig. 3, when RS485 is in communication, a signal cannot directly enter the central processing module, and needs to pass through the protection unit, and then enter the central processing module, where the protection unit specifically includes an isolation chip U1, a resistor R2, a resistor R3, a capacitor C1 and an optocoupler; the first pin of the isolation chip U1 is connected to the fourth end of the double-path common mode filter T1 through a resistor R2, the second pin of the isolation chip U1 is also connected to the fourth end of the double-path common mode filter T1, the third pin of the isolation chip U1 is connected to the third end of the double-path common mode filter T1, the third pin of the isolation chip U1 is grounded through a resistor R3, the fourth pin of the isolation chip U1 is grounded, the first end of the capacitor C1 is grounded, the second end of the capacitor C1 is grounded, and the fifth pin, the sixth pin, the seventh pin and the eighth pin of the isolation chip U1 are all connected to the RS485 repeater through optocoupler devices; the isolation chip U1 is a TDH541S485H isolation chip.
In addition, the RS485 repeater is also connected with a debugging unit, the debugging unit comprises a first dial switch and a second dial switch, the first dial switch and the second dial switch are both connected to the RS485 repeater, the first dial switch is used for setting the baud rate of external main terminal equipment, and the second dial switch is used for setting the baud rate of external slave terminal equipment.
The external slave device realizes data communication (RS 485_A and RS 485_B) through two-wire RS485 (RS 485 communication A wire and RS485 communication B wire), firstly performs first-stage lightning surge protection through a gas discharge tube TV1, performs line overcurrent protection through a thermistor PTC1 and a thermistor PTC2, suppresses overvoltage through a parallel bidirectional transient suppression diode TVS2, then performs further common mode noise suppression on an input 485 signal through a double-path common mode filter T1, and selects a DFN packaged RS485 isolation chip U1 to perform physical isolation on a signal finally transmitted to an RS485 bus of a central processing module. The capacitor C1 between the isolation ground GND (power supply ground) and the signal ground gnd_o1 functions to filter out high-frequency signal disturbances. The RS485 repeater plays a role in the baud rate conversion of the master end and the slave end, and the baud rate of the communication serial ports of the master end and the slave end is preset through a debugging port in an installation site generally, but the baud rates may be different when different downlink slave end equipment data are acquired through the RS485 repeater, the site debugging is required, and when the software debugging is inconvenient, the baud rate setting of the slave end of the master end can be respectively completed through two dial switches. And the output signal of the RS485 communication unit enters the MCU of the RS485 repeater after being isolated by an optical coupler to perform baud rate conversion, and then the signal is forwarded to the central processing module. Meanwhile, in the communication process, an information acquisition request is usually initiated from a master end to a slave end, and in the process that the central processing module sends data to the MCU of the RS485 repeater, the MCU of the repeater can automatically identify and store the baud rate of the master end.
In addition, an FPGA programmable logic device can be used for replacing a central processing module and two dial switches, and the FPGA programmable logic device is realized through hardware logic. The FPGA design mainly comprises a sending module, a receiving module and an interface module, wherein the sending module is used for data caching and parallel-serial conversion of 485 asynchronous communication, the receiving module is mainly used for data serial-parallel conversion, data frame zone bit identification and data caching, and the interface module is mainly used for completing data communication with a terminal MCU, the sending module and the receiving module.
The main terminal corresponds to the intelligent fusion terminal body of the platform region, and the slave terminal corresponds to the downlink equipment collected by the intelligent fusion terminal of the platform region; it is assumed that n paths of devices are shared to perform data collection communication on downlink devices at the same time, namely, a multi-master one-slave communication mode is adopted.
The working principle of the system is as follows: firstly, controlling external master terminal equipment to send an information acquisition request frame to target external slave terminal equipment; then judging whether all communication channels corresponding to the target external slave terminal equipment are idle or not; if yes, judging the serial port state of the external main terminal equipment which sends the information acquisition request frame; if the Ready flag bit and the Lock flag bit in the serial port on the external main terminal equipment sending the information acquisition request frame are both 0, the Lock flag positions on other external main terminal equipment are 1, and interlocking is formed; the target external slave terminal equipment can receive data from the external master terminal equipment through a communication channel with the Ready flag bit and the Lock flag bit being 0, and send the data to the external master terminal equipment through the communication channel to wait for the next receiving; if not, determining the occupied communication channel, controlling the external master terminal equipment corresponding to the occupied channel to send data to the external slave terminal equipment, and waiting for the next receiving.
In addition, when judging that the Ready flag bit and the Lock flag bit in the serial port on the external main terminal equipment sending the information acquisition request frame are both 0, setting the serial port state on the external main terminal equipment sending the information acquisition request frame as a NOTRADY state, after the serial port state is set, interrupting a direct memory access idle channel, and then judging whether frame data is completed; and after the frame data transmission is judged to be completed, setting the Lock mark position on other external master terminal equipment to 0.
In order to facilitate understanding of the present invention, the working principle of the system is used to further describe the working method of the RS485 communication online switching system provided by the present invention.
Firstly, initializing a system, and initializing and configuring interfaces such as a system clock, a system interrupt, a serial port and the like; and then the master end sends frame data of the information acquisition request to the slave end, and then judges whether the current serial port channel is idle (an occupied channel mark is set in the serial port, when the mark bit is 0, the serial port is idle), and as 485 communication is in a half duplex mode, the receiving and the transmitting cannot be simultaneously carried out, when the occupied channel is 0, the downstream slave end equipment 485 is in a receivable state, the slave end is idle to monitor the channel, after receiving the data, the slave end can enter a sending state to reply, and then when the occupied channel value is no longer 0, the channel occupied by the slave end is set (1, 2, 3..and n), the 485 channel is in a master end 485 state, and at the moment, the master end 485 is in a transmittable state, and after the master end completes the sending, the slave end can enter a receiving state.
Further, when the occupied channel value is judged to be 0, the slave 485 mode is entered. And continuously judging whether the serial port state of the main end of each path is 'Ready' and whether the Lock flag bit is 0, and when a certain path of serial port is found to be in the state, indicating that the path of serial port receives the data of the main end and that the data need to be returned to the main end. At this time, the serial port of the path is selected, and the Lock positions of the serial ports of other paths are needed to be 1 to form interlocking, so that the data transmission of the other paths cannot be carried out at the same time; then, data is sent and waiting for receiving, and the current serial port state is set as NOTRADY while receiving, so that the current serial port state is ensured not to enter the process before the completion of one-time receiving and transmitting; after the serial port state is set, entering DMA idle interrupt, and then judging the completion of frame data transmission, so as to avoid the resources of data packaging and multiple judgment. In the receiving process of the slave 485, the received data is firstly judged and then replied. If the Modbus protocol is used for communication, the slave terminal device has fixed frame length, frame head, frame tail and CRC check parameter model selection, and can determine whether the data received by the slave terminal is Modbus protocol data or not by judging the received data, and if not, the data is directly forwarded to the slave terminal in a transparent transmission mode. After the slave end 485 sends, the master end judges the value (1-n) of the occupied channel according to the serial number of the master end, and after the occupied channel is determined, data receiving and sending are carried out, so that the data interaction collection of the station area terminal and a certain downlink device is completed. Meanwhile, the current serial port state is set as NOTRADY, so that the data cannot enter the process before the completion of one-time transceiving, the DMA idle interrupt judging frame data transmission is completed, the Lock of the communication with a certain serial port is released by marking the position 0 of the Lock mark of the other serial ports, the occupied channel value is set as 0, the completion of data transceiving is indicated, and the data can enter the monitoring state of serial port transmission at the moment. If the occupied channel value is not any value of 1-n, the channel is unoccupied and no serial port is used for transmitting data, the main terminal is in a monitoring state of data receiving continuously, meanwhile, the occupied channel value is set to 0, and the serial port waits for transmitting data. The invention can realize transparent transmission in a network serial port and adaptive conversion of Modbus protocol so as to meet the hot plug requirement of equipment, and has message analysis, CRC check and frame failure retransmission mechanisms in Modbus mode.
Although the present invention has been described in detail by way of preferred embodiments with reference to the accompanying drawings, the present invention is not limited thereto. Various equivalent modifications and substitutions may be made in the embodiments of the present invention by those skilled in the art without departing from the spirit and scope of the present invention, and it is intended that all such modifications and substitutions be within the scope of the present invention/be within the scope of the present invention as defined by the appended claims. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.