CN109993958B - Data acquisition system and method of RS485 bus - Google Patents

Data acquisition system and method of RS485 bus Download PDF

Info

Publication number
CN109993958B
CN109993958B CN201910381409.5A CN201910381409A CN109993958B CN 109993958 B CN109993958 B CN 109993958B CN 201910381409 A CN201910381409 A CN 201910381409A CN 109993958 B CN109993958 B CN 109993958B
Authority
CN
China
Prior art keywords
transceiver
slave
host
data
link
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910381409.5A
Other languages
Chinese (zh)
Other versions
CN109993958A (en
Inventor
林波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Xbrother Technology Co ltd
Original Assignee
Shenzhen Xbrother Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Xbrother Technology Co ltd filed Critical Shenzhen Xbrother Technology Co ltd
Priority to CN201910381409.5A priority Critical patent/CN109993958B/en
Publication of CN109993958A publication Critical patent/CN109993958A/en
Application granted granted Critical
Publication of CN109993958B publication Critical patent/CN109993958B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G08SIGNALLING
    • G08CTRANSMISSION SYSTEMS FOR MEASURED VALUES, CONTROL OR SIMILAR SIGNALS
    • G08C19/00Electric signal transmission systems
    • GPHYSICS
    • G08SIGNALLING
    • G08CTRANSMISSION SYSTEMS FOR MEASURED VALUES, CONTROL OR SIMILAR SIGNALS
    • G08C25/00Arrangements for preventing or correcting errors; Monitoring arrangements

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Small-Scale Networks (AREA)

Abstract

The embodiment of the invention discloses a data acquisition system of an RS485 bus, which comprises a host, a first transceiver, a second transceiver and a plurality of slaves, wherein the host comprises at least one serial port, the first transceiver and the second transceiver are both connected with the serial port, the slaves are connected in series between the first transceiver and the second transceiver, a communication link formed by the slaves in the direction from the first transceiver to the second transceiver is preset as a main link, a communication link formed in the direction from the second transceiver to the first transceiver is preset as a standby link, the host acquires data from each slave through the main link, and when the main link fails, the communication link is switched to the standby link so as to acquire data of the slaves between the second transceiver and the first transceiver and up to a failure point. The invention also provides a data acquisition method of the RS485 bus, and the communication reliability and the fault detection accuracy of the RS485 bus are improved.

Description

Data acquisition system and method of RS485 bus
Technical Field
The invention relates to the technical field of communication, in particular to a data acquisition system and method of an RS485 bus.
Background
Currently, the current practice is. The RS485 bus is adopted for communication in an industrial field, the problem that one host computer communicates a plurality of slave computers is solved, networking communication of a plurality of devices is achieved through few communication lines, the communication is limited to the topological characteristic of the RS485 bus, the standard connection topological structure of the RS485 bus is a hand-pulled daisy chain type topology, and under the condition, as long as one node on the bus is broken, the slave computers behind the node cannot communicate with the host computer any more.
In order to reduce the risk of disconnection, a topological structure such as a star topology or a tree topology is mostly adopted to avoid the risk, but the modes all realize the stability of communication at the cost of increasing a large number of bus connecting lines and reducing the load capacity of a bus slave machine, and the minimum number of communication connecting lines cannot be ensured. In addition, the purpose of enhancing the reliability of the communication link is realized by adopting double-serial-port resources to perform transceiving switching at the host, but the communication link needs to occupy the double-serial-port resources of the host, so that the resource utilization and the cost performance are not high, and complicated logic judgment needs to be performed on a data acquisition system of the RS485 bus, so that the data acquisition efficiency in the communication link is reduced.
Disclosure of Invention
In view of this, the present invention provides a RS485 data acquisition system and method, which implement that a host polls each slave in a communication link in sequence to determine a failure point, so as to solve the above technical problems.
In one aspect, the RS485 data acquisition system provided by the present invention includes:
the host comprises at least one serial port;
the first transceiver and the second transceiver are used for being connected with one serial port;
a plurality of slaves connected in series between the first transceiver and the second transceiver; the communication links formed by the plurality of slaves in the direction from the first transceiver to the second transceiver are preset as main links, and the communication links formed in the direction from the second transceiver to the first transceiver are preset as standby links;
the master is used for collecting data from each slave through the main link and switching the communication link to the standby link when judging that the main link fails so as to collect data of the slave between the second transceiver and the first transceiver and a failure point.
As a further improvement of the above technical solution, the host includes a first transceiving state control port connected to the first transceiver, and a second transceiving state control port connected to the second transceiver;
the first transceiving state control port is used for setting the first transceiver to switch between a transmitting state and a receiving state;
and when the main link fails, the second transceiving state control port is used for setting the second transceiver to switch between a transmitting state and a receiving state.
As a further improvement of the above technical solution, when the host determines whether the main link fails, the host switches the second transceiver to a receiving state through the second transceiving state control port;
the master machine sends data to each slave machine through the first transceiver and receives returned data through the second transceiver;
if the sent data is inconsistent with the received data, the host judges whether each slave machine has returned confirmation information, and judges that the main link fails if the slave machines do not have returned confirmation information.
As a further improvement of the above technical solution, after the master determines that the master link fails, the master acquires an address code of a first slave that does not return the confirmation information in the master link, and uses the address code as a failed node.
As a further improvement of the above technical solution, the master sequentially sends data to each slave between the second transceiver and the failed node through the second transceiver and receives acknowledgement information returned by the current slave;
before the slave machine corresponding to the fault node, if the current slave machine does not return the confirmation information, the host machine judges that the position of the current slave machine is the second fault node and records the address code of the current slave machine.
As a further improvement of the above technical solution, the serial port is connected to the first transceiver or the second transceiver through a double-pole double-throw switch; the host further comprises a switch control port for controlling the double-pole double-throw switch;
when the serial port is connected to the first transceiver, the first transceiving state control port is used for switching the first transceiver between a transmitting state and a receiving state;
when the main link fails, the serial port is connected to the second transceiver, and the second transceiver state control port is used for switching the second transceiver between a transmitting state and a receiving state.
As a further improvement of the above technical solution, the double-pole double-throw switch includes a fixed end and a movable end, the fixed end is electrically connected to the serial port, and the movable end is electrically connected to the first transceiver or the second transceiver.
As a further improvement of the above technical solution, the first transceiver and the second transceiver both use RS485 bus level conversion chips, the host is an MCU master chip, the first transceiver is set to a transmitting state when the first transceiving state control port is at a low level, and the first transceiver is set to a receiving state when the first transceiving state control port is at a high level.
As a further improvement of the above technical solution, the serial port transmits and receives data in a half-duplex manner, and the master polls and acquires data from the plurality of slaves when the main link is switched to the standby link.
On the other hand, the invention also provides a data acquisition method of the RS485 bus, which is applied to an RS485 bus communication system, wherein the communication system comprises a host, a first transceiver, a second transceiver and a plurality of slaves, the host comprises at least one serial port, the first transceiver and the second transceiver are both connected with the serial port, the slaves are connected in series between the first transceiver and the second transceiver, a communication link formed by the slaves in the direction from the first transceiver to the second transceiver is preset as a main link, and a communication link formed in the direction from the second transceiver to the first transceiver is preset as a standby link; the method comprises the following steps:
the master machine collects data from each slave machine through the main link, and when the main link fails, the communication link is switched to the standby link so as to collect data of the slave machine between the direction from the second transceiver to the first transceiver and the failure point.
According to the data acquisition system and method of the RS485 bus, the first transceiver and the second transceiver which are connected in parallel are arranged between the host and the plurality of the slave machines, so that the switching of the main link and the standby link is realized to acquire data of all the slave machines, when a fault occurs in a communication link, the address code of the slave machine corresponding to the fault point can be accurately positioned, the data acquisition efficiency of the RS485 bus is improved, and maintenance personnel can accurately position the fault point. The host adopts a single serial port, and a retransmission acquisition mechanism can realize data acquisition on nodes where all RS485 buses in the two links are located, so that the construction wiring of the field communication link is simplified. When a fault point in the main link is detected, the standby link is switched to, data of the slave machine with the fault point can be acquired, and the stability of the communication link between the master machine and the slave machine is improved to a certain extent.
Drawings
In order to more clearly illustrate the technical solution of the present invention, the drawings required to be used in the embodiments will be briefly described below, and it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope of the present invention. Like components are numbered similarly in the various figures.
FIG. 1 is a block diagram showing a data acquisition system of an RS485 bus according to a first embodiment of the present invention;
FIG. 2 shows a schematic circuit configuration of a first embodiment of the present invention;
FIG. 3 shows a block diagram of a data acquisition system of an RS485 bus according to a second embodiment of the present invention;
FIG. 4 shows a schematic circuit configuration of a second embodiment of the present invention;
FIG. 5 is a schematic diagram illustrating a second embodiment of the present invention for determining a single point of failure;
fig. 6 is a schematic structural diagram showing a two-point fault determination according to a second embodiment of the present invention;
fig. 7 shows a flow chart of the data acquisition method of the RS485 bus of the present invention.
Description of the main element symbols:
a data acquisition system of a 300-RS485 bus; 310-a host; 320-serial port; 321-a transmission port; 322-a receiving port; 330-a first transceiver; 340-a second transceiver; 350-a plurality of slaves; 360-a first transceiving state control port; 370-a second transceiving state control port; 380-switch control port; 390-double pole double throw switch.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments.
The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
Hereinafter, the terms "including", "having", and their derivatives, which may be used in various embodiments of the present invention, are only intended to indicate specific features, numbers, steps, operations, elements, components, or combinations of the foregoing, and should not be construed as first excluding the existence of, or adding to, one or more other features, numbers, steps, operations, elements, components, or combinations of the foregoing.
Furthermore, the terms "first," "second," "third," and the like are used solely to distinguish one from another and are not to be construed as indicating or implying relative importance.
Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which various embodiments of the present invention belong. The terms (such as those defined in commonly used dictionaries) should be interpreted as having a meaning that is consistent with their contextual meaning in the relevant art and will not be interpreted in an idealized or overly formal sense unless expressly so defined herein in various embodiments of the present invention.
Referring to fig. 1, in one aspect, the present invention provides a data acquisition system 300 of an RS485 bus, including:
a host 310 comprising at least one serial port 320;
the first transceiver 330 and the second transceiver 340 are both used for being connected with one serial port 320;
a plurality of slaves 350, said plurality of slaves 350 connected in series between said first transceiver 330 and said second transceiver 340; wherein, the communication link formed by the plurality of slaves 350 in the direction from the first transceiver 330 to the second transceiver 340 is preset as a main link, and the communication link formed in the direction from the second transceiver 340 to the first transceiver 330 is preset as a standby link;
the master 310 is configured to collect data from each slave via the master link, and switch the communication link to the backup link when it is determined that the master link fails, so as to collect data from the slave up to a failure point in a direction from the second transceiver 340 to the first transceiver 330.
The parameter structures of the first transceiver 330 and the second transceiver 340 may be the same or different, in this embodiment, it is preferable that the parameter structures of the first transceiver 330 and the second transceiver 340 are the same, and the host 310 preferentially performs data acquisition on the main link, and it can be understood that the host 310 may also preferentially perform data acquisition on the backup link. The communication link formed by the plurality of slaves 350 in the direction from the first transceiver 330 to the second transceiver 340 is preset as a main link, and the communication link formed in the direction from the second transceiver 340 to the first transceiver 330 is preset as a backup link. The RS485 bus has the advantages of simple structure, low cost, high communication rate, long transmission distance and the like, is widely applied to the field of industrial control, adopts half-duplex communication, generally comprises a main node and a plurality of slave nodes, and adopts a communication mode of polling the slave nodes by the main node, so that the efficiency of fault detection in a communication link is improved.
In addition, the serial port 320 includes a transmitting port 321 and a receiving port 322, the transmitting port 321 and the receiving port 322 both use UART (Universal Asynchronous Receiver/Transmitter), the host 310 is an mcu (microcontroller unit) main chip, the first transceiver 330 and the second transceiver 340 are RS485 bus level converter chips, the host 310 can perform data acquisition on the multiple slaves 350 through a full-duplex operating mode, it should be noted that, in this embodiment, when the host 310 determines that the main link is normal, the serial port 320 can communicate with the multiple slaves 350 through a full-duplex mode, when the host 310 needs to detect whether the main link fails, the host 310 does not use a half-duplex operating mode, switches to a standby link to acquire data of the slaves from the second transceiver 340 to the first transceiver 330 up to a failure point, therefore, the efficiency of data acquisition and the accuracy of fault detection are improved.
The main implementation circuit and the modified circuit of the data acquisition system 300 of RS485 bus of the present invention are further described below.
Example 1
Referring again to fig. 1, the host 310 includes a first transceiving state control port 360 connected to the first transceiver 330, and a second transceiving state control port 370 connected to the second transceiver 340;
the first transceiving state control port 360 is configured to set the first transceiver 330 to switch between a transmitting state and a receiving state;
when the main link fails, the second transceiving state control port 370 is configured to switch the second transceiver 340 between a transmitting state and a receiving state.
After the master 310, the first transceiver 330, the multiple slaves 350, and the second transceiver 340 form a daisy-chained communication link, the master 310 performs data acquisition on the multiple slaves 350, and needs to detect the communication link, at this time, the master 310 preferentially sets the first transceiver 330 in a transmitting state through the first transceiving state control port 360 and transmits data to each slave of the master link, and sets the second transceiver 340 in a receiving state through the second transceiving state control port 370 to receive data, when the master 310 determines that the transmitted data and the received data are consistent, it determines that the master link is a normal link, and the master 310 may perform normal data acquisition with the multiple slaves 350 through the serial port 320. When the host 310 determines that the transmitted data and the received data are inconsistent, that is, the main link fails, the host 310 sets the second transceiver 340 to a transmitting state through the second transceiving state control port 370, and the first transceiving state control port 360 sets the first transceiver 330 to a receiving state, so as to switch the main link to the standby link.
Further, when the host 310 determines whether the main link fails, the second transceiver 340 is switched to a receiving state through the second transceiving state control port 370;
the master 310 transmits data to each slave through the first transceiver 330 and receives returned data through the second transceiver 340;
if the sent data is inconsistent with the received data, the master 310 determines whether each slave has returned confirmation information, and if not, determines that the master link fails.
When the host 310 determines that the main link fails, the first transceiver 330 is switched from the sending state to the receiving state, the second transceiver 340 is switched from the receiving state to the sending state, and then the host 310 performs data acquisition on each slave in the backup link through the second transceiver 340 in a polling manner, that is, the host 310 sends data to the slave directly connected to the second transceiver 340 through the second transceiver 340 first and waits for confirmation information returned by the slave within a certain time, it can be understood that when the main link fails, the host 310 performs data acquisition on the backup link in a polling manner, and detects whether the slave and the RS485 bus between the backup link and the failure point are normal.
Further, after the master 310 determines that the master link fails, the address code of the first slave that does not return the confirmation information in the master link is obtained to serve as a failed node.
When the master 310 has determined that the master link has failed, it may be that a slave in the master link or an RS485 bus connected to the slave has failed, and it can be understood that the failed node is not returning the acknowledgement information to the master 310, and other slaves that do not return the acknowledgement information are also present on the master link, that is, slaves behind the failed node also do not return the acknowledgement information, and the acknowledgement information is a data packet returned from a slave to the master 310. And acquiring the address code of the first slave which does not return the confirmation information in the main link, so as to conveniently detect whether a new fault node appears or confirm the specific position of the fault node in the standby link, thereby achieving the effect of accurately positioning fault detection.
Further, the master 310 sequentially sends data to each slave between the second transceiver 340 and the failed node through the second transceiver 340 and receives acknowledgement information returned by the current slave;
before the slave corresponding to the fault node, if the current slave does not return the confirmation information, the master 310 determines that the position of the current slave is the second fault node and records the address code of the current slave.
The host 310 performs data acquisition on the standby link in a polling manner, the polling is performed by sending out an inquiry by the processor at regular time, each peripheral device is sequentially inquired whether to need the service thereof, the service is given immediately if so, and the next peripheral device is inquired after the service is finished, so that the data acquisition can be performed on each slave in the standby link, whether the standby link is normal can also be detected, and the accuracy of fault detection is further improved.
Referring to fig. 2, fig. 2 is a schematic circuit structure diagram of fig. 1, the serial port 320 includes a transmitting port 321 and a receiving port 322, the host 310 is an MCU main chip, the transmitting port 321 is UART _ TX, the receiving port 322 is UART _ RX, the first transceiving state control port 360 is GPIO1, the second transceiving state control port 370 is GPIO2, the first transceiver 330 and the second transceiver 340 are both RS485 transceivers, and the RS485 transceivers employ RS485 bus level conversion chips. The first transceiver 330 is used as a master transceiver. Controlled by GPIO1, when there is no data to transmit, GPIO1 is 0, and the host 310 is in a receiving state; the second transceiver 340 is used as a standby transceiver and controlled by GPIO2, and when the line of the communication link is normal, GPIO2 is 0 and is always in a receiving state; when the host 310 needs to query the slave, the host 310 controls GPIO1 to switch the first transceiver 330 to a transmitting state, where GPIO1 is 1, and transmits a packet through the TXD of the UART.
The TXD of the host 310 is transmitted through the first transceiver 330 through the RS485 bus, reaches each slave and the second transceiver 340, and then returns to the RXD of the MCU, and if the host 310 can receive complete data sent by itself on the RXD, the data acquisition system of the RS485 bus verifies that the received and transmitted data are identical, the data acquisition system 300 of the RS485 bus determines that the communication link is normal. Otherwise, it is further determined whether the communication link is normal by determining whether the master 310 can receive the loopback packet of each slave, and if the loopback packet of each slave can be received, the communication link is still considered to be normal; otherwise, if the packet returned from the slave is not received, the data acquisition system 300 of the RS485 bus automatically determines that the communication link has a fault, and automatically records and queries the address code of the slave, and reports the address code as a fault node to the upper system.
The host 310 initiates a link exception handling mechanism to switch the first transceiver 330 to a standby transceiver and the second transceiver 340 to a primary transceiver; the first transceiving state control port 360 sets the first transceiver 330 to a receiving state (GPIO1 is 0), the second transceiving state control port 370 sets the second transceiver 340 to a transmitting state (GPIO2 is 1), and retransmits the instruction data of the slave that was last queried through a UART serial port, so as to synchronously perform a failure determination procedure, because the host 310 does not receive a packet from the slave during the last communication, and therefore needs to retransmit the packet, the host 310 still cannot receive its own data, but can receive the packet from the slave, and if the host 310 can receive the packet, it can determine that a single point failure occurs in the communication link; if the host 310 does not receive the packet from the slave again, the data acquisition system 300 of the RS485 bus automatically records the address code of the slave and reports the address code to the upper system.
In addition, the master/standby functions of the transceiver are switched again, and then the state that the first transceiver 330 is the master transceiver is returned, and the address of the next slave is continuously queried; until the address queries for all slaves are completed. It should be noted that the states of the master and slave transceivers are maintained on the result of the current intelligent judgment of the data acquisition system of the RS485 bus according to the actual communication conditions, and unless the host 310 is powered off or reset to work again, the link communication operation is performed according to the current master and slave switching relationship.
In this embodiment, the master 310 uses a single serial port to perform active/standby switching through the GPIO1 and the GPIO2, so as to implement sending and receiving of the data packets, and check the sent and received data packets, thereby determining whether the communication link is normal, and improving the stability and reliability of communication between the master 310 and the plurality of slaves 350 to a certain extent.
Example 2
Referring to fig. 3, the serial port 320 is further connected to the first transceiver 330 and the second transceiver 340 through a double-pole double-throw switch 390, and the host 310 further includes a switch control port 380 for controlling the double-pole double-throw switch 390;
when the serial port 320 is connected to the first transceiver 330, the first transceiving state control port 360 is configured to switch the first transceiver 330 between a transmitting state and a receiving state;
when the main link fails, the serial port 320 is connected to the second transceiver 340, and the second transceiver state control port 370 is configured to switch the second transceiver 340 between a transmitting state and a receiving state.
The double-pole double-throw switch 390 comprises a fixed end and an active end, wherein the fixed end is connected with the serial port 320, and the active end is used for being connected with the first transceiver 330 and the second transceiver 340 respectively;
when the active end is connected to the first transceiver 330, the first transceiving state control port 360 sets the first transceiver 330 to a transmitting state, and the second transceiving state control port 370 sets the second transceiver 340 to a receiving state;
when a fault occurs, the switch control port 380 controls the active end to be connected with the second transceiver 340, the first transceiver state control port 360 sets the first transceiver 330 to a receiving state, and the second transceiver state control port 370 sets the second transceiver 340 to a receiving state.
Referring to fig. 4, fig. 4 is a schematic circuit structure diagram of fig. 3, the double-pole double-throw switch 390 switches channels of the UART of the host 310 by using a double-pole double-throw analog switch, is controlled by the GPIO3 of the host 310 to realize the main/standby switching of the RS485 transceiver, and then controls the transceiving states of the main/standby transceivers by the GPIOs 1 and the GPIO2 of the host 310. The single serial port 320 can also realize that two bus links are communicated, and when the communication of the main link is interrupted (no packet returns from the slave), the link is switched, and the query instruction of the host 310 is retransmitted. If the backup link resends the data, the slave machine can still not receive the correct return packet, the slave machine automatically jumps to the next address code for polling operation, the data acquisition system 300 of the RS485 bus automatically records the position of the fault breakpoint (the address code of the slave machine which can not communicate), reports the fault breakpoint to an upper layer system, and provides the fault breakpoint for a user to quickly judge the fault point and maintain the fault breakpoint. It should be noted that the fault detection method of this embodiment is the same as the data acquisition process of the RS485 bus, and is not described herein again.
Referring to fig. 5, fig. 5 is a schematic structural diagram for determining a single point fault, where TX and RX data transceiver pins of a UART serial port of the host are switched by a hardware switch, and can be respectively switched to an RS485 bus level conversion chip in the main link and an RS485 bus level conversion chip in the standby link, so as to implement data acquisition on a slave under an RS485 chain bus, and when a connection breakpoint occurs on one slave node (a position of a cross in the drawing), the host can only acquire data of the slave 1 and the slave 2 through a main link (normally closed) of the RS485 bus, but cannot acquire data of the slaves 3 to 256, and at this time, a data acquisition system of the RS485 bus needs to switch a signal of the UART serial port to the standby link, and continue to acquire data of the slaves 3 to 256.
Referring to fig. 6, fig. 6 is a schematic structural diagram for determining two-point faults, which can improve the communication success rate of an RS485 bus and accurately locate the specific positions of the two-point faults, and can implement normal communication between all slaves (slave 1 and slave 2) between a main link and a first breakpoint (marked by a cross in the drawing) and all slaves (slave 6 to slave 256) between a standby link and a second breakpoint in a time-sharing switching query manner of a main line and a standby line, while the slaves between two breakpoints cannot communicate (slave 3 to slave 5), but through switching query, a data acquisition system of the RS485 bus can accurately identify the positions of the first breakpoint and the second breakpoint. As for the faults above multiple points, the system has little judgment value on the actual site, if the breakpoint between the first breakpoint and the second breakpoint occurs, the system can judge the breakpoint again after the user removes the two existing breakpoints, all the breakpoints are gradually removed through multiple rounds of judgment, and for the actual use, the purpose of accurate maintenance of the user can be met.
Referring to fig. 7, in another aspect, the present invention further provides a data acquisition method for an RS485 bus, which is applied to an RS485 bus communication system, where the communication system includes a host, a first transceiver, a second transceiver, and a plurality of slaves, where the host includes at least one serial port, the first transceiver and the second transceiver are both connected to one serial port, and the slaves are connected in series between the first transceiver and the second transceiver, where a communication link formed by the slaves in a direction from the first transceiver to the second transceiver is preset as a main link, and a communication link formed in a direction from the second transceiver to the first transceiver is preset as a backup link; the method comprises the following steps:
the master machine collects data from each slave machine through the main link, and when the main link fails, the communication link is switched to the standby link so as to collect data of the slave machine between the direction from the second transceiver to the first transceiver and the failure point.
Preferably, the step of determining that the main link fails includes:
step S10: setting the first transceiver to be in a transmitting state and the second transceiver to be in a receiving state;
step S20: sending data to each slave machine through the first transceiver, and receiving returned data through the second transceiver;
step S30: judging whether the sent data is consistent with the received data;
step S40: if not, judging whether each slave machine has returned confirmation information;
step S50: and if not, judging that the main link fails.
Preferably, when the master determines that the master link fails, the address of a first slave that does not return the confirmation information in the master link is acquired to serve as a failed node.
Taking slave computers with address codes ranging from 1 to 256 as an example, when a system is in an initialization state, setting the host computer, the first transceiver and the second transceiver to be in a receiving state, then setting the first transceiver to be in a sending state, sequentially sending data to a plurality of slave computers in the main link through the first transceiver by a sending port of the host computer, receiving the data sent by the sending port through the second transceiver by a receiving port of the host computer, checking after the receiving port receives the data returned by the second transceiver, and when the feedback information is matched with the data packet in a consistent manner, the first link is a normal link; when the sent data is inconsistent with the received data in a matching manner, the host waits for receiving confirmation information returned by the slave, wherein the confirmation information is a data packet (return packet) returned to the host by the slave within a preset time, and if the host does not receive the confirmation information returned by the slave, the host judges that the main link fails; and when the host judges that the main link has a fault, the host controls and acquires an address code of a first slave which does not return the confirmation information in the main link through a data acquisition system of the RS485 bus to be used as a first fault node.
It should be noted that, when the sending data and the receiving data of the host are determined to be consistent by the data acquisition system of the RS485 bus, data acquisition may be performed on each slave in a full-duplex operating mode, and only when the sending data and the receiving data of the host are determined to be inconsistent, switching of the communication link is required, and detection is performed in a polling manner, and an address code of a slave that does not currently receive the return packet is recorded to determine the position of a failure node, where the failure node is an RS485 bus connected between a slave that has received the return packet and a slave that does not receive the return packet.
In addition, after the main link is judged to have a fault, the method for switching the communication link to the standby link for data acquisition comprises the following steps:
step S60: setting the first transceiver to be in a receiving state and the second transceiver to be in a sending state;
step S70: sending data to each slave machine through the second transceiver, and receiving returned data through the first transceiver;
step S80: judging whether confirmation information returned by each slave machine between the second transceiver and the fault node is received or not;
step S90: if yes, judging that the number of the fault nodes is one;
step S100: if not, the address code of the first slave machine which does not return the confirmation information in the standby link is obtained to be used as a second fault node.
When the main link is detected to be faulty, the communication link is switched to a standby link, the first transceiver is set to be in a receiving state, and the second transceiver is set to be in a sending state, so that the host can collect data from the second transceiver to each slave between the faulty nodes, it should be noted that a slave corresponding to the faulty node exists in the main link, and if the host can receive return packets of all slaves after the faulty node in the main link in the process of collecting data in the standby link, and the return packets also include data packets of the slaves corresponding to the faulty node, the position and number of the faulty node are further located, so that the problem that the slaves corresponding to the faulty node may be faulty is solved, and the accuracy of locating the faulty node is further improved, the reliability of data acquisition of the RS485 bus is also improved.
Similarly, the master does not receive the acknowledgement information returned by each slave between the second transceiver and the failed node through the backup link, that is, a breakpoint other than the failed node occurs in the backup link, that is, the number of the failed nodes in the communication link is more than one, the master obtains the address code of the first slave which does not return the acknowledgement information in the backup link, it should be noted that, in the backup link, the slave between the second transceiver and the failed node determines whether a packet exists, the first slave without a packet appears and records the address code thereof as the second failed node, so as to report to the upper system or the operation and maintenance staff.
According to the data acquisition system and method of the RS485 bus, the first transceiver and the second transceiver which are connected in parallel are arranged between the host and the plurality of the slave machines, so that the switching of the main link and the standby link is realized to acquire data of all the slave machines, when a fault occurs in a communication link, the address code of the slave machine corresponding to the fault point can be accurately positioned, the data acquisition efficiency of the RS485 bus is improved, and maintenance personnel can accurately position the fault point. The host adopts a single serial port, and a retransmission acquisition mechanism can realize data acquisition on nodes where all RS485 buses in the two links are located, so that the construction wiring of the field communication link is simplified. When a fault point in the main link is detected, the standby link is switched to, data of the slave machine with the fault point can be acquired, and the stability of the communication link between the master machine and the slave machine is improved to a certain extent.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative and, for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, each functional module or unit in each embodiment of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
If the functions are realized in the form of the data acquisition system function module of the RS485 bus and are sold or used as independent products, the functions can be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a data acquisition system product of the RS485 bus, where the data acquisition system product of the RS485 bus is stored in a storage medium, and includes several instructions to enable a computer device (which may be a smart phone, a personal computer, a server, or a network device) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention.

Claims (6)

1. The data acquisition system of the RS485 bus is characterized by comprising:
the host comprises at least one serial port, a first receiving and sending state control port and a second receiving and sending state control port, wherein the serial port sends and receives data in a half-duplex mode;
the first transceiver is used for being connected with the first transceiving state control port, and the second transceiver is used for being connected with the second transceiving state control port;
a plurality of slaves connected in series between the first transceiver and the second transceiver; communication links formed by the plurality of slave machines in the direction from the first transceiver to the second transceiver are preset as main links, communication links formed in the direction from the second transceiver to the first transceiver are preset as standby links, and the main links and the standby links are communicated by the RS485 bus; the master computer is used for acquiring data from each slave computer through the main link, switching the communication link to the standby link when judging that the main link fails, and polling the plurality of slave computers to acquire data of the slave computers between the second transceiver and the first transceiver and a failure point;
the first transceiving state control port is used for setting the first transceiver to switch between a transmitting state and a receiving state;
when the main link fails, the second transceiving state control port is used for setting the second transceiver to switch between a transmitting state and a receiving state;
when the host judges whether the main link has a fault, the host switches the second transceiver to a receiving state through the second transceiving state control port;
the master machine sends data to each slave machine through the first transceiver and receives returned data through the second transceiver;
if the sent data is inconsistent with the received data, the host judges whether each slave machine has returned confirmation information, and judges that the main link fails when the slave machine does not have returned confirmation information;
and after judging that the main link has a fault, the host acquires an address code of a first slave which does not return the confirmation information in the main link to be used as a first fault node.
2. The data acquisition system of the RS485 bus of claim 1, further comprising:
the master machine sequentially sends data to each slave machine between the second transceiver and the first fault node through the second transceiver and receives confirmation information returned by the current slave machine;
before the slave machine corresponding to the first fault node, if the current slave machine does not return the confirmation information, the host machine judges that the position of the current slave machine is the second fault node and records the address code of the current slave machine.
3. The data acquisition system of the RS485 bus of claim 1, wherein the serial port is connected to the first transceiver or the second transceiver through a double-pole double-throw switch, the host further comprises a switch control port for controlling the double-pole double-throw switch;
when the serial port is connected to the first transceiver, the first transceiving state control port is used for switching the first transceiver between a transmitting state and a receiving state;
when the main link fails, the serial port is connected to the second transceiver, and the second transceiver state control port is used for switching the second transceiver between a transmitting state and a receiving state.
4. The data acquisition system of the RS485 bus of claim 3, wherein the double-pole double-throw switch comprises a fixed end and a movable end, the fixed end is electrically connected with the serial port, and the movable end is electrically connected with the first transceiver or the second transceiver.
5. The data acquisition system of the RS485 bus of claim 1,
the first transceiver and the second transceiver both adopt RS485 bus level conversion chips, the host is an MCU main chip, the first transceiver is set to be in a receiving state when the first transceiving state control port is at a low level, and the first transceiver is set to be in a transmitting state when the first transceiving state control port is at a high level.
6. The data acquisition method of the RS485 bus is characterized by being applied to an RS485 bus communication system, wherein the communication system comprises a host, a first transceiver, a second transceiver and a plurality of slave machines, the host comprises at least one serial port, a first transceiving state control port and a second transceiving state control port, and the serial port transmits and receives data in a half-duplex mode; the first transceiver is used for being connected with the first transceiving state control port, the second transceiver is used for being connected with the second transceiving state control port, and the plurality of slaves are connected in series between the first transceiver and the second transceiver, wherein a communication link formed by the plurality of slaves in the direction from the first transceiver to the second transceiver is preset as a main link, and a communication link formed in the direction from the second transceiver to the first transceiver is preset as a standby link; the method comprises the following steps:
the master machine collects data from all slave machines through the main link, switches the communication link to the standby link when the main link fails, and polls the slave machines to collect data of the slave machines from the second transceiver to the first transceiver in the direction up to the failure point;
the first transceiving state control port is used for setting the first transceiver to switch between a transmitting state and a receiving state;
when the main link fails, the second transceiving state control port is used for setting the second transceiver to switch between a transmitting state and a receiving state;
when the host judges whether the main link has a fault, the host switches the second transceiver to a receiving state through the second transceiving state control port;
the master machine sends data to each slave machine through the first transceiver and receives returned data through the second transceiver;
if the sent data is inconsistent with the received data, the host judges whether each slave machine has returned confirmation information, and judges that the main link fails when the slave machine does not have returned confirmation information;
and after judging that the main link has a fault, the host acquires an address code of a first slave which does not return the confirmation information in the main link to be used as a first fault node.
CN201910381409.5A 2019-05-08 2019-05-08 Data acquisition system and method of RS485 bus Active CN109993958B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910381409.5A CN109993958B (en) 2019-05-08 2019-05-08 Data acquisition system and method of RS485 bus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910381409.5A CN109993958B (en) 2019-05-08 2019-05-08 Data acquisition system and method of RS485 bus

Publications (2)

Publication Number Publication Date
CN109993958A CN109993958A (en) 2019-07-09
CN109993958B true CN109993958B (en) 2021-06-11

Family

ID=67136317

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910381409.5A Active CN109993958B (en) 2019-05-08 2019-05-08 Data acquisition system and method of RS485 bus

Country Status (1)

Country Link
CN (1) CN109993958B (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111007788B (en) * 2019-09-17 2021-06-04 杭州易闻科技有限公司 Free port communication polling system and method based on PLC and communication module
CN110635948B (en) * 2019-09-23 2022-01-18 中国航空综合技术研究所 Fault detection and isolation method for communication between computer boards of refrigeration system
CN111224748A (en) * 2019-12-26 2020-06-02 北京启冠智能科技股份有限公司 Data transmission by wired network
CN112260916B (en) * 2020-09-18 2022-11-25 富联裕展科技(深圳)有限公司 Communication circuit, communication network, and communication abnormality processing method
CN112180906A (en) * 2020-10-26 2021-01-05 沃尔士环控系统工程(深圳)有限公司 Fault self-diagnosis communication system and fault self-diagnosis method thereof
CN112468269B (en) * 2020-11-26 2024-05-10 北京中电飞华通信有限公司 Controller communication method, system and electronic equipment
CN112543125B (en) * 2020-12-22 2022-08-09 宁波均联智行科技股份有限公司 Serial communication system and link switching method applied to same
CN114397832A (en) * 2021-11-22 2022-04-26 中国科学院西安光学精密机械研究所 Serial port multi-machine communication circuit and method
CN114500159B (en) * 2022-02-17 2023-12-15 杭州老板电器股份有限公司 Wired communication method and device of central range hood system and electronic equipment
CN114726494B (en) * 2022-03-04 2024-03-29 深圳拓邦股份有限公司 UART interface circuit, UART communication method and device
CN115085758A (en) * 2022-06-10 2022-09-20 贵州电网有限责任公司 Dual-transceiver multi-mode RS-485 communication host and working method
CN115862181B (en) * 2023-02-01 2023-06-02 钛能科技股份有限公司 Chain type communication display instrument group and chain type communication method thereof
CN116132218A (en) * 2023-03-30 2023-05-16 杭州协能科技股份有限公司 Communication system of master machine and multi-slave machine and communication method thereof

Family Cites Families (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPS5538715A (en) * 1978-09-11 1980-03-18 Hitachi Ltd Fault detection system
JPH03120931A (en) * 1989-10-03 1991-05-23 Nec Corp Loop type transmission line fault detection system
KR950035209A (en) * 1994-05-26 1995-12-30 가나이 쯔도무 Horizontally distributed network system and multiprocessor system
DE102006055887A1 (en) * 2006-11-27 2008-05-29 Beckhoff Automation Gmbh Communication system with a master-slave structure
DE102006055889B3 (en) * 2006-11-27 2008-05-29 Beckhoff Automation Gmbh Communication system with a master-slave structure
CN102318267A (en) * 2009-07-29 2012-01-11 华为技术有限公司 Data communication method, communication equipment and communication system
CN102098838B (en) * 2010-12-28 2013-08-28 重庆星河光电科技有限公司 LED control method and equipment
CN102710483A (en) * 2012-05-21 2012-10-03 周明 RS485 (Recommended Standard 485) intelligent loop
CN103115536B (en) * 2013-02-08 2016-08-10 前进民爆股份有限公司 A kind of large-scale method of ignition of the digital electric detonator for engineering explosion
CN104079677A (en) * 2013-03-29 2014-10-01 上海开通数控有限公司 Automatic allocation method of RS485 communication port address
CN103645718A (en) * 2013-12-14 2014-03-19 广东志高空调有限公司 Air conditioner monitoring system based on RS-485 bus
CN103812744B (en) * 2014-01-10 2017-04-12 沈阳汇通智联电子工程设计安装有限公司 Bidirectional double-loop alarm communication control system based on RS-422 bus structure
CN105207971A (en) * 2014-06-13 2015-12-30 艾默生网络能源有限公司 Data transmission method and device
CN106254199B (en) * 2016-09-19 2020-03-31 重庆世纪之光科技实业有限公司 Unidirectional ring network fault point positioning method, concentrator, terminal equipment and system
CN106547223A (en) * 2016-10-10 2017-03-29 深圳市沃特玛电池有限公司 A kind of automatic addressing method of CAN and its system
CN108055185B (en) * 2017-12-18 2020-08-04 合肥华凌股份有限公司 Communication system and communication method of household appliance and household appliance
CN108809791B (en) * 2018-07-05 2020-10-13 福州福大海矽微电子有限公司 Multi-device ring structure communication method and system
CN109088753B (en) * 2018-07-27 2021-10-26 江苏航天大为科技股份有限公司 Circuit and method for automatically detecting RS485 communication fault
CN109462532B (en) * 2018-09-07 2021-02-26 中国矿业大学 Communication method of communication system

Also Published As

Publication number Publication date
CN109993958A (en) 2019-07-09

Similar Documents

Publication Publication Date Title
CN109993958B (en) Data acquisition system and method of RS485 bus
EP1832044B1 (en) Wireless communication path management methods and systems
CN102984059B (en) Gigabit Ethernet redundancy network interface card and link switching condition criterion output control method thereof
US10348616B2 (en) Packet transmission method and apparatus, and interconnect interface
CN100388703C (en) A method and system for Ethernet interface node backup
CN101309135B (en) Method for enhancing reliability of industrial wireless sensor network
CN101707536A (en) Fault detection method, line card and main control card
US10938628B2 (en) Battery management system and communication method thereof
CN103560898A (en) Port state setting method, and port priority selection method and device
CN111740877A (en) Link detection method and system
CN101286900B (en) Port fault detecting method, device, and access device
CN109981404B (en) Ad hoc network structure and diagnosis method thereof
CN102158383A (en) Data transmission method, device and system for E1 bidirectional ring network
CN113645048B (en) Network card switching method and device and field programmable gate array FPGA
CN113114551B (en) Dual-redundancy LIN bus communication device
US6393020B1 (en) Gated multi-drop communication system
CN107465487B (en) Bus data sending method, system and sub-equipment
CN113726402B (en) Satellite-borne RS 485-based dual-bus self-adaptive control method
CN208076997U (en) A kind of equipment high in the clouds monitoring management system
CN116137603A (en) Link fault detection method and device, storage medium and electronic device
JP6134720B2 (en) Connection method
CN106411616B (en) A kind of device and method by 1553B bus management ethernet terminal
EP4148549A1 (en) Distributed storage system, abnormality processing method therefor, and related device
CN111770567B (en) Time slot communication method based on micropower wireless technology
CN109088753B (en) Circuit and method for automatically detecting RS485 communication fault

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant