Serial port data acquisition device and method
By integrating a serial communication module, a microcontroller, and a storage medium, the serial data acquisition device solves the problem of relying on a computer for serial data acquisition, and realizes automated and convenient data acquisition and storage, which is suitable for a variety of scenarios.
Patent Information
- Application Number
- CN202511689760.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2026-02-27
AI Technical Summary
In existing technologies, serial port data acquisition relies on computers and host computer software, which makes operation inconvenient in production lines, outdoors, or in scenarios where the device under test is mobile.
Design a serial port data acquisition device that integrates a serial communication module, a microcontroller, and a storage medium to achieve automatic data acquisition and real-time writing to a log file. The device includes a baud rate configuration module and an alarm module to adapt to different devices and scenarios.
It achieves automatic acquisition and real-time writing of serial port data without relying on a computer or host computer software, improving the convenience of acquisition and the scope of application, and meeting the needs of different scenarios.
Smart Images

Figure CN121579285A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and particularly relates to a serial port data acquisition device and method. BACKGROUND
[0002] In the development, testing and abnormal problem analysis process of products such as televisions, serial port printing LOG (log) is an important basis for analyzing problems. Technical personnel can locate the abnormal reason according to the LOG log file and quickly solve the problem.
[0003] At present, technical personnel usually collect serial port data based on a computer connected to the measured device, and need to manually configure the host computer software on the computer to record. It is very inconvenient to operate in the scene of production line, outdoor or measured device with mobile demand.
[0004] In summary, how to improve the convenience of serial port data acquisition has become a technical problem to be solved in the field. SUMMARY
[0005] The main purpose of the present application is to provide a serial port data acquisition device and method, which aims to improve the convenience of serial port data acquisition.
[0006] To achieve the above purpose, the present application provides a serial port data acquisition device, which comprises: a serial port communication module, a microcontroller and a storage medium connected in sequence. The serial port communication module is used for receiving serial port data transmitted by a measured device. The microcontroller is used for creating a log file in the storage medium and writing the serial port data into the log file in real time.
[0007] In an embodiment, the serial port data acquisition device further comprises: A baud rate configuration module connected with the microcontroller, used for setting the communication parameters of the serial port communication module.
[0008] In an embodiment, the baud rate configuration module is a dial switch.
[0009] In an embodiment, the serial port communication module is a UART (Universal Asynchronous Receiver / Transmitter, asynchronous receiver / transmitter) serial port of TTL (Transistor-Transistor Logic, transistor-transistor logic) level.
[0010] In an embodiment, the microcontroller and the storage medium are connected based on a storage interface module.
[0011] In an embodiment, the storage interface module is an SPI (Serial Perripheral Interface) interface or an SDIO (Secure Digital Input and Output) interface, and the storage medium is a TF (Trans-flash) card, a U disk, an SD (Secure Digital) card, a Flash or a hard disk.
[0012] In an embodiment, the microcontroller runs a FatFS (Fat FileSystem) file system module, which is used to create, write and manage the log file in the storage medium.
[0013] In an embodiment, the serial port data acquisition device further comprises an alarm module, which is connected with the microcontroller. The microcontroller is further configured to, during writing of the serial port data into the log file, if it is detected that the storage space of the storage medium is insufficient or a write error occurs, instruct the alarm module to output an alarm signal and pause data writing. The alarm module is configured to output an alarm prompt after receiving the alarm signal.
[0014] In addition, to achieve the above object, the application further provides a serial port data acquisition method, which is applied to the serial port data acquisition device as described above, and comprises a serial port communication module, a microcontroller and a storage medium connected in sequence; the serial port data acquisition method comprises the following steps: Receiving serial port data transmitted by a device under test through the serial port communication module; Creating a log file in the storage medium through the microcontroller and writing the serial port data into the log file in real time.
[0015] In an embodiment, after the step of creating a log file in the storage medium through the microcontroller and writing the serial port data into the log file in real time, the method further comprises the following steps: When it is detected that the size of a storage file in the log file reaches a preset file threshold value or the writing time length of the serial port data reaches a preset time length threshold value, creating a new log file in the storage medium through the microcontroller and writing new serial port data into the new log file.
[0016] The serial port data acquisition device provided in the application comprises a serial port communication module, a microcontroller and a storage medium connected in sequence; the serial port communication module is configured to receive serial port data transmitted by a device under test; and the microcontroller is configured to create a log file in the storage medium and write the serial port data into the log file in real time.
[0017] In conclusion, the serial port data acquisition device provided in the application integrates the serial port communication module, the microcontroller and the storage medium, realizes automatic acquisition of serial port data of the device under test and real-time writing into a log file, does not need to rely on a computer and upper machine software, improves the convenience of serial port data acquisition, and meets the demand for serial port data acquisition in different scenarios. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and serve to explain the principles of the application together with the specification.
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced hereinafter. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.
[0020] Figure 1 A module structure schematic diagram provided for the serial port data acquisition device embodiment one of the application; Figure 2 A hardware function block diagram schematic diagram provided for the serial port data acquisition device embodiment one of the application; Figure 3 A running flowchart schematic diagram provided for the serial port data acquisition device embodiment one of the application; Figure 4 A flowchart schematic diagram of the serial port data acquisition method of the embodiment of the application; Figure 5 Another flowchart schematic diagram of the serial port data acquisition method of the embodiment of the application.
[0021] The object implementation, functional features and advantages of the application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0022] It should be understood that the specific embodiments described here are only used to explain the technical solutions of the application, and are not used to limit the application.
[0023] In the product development, testing and abnormal problem analysis process of a television and the like, serial port printing LOG is an important basis for analyzing problems, and a technician can locate abnormal reasons according to the LOG log file and quickly solve problems.
[0024] At present, the technical personnel usually collects serial port data based on computer connection of the measured equipment, and needs to manually configure the host computer software on the computer to record, which is very inconvenient in the production line, outdoor or the scene where the measured equipment has mobile demand.
[0025] Therefore, how to improve the convenience of serial port data collection has become a technical problem to be solved in the field.
[0026] The embodiment of the application provides a kind of serial port data acquisition device, which includes: serial port communication module, microcontroller and storage medium connected in sequence;Serial port communication module is used to receive the serial port data transmitted by measured equipment;Microcontroller is used to create log file in storage medium, and real-time write serial port data into log file.
[0027] Therefore, the serial port data acquisition device in the embodiment of the application realizes the automatic collection of the serial port data of the measured equipment and the real-time writing function of log file by integrating serial port communication module, microcontroller and storage medium, without relying on computer and host computer software, improve the convenience of serial port data collection, meet the demand of serial port data collection in different scenes.
[0028] Therefore, the serial port data acquisition device in the embodiment of the application realizes the automatic collection of the serial port data of the measured equipment and the real-time writing function of log file by integrating serial port communication module, microcontroller and storage medium, without relying on computer and host computer software, improve the convenience of serial port data collection, meet the demand of serial port data collection in different scenes. Figure 1 , Figure 1 It is the module structure schematic diagram of the first embodiment of the serial port data acquisition device of the application.
[0029] In the embodiment, the serial port data acquisition device includes: serial port communication module, microcontroller and storage medium connected in sequence; Serial port communication module is used to receive the serial port data transmitted by measured equipment; Microcontroller is used to create log file in storage medium, and real-time write serial port data into log file.
[0030] In this embodiment, the serial port data acquisition device is an electronic device capable of acquiring and storing data transmitted by the device under test (DUT) via a serial port. It can be applied to product development, testing, and anomaly analysis scenarios for DUT devices such as PLCs (Programmable Logic Controllers), PCs (Personal Computers), and TVs (Televisions), achieving data acquisition and storage without relying on a computer. The serial communication module is a functional module in the serial port data acquisition device that establishes a connection with the serial port of the DUT and receives data transmitted by the DUT. The microcontroller unit (MCU) is a functional module in the serial port data acquisition device with data processing and instruction execution capabilities, coordinating the work of various modules. The storage medium is a carrier for storing log files created by the microcontroller and the serial port data written, possessing a certain storage capacity and data read / write stability.
[0031] In the serial port data acquisition device, the serial communication module, microcontroller, and storage medium are connected sequentially to realize a complete process of receiving and storing data from the device under test (DUT). Specifically, the serial communication module establishes a physical communication connection with the serial port of the DUT. During operation, the DUT sends serial port data (such as device operating status information, abnormal prompts, etc.) to the serial communication module according to its own serial communication protocol, ensuring that the serial communication module can accurately receive the serial port data output by the DUT. The microcontroller receives the serial port data from the serial communication module and creates a log file that conforms to the data recording format in the storage medium. Then, it continuously writes the received serial port data into the created log file according to real-time requirements. The entire process requires no manual intervention, realizing automated serial port data acquisition and recording.
[0032] In one feasible implementation, the serial port data acquisition device can automatically record data each time it is powered on. That is, the microprocessor automatically creates a log file after each power-on. The created log file can be named according to specific naming rules, such as naming the log file according to the rules that include the acquisition date, time, and device number under test. The log file adopts a common text format, such as TXT (text file) format, which is convenient for technicians to open and analyze using conventional software.
[0033] Thus, by integrating a serial communication module, a microcontroller, and a storage medium, the serial port data acquisition device realizes the function of automatically acquiring serial port data of the device under test and writing it to a log file in real time. It does not rely on a computer and host computer software, which improves the convenience of serial port data acquisition and meets the needs of serial port data acquisition in different scenarios.
[0034] In one feasible embodiment, the serial port data acquisition device further includes: The baud rate configuration module connects to the microcontroller and is used to set the communication parameters of the serial communication module.
[0035] In this embodiment, the baud rate configuration module is a functional module used to set the communication parameters of the serial communication module. The baud rate of the serial communication can be adjusted through this baud rate configuration module to ensure that the serial communication module and the serial communication rate of the device under test are consistent, so as to achieve accurate data transmission. The communication parameters are the serial communication baud rate. In addition, based on the actual application scenario, the communication parameters may also include data bits, stop bits, parity bits, etc.
[0036] Because the serial communication parameters of different devices under test vary—for example, some TV products have a serial port baud rate of 9600bps while others have 115200bps—if the communication parameters of the serial communication module do not match those of the device under test, it will lead to data reception errors or failure to receive data. Therefore, through the baud rate configuration module, technicians can pre-set the baud rate and other communication parameters of the serial communication module according to the serial port parameter requirements of the device under test. The microcontroller then transmits the configuration parameters to the serial communication module to ensure that the serial communication module and the serial port of the device under test can communicate normally and accurately receive serial data.
[0037] In addition, in one feasible implementation, after the baud rate configuration module completes the parameter configuration, the device can automatically send test data frames to the device under test and receive feedback data frames from the device under test. If the feedback data frame is normal, the parameter configuration is determined to be correct, and an indicator light (such as a green light) can be used to indicate this. If the feedback data frame is abnormal or there is no feedback, the parameter configuration is determined to be incorrect, and an indicator light (such as a red light) or a buzzer alarm can be used to indicate this, so as to help technicians quickly verify the correctness of the parameter configuration and reduce the problem of acquisition failure caused by parameter configuration errors.
[0038] Therefore, the communication parameters of the serial communication module can be flexibly adjusted through the baud rate configuration module, enabling the serial data acquisition device to adapt to devices under test of different brands, models, and serial port parameter settings. This eliminates the need to design a dedicated acquisition device for each device under test, thus expanding the applicability of the device.
[0039] In one feasible embodiment, the baud rate configuration module is a DIP switch.
[0040] In this embodiment, the baud rate configuration module is a DIP switch. The DIP switch, through different combinations of on / off states of its various switching units, corresponds to different communication parameters. Specifically, the DIP switch can be a rotary DIP switch or a slide DIP switch. Taking baud rate as an example, since each switching unit of the DIP switch has only two states (on and off), a pre-defined encoding rule can be used to establish a correspondence between the switch combination states and specific baud rate values. For example, a 4-bit DIP switch can be set to 16 different combination states, corresponding to 16 different baud rate values (e.g., 0000 corresponds to 2400bps, 0001 corresponds to 4800bps, 0010 corresponds to 9600bps, etc.). Technicians, according to the serial port baud rate requirements of the device under test, and following the pre-defined encoding rule, toggle the corresponding switching unit of the DIP switch to place the DIP switch in the combination state corresponding to the target baud rate. The DIP switch then transmits the electrical signal corresponding to this state to the microcontroller. The microcontroller parses the corresponding baud rate value according to the pre-defined encoding rule and then configures the baud rate of the serial communication module to achieve baud rate matching with the device under test.
[0041] For example, during the device design phase, baud rate encoding rules can be pre-defined for the DIP switches and written into the microcontroller's program. Simultaneously, the encoding rule descriptions can be marked on the device casing near the DIP switches for easy reference by technicians. After obtaining the serial port baud rate of the device under test, the technicians refer to the encoding rule description of the DIP switches to find the corresponding DIP switch combination state. Then, they manually toggle the switch units of the DIP switches to bring the entire switch to the combination state corresponding to that baud rate. After the device is powered on, the microcontroller automatically reads the state of the DIP switches. By reading the pin levels corresponding to each switch unit of the DIP switches, it obtains the combination state of the DIP switches and, based on the internally stored encoding rules, parses the baud rate value corresponding to that combination state. Subsequently, it sends a configuration command to the serial communication module to set the baud rate of the serial communication module to the corresponding baud rate value. At this point, the serial communication module can perform normal serial communication with the device under test.
[0042] In one feasible embodiment, the serial communication module is a TTL level UART serial port.
[0043] In this embodiment, TTL level is a transistor-to-transistor logic level standard, a commonly used level specification in digital circuits. It features clear level signals, fast transmission speed, and strong anti-interference capability, making it suitable for short-distance data transmission scenarios and widely used in communication between electronic components such as microcontrollers and sensors. UART serial port is the serial port corresponding to a universal asynchronous transceiver, an asynchronous serial communication interface that does not require clock signal synchronization. Data transmission is achieved through pre-agreed communication parameters such as baud rate, data bits, stop bits, and parity bits, enabling bidirectional data communication. It has a simple structure and low cost.
[0044] TTL level UART serial ports have extremely high compatibility with microcontrollers. Most microcontrollers (such as STM32, 51 series, and PIC series) have built-in UART interfaces, allowing direct hardware connection to this serial communication module without the need for additional level conversion chips or interface adapter circuits, simplifying device hardware design. Furthermore, the TTL level signal transmission speed meets the serial data transmission requirements of most devices under test (such as TVs, MCUs, and PLCs), and in short-distance acquisition scenarios (such as when the device is mounted on the device under test or placed close to it), signal attenuation is minimal, resulting in stable data transmission. This serial communication module establishes a connection with the UART serial port of the device under test through its own UART interface, receives serial data transmitted from the device under test according to the TTL level standard, and then directly transmits the data to the microcontroller for subsequent processing, ensuring that data is not distorted or lost during transmission.
[0045] In addition, in one feasible implementation, the serial communication module adopts a multi-channel TTL level UART serial port. This module contains multiple independent UART serial port channels, each of which can be configured with communication parameters independently and connected to the serial ports of different devices under test. Thus, a single serial data acquisition device can simultaneously acquire serial data from multiple devices under test, improving data acquisition efficiency and making it suitable for scenarios that require simultaneous monitoring of the operating status of multiple devices.
[0046] In one feasible embodiment, the microcontroller is connected to the storage medium via a storage interface module.
[0047] In this embodiment, the storage interface module is a functional module that connects the microcontroller and the storage medium, providing a physical channel and communication protocol support for data transmission between the two, enabling the microcontroller to send instructions such as data writing, file reading, and storage status detection to the storage medium, while receiving operation result signals fed back by the storage medium.
[0048] Because the pin functions of a microcontroller and the interface type of a storage medium may differ—for example, microcontrollers typically provide interfaces such as SPI and SDIO, while storage media may require specific interface protocols for data reading and writing—direct connection may not enable normal communication. Therefore, a conversion circuit and drive logic that conforms to the microcontroller interface protocol and the storage medium interface protocol are integrated inside the storage interface module. This converts the instructions and data issued by the microcontroller into a format recognizable by the storage medium, and converts the feedback information from the storage medium into signals that the microcontroller can parse. This ensures that the microcontroller can stably and efficiently perform operations such as log file creation, data writing, and file reading on the storage medium, achieving reliable storage of serial port data.
[0049] For example, if the microcontroller supports the SPI interface and the storage medium is a TF card, then select the storage interface module with the SPI protocol; if the microcontroller supports the SDIO interface and the storage medium is an SD card, then select the storage interface module with the SDIO protocol, to ensure that the storage interface module can adapt to the interface requirements of both the microcontroller and the storage medium.
[0050] Therefore, the storage interface module can adapt to different interface types and communication protocols of microcontrollers and storage media, avoiding connection failures or communication failures caused by interface incompatibility. This allows microcontrollers to be flexibly paired with various types of storage media, while storage media can also be adapted to microcontrollers with different interfaces, improving the flexibility and compatibility of device hardware selection.
[0051] Furthermore, in one feasible implementation, the storage interface module is designed as a switchable multi-protocol interface module. The module integrates driver circuits for multiple interface protocols such as SPI, SDIO, USB (Universal Serial Bus), and I2C (Inter-Integrated Circuit), and is equipped with an interface selection switch, such as a DIP switch or button. Technicians can switch the working protocol of the storage interface module according to the actual type of storage medium selected, so that the module can adapt to different types of storage media. For example, switching to the SPI protocol to adapt to TF cards, and switching to the USB protocol to adapt to USB flash drives. In this way, a serial port data acquisition device can be flexibly matched with multiple storage media, improving the versatility and flexibility of the device.
[0052] In one feasible embodiment, the storage interface module is an SPI interface or an SDIO interface, and the storage medium is a TF card, USB flash drive, SD card, Flash or hard disk.
[0053] Different storage interface modules and storage media combinations are suitable for different data acquisition scenarios: SPI interfaces have relatively slow transmission speeds but simple hardware connections and strong compatibility, making them suitable for use with TF cards, Flash memory, and other storage media in scenarios where transmission speed requirements are not high and hardware cost control is strict; SDIO interfaces have fast transmission speeds and support high-speed data read and write, making them suitable for use with TF cards and SD cards in scenarios where both transmission speed and storage capacity requirements are high. The choice of storage media is determined by factors such as storage capacity requirements, portability requirements, and cost requirements of the acquisition scenario. TF cards and USB flash drives are highly portable and suitable for mobile data acquisition or scenarios requiring frequent changes in storage media; SD cards and hard drives have large storage capacities and are suitable for scenarios requiring long-term storage of large amounts of data; Flash memory has high stability and is suitable for scenarios where it is built into the device and does not require changing the storage media. By clarifying these specific types, the hardware selection of serial port data acquisition devices becomes clearer, meeting the actual needs of different scenarios.
[0054] Furthermore, in one feasible implementation, the microcontroller divides the received serial port data into data blocks of a fixed size (e.g., 1KB). After each data block is written to the log file, a checksum for that data block is immediately calculated. The checksum can be a CRC (Cyclic Redundancy Check) checksum or an MD5 (Message-Digest Algorithm 5) checksum. The calculated checksum is written to the end of the data block in the log file. When reading data subsequently, the checksum can be used to verify whether the data block is complete, further ensuring data reliability and avoiding the problem of data corruption going undetected due to partial failure of the storage medium.
[0055] Furthermore, in one feasible implementation, the storage interface module supports the AES (Advanced Encryption Standard) encryption algorithm or other encryption protocols, which can perform real-time encryption processing on log files written to the storage medium. Only with a preset decryption key can the log files be opened and viewed on other devices, preventing the collection of sensitive serial port data from being obtained by unauthorized personnel and ensuring data confidentiality.
[0056] In one feasible embodiment, the microcontroller runs a FatFS file system module, which is used to create, write, and manage log files in the storage medium.
[0057] In this embodiment, the FatFS file system module is an open-source FAT (FileAllocationTable) / exFAT file system module, which is suitable for various microcontroller platforms and can provide file management functions for storage media, supporting operations such as file creation, opening, reading, writing, closing, and deletion, as well as directory creation and management.
[0058] Since storage media, without a configuration system, consists only of raw storage blocks, microcontrollers cannot directly perform file creation or data writing operations; they can only perform low-level block read / write operations. This is complex and inconvenient for data management. The FatFS file system module addresses this by building a FAT / exFAT file system structure on the storage medium. This structure includes a boot sector, file allocation table, directory entries, and data area, dividing the storage blocks of the storage medium into organized files and directories. This allows the microcontroller to perform data operations on a file-by-file basis. Specifically, the FatFS file system module receives file operation commands from the microcontroller, such as creating log files or writing serial port data. It translates these commands into read / write operations on the underlying storage blocks of the storage medium, while managing file metadata such as filename, creation time, file size, and storage location. This ensures orderly file storage and fast access, achieving standardized and convenient management of serial port data.
[0059] For example, when the microcontroller needs to store serial port data, it sends a command to the FatFS file system module to create a log file. The command includes information such as the name of the log file, the file format, and the creation path. After receiving the command, the FatFS file system module creates a corresponding directory entry in the directory area of the storage medium, recording metadata such as the file name, creation time, initial file size, and the starting address of the storage data area. At the same time, it allocates an initial storage block for the file in the file allocation table, completing the creation of the log file. Then, the FatFS file system module sends a signal to the microcontroller that the file creation was successful.
[0060] After receiving serial data from the serial communication module, the microcontroller sends a data write command to the FatFS file system module. The FatFS file system module then sequentially writes the serial data to be written into the data area of the storage medium. Upon completion of the write operation, the FatFS file system module sends a successful write signal back to the microcontroller. If the write operation fails, such as due to insufficient storage space or data transmission errors, an error signal is sent, and the microcontroller takes appropriate action, such as pausing the write process or issuing an alarm. During data acquisition, the microcontroller can also perform other management operations on the log file through the FatFS file system module, such as file reading and file deletion.
[0061] In one feasible embodiment, the serial port data acquisition device further includes an alarm module, which is connected to the microcontroller; The microcontroller is also used to send an alarm signal to the alarm module indicator and suspend data writing if insufficient storage space or a write error is detected during the writing of serial port data to the log file. The alarm module is used to output an alarm prompt after receiving an alarm signal.
[0062] During serial port data acquisition, insufficient storage space or data write errors are common anomalies. If not detected and handled promptly, they can lead to data acquisition interruption or data loss. Therefore, while writing serial port data to the log file, the microcontroller monitors the storage medium's status in real time. Firstly, it periodically reads the total and used storage space of the storage medium through the storage interface module, calculating the remaining storage space. If the remaining storage space is less than a preset threshold (e.g., 10% of the total capacity), it is considered insufficient storage space. Secondly, after each data write to the storage medium, it receives the write result signal from the storage interface module (e.g., success, failure) or verifies the correctness of the written data through data verification. If the write result signal is a failure or the verification result is inconsistent, it is considered a write error. When any of the above anomalies is detected, the microcontroller immediately sends a corresponding alarm signal to the alarm module (e.g., one alarm signal for insufficient storage space, another for a write error), and simultaneously suspends the data write operation to prevent further serious problems from occurring. Upon receiving the alarm signal, the alarm module outputs an alarm prompt according to a preset alarm method, notifying technical personnel to handle the anomaly promptly. Alarm prompts can include indicator lights illuminating, a buzzer sounding, etc.
[0063] Therefore, the alarm module can promptly issue alarm prompts to technicians when the storage medium is running out of space or when a write error occurs, thus preventing the storage medium from becoming full and unable to continue collecting data due to failure to detect abnormalities in time, or causing a large amount of serial port data to be lost or log files to be corrupted due to continuous write errors, thereby ensuring the continuity of data collection and the integrity of the data.
[0064] Furthermore, in one feasible implementation, the serial port data acquisition device may also include a wireless communication module, specifically a WiFi (Wireless Fidelity) module and / or a Bluetooth module, which is connected to the microcontroller. While the microcontroller writes serial port data to the storage medium, it can transmit the serial port data in real time to a remote monitoring terminal, such as a mobile phone, tablet, or remote computer, via the wireless communication module. Technicians can remotely view the serial port data in real time without needing to go to the acquisition site to obtain the storage medium, improving the convenience of data acquisition, especially suitable for scenarios with harsh acquisition environments or where frequent access is difficult. When the device detects an anomaly, the microcontroller can also send an alarm signal through the wireless communication module.
[0065] For example, in one feasible implementation, the hardware functional block diagram of the serial port data acquisition device is as follows: Figure 2As shown, this serial data acquisition device includes a DC-DC (Direct Current-to-Direct Current) converter module, an oscillation circuit, a reset circuit, an MCU, a DIP switch, a TTL serial port, and a TF card. The MCU is connected to the DC-DC module, the oscillation circuit, the reset circuit, the DIP switch, the TTL serial port, and the TF card. The DC-DC module, the oscillation circuit, and the reset circuit are the basic circuits that ensure the operation of the MCU. The DC-DC module converts the external power supply voltage to provide the operating voltage for the serial data acquisition device, ensuring that each module can start and operate normally. The oscillation circuit generates a stable clock signal, which is transmitted to the MCU as the timing reference for various operations within the MCU, allowing the MCU to execute instructions and process data according to a precise timing rhythm. The reset circuit sends a reset signal to the MCU when the device starts up or when an abnormal situation occurs, restoring the MCU to its initial state and ensuring that the MCU can start working from a defined state, avoiding erroneous operation caused by abnormalities.
[0066] After receiving stable power and clock signals and completing a reset, the MCU begins a series of preparatory tasks, including initialization. Technicians adjust the DIP switch according to the baud rate requirements of the device under test's (DUT) serial port. The DIP switch transmits the corresponding electrical signal to the MCU. Upon receiving this signal, the MCU parses the corresponding TTL serial port baud rate value and configures the TTL serial port to match the baud rate of the DUT's serial port. Subsequently, when the DUT transmits serial data through its own serial port, the data is transferred to the TTL serial port, which then transmits the data to the MCU. Upon receiving the serial data from the TTL serial port, the MCU interacts with the TF card. The MCU sends instructions to the TF card through a suitable interface (such as SDIO) to create a compliant log file on the TF card. The received serial data is then written to this log file in real time, thus achieving serial data acquisition and storage.
[0067] In one feasible implementation, the operation flowchart of the serial port data acquisition device is as follows: Figure 3As shown, after the serial data acquisition device is powered on, the system clock is initialized first to ensure the correct timing logic of the entire device. After the system clock initialization is completed, the SDIO interface is initialized. The SDIO interface is the channel for data interaction between the MCU and the TF card. By initializing the SDIO interface, the working mode, transmission rate and other parameters of the interface are configured, enabling the MCU to establish a stable and efficient data transmission connection with the TF card. Then, FatFS is initialized. FatFS is a module used to manage the TF card file system. After FatFS is initialized, the MCU can perform file creation, writing and reading operations on the TF card. Then, the TTL serial port is initialized. In this step, the MCU will configure the TTL serial port according to the communication parameters such as the baud rate determined by the status read from the DIP switch, so that the TTL serial port can accurately receive the serial port data transmitted by the device under test according to the parameters matched with the serial port of the device under test.
[0068] After completing the above initialization steps, the MCU will read the state of the DIP switch and then set the baud rate of the TTL serial port to ensure that the communication parameters of the TTL serial port are consistent with those of the device under test. Then, the MCU will create a blank TXT file in the TF card as a carrier for storing serial port data. After creating the blank TXT file, the MCU will continuously monitor for serial port interrupts. If there is no serial port interrupt, it means that the device under test has not yet transmitted new serial port data, and the MCU will continue to monitor. When a serial port interrupt occurs, it means that the TTL serial port has received serial port data transmitted by the device under test. The MCU will write the received serial port data to the previously created TXT file to complete the serial port data writing operation.
[0069] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the serial port data acquisition device of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0070] This application also provides a serial port data acquisition method, which is applied to the serial port data acquisition device as described in the above embodiments. The serial port data acquisition device includes a serial communication module, a microcontroller, and a storage medium connected in sequence. Please refer to... Figure 4 The serial port data acquisition method includes steps S10~S20: Step S10: Receive serial port data transmitted by the device under test through the serial communication module; Step S20: Create a log file in the storage medium using the microcontroller and write serial port data to the log file in real time.
[0071] In this embodiment, the serial communication module, microcontroller, and storage medium are sequentially connected in the serial data acquisition device to realize a complete process of receiving and storing data from the device under test. Specifically, the serial communication module establishes a physical communication connection with the serial port of the device under test. During operation, the device under test sends serial port data (such as device operating status information, abnormal prompts, etc.) to the serial communication module according to its own serial communication protocol, ensuring that the serial communication module can accurately receive the serial port data output by the device under test. The microcontroller receives the serial port data from the serial communication module and creates a log file that conforms to the data recording format in the storage medium. Then, it continuously writes the received serial port data into the created log file according to real-time requirements. The entire process requires no manual intervention, realizing automated serial port data acquisition and recording.
[0072] Thus, by integrating a serial communication module, a microcontroller, and a storage medium, the serial port data acquisition device realizes the function of automatically acquiring serial port data of the device under test and writing it to a log file in real time. It does not rely on a computer and host computer software, which improves the convenience of serial port data acquisition and meets the needs of serial port data acquisition in different scenarios.
[0073] In addition, in one feasible implementation, when the microcontroller receives serial port data, it automatically adds a timestamp tag and a data type tag to each frame of data, and then writes the tagged data to a log file. During subsequent analysis, technicians can quickly locate the device status at a specific point in time through the timestamp and filter key data through the data type tag, such as only viewing fault alarm data, thereby improving data analysis efficiency.
[0074] In one feasible embodiment, such as Figure 5 As shown, step S20 may be followed by step S30: Step S30: When the microcontroller detects that the size of the stored file in the log file has reached a preset file threshold, or the writing time of the serial port data has reached a preset time threshold, a new log file is created in the storage medium, and the new serial port data is written to the new log file.
[0075] In actual data acquisition scenarios, if the files are not split, the single log file may become too large, increasing the difficulty of file transfer (such as copying to a computer) and analysis. Therefore, while continuously writing data, the microcontroller can simultaneously monitor the size of the current log file and the writing time of the current serial port data. When either indicator reaches a preset threshold, the microcontroller first closes the current log file, then creates a new log file according to the preset naming rules, and finally writes the subsequently received serial port data into the new log file.
[0076] For example, during the process of collecting serial port data, the microcontroller periodically reads the used space of the current log file, i.e. the file size, through the FatFS file system module at certain time intervals, and compares it with a preset file threshold. For example, if the file threshold is set to 1GB, writing continues when the current file size is 980MB, and the file switching condition is triggered when the file size reaches 1GB.
[0077] After creating the current log file, the microcontroller starts an internal timer to count the time taken to write the current file and compares it with a preset time threshold. For example, if the time threshold is set to 30 minutes, when the timer reaches 30 minutes, the file switching condition is triggered regardless of whether the current file size has reached the file threshold.
[0078] After the microcontroller triggers the file switching condition, it first stops writing data to the current log file, sends a file close command to the FatFS file system module, and completes the archiving of the current log file. At the same time, it creates a new log file. After the new file is successfully created, it writes the subsequent received serial port data (starting from the first frame of data received after closing the current file) to the new log file.
[0079] Therefore, by automatically splitting files, the size of individual log files is kept within an easily manageable range, preventing them from becoming too large. Technicians can quickly open files to view data during analysis, and the waiting time can be reduced when transferring files.
[0080] The serial port data acquisition method provided in this application, employing the serial port data acquisition device described in the above embodiments, can improve the convenience of serial port data acquisition. Compared with the prior art, the beneficial effects of the serial port data acquisition method provided in this application are the same as those of the serial port data acquisition device provided in the above embodiments, and other technical features in the serial port data acquisition method are the same as those disclosed in the serial port data acquisition device of the above embodiments, and will not be repeated here.
[0081] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a read-only memory. When the computer program is executed by a processing device, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0082] It should be understood that the various parts disclosed in the embodiments of this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0083] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0084] Computer program code for performing the operations of the embodiments of this application can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0085] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0086] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0087] The above are only some embodiments of this application and do not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the content of this application specification and drawings, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A serial port data acquisition device, characterized in that, The serial port data acquisition device includes: a serial port communication module, a microcontroller, and a storage medium connected in sequence; The serial communication module is used to receive serial data transmitted by the device under test; The microcontroller is used to create a log file in the storage medium and write the serial port data to the log file in real time.
2. The serial port data acquisition device as described in claim 1, characterized in that, The serial port data acquisition device also includes: A baud rate configuration module, connected to the microcontroller, is used to set the communication parameters of the serial communication module.
3. The serial port data acquisition device as described in claim 2, characterized in that, The baud rate configuration module is a DIP switch.
4. The serial port data acquisition device as described in claim 1, characterized in that, The serial communication module is a TTL level UART serial port.
5. The serial port data acquisition device as described in claim 1, characterized in that, The microcontroller is connected to the storage medium via a storage interface module.
6. The serial port data acquisition device as described in claim 5, characterized in that, The storage interface module is an SPI interface or an SDIO interface, and the storage medium is a TF card, USB flash drive, SD card, Flash or hard disk.
7. The serial port data acquisition device as described in claim 1, characterized in that, The microcontroller runs a FatFS file system module, which is used to create, write, and manage the log files in the storage medium.
8. The serial port data acquisition device as described in claim 1, characterized in that, The serial port data acquisition device also includes an alarm module, which is connected to the microcontroller. The microcontroller is also configured to, during the process of writing the serial port data to the log file, if it detects that the storage space of the storage medium is insufficient or a writing error occurs, send an alarm signal to the alarm module indicator light and suspend data writing. The alarm module is used to output an alarm prompt after receiving the alarm signal.
9. A serial port data acquisition method, characterized in that, The serial port data acquisition method is applied to the serial port data acquisition device as described in any one of claims 1 to 8, wherein the serial port data acquisition device includes a serial communication module, a microcontroller, and a storage medium connected in sequence. The serial port data acquisition method includes: The serial communication module receives serial data transmitted by the device under test. The microcontroller creates a log file in the storage medium and writes the serial port data to the log file in real time.
10. The serial port data acquisition method as described in claim 9, characterized in that, After the step of creating a log file in the storage medium via the microcontroller and writing the serial port data to the log file in real time, the method further includes: When the microcontroller detects that the size of the stored file in the log file has reached a preset file threshold, or that the writing time of the serial port data has reached a preset duration threshold, it creates a new log file in the storage medium and writes the new serial port data into the new log file.