Communication method and device based on RS-485 communication module and electronic equipment

By using polling cycles and time slice information to manage sensor data transmission in the RS-485 communication system, data conflict problem is solved, real-time and reliability of communication are improved, the service life of the sensor is extended, and data integrity is ensured.

CN119052293AInactive Publication Date: 2024-11-29BEIJING HUINENGDA ELECTRIC POWER TECH
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202411270729.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-11-29
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The RS-485 communication system is prone to data conflicts when processing multiple sensor data, resulting in communication instability and data loss.

Method used

Send data request instructions to the sensor through polling period and time slice information, ensuring that each sensor sends data within the specified time slice, distinguishes sensors that have not been sent and successfully sent, and generates a return value to judge the data transmission status, realizing time-division multi-address polling communications reduce data conflicts and loss.

Benefits of technology

It improves the real-time, reliability and order of communication between the sensor and the communication management board, extends the service life of the sensor, ensures data integrity and continuity, and provides effective monitoring and management of the communication process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119052293A_ABST
    Figure CN119052293A_ABST
Patent Text Reader

Abstract

The invention discloses a communication method and device based on an RS-485 communication module and electronic equipment, and relates to the field of data processing. The method comprises the following steps: acquiring configuration data sent by an MCU (Microprogrammed Control Unit) of a communication management board; according to the configuration data, a data request instruction is sent to each sensor, and the data request instruction comprises a polling period and time slice information; acquiring sensor data sent by each sensor; if it is determined that the sensor data sent by the sensor is not received in the polling period, marking the sensor as a first sensor; if it is determined that the sensor data sent by the sensor is received in the polling period, marking the sensor as a second sensor; and sending a return value to the MCU according to the first sensor and the second sensor, so that the MCU judges whether the sensor successfully sends the sensor data or not according to the return value. According to the technical scheme provided by the invention, the sensors strictly communicate in the corresponding time slices according to the polling period and the time slice information, so that data conflicts are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a communication method, device and electronic equipment based on an RS-485 communication module. Background Art

[0002] With the rapid development of information technology and automation industry, industrial communication protocols and effective communication between devices have become essential. Among many industrial communication technologies, RS-485 communication modules are widely used due to their high reliability and strong anti-interference ability. RS-485 is a standard serial communication protocol that supports multi-point communication and allows up to 32 devices to be connected on the same serial bus. This communication method not only enables long-distance communication, but also supports high-speed data transmission, which is suitable for complex industrial environments.

[0003] At present, although RS-485 communication modules have performed well in industrial applications, they still face some technical challenges in actual use. When the RS-485 communication system of the related art processes multiple sensor data, it is easy to cause data conflicts due to the simultaneous communication of multiple sensor data.

[0004] Therefore, there is an urgent need for a communication method, device and electronic equipment based on the RS-485 communication module. Summary of the invention

[0005] The present application provides a communication method, device and electronic device based on RS-485 communication module, which sends data request instructions to each sensor node in turn according to the polling cycle and time slice information, and each sensor strictly communicates within the corresponding time slice to avoid data conflicts.

[0006] In a first aspect of the present application, a communication method based on an RS-485 communication module is provided. The method is applied to the RS-485 communication module. The RS-485 communication module is located on a communication management board. The RS-485 communication module is connected to an MCU of the communication management board. The RS-485 communication module is also connected to a plurality of sensors. The method comprises: obtaining configuration data sent by the MCU of the communication management board; according to the configuration data, sending a data request instruction to each of the sensors, the data request instruction comprising a polling cycle and time slice information, so that each of the sensors sends corresponding sensor data within a specified time slice according to the time slice information, and the polling cycle is the communication management board. The time required for the board to poll multiple sensors, the time slice information is the specified time slice for the sensor to communicate with the communication management board within a polling cycle, and the specified time slice includes a start time and a duration; obtaining sensor data sent by each of the sensors; if it is determined that the sensor data sent by the sensor is not received within the polling cycle, marking the sensor as a first sensor; if it is determined that the sensor data sent by the sensor is received within the polling cycle, marking the sensor as a second sensor; sending return values ​​to the MCU according to the first sensor and the second sensor, so that the MCU can determine whether the sensor successfully sends the sensor data according to the return value.

[0007] By adopting the above technical solution, the configuration data sent by the MCU is obtained, and a data request instruction containing polling cycle and time slice information is sent to the sensor according to the configuration data, so that the sensor can send data in an orderly manner within the specified time slice, avoiding data transmission conflicts. After receiving the sensor data, the RS-485 communication module can distinguish the first sensor that has not sent data and the second sensor that has successfully sent data, and generate a return value to send to the MCU, so that the MCU can determine the data transmission status of each sensor. This polling communication method based on time division multiple access improves the real-time, reliability and orderliness of communication between the sensor and the communication management board. At the same time, by marking the sensor type, generating return values ​​and other measures, effective monitoring and management of the communication process is achieved, providing a basis for subsequent exception handling and system maintenance.

[0008] Optionally, before sending the return values ​​to the MCU based on the first sensor and the second sensor, the method also includes: sending a reception confirmation signal to the second sensor so that the second sensor enters a sleep state within the polling cycle; and sending a retransmission instruction to the first sensor so that the first sensor resends the sensor data within the next polling cycle.

[0009] By adopting the above technical solution, after determining the first sensor and the second sensor, the RS-485 communication module sends a reception confirmation signal to the second sensor, causing it to enter a dormant state in the next polling cycle; and sends a retransmission instruction to the first sensor, causing it to resend data in the next polling cycle. This targeted response and processing mechanism can effectively reduce data loss and conflicts during the communication process. Putting the sensor that successfully sends data into a dormant state can reduce its power consumption and extend its service life; letting the sensor that failed to send data resend data can increase its data transmission success rate and ensure data integrity and continuity.

[0010] Optionally, the obtaining of configuration data sent by the MCU of the communication management board specifically includes: obtaining an enable signal and configuration data sent by the MCU of the communication management board; completing a power-on operation according to the enable signal, and writing the configuration data into a configuration register.

[0011] By adopting the above technical solution, after receiving the enable signal and configuration data sent by the MCU, the power-on operation is completed according to the enable signal, and the configuration data is written into the configuration register. The enable signal controls the power-on and working state of the communication module, and can realize the remote switch control of the module, avoiding the trouble of manual operation. Writing the received configuration data into the register can ensure the persistent storage and real-time update of the configuration parameters, providing reliable parameter support for subsequent communication control.

[0012] Optionally, after sending the return values ​​to the MCU according to the first sensor and the second sensor, the method further includes: converting the sensor data into parallel sensor data through level conversion and serial-to-parallel conversion, and storing the parallel sensor data in a data buffer.

[0013] By adopting the above technical solution, after receiving the sensor data, the RS-485 communication module converts the serial RS-485 differential signal into a parallel TTL level signal through level conversion and serial-to-parallel conversion, and caches it in the data buffer. This data conversion and storage method can effectively solve the problems of RS-485 signal incompatibility with MCU level and data bit width mismatch. Through level conversion, it ensures that the sensor data can be correctly identified and collected by the MCU; through serial-to-parallel conversion, the MCU's access and processing efficiency of sensor data is improved; caching data in the buffer can provide data buffering and synchronization services for the MCU, reducing the data reading burden of the MCU.

[0014] Optionally, the configuration data includes a sensor address, and sending a data request instruction to each of the sensors according to the configuration data specifically includes: generating an address table for communicating with each of the sensors according to the sensor address, the address table including the sensor address of each sensor and corresponding time slice information; in the address table, obtaining the sensor address of each sensor in turn, and sending the data request instruction to the corresponding sensor according to the sensor address.

[0015] By adopting the above technical solution, the RS-485 communication module generates an address table for communicating with each sensor according to the configuration data containing the sensor address issued by the MCU. The address table contains the sensor address and corresponding time slice information of each sensor. During the communication process, the RS-485 communication module obtains the sensor address in the address table in turn, and sends a data request instruction to the corresponding sensor according to the address, which can accurately control the data sending timing of each sensor and ensure the timing and synchronization of data transmission. By generating a sensor address table, the time overhead of each table lookup is eliminated, and the communication efficiency is improved; the time slice information is clearly marked to ensure that the communication between sensors will not interfere with each other; the sensors are polled in address order to avoid omissions and duplications in the communication process.

[0016] Optionally, after sending the return values ​​to the MCU according to the first sensor and the second sensor, the method further includes: counting the first number of the first sensors and the second number of the second sensors to obtain the total number of sensors; calculating the ratio of the first number to the total number of sensors; if it is determined that the ratio is greater than a preset threshold, determining that a system fault occurs, and sending a fault alarm signal to the MCU.

[0017] By adopting the above technical solution, the RS-485 communication module counts the first number of the first sensor and the second number of the second sensor after each polling cycle, calculates the ratio of the first number to the total number, and compares it with the preset threshold. When the ratio exceeds the preset threshold, it is determined that the system has a fault and sends an alarm signal to the MCU. This real-time statistical detection and ratio calculation can dynamically evaluate the operating status of the sensor network and detect communication anomalies in a timely manner.

[0018] Optionally, sending a return value to the MCU based on the first sensor and the second sensor specifically includes: determining, based on the first sensor, a first sensor address list that failed to send sensor data successfully; determining, based on the second sensor, a second sensor address list that successfully sent sensor data; and sending the first sensor address list and the second sensor address list as the return values ​​to the MCU.

[0019] By adopting the above technical solution, the RS-485 communication module determines the sensor address lists of unsuccessful and successful data transmission according to the first sensor and the second sensor, and sends the two sensor address lists to the MCU as return values. Compared with simple quantitative statistics, the address list can clearly identify the identity information of each abnormal sensor, which is convenient for the MCU to perform targeted status query and fault diagnosis. The sensor address list adopts a compact data structure, which can reduce the amount of data and improve transmission efficiency; distinguishing between successful and failed sensor addresses can accurately describe the current communication situation and provide decision-making reference for the MCU; encapsulating the sensor address list as a return value and using an active reporting method can reduce the calculation burden of the MCU.

[0020] In a second aspect of the present application, a communication device based on an RS-485 communication module is provided. The device is an RS-485 communication module. The RS-485 communication module includes an acquisition module and a processing module, wherein: the acquisition module is used to acquire configuration data sent by the MCU of the communication management board; the processing module is used to send a data request instruction to each of the sensors according to the configuration data, and the data request instruction includes a polling cycle and time slice information, so that each of the sensors sends corresponding sensor data within a specified time slice according to the time slice information, and the polling cycle is the time required for the communication management board to poll multiple sensors, and the time slice information is the number of sensors within a polling cycle. The device communicates with the communication management board at a designated time slice, wherein the designated time slice includes a start time and a duration; the acquisition module is also used to acquire the sensor data sent by each of the sensors; the processing module is also used to mark the sensor as a first sensor if it is determined that the sensor data sent by the sensor is not received within the polling cycle; the processing module is also used to mark the sensor as a second sensor if it is determined that the sensor data sent by the sensor is received within the polling cycle; the processing module is also used to send a return value to the MCU according to the first sensor and the second sensor, so that the MCU can determine whether the sensor successfully sends the sensor data according to the return value.

[0021] In the third aspect of the present application, an electronic device is provided, including a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes any one of the methods described above.

[0022] In a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores instructions, and when the instructions are executed, any of the methods described above is executed.

[0023] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: 1. Get the configuration data sent by the MCU, and send a data request instruction containing the polling cycle and time slice information to the sensor according to the configuration data, so that the sensor can send data in an orderly manner within the specified time slice, avoiding data transmission conflicts. After receiving the sensor data, the communication module can distinguish the first sensor that has not sent data and the second sensor that has successfully sent data, and generate a return value to send to the MCU, so that the MCU can determine the data transmission status of each sensor. This polling communication method based on time division multiple access improves the real-time, reliability and orderliness of communication between the sensor and the communication management board. At the same time, by marking the sensor type, generating return values ​​and other measures, effective monitoring and management of the communication process is achieved, providing a basis for subsequent exception handling and system maintenance.

[0024] 2. After determining the first sensor and the second sensor, the communication module sends a reception confirmation signal to the second sensor, causing it to enter a dormant state in the next polling cycle; and sends a resend instruction to the first sensor, causing it to resend data in the next polling cycle. This targeted response and processing mechanism can effectively reduce data loss and conflicts during the communication process. Putting the sensor that successfully sends data into a dormant state can reduce its power consumption and extend its service life; letting the sensor that failed to send data resend data can increase its data sending success rate and ensure data integrity and continuity.

[0025] 3. After receiving the enable signal and configuration data sent by the MCU, the power-on operation is completed according to the enable signal, and the configuration data is written into the configuration register. The enable signal controls the power-on and working status of the communication module, and can realize the remote switch control of the module, avoiding the trouble of manual operation. Writing the received configuration data into the register can ensure the persistent storage and real-time update of the configuration parameters, providing reliable parameter support for subsequent communication control. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 It is a flow chart of a communication method based on RS-485 communication module disclosed in an embodiment of the present application; Figure 2 It is a module schematic diagram of a communication device based on an RS-485 communication module disclosed in an embodiment of the present application; Figure 3 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application.

[0027] Explanation of the reference numerals: 201, acquisition module; 202, processing module; 300, electronic device; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. DETAILED DESCRIPTION

[0028] In order to enable technicians in this field to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.

[0029] In the description of the embodiments of the present application, words such as "for example" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "for example" or "for example" is intended to present related concepts in a specific way.

[0030] In the description of the embodiments of the present application, the meaning of the term "multiple" refers to two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprise", "have" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.

[0031] This application provides a communication method based on RS-485 communication module, referring to Figure 1 , Figure 1 1 is a flow chart of a communication method based on an RS-485 communication module provided in an embodiment of the present application. The method is applied to the RS-485 communication module, the RS-485 communication module is located on a communication management board, the RS-485 communication module is connected to the MCU of the communication management board, and the RS-485 communication module is also connected to a plurality of sensors. The method includes steps S101 to S106, and the steps are as follows: Step S101: Acquire configuration data sent by the MCU of the communication management board.

[0032] In step S101, an enable signal and configuration data sent by the MCU of the communication management board are obtained; a power-on operation is completed according to the enable signal, and the configuration data is written into a configuration register.

[0033] Specifically, the RS-485 communication module monitors the enable signal from the MCU through a dedicated signal line. The enable signal can be an independent GPIO pin or multiplex other pins. When the MCU is ready to communicate with the RS-485 communication module, the enable signal is set to a high level. The level conversion circuit inside the RS-485 communication module detects the state of the enable signal in real time. Once the enable signal is detected to become a valid level, the RS-485 communication module will start the power-on sequence. After the power-on sequence is completed, the RS-485 communication module will send a ready signal to the MCU, indicating that it has entered a normal working state and can receive the configuration data of the MCU. The ready signal is sent through an independent GPIO pin, or it can be sent through a multiplexed pin or a serial communication interface (such as UART). The MCU sends the configuration data to the RS-485 communication module through the serial communication interface. The configuration data is sent in the form of a frame, and each frame of data includes three parts: a frame header, a data segment, and a frame trailer. After receiving the configuration data frame, the RS-485 communication module will first check the frame format and the checksum to ensure the integrity and correctness of the data. After the check is passed, the RS-485 communication module will remove the frame header and frame footer to extract the pure configuration parameters. Then, the RS-485 communication module writes these configuration parameters one by one into the internal configuration register.

[0034] Step S102: According to the configuration data, a data request instruction is sent to each of the sensors, and the data request instruction includes a polling cycle and time slice information, so that each of the sensors sends corresponding sensor data within a specified time slice according to the time slice information. The polling cycle is the time required for the communication management board to poll multiple sensors, and the time slice information is the specified time slice for the sensor to communicate with the communication management board within a polling cycle, and the specified time slice includes a start time and a duration.

[0035] In step S102, the configuration data includes a sensor address. Based on the sensor address, an address table for communicating with each of the sensors is generated, wherein the address table includes the sensor address of each sensor and corresponding time slice information. In the address table, the sensor address of each sensor is obtained in turn, and the data request instruction is sent to the corresponding sensor based on the sensor address.

[0036] Specifically, the RS-485 communication module sends data request instructions to each sensor according to the configuration data received from the MCU. The configuration data includes the sensor address, polling cycle and time slice information. Among them, the sensor address is used to identify each sensor, the polling cycle indicates the time required for the communication management board to poll all sensors, and the time slice information specifies the start time and duration of each sensor's communication with the communication management board within a polling cycle. First, the RS-485 communication module generates an address table for communicating with each sensor based on the sensor address in the configuration data. The address table is in the form of a table, where each row corresponds to a sensor, containing the sensor address and the assigned time slice information of the sensor. After the address table is generated, the RS-485 communication module can send data request instructions to each sensor in an orderly manner according to the information in the table. The specific sending process can be divided into the following steps: The RS-485 communication module initializes a timer, and the timing cycle is equal to the polling cycle. Whenever the timer overflows, it indicates that a new round of polling has begun. At the beginning of each polling cycle, the RS-485 communication module sets the current row index in the address table to 0, indicating that polling starts from the first sensor. The RS-485 communication module reads the sensor address and time slice information of the corresponding sensor from the address table according to the current row index. The RS-485 communication module waits until the current time reaches the start time of the sensor by comparing the system clock with the start time. After the current time reaches the start time, the RS-485 communication module sends a data request instruction to the sensor. The data request instruction also includes the sensor address, function code, and data length fields, which are used to inform the sensor of the type and length of the data to be read. The RS-485 communication module waits for the response data of the sensor, or waits for the duration to end. If the response data of the sensor is received within the duration, the data is stored in the buffer; if no response is received after the timeout, the sensor is marked as unresponsive. After the duration of the current sensor ends, the RS-485 communication module adds 1 to the current row index of the address table and moves to the next sensor. The RS-485 communication module repeats the above steps until all sensors in the address table have been polled. When a polling cycle ends, the RS-485 communication module enters the idle state, waiting for the next timer overflow to start a new round of polling.

[0037] Step S103: Acquire sensor data sent by each of the sensors.

[0038] In step S103, after sending the data request instruction to the sensor, the RS-485 communication module will immediately enter the receiving state and wait for the response data of the sensor. After receiving the data request instruction, the sensor will send the sensor data collected by itself to the RS-485 communication module within the specified time slice. These sensor data are usually sent in the form of frames, and each frame of data includes three parts: frame header, data segment and frame tail, which is similar to the format of MCU sending configuration data in step S101. After receiving the sensor data frame, the RS-485 communication module will first check the frame format and check code to ensure the integrity and correctness of the data. After the check is passed, the RS-485 communication module will remove the frame header and frame tail to extract pure sensor data. Sensor data includes measurement values ​​of various physical quantities, such as temperature, humidity, pressure, and speed, depending on the type and function of the sensor. After extracting the sensor data, the RS-485 communication module will store the sensor data in an internal data buffer, which is usually a fixed-size RAM area for temporarily storing sensor data from various sensors.

[0039] Step S104: if it is determined that the sensor data sent by the sensor is not received within the polling period, the sensor is marked as a first sensor.

[0040] In step S104, the RS-485 communication module determines whether the sensor data sent by each sensor is successfully received within a polling cycle. If it is determined that the data of a certain sensor is not received, the sensor is marked as the first sensor. At the beginning of each polling cycle, the RS-485 communication module will initialize a sensor state table. The sensor state table adopts the form of a bitmap, and each bit corresponds to a sensor, which is used to mark the data receiving state of the sensor. For example, for an RS-485 communication module that supports 16 sensors, the sensor state table can be represented by a 16-bit unsigned integer. Initially, all bits of the sensor state table are cleared, indicating that the data of all sensors have not been received. During the polling cycle, whenever the RS-485 communication module successfully receives and parses a data frame of a sensor, the corresponding position in the sensor state table will be set to 1, otherwise, it will be set to 0. This indicates that the sensor data of the sensor has been successfully received. After a polling cycle ends, the RS-485 communication module will check each bit in the sensor state table. If a bit is 0, it means that the corresponding sensor failed to send data successfully or the sent data frame has errors during this polling cycle. The RS-485 communication module will mark these sensors that failed to respond as the first sensor for subsequent processing.

[0041] Step S105: If it is determined that the sensor data sent by the sensor is received within the polling period, the sensor is marked as a second sensor.

[0042] In step S105, at the end of the polling cycle, the RS-485 communication module analyzes the sensor status table, finds all bits that are 1, and marks the corresponding sensor as the second sensor.

[0043] Step S106: Sending return values ​​to the MCU according to the first sensor and the second sensor, so that the MCU can determine whether the sensor successfully sends sensor data according to the return values.

[0044] Before step S106, the method further includes: sending a reception confirmation signal to the second sensor so that the second sensor enters a sleep state in a next polling cycle; sending a retransmission instruction to the first sensor so that the first sensor retransmits sensor data in a next polling cycle.

[0045] Specifically, after successfully receiving a data frame from a sensor, the RS-485 communication module will send a reception confirmation signal to the sensor. The reception confirmation signal is a data frame in a specific format, which is used to inform the sensor that its data has been correctly received and can enter a dormant state to save energy. The format and content of the reception confirmation signal can be designed according to the needs of the specific application. The reception confirmation signal includes the following key fields: sensor address, confirmation flag, and status code; among them, the sensor address is used to identify the target sensor of the confirmation signal, which is consistent with the sensor address in the data frame; the confirmation flag indicates that this is a reception confirmation signal, not a data request instruction or other types of commands; the status code indicates the reception status of the sensor data, which is represented by one byte, and different values ​​correspond to different states.

[0046] When the sensor receives the reception confirmation signal sent by the RS-485 communication module, it will check the status code. For example, if the status code is 0x00, it means that the RS-485 communication module has successfully received the data sent by itself, and the sensor can enter the sleep state until the next polling cycle starts. In the sleep state, the sensor will shut down unnecessary circuits and functions, retaining only the basic clock and wake-up circuits, waiting for the next communication with minimal power consumption. This sleep mechanism can greatly extend the battery life of the sensor.

[0047] Secondly, for the first sensor that fails to successfully send data in the current polling cycle, the RS-485 communication module will send a resend instruction to it before the end of this cycle. The resend instruction is also a data frame in a specific format, which is used to tell the first sensor to resend the sensor data of the previous cycle in the next polling cycle. When the first sensor receives the resend instruction sent by the RS-485 communication module, it will resend the sensor data of the previous cycle and the sensor data of this polling cycle at the specified time slice in the next polling cycle. This resend mechanism can ensure that the necessary sensor data can still be obtained when there is a temporary abnormality in the communication, thereby improving the reliability of data transmission.

[0048] In step S106, a first sensor address list that failed to send sensor data is determined based on the first sensor; a second sensor address list that successfully sent sensor data is determined based on the second sensor; and the first sensor address list and the second sensor address list are sent to the MCU as the return values.

[0049] Specifically, after the RS-485 communication module completes the reception and judgment of each sensor data, it needs to generate a corresponding sensor address list according to the judgment result. For sensors that have not successfully received sensor data, the RS-485 communication module marks it as the first sensor and adds its sensor address to the first sensor address list; for sensors that have successfully received sensor data, the RS-485 communication module marks it as the second sensor and adds its sensor address to the second sensor address list. The RS-485 communication module can use two arrays or linked lists to store the first sensor address list and the second sensor address list respectively. In the process of judging the sensor data reception status, the communication module can dynamically update the contents of the two lists. For example, when the communication module determines that a certain sensor has failed to send data successfully, the address of the sensor is added to the first sensor address list; when it is determined that a certain sensor has successfully sent data, the address of the sensor is added to the second sensor address list.

[0050] After generating two sensor address lists, the RS-485 communication module needs to package them into a complete return value to send to the MCU. The return value includes the following key elements: data frame header, length of the first sensor address list, content of the first sensor address list, length of the second sensor address list and content of the second sensor address list, data frame tail: indicates the end of the return value, which can be identified by a specific character or byte sequence; the data frame header indicates the beginning of the return value, which can be identified by a specific character or byte sequence; the length of the first sensor address list indicates the number of sensor addresses included in the first sensor address list; the content of the first sensor address list contains the addresses of all sensors that have not successfully sent data, and a fixed-length byte sequence can be used to represent each address; the length of the second sensor address list indicates the number of sensor addresses included in the second sensor address list; the content of the second sensor address list contains the addresses of all sensors that have successfully sent data, and the representation method is the same as the first sensor address list; the data frame tail indicates the end of the return value, which can be identified by a specific character or byte sequence.

[0051] In a possible implementation, after step S106, the method further includes: converting the sensor data into parallel sensor data by level conversion and serial-to-parallel conversion, and storing the parallel sensor data in a data buffer.

[0052] Specifically, after receiving the sensor data, the RS-485 communication module needs to perform level conversion on the data. This is because RS-485 communication uses differential signals, and its level range may be incompatible with the level standard (such as TTL) used by the MCU. In order to ensure that the data can be correctly recognized and processed by the MCU, the RS-485 communication module must convert the RS-485 level to a level that matches the MCU. The level conversion is implemented using a dedicated RS-485 transceiver chip. After completing the level conversion, the RS-485 communication module needs to convert the serial sensor data into parallel data for subsequent storage and processing. This is because serial data is transmitted in bits, while the MCU usually reads, writes and processes data in bytes or words. In order to improve data processing efficiency and reduce the burden on the MCU, the RS-485 communication module needs to assemble serial data into parallel bytes or words.

[0053] In a possible implementation, the method further includes: counting a first number of the first sensors and a second number of the second sensors to obtain a total number of sensors; calculating a ratio of the first number to the total number of sensors; if it is determined that the ratio is greater than a preset threshold, determining that a system fault exists, and sending a fault alarm signal to the MCU.

[0054] Specifically, after each polling cycle, the RS-485 communication module counts the number of first sensors that have not successfully sent data and the number of second sensors that have successfully sent data. The RS-485 communication module is implemented by counting the elements in the first sensor address list and the second sensor address list. For example, the RS-485 communication module can set two counter variables, which are used to record the number of first sensors and the number of second sensors respectively. In the process of generating the sensor address list, each time a sensor address is added to the corresponding list, the corresponding counter is increased by 1. When a polling cycle is completed, the values ​​of the two counters represent the number of first sensors and the number of second sensors respectively. After obtaining the number of first sensors and the number of second sensors, the RS-485 communication module calculates the total number of sensors, that is, the number of first sensors and the number of second sensors are added, and the result is the total number of sensors in the current polling cycle. It should be noted that in actual applications, the total number of sensors may be a fixed constant or a dynamically changing variable. If the total number of sensors is fixed, the RS-485 communication module can directly set it to a constant value during initialization; if the total number of sensors is dynamically changing, it needs to be recalculated and updated in each polling cycle.

[0055] After obtaining the number of first sensors and the total number of sensors, the RS-485 communication module calculates the ratio of the number of first sensors to the total number of sensors through floating-point division, that is, converting the number of first sensors into floating-point numbers and dividing it by the total number of sensors. The result is the ratio of the number of first sensors. After calculating the ratio of the number of first sensors, the RS-485 communication module compares it with the preset threshold to determine whether the system is faulty. The fault threshold is a constant value pre-set according to the system reliability requirements and application scenario characteristics, indicating the maximum ratio of the number of first sensors that can be tolerated. The RS-485 communication module only needs to compare the calculated ratio of the number of first sensors with the preset threshold. If the ratio is greater than the preset threshold, the system is judged to be faulty; otherwise, the system is considered to be operating normally. When the RS-485 communication module determines that the system is faulty, it is necessary to send a fault alarm signal to the MCU in a timely manner so that the MCU can take corresponding fault handling measures.

[0056] Reference Figure 2The present application also provides a communication device based on an RS-485 communication module, which is an RS-485 communication module. The RS-485 communication module includes an acquisition module 201 and a processing module 202, wherein: the acquisition module 201 is used to acquire the configuration data sent by the MCU of the communication management board; the processing module 202 is used to send a data request instruction to each of the sensors according to the configuration data, and the data request instruction includes a polling cycle and a time slice information, so that each of the sensors sends the corresponding sensor data within a specified time slice according to the time slice information, and the polling cycle is the time required for the communication management board to poll multiple sensors, and the time slice information is the time required for the sensor and the processing module to poll each other within a polling cycle. The communication management board specifies a time slice for communication, wherein the specified time slice includes a start time and a duration; the acquisition module 201 is also used to acquire sensor data sent by each of the sensors; the processing module 202 is also used to mark the sensor as a first sensor if it is determined that the sensor data sent by the sensor is not received within the polling cycle; the processing module 202 is also used to mark the sensor as a second sensor if it is determined that the sensor data sent by the sensor is received within the polling cycle; the processing module 202 is also used to send a return value to the MCU according to the first sensor and the second sensor, so that the MCU can determine whether the sensor has successfully sent the sensor data according to the return value.

[0057] In a possible implementation, before the processing module 202 sends the return value to the MCU based on the first sensor and the second sensor, the method also includes: the processing module 202 sends a reception confirmation signal to the second sensor so that the second sensor enters a sleep state within the polling cycle; the processing module 202 sends a retransmission instruction to the first sensor so that the first sensor resends the sensor data within the next polling cycle.

[0058] In a possible implementation, the acquisition module 201 acquires the configuration data sent by the MCU of the communication management board, specifically including: the acquisition module 201 acquires the enable signal and configuration data sent by the MCU of the communication management board; the processing module 202 completes the power-on operation according to the enable signal, and writes the configuration data into the configuration register.

[0059] In a possible implementation, after the processing module 202 sends the return value to the MCU according to the first sensor and the second sensor, the method further includes: the processing module 202 converts the sensor data into parallel sensor data through level conversion and serial-to-parallel conversion, and stores the parallel sensor data in a data buffer.

[0060] In a possible implementation, the configuration data includes a sensor address, and the processing module 202 sends a data request instruction to each of the sensors according to the configuration data, specifically including: the processing module 202 generates an address table for communicating with each of the sensors according to the sensor address, the address table including the sensor address of each sensor and corresponding time slice information; the processing module 202 obtains the sensor address of each sensor in the address table in turn, and sends the data request instruction to the corresponding sensor according to the sensor address.

[0061] In a possible implementation, after the processing module 202 sends the return value to the MCU according to the first sensor and the second sensor, the method further includes: the processing module 202 counts the first number of the first sensors and the second number of the second sensors to obtain the total number of sensors; the processing module 202 calculates the ratio of the first number to the total number of sensors; if the processing module 202 determines that the ratio is greater than a preset threshold, it determines that the system fails, and sends a fault alarm signal to the MCU.

[0062] In a possible implementation, the processing module 202 sends a return value to the MCU based on the first sensor and the second sensor, specifically including: the processing module 202 determines a first sensor address list that has not successfully sent sensor data based on the first sensor; the processing module 202 determines a second sensor address list that has successfully sent sensor data based on the second sensor; the processing module 202 sends the first sensor address list and the second sensor address list as the return value to the MCU.

[0063] It should be noted that: when the device provided in the above embodiment realizes its function, only the division of the above functional modules is used as an example. In actual application, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0064] The present application also provides an electronic device. Figure 3 , Figure 3 The electronic device 300 may include: at least one processor 301 , at least one network interface 304 , a user interface 303 , a memory 305 , and at least one communication bus 302 .

[0065] The communication bus 302 is used to realize the connection and communication between these components.

[0066] The user interface 303 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.

[0067] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).

[0068] Among them, the processor 301 may include one or more processing cores. The processor 301 uses various interfaces and lines to connect various parts in the entire server, and executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 305, and calling data stored in the memory 305. Optionally, the processor 301 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 301 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 301, and it can be implemented separately through a chip.

[0069] Among them, the memory 305 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 305 includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 305 may optionally also be at least one storage device located away from the aforementioned processor 301. Refer to Figure 3 , the memory 305 as a computer storage medium may include an operating system, a network communication module, a user interface module and an application program of a communication method based on the RS-485 communication module.

[0070] exist Figure 3 In the electronic device 300 shown, the user interface 303 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 301 can be used to call the application program storing a communication method based on the RS-485 communication module in the memory 305, and when executed by one or more processors 301, the electronic device 300 executes one or more of the methods described in the above embodiments. It should be noted that for the aforementioned method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited by the described order of actions, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for the present application.

[0071] The present application also provides a computer-readable storage medium, which stores instructions. When executed by one or more processors 301, the electronic device 300 executes one or more of the methods described in the above embodiments.

[0072] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0073] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0074] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0075] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0076] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: various media that can store program codes, such as USB flash drives, mobile hard drives, magnetic disks or optical disks.

[0077] The above is only an exemplary embodiment of the present disclosure and cannot be used to limit the scope of the present disclosure. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the disclosure of the specification and the truth of practice, those skilled in the art will easily think of other embodiments of the present disclosure.

[0078] This application is intended to cover any variation, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the art not described in the present disclosure. The description and examples are to be regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. A communication method based on RS-485 communication module, It is characterized in that The method is applied to an RS-485 communication module, the RS-485 communication module is located on a communication management board, the RS-485 communication module is connected to an MCU of the communication management board, and the RS-485 communication module is also connected to a plurality of sensors, and the method comprises: Obtaining configuration data sent by the MCU of the communication management board; According to the configuration data, a data request instruction is sent to each of the sensors, wherein the data request instruction includes a polling cycle and time slice information, so that each of the sensors sends corresponding sensor data within a specified time slice according to the time slice information, wherein the polling cycle is the time required for the communication management board to poll a plurality of the sensors, and the time slice information is a specified time slice for the sensor to communicate with the communication management board within a polling cycle, and the specified time slice includes a start time and a duration; Acquiring sensor data sent by each of the sensors; If it is determined that the sensor data sent by the sensor is not received within the polling period, marking the sensor as a first sensor; If it is determined that the sensor data sent by the sensor is received within the polling period, marking the sensor as a second sensor; The first sensor and the second sensor send return values ​​to the MCU, so that the MCU determines whether the sensor successfully sends the sensor data according to the return values.

2. The method according to claim 1, It is characterized in that Before sending the return value to the MCU according to the first sensor and the second sensor, the method further includes: sending a reception confirmation signal to the second sensor so that the second sensor enters a dormant state within the polling period; A resending instruction is sent to the first sensor so that the first sensor resends the sensor data in a next polling cycle.

3. The method according to claim 1, It is characterized in that The obtaining of the configuration data sent by the MCU of the communication management board specifically includes: Obtaining the enable signal and configuration data sent by the MCU of the communication management board; A power-on operation is completed according to the enable signal, and the configuration data is written into a configuration register.

4. The method according to claim 1, It is characterized in that After sending the return value to the MCU according to the first sensor and the second sensor, the method further includes: The sensor data is converted into parallel sensor data through level conversion and serial-to-parallel conversion, and the parallel sensor data is stored in a data buffer.

5. The method according to claim 1, It is characterized in that The configuration data includes a sensor address, and sending a data request instruction to each of the sensors according to the configuration data specifically includes: generating an address table for communicating with each of the sensors according to the sensor addresses, the address table including the sensor address of each sensor and corresponding time slice information; In the address table, the sensor address of each sensor is acquired in turn, and the data request instruction is sent to the corresponding sensor according to the sensor address.

6. The method according to claim 1, It is characterized in that After sending the return value to the MCU according to the first sensor and the second sensor, the method further includes: Counting a first number of the first sensors and a second number of the second sensors to obtain a total number of sensors; Calculate the ratio of the first number to the total number of sensors; If it is determined that the ratio is greater than a preset threshold, a system failure is determined and a failure alarm signal is sent to the MCU.

7. The method according to claim 1, It is characterized in that The sending of the return value to the MCU according to the first sensor and the second sensor specifically includes: Determining, based on the first sensor, a list of first sensor addresses that failed to send sensor data; Determining, based on the second sensor, a list of second sensor addresses that successfully sent sensor data; The first sensor address list and the second sensor address list are sent to the MCU as the return value.

8. A communication device based on the communication management board 485 module, It is characterized in that The device is an RS-485 communication module, which includes an acquisition module (201) and a processing module (202), wherein: The acquisition module (201) is used to acquire the configuration data sent by the MCU of the communication management board; The processing module (202) is used to send a data request instruction to each of the sensors according to the configuration data, the data request instruction including a polling cycle and time slice information, so that each of the sensors sends corresponding sensor data within a specified time slice according to the time slice information, the polling cycle is the time required for the communication management board to poll a plurality of the sensors, the time slice information is the specified time slice for the sensor to communicate with the communication management board within a polling cycle, and the specified time slice includes a start time and a duration; The acquisition module (201) is further used to acquire sensor data sent by each of the sensors; The processing module (202) is further configured to mark the sensor as a first sensor if it is determined that the sensor data sent by the sensor is not received within the polling period; The processing module (202) is further configured to mark the sensor as a second sensor if it is determined that the sensor data sent by the sensor is received within the polling period; The processing module (202) is further configured to send return values ​​to the MCU according to the first sensor and the second sensor, so that the MCU can determine whether the sensor has successfully sent the sensor data according to the return values.

9. An electronic device, It is characterized in that The electronic device (300) comprises a processor (301), a memory (305), a user interface (303) and a network interface (304), wherein the memory (305) is used to store instructions, the user interface (303) and the network interface (304) are used to communicate with other devices, and the processor (301) is used to execute the instructions stored in the memory (305) so that the electronic device (300) executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 7 is executed.

Citation Information

Patent Citations

  • Communication control method and device

    CN105681372A

  • Time slot multiplexing communication method, time slot distribution method and wireless access device

    CN106954179A

  • Charging pile fault identification method, storage medium, charging pile and electronic equipment

    CN110646699A

  • Bus system applied to large-scale parking space management and provided with polling fault inquiry and heartbeat state reporting functions

    CN111510352A

  • Low-power-consumption general agricultural environment monitoring terminal

    CN113848791A