A high-efficiency and high-security communication method and device based on a serial port
By constructing a structured serial communication protocol and combining CRC checksum and ACK confirmation, the contradiction between reliability and efficiency in complex environments of serial communication is resolved, achieving high-security and high-throughput serial communication.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHEJIANG SUPCON RES
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-19
Smart Images

Figure CN122247558A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of industrial communication technology, and in particular relates to a high-efficiency and high-security communication method and device based on serial port. Background Technology
[0002] Serial communication is a widely used data transmission method in industrial control, device interconnection, and other fields. It transmits data serially via a single data line, offering advantages such as simple connection, low cost, and support for long-distance transmission. Common serial communication standards and interfaces include UART, RS-485, RS-422, and SPI, which form the foundation for inter-device communication. However, while possessing these advantages, serial communication also has inherent technical limitations, primarily in terms of reliability and efficiency. First, because serial communication typically transmits signals over a single or limited number of lines, these signals are highly susceptible to external interference over long distances or in complex electromagnetic environments, leading to data errors and affecting communication reliability. To address this, existing technologies usually add isolation devices, shielding layers, or use differential signals at the hardware level to enhance anti-interference capabilities, but this increases system cost and complexity.
[0003] Secondly, the essence of serial communication is that only one bit of data is transmitted per clock cycle. Therefore, to achieve a higher data transmission rate, the communication clock frequency must be increased. However, increasing the clock frequency brings new problems: firstly, high-frequency signals are more prone to attenuation and distortion during transmission; secondly, higher frequencies mean shorter signal periods, requiring stricter timing, which also increases the risk of signal interference, creating a contradictory situation of improving efficiency by increasing frequency, but becoming more susceptible to interference after increasing frequency. Summary of the Invention
[0004] To address the aforementioned issues, this invention proposes a highly efficient and secure serial communication method and apparatus. It constructs a structured, efficient interactive foundation for serial communication, including instruction data, address data, length data, and a checksum field. A bidirectional verification mechanism combining full-message CRC checksum and receiver ACK confirmation significantly improves the communication's anti-interference capability and data reliability. Utilizing address and length data supports single-instruction batch read / write operations, greatly reducing protocol overhead and improving register configuration and data access efficiency. By centralizing key control information in the message header, a complete transaction involving request, response, and confirmation is achieved within a single frame, avoiding delays caused by multiple frames. Ultimately, this method resolves the contradiction between reliability and efficiency in serial communication at the protocol level, achieving a synergistic improvement in both high security and high throughput.
[0005] The first aspect of the present invention provides a high-efficiency and high-security communication method based on a serial port, applied to a serial port communication device, including a master and a slave, comprising: A communication protocol is constructed for data communication between the host and the slave. The communication protocol includes at least instruction data for distinguishing operation types, address data for indicating the start position of the operation, length data for indicating the amount of operation data, a data field, and a check field generated based on the message content for identifying the ACK signal of the receiver receiving the data result. The check field is obtained as a 32-bit check field through binary division. To complete a communication transaction, the communication transaction shall include at least the following steps: The host constructs communication messages conforming to the communication protocol; The communication message is transmitted to the slave device via a serial port. Based on the communication message, the slave machine calculates and obtains the verification result, and performs corresponding operations. It generates response data conforming to the communication protocol and transmits the response data to the host via the serial port. Based on the response data, the host processes and obtains the communication transaction result.
[0006] Preferably, the step of constructing a communication message conforming to the communication protocol through the host further includes: If the instruction data is write data, the address data is the starting position of the write data, the length data is the length of the write data, the data field is the content of the write data, and the verification field is obtained based on the instruction data, the address data, the length data, and the data field; If the instruction data is read data, the address data is the starting position of the read data, the length data is the length of the read data, and the verification field is obtained based on the instruction data, the address data, and the length data; If the instruction data is to write to the register, the address data is the register address of the slave device, the data field is the content to be written to the register, the length data is the length of the data field, and the verification field is obtained based on the instruction data, the address data, the length data, and the data field. If the instruction data is a read register, the address data is the address of the slave device being read from the register, the length data is the preset length to be read, and the verification field is obtained based on the instruction data, the address data, and the length data.
[0007] Preferably, it further includes: If the instruction data is a write register and the write registers are multiple addresses that are consecutive, the length data is the number of registers to be written, and the data field sequentially contains the data corresponding to each of the multiple registers.
[0008] Preferably, the step of obtaining the verification result through the slave device based on the communication message, performing corresponding operations, and generating response data conforming to the communication protocol further includes: Initialize the response data; Based on the communication message, the slave verification field is obtained through slave calculation. The ACK signal of the response data is obtained by comparing the slave verification field and the verification field. The specific rule is: if the slave verification field and the verification field are consistent, the ACK signal is set to 1; otherwise, the ACK signal is set to 0. Based on the instruction data, the ACK signal, and the communication message, perform the corresponding operation and update the response data.
[0009] Preferably, the step of obtaining the verification field through binary division further includes: The slave device or the master device parses the received message and obtains instruction data, address data, length data, and data fields; Determine whether any field in the instruction data, address data, length data, or data field is empty. If so, the corresponding field is 0 and constitutes the basic CRC data. The verification field is obtained by binary division based on the CRC base data.
[0010] Preferably, the step of performing corresponding operations based on the instruction data, the ACK signal, and the communication message further includes: If the instruction data is write data or write register and the ACK signal is 1, the slave device writes the data field of the communication message to the slave device's address data to (the address data + the length data - 1). If the instruction data is read data or read register, the data field of the response data is the content of the slave read data, and the length of the response data is the length of the data field of the response data.
[0011] Preferably, it further includes: If the instruction data is to read a register and the length of the communication message is greater than 1, and the ACK signal is 1, the length of the response data is the number of registers, the address data of the response data is the starting address of the register, and the data field of the response data is the data of the corresponding register.
[0012] Preferably, the step of obtaining the communication transaction result through the host processing based on the response data further includes: If the instruction data of the response data is write data or write register, the ACK signal of the response data is further determined. If the ACK signal of the response data is 0, the remaining number of times to send the communication message is greater than 0. If it is greater than 0, the host sends the communication message to the slave. After the sending is completed, the remaining number of times is decremented by 1. If the instruction data is read data or read register, the host verification field is obtained by binary division based on the response message; the verification field is compared with the verification field of the response data, and the specific rule is as follows: if they are inconsistent, it is further determined whether the remaining number of times to send the communication message is greater than 0. If it is greater than 0, the host sends the communication message to the slave, and after sending, the remaining number is decremented by 1; if they are consistent, the host operates on the data field of the response data.
[0013] A second aspect of the present invention provides a high-efficiency and high-security communication device based on a serial port, comprising: A serial port transmission module is used to transmit the communication messages via a serial port; The serial port receiving module is used to receive communication messages or response data via the serial port. The serial port receive verification module is used to obtain a 32-bit local verification value by binary division based on the content of the received communication message or response message, and compare the local verification value with the received verification field to obtain the verification result. The response generation module is used to perform corresponding read or write operations according to instruction data and address data when the verification result is passed, and generate response data that conforms to the communication protocol. The response data includes an ACK signal for identifying the result of the receiver receiving the data. The result processing module is used to process and obtain the final communication transaction result based on the received response data and the verification result. The message construction module is used to construct communication messages or response messages that conform to a predetermined communication protocol. The communication protocol includes at least instruction data for distinguishing operation types, address data for indicating the start position of the operation, length data for indicating the amount of operation data, data fields, and a verification field generated based on the message content.
[0014] A third aspect of the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the efficient and secure serial port-based communication method as described in any of the preceding claims.
[0015] Compared with existing technologies, this invention has the following beneficial effects: It constructs a structured and efficient interactive foundation for serial communication, including instruction data, address data, length data, and a checksum field. The bidirectional verification mechanism, combining full-message CRC checksum with receiver ACK confirmation, significantly improves the anti-interference capability and data reliability of communication. Utilizing address and length data to support single-instruction batch read / write operations greatly reduces protocol overhead and improves the efficiency of register configuration and data access. By centralizing key control information in the message header, it achieves a complete transaction of request, response, and confirmation within a single frame, avoiding the delay of multiple frames. Ultimately, this method uniformly resolves the contradiction between reliability and efficiency in serial communication at the protocol level, achieving a synergistic improvement in high security and high throughput. Attached Figure Description
[0016] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings, wherein: Figure 1 This is the main flowchart of a high-efficiency and high-security communication method based on serial port in this invention; Figure 2 This is a diagram illustrating the communication protocol structure in this invention. Detailed Implementation
[0017] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. The advantages and features of the present invention will become clearer from the following description and claims. It should be noted that the drawings are all in a very simplified form and use non-precise ratios, and are only used to facilitate and clarify the illustration of the embodiments of the present invention.
[0018] It should be noted that all directional indicators (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicator will also change accordingly.
[0019] First Embodiment See Figure 1 and Figure 2 The first aspect of the present invention provides a high-efficiency and high-security communication method based on a serial port, applied to a serial port communication device, including a master and a slave, comprising: A communication protocol is constructed for data communication between the master and slave devices. The communication protocol includes at least instruction data for distinguishing operation types, address data for indicating the start position of the operation, length data for indicating the amount of operation data, data fields, and a check field generated based on the message content, which is used to identify the ACK signal of the receiver receiving the data result; the check field is obtained by binary division to obtain a 32-bit check field. S100: Complete a communication transaction, which includes at least the following steps: S200: Constructs communication messages conforming to the communication protocol through the host; S300: Based on communication messages, it transmits data to the slave device via serial port; S400: Based on communication messages, the slave device calculates and obtains the verification result and performs corresponding operations. It generates response data that conforms to the communication protocol and transmits the response data to the host via serial port; S500: Obtain the communication transaction result through host processing based on the response data.
[0020] The hardware assembly includes a master and at least one slave. The master's SCLK, MOSI, and MISO lines can be connected in parallel to all slaves, but each slave must have its own independent CS line, controlled individually by the master. The master is always the provider of clock and chip select, and the slave is always the responder. These roles cannot be interchanged during communication. After correct physical connection, both the master and slave use the same parameter clock polarity and clock phase. The master and slave use the same communication protocol; see [link to protocol details] for more information. Figure 2 INT represents instruction data, which includes at least read data, write data, read register, and write register. Addr represents the access address data. When the instruction data is read data or read register, Addr represents the starting address of the access. Len represents the length data, indicating the length of the data being operated on in the instruction data. Data represents the data field, indicating the data to be read or written or the register data. CRC represents a 32-bit check field. ACK represents the result obtained by the receiving end (master or slave) in judging the message.
[0021] The specific communication process is as follows: The communication process is as follows: If the instruction data is write data, the host will follow the attached... Figure 2 The defined communication protocol sends communication messages to the slave device. Each communication message includes instruction data, address data (i.e., the starting address), length data, and a data field (data written to the slave device). Upon receiving the communication message, the slave device stores the address data and length data in its buffer. Simultaneously, it calculates a checksum field from the received instruction data, address data, length data, and data field. The checksum field of the communication message is compared with the checksum field of the slave device. If they match, the ACK field in the response data is set to 1; otherwise, the ACK field is set to 0. After sending the communication message, the master device waits for a response. If the ACK field is 1, the master determines that the slave device successfully received the communication message. If the ACK field is 0, the master further checks if the remaining number of transmission attempts for the corresponding message is greater than 0. If it is greater than 0, the master triggers a retransmission mechanism to resend the communication message to the slave device, decrementing the remaining number of transmission attempts by 1.
[0022] If the instruction data is read data, the host will follow the attached instructions. Figure 2 The defined communication protocol sends communication messages to the slave device. These messages sequentially include instruction data, address data (i.e., start address), and length data, and are sent to the SPI output data line. When receiving a message, the slave device synchronously calculates a checksum based on the communication message. It compares the checksum of the communication message with its own checksum. If they match, the ACK field of the acknowledgment data is set to 1. The data field of the acknowledgment data contains the read data from the address and length data sets, i.e., the read data within the address range [address data, address data + length data - 1]. Otherwise, the ACK field is set to 0. After sending a communication message, the master device waits for acknowledgment data. If the ACK field is 1, the master determines that the slave device has successfully received the communication message. If the ACK field is 0, it further checks if the remaining number of transmissions for the corresponding message is greater than 0. If it is, the master triggers a retransmission mechanism to resend the communication message to the slave device, decrementing the remaining number of transmissions by 1.
[0023] If the instruction data is a write register, the host will follow the attached instructions. Figure 2 The defined communication protocol sends communication messages to the slave device. These messages sequentially include instruction data, address data (i.e., the starting address), length data, and a data field (data written to the slave device). The slave device calculates and retrieves a checksum field. It checks if the retrieved checksum field matches the checksum field of the communication message. If they match, the slave device writes the data field to its register, with the write object being [address data, address data + length data - 1]. After processing, the ACK value of the response data is set to 1; otherwise, the slave device does not write data and sets the ACK value of the response data to 0. The master device receives the response message. If the ACK value of the response message is 1, the master device considers the slave device's operation complete; otherwise, it triggers a mechanism to resend the communication message. After resending, the master device decrements the remaining amount of the corresponding message by 1.
[0024] If the instruction data is a write / read register, the host will follow the attached instructions. Figure 2The defined communication protocol sends communication messages to the slave device. These messages sequentially include instruction data, address data (i.e., the starting address of the register), and length data. The communication messages are sent to the SPI output data line. When receiving a message, the slave device synchronously calculates a checksum based on the communication message. It compares the checksum of the communication message with its own checksum. If they match, the ACK field of the acknowledgment data is set to 1. The data field of the acknowledgment data contains the read data from the address and length data, i.e., the address range is [register address data, register address data + length data - 1]. Otherwise, the ACK field of the acknowledgment data is set to 0. After sending a communication message, the master device waits for acknowledgment data. If the ACK field is 1, the master determines that the slave device has successfully received the communication message. If the ACK field is 0, it further checks if the remaining number of transmissions for the corresponding message is greater than 0. If it is, the master triggers a retransmission mechanism to resend the communication message to the slave device, decrementing the remaining number of transmissions by 1.
[0025] Preferably, the step of constructing a communication message conforming to the communication protocol via the host further includes: If the instruction data is write data, the address data is the starting position of the write data, the length data is the length of the write data, the data field is the content of the write data, and the verification field is obtained based on the instruction data, address data, length data, and data field. If the instruction data is read data, the address data is the starting position of the read data, the length data is the length of the read data, and the verification field is obtained based on the instruction data, address data, and length data. If the instruction data is to write to the register, the address data is the slave's register address, the data field is the content to be written to the register, the length data is the length of the data field, and the check field is obtained based on the instruction data, address data, length data, and data field. If the instruction data is to read the register, the address data is the address of the slave device being read from the register, the length data is the preset length to be read, and the check field is obtained based on the instruction data, address data, and length data.
[0026] By dynamically adjusting the calculation range of the verification field based on the instruction data, data integrity is ensured while avoiding invalid calculations of non-existent data during the read request phase, thus improving protocol processing efficiency. Four core operations (read / write data, read / write register) are flexibly defined using the same field structure, and the precise interpretation of field semantics reduces implementation complexity. The mandatory inclusion of a verification field in all operations, with its calculations covering critical control information, ensures that the operation intent and parameters are not tampered with during transmission, laying a reliable security foundation for each type of communication transaction.
[0027] Preferably, it further includes: If the instruction data is to write to a register and the registers to be written to are multiple and consecutive, the length data is the number of registers to be written, and the data field contains the data corresponding to each of the multiple registers in sequence.
[0028] By merging the writes of multiple consecutive registers into a single communication transaction, the redundant transmission of protocol overhead such as commands and addresses is significantly reduced. By cleverly utilizing semantic extensions of existing fields, batch functionality is achieved without introducing new dedicated instructions or complex structures. The writes of multiple registers are verified and confirmed as a complete transaction, ensuring the consistency of configuration actions and avoiding inconsistencies in intermediate states that could result from separate writes.
[0029] Preferably, the steps of obtaining the verification result through slave calculation based on the communication message, performing corresponding operations, and generating response data conforming to the communication protocol further include: Initialize response data; The slave verification field is obtained by calculating the slave device based on the communication message. The ACK signal for the response data is obtained by comparing the slave verification field and the verification field. The specific rule is: if the slave verification field and the verification field are consistent, the ACK signal is set to 1; otherwise, the ACK signal is set to 0. Execute corresponding operations and update response data based on command data, ACK signals, and communication messages.
[0030] A secure verification-decision-execution link is established: By solidifying the process of calculating a local checksum, comparing it with the received checksum, and deciding whether to execute the operation based on the comparison result (ACK), the system logically and strictly guarantees that writing is only performed when the data is complete and error-free, fundamentally preventing erroneous data from taking effect. By generating a binary ACK signal as the core state of the response data, a clear success or failure indicator is provided to the host, enabling the host to instantly determine the transaction status and drive subsequent processes. The response data is generated using a progressively updating initialization method, providing a clear and flexible structural framework for the response message. This ensures that even if more information is needed in the future, it can be integrated orderly within this framework. The process clearly distinguishes between the two stages of communication integrity verification and business function execution, and forces their sequential execution. This design improves the clarity of the processing logic and the determinism of the system state, avoiding inconsistencies that may result from cross-execution.
[0031] Preferably, the step of obtaining the verification field through binary division further includes: The slave or master device parses the received message and obtains the instruction data, address data, length data, and data field; Determine whether any field in the instruction data, address data, length data, or data field is empty. If so, set the corresponding field to 0 and form the basic CRC data. The verification field is obtained by binary division based on the CRC base data.
[0032] Achieving flexibility and instruction adaptability in CRC verification: By dynamically judging and removing empty fields in the message according to actual instructions, it ensures that the basic data for CRC calculation can adapt to different operation types (such as read operations with no data field), so that the same verification algorithm can be universally and correctly applied to all communication scenarios.
[0033] Ensuring consistency and accuracy of verification: The underlying data structure for CRC calculation is clearly defined, eliminating the risk of inconsistent calculation sources between the sender and receiver due to missing or inconsistent padding of fields, thus guaranteeing the effectiveness and reliability of the verification comparison. By calculating CRC only on valid fields, unnecessary calculations or padding for non-existent or invalid fields are avoided, reducing processing overhead for slave or master devices and improving the overall efficiency of protocol parsing and verification. Decoupling CRC calculation from the specific semantic content of the message makes the verification mechanism an independent, clear, and uniformly regulated processing layer, improving the modularity of the protocol implementation and reducing the complexity of verification logic caused by instruction set expansion.
[0034] Preferably, the step of performing the corresponding operation based on the instruction data, ACK signal, and communication message further includes: If the instruction data is write data or write register and the ACK signal is 1, the slave device will write the data field of the communication message into the slave device's address data (address data + length data - 1). If the instruction data is to read data or read register and the ACK signal is 1, the data field of the acknowledgment data is the content of the data read by the slave device, and the length of the acknowledgment data is the length of the data field of the acknowledgment data.
[0035] Substantive data write or read operations can only be performed when the ACK signal is 1. This establishes a clear security gating mechanism, preventing erroneous or unverified data from contaminating storage space or registers. For write operations, the complete write address range is explicitly calculated based on the starting address and length. This precisely translates the protocol layer's logical description into physical operations on memory or registers, enabling batch writes of consecutive addresses with a single instruction, thus improving configuration efficiency. For read operations, the response data must contain the actual content read, and its actual length is filled into the length field of the response message. This ensures that the response message itself is structurally complete and information is clear, allowing the host to correctly parse and use the data without relying on other contexts, improving protocol independence and interoperability. The execution of write data, write register, read data, read register operations, and response construction are all summarized under the same judgment framework based on instructions and ACK signals. This simplifies the slave's state machine or processing logic, improving firmware code reusability and system reliability.
[0036] Preferably, it further includes: If the instruction data is to read a register and the length of the communication message is greater than 1 and the ACK signal is 1, the length of the acknowledge data is the number of registers, the address data of the acknowledge data is the starting address of the register, and the data field of the acknowledge data is the data of the corresponding register.
[0037] By returning data from multiple consecutive registers in a single read request, multiple discrete request and response interactions are merged into a single transaction, reducing protocol overhead and communication latency, and significantly improving the efficiency of batch parameter reading. Explicitly including the number of registers and their starting addresses in the response data ensures that the response message itself fully defines the range and order of the returned data. The host can accurately parse this data without relying on external context, improving independence and reliability. Returning the values of multiple registers as a complete data field within the same transaction and accepting unified verification guarantees that the host obtains a snapshot of synchronized parameters at a specific moment, avoiding potential inconsistencies in intermediate states during reading.
[0038] Preferably, the step of obtaining the communication transaction result through host processing based on the response data further includes: If the instruction data of the response data is write data or write register, further check the ACK signal of the response data. If the ACK signal of the response data is 0, further check whether the remaining number of times to send the communication message is greater than 0. If it is greater than 0, the master sends the communication message to the slave. After the sending is completed, the remaining number is decremented by 1. If the instruction data is to read data or read a register and the ACK signal is 1, the host verification field is obtained by binary division based on the acknowledgment message. The verification field is compared with the verification field of the acknowledgment data. The specific rules are as follows: if they do not match, it is further determined whether the remaining number of times to send the communication message is greater than 0. If it is greater than 0, the host sends the communication message to the slave and decrements the remaining number by 1 after sending. If they match, the host operates on the data field of the acknowledgment data.
[0039] By having the host actively verify read data and determine the success or failure of a write operation based on the ACK, the responsibility for reliability assurance is ultimately anchored to the host, forming a control loop of request, response, verification, and decision-making. This is the core logic for achieving high-security communication. For two different types of errors—write failure (ACK=0) and read data verification failure—a unified retransmission judgment framework based on the remaining number of attempts is incorporated. It possesses intelligent error correction capabilities, automatically repairing temporary transmission errors within a limited number of retries, improving the success rate and robustness of communication. By introducing a clear upper limit on the remaining number of attempts, infinite repetition loops caused by faults are avoided, ensuring that the system can still release resources or switch states in abnormal situations, improving system controllability and stability. Converging the judgment of failed retransmissions for both write and read operations into a single simple rule of checking if the remaining number of attempts is >0 simplifies the host-side state machine design, reducing implementation complexity and maintenance costs. It is explicitly stipulated that the host can only ultimately operate on the data field after the data verification is completely consistent.
[0040] Second Embodiment A second aspect of the present invention provides a high-efficiency and high-security communication device based on a serial port, comprising: The serial port transmission module is used to transmit communication messages via the serial port; The serial port receiving module is used to receive communication messages or response data via the serial port. The serial port receive verification module is used to obtain a 32-bit local verification value by binary division based on the content of the received communication message or response message, and compare the local verification value with the received verification field to obtain the verification result. The response generation module is used to perform corresponding read or write operations based on instruction data and address data when the verification result is successful, and to generate response data that conforms to the communication protocol. The response data includes an ACK signal used to identify the result of the receiver receiving the data. The result processing module is used to process and obtain the final communication transaction result based on the received response data and verification results. The message construction module is used to construct communication messages or response messages that conform to a predetermined communication protocol. The communication protocol includes at least instruction data for distinguishing operation types, address data for indicating the start position of the operation, length data for indicating the amount of operation data, data fields, and a verification field generated based on the message content.
[0041] By establishing six dedicated modules, the abstract communication protocol and interaction process are transformed into explicit and executable hardware logic or software units, providing a clear architectural blueprint for the physical implementation of the method. Each module has a clear responsibility and is sequentially connected, forming an efficient, unidirectional communication transaction processing pipeline, reducing state conflicts and logical coupling, and improving throughput and real-time performance. A dedicated serial port receiving and verification module independently undertakes CRC calculation and comparison tasks, ensuring the focus, consistency, and high reliability of this critical security operation, avoiding vulnerabilities or delays that may be introduced due to functional overlap. Each module is functionally cohesive and has clearly defined interfaces, making the debugging, upgrading, or replacement of individual modules feasible and convenient, significantly reducing system maintenance complexity and long-term evolution costs. As the physical carrier of the method, this device not only fully realizes all the methodological advantages such as protocol interaction, batch processing, and verification retransmission, but also, through a stable modular architecture, ensures that these advantages are solidified, reproduced, and reliably executed in real products, ultimately achieving the system-level goal of efficient and highly secure communication.
[0042] Third Embodiment A third aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the efficient and secure serial port-based communication method of any of the preceding claims.
[0043] By transforming the aforementioned efficient and secure communication method into a computer program that can run on standard electronic devices, the communication scheme achieves high portability and convenient deployment, enabling any hardware platform with basic computing capabilities to quickly acquire the advanced serial communication capabilities. The programmatic execution of this method on a general-purpose processor ensures the accuracy and consistency of communication transaction processing, as well as the reliable reproduction of the complete logic of requests, responses, and verifications, thereby solidifying the protocol's efficiency and security advantages at the software level.
[0044] In the description of this application, it should be noted that the terms "inner" and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship commonly used when the product is in use. They are used only for the convenience of describing this application and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application. Furthermore, the terms "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0045] It should also be noted that, unless otherwise explicitly specified and limited, the terms "setup" and "connection" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0046] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific identification content executed by the system and device described above can be referred to the corresponding process in the foregoing method embodiments.
[0047] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings, but the present invention is not limited to the above embodiments. Even if various changes are made to the present invention, if these changes fall within the scope of the claims of the present invention and their equivalents, they shall still fall within the protection scope of the present invention.
Claims
1. A high-efficiency and high-security communication method based on a serial port, applied to a communication device of the serial port, including a host and a slave, characterized in that, include: A communication protocol is constructed for data communication between the host and the slave. The communication protocol includes at least instruction data for distinguishing operation types, address data for indicating the start position of the operation, length data for indicating the amount of operation data, a data field, and a check field generated based on the message content for identifying the ACK signal of the receiver receiving the data result. The check field is obtained as a 32-bit check field through binary division. To complete a communication transaction, the communication transaction shall include at least the following steps: The host constructs communication messages conforming to the communication protocol; The communication message is transmitted to the slave device via a serial port. Based on the communication message, the slave device calculates and obtains the verification result and performs corresponding operations; It generates response data conforming to the communication protocol and transmits the response data to the host via the serial port. Based on the response data, the host processes and obtains the communication transaction result.
2. The high-efficiency and high-security communication method based on a serial port according to claim 1, characterized in that, The step of constructing a communication message conforming to the communication protocol through the host further includes: If the instruction data is write data, the address data is the starting position of the write data, the length data is the length of the write data, the data field is the content of the write data, and the verification field is obtained based on the instruction data, the address data, the length data, and the data field; If the instruction data is read data, the address data is the starting position of the read data, the length data is the length of the read data, and the verification field is obtained based on the instruction data, the address data, and the length data; If the instruction data is to write to the register, the address data is the register address of the slave device, the data field is the content to be written to the register, the length data is the length of the data field, and the verification field is obtained based on the instruction data, the address data, the length data, and the data field. If the instruction data is a read register, the address data is the address of the slave device being read from the register, the length data is the preset length to be read, and the verification field is obtained based on the instruction data, the address data, and the length data.
3. The high-efficiency and high-security communication method based on a serial port according to claim 2, characterized in that, Further includes: If the instruction data is a write register and the write register is multiple addresses that are consecutive, the length data is the number of registers to be written, and the data field sequentially contains the data corresponding to each of the multiple registers.
4. The efficient and secure serial port-based communication method according to claim 1, characterized in that, The steps of obtaining the verification result through the slave device based on the communication message, performing corresponding operations, and generating response data conforming to the communication protocol further include: Initialize the response data; Based on the communication message, the slave verification field is obtained through slave calculation. The ACK signal of the response data is obtained by comparing the slave verification field and the verification field. The specific rule is: if the slave verification field and the verification field are consistent, the ACK signal is set to 1; otherwise, the ACK signal is set to 0. Based on the instruction data, the ACK signal, and the communication message, perform the corresponding operation and update the response data.
5. The efficient and secure communication method based on a serial port according to claim 1, characterized in that, The step of obtaining the verification field through binary division further includes: The slave device or the master device parses the received message and obtains instruction data, address data, length data, and data fields; Determine whether any field in the instruction data, address data, length data, or data field is empty. If so, the corresponding field is 0 and constitutes the basic CRC data. The verification field is obtained by binary division based on the CRC base data.
6. The efficient and secure communication method based on a serial port according to claim 4, characterized in that, The step of performing corresponding operations based on the instruction data, the ACK signal, and the communication message further includes: If the instruction data is write data or write register and the ACK signal is 1, the slave device writes the data field of the communication message to the slave device's address data to (the address data + the length data - 1). If the instruction data is read data or read register, the data field of the response data is the content of the slave read data, and the length of the response data is the length of the data field of the response data.
7. The efficient and secure communication method based on a serial port according to claim 6, characterized in that, Further includes: If the instruction data is to read a register and the length of the communication message is greater than 1, and the ACK signal is 1, the length of the response data is the number of registers, the address data of the response data is the starting address of the register, and the data field of the response data is the data of the corresponding register.
8. The efficient and secure communication method based on a serial port according to claim 1, characterized in that, The step of obtaining the communication transaction result through the host based on the response data further includes: If the instruction data of the response data is write data or write register, the ACK signal of the response data is further determined. If the ACK signal of the response data is 0, the remaining number of times to send the communication message is greater than 0. If it is greater than 0, the host sends the communication message to the slave. After the sending is completed, the remaining number of times is decremented by 1. If the instruction data is read data or read register, the host verification field is obtained by binary division based on the response message; the verification field is compared with the verification field of the response data, and the specific rule is as follows: if they are inconsistent, it is further determined whether the remaining number of times to send the communication message is greater than 0. If it is greater than 0, the host sends the communication message to the slave, and after sending, the remaining number is decremented by 1; if they are consistent, the host operates on the data field of the response data.
9. A high-efficiency and high-security communication device based on a serial port, characterized in that, include: A serial port transmission module is used to transmit the communication messages via a serial port; The serial port receiving module is used to receive communication messages or response data via the serial port. The serial port receive verification module is used to obtain a 32-bit local verification value by binary division based on the content of the received communication message or response message, and compare the local verification value with the received verification field to obtain the verification result. The response generation module is used to perform corresponding read or write operations according to instruction data and address data when the verification result is passed, and generate response data that conforms to the communication protocol. The response data includes an ACK signal for identifying the result of the receiver receiving the data. The result processing module is used to process and obtain the final communication transaction result based on the received response data and the verification result. The message construction module is used to construct communication messages or response messages that conform to a predetermined communication protocol. The communication protocol includes at least instruction data for distinguishing operation types, address data for indicating the start position of the operation, length data for indicating the amount of operation data, data fields, and a verification field generated based on the message content.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is executed by the processor, it implements the steps of the efficient and secure serial port-based communication method as described in any one of claims 1-8.