Multi-channel RS485 data acquisition method and system

By setting up multiple acquisition units in the acquisition device and sending acquisition instructions in sequence in preset order, the slow problem caused by waiting for response data during the RS485 data acquisition process is solved, and more efficient data acquisition and stable communication are achieved.

CN118778524BActive Publication Date: 2024-12-31SHENZHEN CHEVEN TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411238157.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2024-12-31
Estimated Expiration
2044-09-05

AI Technical Summary

Technical Problem

Due to its half-duplex communication method, the existing RS485 data acquisition method leads to slow acquisition of sensor data, and increasing the bus baud rate will lead to instability in communication, especially during long-distance communication.

Method used

By adopting the multi-channel RS485 data acquisition method, multiple acquisition units are set up in the acquisition device, each acquisition unit includes multiple RS485 interfaces, and the acquisition instructions are sent to the sensor in sequence in a preset order, and the current sensor is received before sending the next instruction. Response data to reduce latency and communication time.

Benefits of technology

It effectively improves data acquisition efficiency, reduces the time required for a round of acquisition, avoids delays caused by waiting for response data, and improves communication stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118778524B_ABST
    Figure CN118778524B_ABST
Patent Text Reader

Abstract

The present invention proposes a multi-channel RS485 data acquisition method and system, which is applied to an acquisition device, wherein the acquisition device includes multiple acquisition units, each acquisition unit includes multiple RS485 interfaces, each RS485 interface is connected to each sensor through an RS485 bus, and the multi-channel RS485 data acquisition method includes: for each acquisition unit, in accordance with a preset order, sequentially sending an acquisition instruction to each sensor through each RS485 interface; repeating the above steps until the acquisition stop condition is met; wherein, after sending an acquisition instruction to the current sensor through the current RS485 interface, in the process of sending an acquisition instruction to the next sensor through the next RS485 interface, receiving the response data returned by the current sensor through the current RS485 interface. The present invention can reduce the communication time required for one polling and effectively improve the data acquisition efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a multi-channel RS485 data acquisition method and system. Background Art

[0002] In the tool industry, it is often necessary to collect data from various sensors and then upload them to various industrial Ethernet networks. The digital acquisition interface of general sensors basically uses the RS485 interface because the RS485 bus is simple to use, low-cost, can achieve long-distance communication, and has strong anti-interference ability and is widely used.

[0003] However, since RS485 is a half-duplex communication method, the RS485 bus communication protocol mainly adopts a question-and-answer interaction method. In this method, the master device sends a command to the slave device, and after the slave device executes the command, it returns a response command. For example, a collection device can be connected to four sensors. The traditional collection method is that the collection device sends a collection command to the first sensor, and the collection device waits for the collection data returned by the first sensor within a specified time, and after the first sensor executes the command, it returns a response command; then the collection device sends a collection command to the second sensor, and the collection device waits for the collection data returned by the second sensor within a specified time, and so on, until all sensors are collected. In this process, the collection device must wait for the previous sensor to return the response data before sending the collection command to the current sensor, which makes the process of collecting sensor data very slow. It takes a long time to collect a round of data. The current way to increase the speed is to increase the bus baud rate, but if the communication distance is very long, increasing the bus baud rate will cause unstable communication. Summary of the invention

[0004] The present invention provides a multi-channel RS485 data acquisition method and system, the main purpose of which is to reduce the communication time required for one polling and effectively improve the data acquisition efficiency.

[0005] In a first aspect, an embodiment of the present invention provides a multi-channel RS485 data acquisition method, which is applied to an acquisition device, wherein the acquisition device includes multiple acquisition units, each acquisition unit includes multiple RS485 interfaces, and each RS485 interface is connected to each sensor via an RS485 bus. The multi-channel RS485 data acquisition method includes:

[0006] For each acquisition unit, according to the preset order, the acquisition instructions are sent to each sensor in turn through each RS485 interface;

[0007] Repeat the above steps until the acquisition stop condition is met;

[0008] After sending the acquisition instruction to the current sensor through the current RS485 interface, in the process of sending the acquisition instruction to the next sensor through the next RS485 interface, the response data returned by the current sensor is received through the current RS485 interface.

[0009] Furthermore, sending the acquisition instruction to each sensor in turn through each RS485 interface in a preset order includes:

[0010] Set the command sending time corresponding to each sensor;

[0011] The acquisition instruction is sent to the current sensor, and after the instruction sending time corresponding to the current sensor has passed, the next sensor is used as the current sensor again.

[0012] Furthermore, after the step of sending the acquisition instruction to the current sensor, the method further includes:

[0013] The acquisition flag corresponding to the current sensor is set to a preset value.

[0014] Furthermore, before the step of re-using the next sensor as the current sensor, the method further includes:

[0015] The acquisition flag bit corresponding to the current sensor is queried, and if the acquisition flag bit corresponding to the current sensor is the preset value, the next sensor is used as the current sensor again.

[0016] Furthermore, it also includes:

[0017] Query the acquisition flag corresponding to each sensor and the response data returned by each sensor;

[0018] For any sensor, if the collection flag corresponding to any sensor is a preset value and the response data returned by any sensor is empty, an alarm instruction is sent.

[0019] Furthermore, before the step of sending the acquisition instruction to each sensor in turn through each RS485 interface in a preset order, the method further includes:

[0020] Receive a data collection instruction, and start data collection according to the data collection instruction.

[0021] Furthermore, each acquisition unit also includes an output serial port and multiple input serial ports, each acquisition unit is connected to the RS485 interface of the host computer through the output serial port, and each acquisition unit is connected to each RS485 interface through the input serial port.

[0022] In a second aspect, an embodiment of the present invention provides a multi-channel RS485 data acquisition system, which is applied to an acquisition device, wherein the acquisition device includes a plurality of acquisition units, each acquisition unit includes a plurality of RS485 interfaces, each RS485 interface is connected to each sensor via an RS485 bus, and the multi-channel RS485 data acquisition system includes:

[0023] The acquisition module is used to send acquisition instructions to each sensor in turn through each RS485 interface according to a preset order for each acquisition unit;

[0024] A polling module is used to repeat the above steps until the acquisition stop condition is met;

[0025] After sending the acquisition instruction to the current sensor through the current RS485 interface, in the process of sending the acquisition instruction to the next sensor through the next RS485 interface, the response data returned by the current sensor is received through the current RS485 interface.

[0026] In a third aspect, an embodiment of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned multi-channel RS485 data acquisition method when executing the computer program.

[0027] In a fourth aspect, an embodiment of the present invention provides a computer storage medium, wherein the computer storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned multi-channel RS485 data acquisition method are implemented.

[0028] A multi-channel RS485 data acquisition method and system proposed in an embodiment of the present invention is applied to an acquisition device, the acquisition device includes multiple acquisition units, the number of which is determined by the number of sensors, and the acquisition unit includes multiple RS485 interfaces, each of which is connected to a sensor. During data acquisition, each acquisition unit sends an acquisition instruction to each sensor in turn through each RS485 interface in a preset order, without waiting for the current sensor to return response data before sending an acquisition instruction to the next sensor, thereby reducing the time required to wait for the sensor to return data, reducing the communication time required for one polling, and effectively improving data acquisition efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 A flow chart of a multi-channel RS485 data acquisition method is provided for an embodiment of the present invention.

[0030] Figure 2A structural schematic diagram of the connection between a collection device, a host computer, and a sensor provided in an embodiment of the present invention.

[0031] Figure 3 A structural schematic diagram of the connection between a collection device, a host computer, and a sensor provided in one embodiment of the present invention.

[0032] Figure 4 A structural schematic diagram of a multi-channel RS485 data acquisition system is provided for an embodiment of the present invention.

[0033] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention.

[0034] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0035] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limiting the present application.

[0036] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.

[0037] In the embodiments of the present application, at least one refers to one or more; multiple refers to two or more. In the description of the present application, words such as "first", "second", "third", etc. are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order. In addition, the terms "first" and "second" are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.

[0038] References to "one embodiment" or "some embodiments" etc. described in this specification mean that one or more embodiments of the present application include a particular feature, structure or characteristic described in conjunction with the embodiment. Thus, in this specification, the terms "include", "comprises", "has" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.

[0039] It should be noted that in the embodiments of the present application, "connection" can be understood as electrical connection, and the connection between two electrical components can be a direct or indirect connection between the two electrical components. For example, the connection between A and B can be either a direct connection between A and B or an indirect connection between A and B through one or more other electrical components.

[0040] The method for collecting sensor data by a collection device in the prior art is as follows:

[0041] In the first round, the acquisition device sends an acquisition instruction to each sensor and sets the corresponding instruction sending flag. For example, the acquisition device is connected to sensor 1, sensor 2 and sensor 3. When the acquisition device sends an acquisition instruction to sensor 1, the instruction sending flag of sensor 1 is set. Similarly, the acquisition instruction is sent to sensor 2 and sensor 3, and the instruction sending flags of sensor 2 and sensor 3 are set.

[0042] In the second round, the command sending flag is used to determine whether the serial port has sent the acquisition command. If there is a command sending flag for sensor 1, it means that the serial port has sent the acquisition command to sensor 1. There is no need to send the command again in this round, but wait for the response data returned by sensor 1; then determine whether other serial ports have received the response data returned by sensor 2 and sensor 3. If the response data is received, the corresponding serial port command sending flag is cleared after parsing the response data, that is, there is no flag, indicating that the response data returned by the sensor has been received, the data acquisition of one sensor has been completed, and the data acquisition of the next sensor can be started, that is, continue to send the acquisition command to the next sensor and set the corresponding command sending flag.

[0043] Among them, if the serial port sends an acquisition command and sets the corresponding command sending flag, if no response data is received from the sensor within the specified time, the corresponding serial port command sending flag will be cleared after the waiting time is up, and the acquisition command will continue to be sent in the next round.

[0044] Taking the acquisition sensors 1, 2 and 3 as examples, the sensors can respond to the acquisition instructions normally. The acquisition device sends the acquisition instruction to sensor 1. The time for sending the acquisition instruction is T1, and then it will wait for sensor 1 to return the response data. The time for sensor 1 to return the response data is T4; after receiving the response data returned by sensor 1, the acquisition device will continue to send the acquisition instruction to sensor 2. The time for sending the acquisition instruction is T2, and then it will wait for sensor 2 to return the response data. The time for sensor 2 to return the response data is T5; after receiving the response data returned by sensor 2, the acquisition device will continue to send the acquisition instruction to sensor 3. The time for sending the acquisition instruction is T3, and then it will wait for sensor 3 to return the response data. The time for sensor 3 to return the response data is T6. The time required for one round of acquisition is T1+T2+T3+T4+T5+T6.

[0045] In view of the above problems, an embodiment of the present invention provides a multi-channel RS485 data acquisition method, such as Figure 1 As shown, the multi-channel RS485 data acquisition method is applied to an acquisition device, the acquisition device includes multiple acquisition units, each acquisition unit includes multiple RS485 interfaces, each RS485 interface is connected to each sensor through an RS485 bus, and the multi-channel RS485 data acquisition method includes:

[0046] In the embodiment of the present invention, the multi-channel RS485 data acquisition method is applied to an acquisition device, which is connected to a host computer and connected to a sensor. The connection between the acquisition device and the host computer and the sensor is as follows: Figure 2 As shown, since there are a large number of sensors in some cases in real life, it is impossible to set up so many RS485 interfaces in just one acquisition device. Therefore, multiple acquisition units can be set in the acquisition device. For example, the acquisition device includes acquisition units 1 to N, each acquisition unit is responsible for collecting a certain amount of sensor data, the number of acquisition units is determined according to the number of sensors, each acquisition unit has the same method of collecting data, and the structure of each acquisition unit is basically the same.

[0047] In the embodiment of the present invention, each acquisition unit includes multiple RS485 interfaces. The RS485 interface in each acquisition unit is connected to the sensor via an RS485 bus. One RS485 interface acquires data of one sensor. Generally, one RS485 interface acquires data of one sensor.

[0048] The acquisition unit may be an MCU, and the sensor may be a temperature sensor, a humidity sensor, a light intensity sensor, etc., which may be determined according to actual conditions, and the embodiment of the present invention does not specifically limit this.

[0049] In the embodiment of the present invention, the RS485 interface in each acquisition unit is connected to the sensor via the RS485 bus, and the stability of communication can be ensured through the RS485 interface and the RS485 bus.

[0050] S110, for each acquisition unit, sending an acquisition instruction to each sensor in turn through each RS485 interface according to a preset order;

[0051] For each acquisition unit, the acquisition unit sends an acquisition instruction to each sensor through the RS485 interface in a preset order. The preset order can be from sensor 1 to sensor N, that is, the acquisition unit first sends an acquisition instruction to sensor 1, and then sends an acquisition instruction to sensor 2, and so on, until the acquisition instruction is sent to sensor N to complete a round of sending of acquisition instructions; it can also be from sensor N to sensor 1, that is, the acquisition unit first sends an acquisition instruction to sensor N, and then sends an acquisition instruction to sensor N-1, and so on, until the acquisition instruction is sent to sensor 1 to complete a round of sending of acquisition instructions; of course, the acquisition instructions can also be sent in other orders, which can be determined according to actual conditions, and the embodiments of the present invention do not make specific limitations on this.

[0052] S120, repeat the above steps until the acquisition stop condition is met;

[0053] After completing one round of data collection as above, repeat the next round of collection, for example, in the order of sensor 1 to sensor N, the collection device sends collection instructions to sensor 1 to sensor N in sequence, and the collection steps are the same as described in the above embodiment until the collection stop condition is reached.

[0054] The collection stop condition is pre-set, for example, the collection stop condition is reached when the polling times reaches 50 times.

[0055] After sending the acquisition instruction to the current sensor through the current RS485 interface, in the process of sending the acquisition instruction to the next sensor through the next RS485 interface, the response data returned by the current sensor is received through the current RS485 interface.

[0056] Here, the next sensor may be each sensor after the current sensor, or may be an adjacent sensor after the current sensor, which may be determined according to actual conditions, and the embodiment of the present invention does not specifically limit this.

[0057] For example, if sensor 1 is the current sensor, RS485 interface 1 corresponds to sensor 1, and in the process of sending a collection instruction to sensor 2 through RS485 interface 2, the collection device receives the response data returned by sensor 1 through RS485 interface 1; or in the process of sending a collection instruction to sensor 3 through RS485 interface 3, the collection device receives the response data returned by sensor 1 through RS485 interface 1. In short, the time required for the response data returned by sensor 1 can be offset by the subsequent RS485 interface sending the collection process.

[0058] The embodiment of the present invention is described by taking each acquisition unit connected to sensor 1, sensor 2 and sensor 3 as an example, assuming that all sensors can respond to acquisition instructions normally. In the first round, the acquisition unit sends all acquisition instructions to each sensor separately, because the acquisition unit may receive response data returned by sensor 1 in the process of sending acquisition instructions to sensor 2; the acquisition unit may receive response data returned by sensor 2 in the process of sending acquisition instructions to sensor 3, and a round of acquisition is completed.

[0059] In the next round of acquisition, the acquisition unit continues to send acquisition instructions to sensor 1, and may receive response data returned by sensor 3. Therefore, the maximum time required for one round of acquisition is T1+T2+T3, mainly using the time of sending instructions to offset the time of receiving reply data to improve the response speed.

[0060] A multi-channel RS485 data acquisition method is proposed in an embodiment of the present invention. The multi-channel RS485 data acquisition method is applied to an acquisition device, the acquisition device includes multiple acquisition units, the number of which is determined by the number of sensors, and the acquisition unit includes multiple RS485 interfaces, each of which is connected to a sensor. During the data acquisition process, each acquisition unit sends an acquisition instruction to each sensor in turn through each RS485 interface in a preset order, without waiting for the current sensor to return response data before sending an acquisition instruction to the next sensor, thereby reducing the time required to wait for the sensor to return data, reducing the communication time required for one polling, and effectively improving the data acquisition efficiency.

[0061] In some embodiments, sending the acquisition instruction to each sensor in turn through each RS485 interface in a preset order includes:

[0062] Set the command sending time corresponding to each sensor;

[0063] The acquisition instruction is sent to the current sensor, and after the instruction sending time corresponding to the current sensor has passed, the next sensor is used as the current sensor again.

[0064] In an embodiment of the present invention, collection instructions are sent to each sensor in turn through each RS485 interface in a preset order. The specific steps are: pre-set the instruction sending time corresponding to each sensor. The instruction sending time corresponding to each sensor can be the same or different. It can be determined according to actual conditions. The embodiment of the present invention does not make specific limitations on this.

[0065] In the above example, the time required for the acquisition unit to send the acquisition instruction to sensor 1 is T1, the time required for the acquisition unit to send the acquisition instruction to sensor 2 is T2, and the time required for the acquisition unit to send the acquisition instruction to sensor 3 is T3. Assuming that sensor 1 is the current sensor, the acquisition unit sends the acquisition instruction to sensor 1 without waiting for sensor 1 to return response data; immediately sends the acquisition instruction to sensor 2, and in the process of sending the acquisition instruction to sensor 2, the response data returned by sensor 1 may be received, so there is no need to wait for sensor 1 to return response data before sending the acquisition instruction to sensor 2, thereby saving data acquisition time.

[0066] In some embodiments, after the step of sending the acquisition instruction to the current sensor, the method further includes:

[0067] The acquisition flag corresponding to the current sensor is set to a preset value.

[0068] In the embodiment of the present invention, after sending the collection instruction to the current sensor, the collection unit also sets a collection flag for the current sensor and sets the collection flag of the current sensor to a preset value, indicating that the collection instruction has been sent to the current sensor.

[0069] The preset value can be determined according to actual conditions, and the embodiments of the present invention do not specifically limit this. For example, the preset value is 1, that is, the acquisition flag corresponding to the current sensor is set to 1, indicating that the acquisition unit has sent an acquisition instruction to the current sensor; for sensors that have not sent an acquisition instruction or have received return data to clear the acquisition flag corresponding to the current sensor, the acquisition flags corresponding to these sensors are set to empty.

[0070] In the embodiment of the present invention, by setting the collection flag bit, it can be clearly indicated whether a collection instruction is sent to each sensor to avoid errors and omissions. In addition, the time spent on querying the collection flag bit is very short and can be almost ignored.

[0071] As an implementation manner, before the step of re-using the next sensor as the current sensor, the method further includes:

[0072] The acquisition flag bit corresponding to the current sensor is queried, and if the acquisition flag bit corresponding to the current sensor is the preset value, the next sensor is used as the current sensor again.

[0073] In the embodiment of the present invention, before resetting the next sensor as the current sensor, it is necessary to query the collection flag corresponding to the current sensor. If the collection flag corresponding to the current sensor is a preset value, it means that the collection unit has sent a collection instruction to the current sensor, so the next sensor is re-set as the current sensor to collect data.

[0074] For example, assuming that sensor 1 is the current sensor, after the acquisition unit sends an acquisition instruction to sensor 1, the acquisition unit also sets an acquisition flag for sensor 1. Before the acquisition unit sends an acquisition instruction to sensor 2, the acquisition unit queries the acquisition flag corresponding to sensor 1. If the acquisition flag is a preset value and is not empty, it means that the acquisition unit has sent the acquisition flag to sensor 1. Sensor 2 is re-set as the current sensor, and the acquisition unit can send an acquisition instruction to sensor 2.

[0075] In some embodiments, it also includes:

[0076] Query the acquisition flag corresponding to each sensor and the response data returned by each sensor;

[0077] For any sensor, if the collection flag corresponding to any sensor is a preset value and the response data returned by any sensor is empty, an alarm instruction is sent.

[0078] In an embodiment of the present invention, the multi-channel RS485 data acquisition method also includes: querying the acquisition flag corresponding to each sensor and the response data returned by each sensor. Under normal circumstances, each sensor will return response data. Even if the sensor does not return response data to the acquisition unit in a certain round of query, there will always be a time in multiple cycles that can successfully return response data to the acquisition unit.

[0079] If the response data returned by the sensor is still empty after multiple cycles, it means that the sensor has not successfully returned response data in each cycle, and the probability of the sensor failing is very high, so an alarm command is sent to the host computer.

[0080] In some embodiments, before the step of sending the acquisition instruction to each sensor in turn through each RS485 interface in a preset order, the method further includes:

[0081] Receive a data collection instruction, and start data collection according to the data collection instruction.

[0082] like Figure 3As shown, each acquisition unit also includes an output serial port and multiple input serial ports. Each acquisition unit is connected to the RS485 interface of the host computer through the output serial port, and each acquisition unit is connected to each RS485 interface through the input serial port. The host computer communicates with the output serial port in the acquisition unit through the RS485 interface. The acquisition unit can receive the data acquisition instruction sent by the host computer. If the acquisition device receives the data acquisition instruction sent by the host computer, each acquisition unit starts to collect data according to the data acquisition instruction.

[0083] The invention is suitable for the occasions where multi-channel RS485 bus acquisition is required, and is particularly suitable for the occasions where one master and multiple slaves are required and the real-time performance is high.

[0084] Figure 4 A schematic diagram of the structure of a multi-channel RS485 data acquisition system provided by an embodiment of the present invention is shown in FIG. Figure 4 As shown, the multi-channel RS485 data acquisition system is applied to an acquisition device, the acquisition device includes multiple acquisition units, each acquisition unit includes multiple RS485 interfaces, each RS485 interface is connected to each sensor through an RS485 bus, and the multi-channel RS485 data acquisition system includes:

[0085] The acquisition module 410 is used to send acquisition instructions to each sensor in turn through each RS485 interface according to a preset order for each acquisition unit;

[0086] The polling module 420 is used to repeat the above steps until the acquisition stop condition is met;

[0087] After sending the acquisition instruction to the current sensor through the current RS485 interface, in the process of sending the acquisition instruction to the next sensor through the next RS485 interface, the response data returned by the current sensor is received through the current RS485 interface.

[0088] The embodiment of the present invention is a system embodiment corresponding to the above method, and its implementation process is the same as the above method embodiment. For details, please refer to the above method embodiment, and this system embodiment will not be repeated here.

[0089] Each module in the above multi-channel RS485 data acquisition system can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.

[0090] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention, the computer device may be a server, and its internal structure diagram may be as follows Figure 5 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a computer storage medium and an internal memory. The computer storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the computer storage medium. The database of the computer device is used to store data generated or obtained during the execution of a multi-channel RS485 data acquisition method, such as acquisition instructions and preset sequences. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a multi-channel RS485 data acquisition method is implemented.

[0091] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of a multi-channel RS485 data acquisition method in the above embodiment when executing the computer program. Alternatively, the processor implements the functions of each module / unit in this embodiment of a multi-channel RS485 data acquisition system when executing the computer program.

[0092] In one embodiment, a computer storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of a multi-channel RS485 data acquisition method in the above embodiment are implemented. Alternatively, when the computer program is executed by a processor, the functions of each module / unit in the embodiment of the multi-channel RS485 data acquisition system are implemented.

[0093] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0094] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0095] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A multi-channel RS485 data acquisition method, characterized in that: Applied to a collection device, the collection device includes a plurality of collection units, each collection unit includes a plurality of RS485 interfaces, each RS485 interface is connected to each sensor via an RS485 bus, and the multi-channel RS485 data collection method includes: For each acquisition unit, according to the preset order, the acquisition instructions are sent to each sensor in turn through each RS485 interface; Repeat the above steps until the acquisition stop condition is met; wherein, after sending an acquisition instruction to the current sensor through the current RS485 interface, in the process of sending the acquisition instruction to the next sensor through the next RS485 interface, receiving response data returned by the current sensor through the current RS485 interface; The method of sending a collection instruction to each sensor in turn through each RS485 interface in a preset order includes: Set the command sending time corresponding to each sensor; The acquisition instruction is sent to the current sensor, and after the instruction sending time corresponding to the current sensor has passed, the next sensor is used as the current sensor again.

2. The multi-channel RS485 data acquisition method according to claim 1, characterized in that: After the step of sending the acquisition instruction to the current sensor, the method further includes: The acquisition flag corresponding to the current sensor is set to a preset value.

3. The multi-channel RS485 data acquisition method according to claim 2, characterized in that: Before the step of re-using the next sensor as the current sensor, the method further includes: The acquisition flag bit corresponding to the current sensor is queried, and if the acquisition flag bit corresponding to the current sensor is the preset value, the next sensor is used as the current sensor again.

4. The multi-channel RS485 data acquisition method according to claim 1, characterized in that: Also includes: Query the acquisition flag corresponding to each sensor and the response data returned by each sensor; For any sensor, if the collection flag corresponding to any sensor is a preset value and the response data returned by any sensor is empty, an alarm instruction is sent.

5. The multi-channel RS485 data acquisition method according to claim 1, characterized in that: Before the step of sending the acquisition instruction to each sensor in turn through each RS485 interface in a preset order, the method further includes: Receive a data collection instruction, and start data collection according to the data collection instruction.

6. The multi-channel RS485 data acquisition method according to claim 1, characterized in that: Each acquisition unit also includes an output serial port and multiple input serial ports. Each acquisition unit is connected to the RS485 interface of the host computer through the output serial port, and each acquisition unit is connected to each RS485 interface through the input serial port.

7. A multi-channel RS485 data acquisition system, characterized in that: Applied to a collection device, the collection device includes multiple collection units, each collection unit includes multiple RS485 interfaces, each RS485 interface is connected to each sensor through an RS485 bus, and the multi-channel RS485 data collection system includes: The acquisition module is used to send acquisition instructions to each sensor in turn through each RS485 interface according to a preset order for each acquisition unit; A polling module is used to repeat the above steps until the acquisition stop condition is met; wherein, after sending an acquisition instruction to the current sensor through the current RS485 interface, in the process of sending the acquisition instruction to the next sensor through the next RS485 interface, receiving response data returned by the current sensor through the current RS485 interface; The method of sending a collection instruction to each sensor in turn through each RS485 interface in a preset order includes: Set the command sending time corresponding to each sensor; The acquisition instruction is sent to the current sensor, and after the instruction sending time corresponding to the current sensor has passed, the next sensor is used as the current sensor again.

8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the multi-channel RS485 data acquisition method as claimed in any one of claims 1 to 6 are implemented.

9. A computer storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the multi-channel RS485 data acquisition method as claimed in any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Satellite-borne controller area network (CAN) bus communication method applied to multi-master communication

    CN101977094A

  • Electricity consumption information acquisition system and acquisition method

    CN106652428A

  • Multi-service processing method and device

    CN111506403A

  • Communication management device, energy storage system and energy storage container

    CN220172863U