A test method, device and equipment for a PC terminal analog serial port screen and a medium
By using a PC-based method to simulate a serial port screen, we solved the problems of low development efficiency caused by hardware damage to the serial port screen and data packaging and downloading. This enabled real-time data parsing and display, improving development efficiency and accuracy.
Patent Information
- Application Number
- CN202310341189.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-03-31
AI Technical Summary
In existing technologies, serial port screen development efficiency is reduced due to hardware damage and the additional time spent on data packaging and downloading.
By using a PC-based simulated serial port screen for testing, data parsing and display are achieved using a simulated serial port screen, avoiding hardware damage to physical serial port screens and the wasted time of data packaging and downloading, thus enabling real-time data parsing and display.
It improves the efficiency of serial port screen development, saves time and costs, and ensures the accuracy and stability of the development process.
Smart Images

Figure CN116383057B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of serial port screen technology, specifically relating to a test method, apparatus, equipment and medium for simulating a serial port screen on a PC. Background Technology
[0002] With the continuous development of serial port screen technology, serial port screens are now widely used. Users only need to design their UI (User Interface) and download it to the serial port screen, then connect to the lower-level machine via the serial port, and send relevant operation commands through the serial port screen to control the lower-level machine. The development of test data packages for serial port screens is often executed on a PC (Personal Computer), and after development, the test data packages are transmitted to the serial port screen for testing and verification.
[0003] Specifically, after a certain function is developed, the data is packaged and downloaded to a serial port screen via a serial port or USB interface for testing and verification. After all functions pass the tests, the developers determine that the serial port screen testing phase is complete.
[0004] However, in existing technologies, serial port display hardware is subject to wear and tear, such as external damage like screen cracks and broken cables, as well as internal chip damage caused by static electricity or overvoltage. Therefore, development progress may be affected or even halted by hardware failures. Furthermore, data packet transmission incurs additional time, reducing the efficiency of serial port display development and testing. Therefore, how to avoid the additional time spent on hardware damage and data download, thus reducing the development efficiency of serial port displays, is a pressing issue that needs to be addressed in this field. Summary of the Invention
[0005] This application provides a testing method, apparatus, device, and medium for simulating a serial port screen on a PC. The aim is to solve the problem in existing technologies where testing and verification require a physical serial port screen, which can lead to hardware damage and additional time consumption due to data download, thus reducing development efficiency. The PC-based serial port screen testing method allows for real-time data parsing and display, enabling users to view data more intuitively and identify anomalies more quickly and accurately, thus facilitating better program debugging. Since no physical serial port screen device is required, the problem of reduced development efficiency due to hardware damage and data download is avoided, saving time and costs.
[0006] In a first aspect, embodiments of this application provide a test method for simulating a serial port screen on a PC, the method comprising:
[0007] In response to the interactive interface design operation of the simulated serial port screen, the format of the test data packet of the simulated serial port screen is determined, as well as the basic running data of the simulated serial port screen is determined; wherein, the basic running data includes: generating a temporary array, generating a callback instruction for running at a certain time, and generating a serial port data parsing function;
[0008] Based on the aforementioned operational data, run a simulated serial port screen locally;
[0009] Run the serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port;
[0010] The serial port receives the data to be parsed from the data interaction terminal, stores the data to be parsed in a temporary array, runs the serial port data parsing function in the simulated serial port screen to parse the data to be parsed, and updates the display on the page of the simulated serial port screen.
[0011] If the update fails, it indicates an error in the simulated serial port screen test.
[0012] Furthermore, after running the serial port data parsing function in the simulated serial port screen to parse the data to be parsed, and updating the display on the simulated serial port screen, the method further includes:
[0013] If the update is successful, the operation command is received through the simulated serial port screen, and the command content is sent to the data interaction terminal through the serial port.
[0014] If no feedback information is received from the data interaction terminal, the simulated serial port screen test is determined to be abnormal.
[0015] Furthermore, the system receives the data to be parsed from the data interaction terminal via the serial port, stores the data to be parsed in a temporary array, and runs the serial port data parsing function in the simulated serial port screen to parse the data, including:
[0016] The serial port receives the data to be parsed from the data interaction terminal and writes it into a temporary storage array.
[0017] The system identifies whether the temporary array is empty based on the callback instruction that runs on a timer.
[0018] If not empty, the serial port data parsing function is called to parse the data to be parsed in the temporary array one by one.
[0019] Furthermore, the data interaction terminal includes a physical lower-level machine and / or a virtual lower-level machine;
[0020] Accordingly, the serial port initialization code is run to connect the simulated serial port screen to the data interaction terminal via the serial port, including:
[0021] Run the serial port initialization code and display the serial port selection interface;
[0022] In response to a serial port selection operation, the simulated serial port screen is connected to the physical lower-level machine and / or the virtual lower-level machine based on the selected serial port.
[0023] Furthermore, if it is the virtual lower-level machine, then before receiving the data to be parsed from the data interaction terminal through the serial port, the method further includes:
[0024] Configure the virtual lower-level machine with the data to be transmitted and parsed, and the transmission period for the data to be parsed.
[0025] Furthermore, after parsing the data to be parsed in the simulated serial port screen, the method further includes:
[0026] If parsing fails, a verification failure message is generated, and the serial port data parsing function in the basic data is redesigned based on the interactive interface.
[0027] Secondly, embodiments of this application provide a test device for simulating a serial port screen on a PC, the device comprising:
[0028] The basic data determination module is used to respond to the interactive interface design operation of the simulated serial port screen, determine the format of the test data packet of the simulated serial port screen, and determine the basic running data of the simulated serial port screen; wherein, the basic running data includes: generating a temporary array, generating a callback instruction for running at a certain time, and generating a serial port data parsing function.
[0029] A simulated serial port screen operation module is used to run a simulated serial port screen locally based on the aforementioned basic operation data;
[0030] The serial port connection module is used to run serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port;
[0031] The data parsing module is used to receive the data to be parsed from the data interaction terminal through the serial port, store the data to be parsed in a temporary array, and run the serial port data parsing function in the simulated serial port screen to parse and process the data to be parsed, and update the display on the page of the simulated serial port screen.
[0032] The test result determination module is used to determine that the simulated serial port screen test is abnormal if the update display fails.
[0033] Furthermore, the device also includes an instruction sending module, which is used for:
[0034] If the update is successful, the operation command is received through the simulated serial port screen, and the command content is sent to the data interaction terminal through the serial port.
[0035] If no feedback information is received from the data interaction terminal, the simulated serial port screen test is determined to be abnormal.
[0036] Thirdly, embodiments of this application provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0037] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0038] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.
[0039] In this embodiment, in response to the interactive interface design operation of the simulated serial port screen, the format of the test data packet of the simulated serial port screen and the basic running data of the simulated serial port screen are determined. The basic running data includes: generating a temporary array, generating a callback instruction to run at a certain time, and generating a serial port data parsing function. Based on the basic running data, the simulated serial port screen is run locally. Serial port initialization code is run to connect the simulated serial port screen to the data interaction terminal via the serial port. Data to be parsed from the data interaction terminal is received through the serial port and stored in the temporary array. The serial port data parsing function is run in the simulated serial port screen to parse and process the data to be parsed, and the page of the simulated serial port screen is updated and displayed. If the update and display fail, the simulated serial port screen test is determined to be abnormal. Through the above PC-side simulated serial port screen testing method, the simulated serial port screen can be used to parse and display data in real time, allowing users to view the data more intuitively and discover anomalies more quickly and accurately, thus enabling better program debugging. Since no physical serial port screen device is required, the development efficiency of serial port screens is reduced due to hardware failure and the additional time spent on data packaging and downloading, thus saving time and costs. Attached Figure Description
[0040] Figure 1 This is a flowchart illustrating the PC-side simulated serial port screen testing method provided in Embodiment 1 of this application;
[0041] Figure 2This is a schematic diagram of the structure of the PC-side simulated serial port screen provided in Embodiment 1 of this application;
[0042] Figure 3 This is a schematic diagram of the method for PC-side simulated serial port screen to interact with lower-level machine provided in Embodiment 1 of this application;
[0043] Figure 4 This is a flowchart illustrating the PC-side simulated serial port screen testing method provided in Embodiment 2 of this application;
[0044] Figure 5 This is a schematic diagram of the structure of the PC-side simulated serial port screen test device provided in Embodiment 3 of this application;
[0045] Figure 6 This is a schematic diagram of the structure of the electronic device provided in Embodiment 4 of this application. Detailed Implementation
[0046] To make the objectives, technical solutions, and advantages of this application clearer, specific embodiments of this application will be described in further detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely for explaining this application and not for limiting it. It should also be noted that, for ease of description, only the parts relevant to this application are shown in the drawings, not all of them. Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe operations (or steps) as sequential processes, many of these operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but may also have additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0047] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0048] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0049] The following description, in conjunction with the accompanying drawings, details the testing method, apparatus, equipment, and medium for a PC-based simulated serial port screen provided in this application, through specific embodiments and application scenarios.
[0050] Example 1
[0051] Figure 1 This is a flowchart illustrating the PC-side simulated serial port screen testing method provided in Embodiment 1 of this application. Figure 1 As shown, the specific steps include the following:
[0052] S101, in response to the interactive interface design operation of the simulated serial port screen, determines the format of the test data packet of the simulated serial port screen, and determines the basic running data of the simulated serial port screen; wherein, the basic running data includes: generating a temporary array, generating a callback instruction for running at a certain time, and generating a serial port data parsing function.
[0053] First, this solution can be used in scenarios where serial port screens are simulated on a PC for development and testing.
[0054] Based on the above usage scenarios, it is understandable that the executing entity of this application can be the PC client, and no further restrictions are imposed here.
[0055] PCs can refer to personal computers, which are multi-purpose computers suitable for personal use in terms of size, price, and performance. Desktop computers, laptops, mini-laptops, tablets, and ultrabooks all fall under the category of personal computers.
[0056] In this plan, Figure 2 This is a schematic diagram of the structure of the PC-side simulated serial port screen provided in Embodiment 1 of this application, as shown below. Figure 2 As shown, a simulated serial port screen can be a virtual serial port screen that creates a display window on a PC, receives and parses serial port commands, and simulates various display and button functions of a serial port screen. It allows for testing of test data packets even without a physical serial port screen or a user's motherboard.
[0057] An interactive interface serves as a channel for information exchange between humans and computers. Users input information and perform operations through the interface, while the computer provides information to the user for reading, analysis, and judgment. Interface design primarily focuses on the product's aesthetics, while interaction design focuses on its usability, emphasizing usability and ease of use during product operation. Both are user-centric, prioritizing user experience. Specific aspects of interactive interface design include controlling the product's visual style, such as icon design, page design, and motion effects design, as well as emphasizing human-computer interaction, operational logic, overall interface aesthetics, and user experience.
[0058] When users design an interactive interface, they first need to use a UI design tool to design the UI and drag and drop to generate buttons. Simultaneously, a UI thread and a dialog box (DialogA) need to be created. The main dialog box of the UI thread is set as DialogA. Each time a button is dragged and dropped to generate a button, a message is sent to the main dialog box. The main dialog box responds to this message and automatically generates a test data packet simulating a serial port screen to test whether the button's function works as expected. For example, when a login button is dragged and dropped, a message testing the login function can be sent to the main dialog box. The main dialog box responds to this message and generates a test data packet simulating a serial port screen to test whether the login function works as expected. The UI thread is the thread that interacts with the UI. The UI thread's thread function creates a special object—the window—and is also responsible for creating various controls on the window. The key to the window and controls responding to user actions is that the UI thread responsible for creating them has a "message loop." This message loop is started by the thread function. The UI thread's main task is to start a message loop, retrieve a message from its own message queue, and then forward it to a specific form object based on the information contained in the message. The form object's corresponding "form procedure" function is then called to process these messages.
[0059] A test data packet can be used to test a specific function of a simulated serial port screen to check whether the function under test works as expected. The test data packet may contain input, output, and expected results. By using test data packets, it is possible to determine whether the simulated serial port screen is working properly and to check whether the input and output meet expectations. The data in a test data packet consists of a frame header, a frame trailer, and a frame length. The frame header is an identifier used to mark the beginning of a frame; it is a special identifier or symbol used to indicate the start of a data frame. The frame trailer is an identifier used to mark the end of a frame; it is a special identifier or symbol used to indicate the end of a data frame. The frame length refers to the number of bits contained in each frame. It refers to the total number of bits in a frame, including the frame header, frame trailer, and payload bits.
[0060] The format of the test data packet reflects the corresponding data type. For example, if the frame length of the test data packet is 128 bytes, and the fifth frame is pre-defined to store temperature data, then when the temperature data needs to be obtained, simply use a protocol parsing tool to parse the data packet, locate the temperature data field according to the protocol structure, and finally extract the value of the temperature data field to obtain the temperature data. The purpose of running the basic data is to simulate a serial port screen, thereby parsing, sending, and receiving data.
[0061] First, based on the specific interactive interface design of the simulated serial port screen, it is necessary to determine the test data packet format of the simulated serial port screen. This can be done by analyzing the menus, buttons, and operations displayed on the screen, conducting relevant research and experiments, and thus determining the format of the test data packet.
[0062] Secondly, it is necessary to determine the basic operating data of the simulated serial port screen. This requires comprehensive consideration and analysis of the actual operating conditions of the simulated serial port screen and data from other related external systems to determine the basic operating data of the simulated serial port screen.
[0063] Temporary arrays are used to store received data, significantly improving overall read and write efficiency. They also reduce the number of times the CPU accesses the hard drive through memory, thus increasing efficiency and reducing disk wear. New temporary arrays can be generated using JavaScript, the Array constructor, and array literal syntax.
[0064] A timed callback instruction can be a command that periodically checks if the data to be parsed exists in a temporary array. If it exists, the data is processed; otherwise, no processing is performed. Specifically, the JavaScript `setInterval` function can be used to create a timed callback instruction. The code for a timed callback instruction could be:
[0065]
[0066]
[0067] The serial port data parsing function is used to parse the received data to enable the operation of the serial port screen. The serial port data parsing function is designed according to functional requirements. For example, if the data to be parsed is temperature and humidity data, and the functional requirement is to only obtain the temperature data, then the serial port data parsing function will be designed to select the temperature data from the data to be parsed.
[0068] The serial port parsing function can be generated by following these steps:
[0069] 1. First, define the data structure for each frame of transmission according to the serial communication protocol;
[0070] 2. Write a function to receive serial port data and store it into a defined data structure;
[0071] 3. Write a function to parse the received data and convert it into a readable data format;
[0072] 4. Write a function to extract the parsed data and store it in the correct data structure;
[0073] 5. Write a function to process the extracted data and complete the final task;
[0074] 6. Write a function to send the processed data back to the serial port, completing the data interaction processing via the serial port.
[0075] S102, run a simulated serial port screen locally based on the aforementioned basic running data.
[0076] To run a simulated serial port screen locally based on the underlying data, follow these steps:
[0077] 1. Implement a serial port data parsing function to parse relevant information from the data frames received from the serial port and store it in a temporary array.
[0078] 2. Implement a timed callback instruction to retrieve relevant information from a temporary array at regular intervals and send it out via the serial port.
[0079] 3. Start the simulated serial port screen. After completing the above steps, the simulated serial port screen will begin running locally.
[0080] S103, run the serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port.
[0081] Serial port initialization code initializes the serial port communication parameters to synchronize communication between modules and prevent errors. Specifically, serial port initialization code can be:
[0082] USART_InitStructure.USART_BaudRate = bound; / / Baud rate setting;
[0083] USART_InitStructure.USART_WordLength = USART_WordLength_8b; / / Word length is 8 bits;
[0084] USART_InitStructure.USART_StopBits = USART_StopBits_1; / / One stop bit;
[0085] USART_InitStructure.USART_Parity = USART_Parity_No; / / No parity bit;
[0086] USART_InitStructure.USART_HardwareFlowControl=;
[0087] USART_HardwareFlowControl_None; / / No hardware flow control;
[0088] USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
[0089] / / Send and receive;
[0090] USART_Init(USART1, &USART_InitStructure); / / Initialize the serial port;
[0091] The data interaction terminal can be an external device such as a PLC (Programmable Logic Controller), frequency converter, temperature controller, or data acquisition module. The data interaction terminal can receive command information sent from the simulated serial port screen, and can also respond to command information by sending corresponding data back to the simulated serial port screen.
[0092] When a user clicks a button, the onclick event is triggered. You can pre-set the script that is executed when the onclick event is triggered to include serial port initialization code. This way, the serial port initialization code will run automatically every time the user clicks the button.
[0093] After the serial port is initialized, the simulated serial port screen can be connected to the data exchange terminal via the serial port. Specifically, the serial port can be a real serial port or a virtual serial port. A real serial port is an extension interface that uses serial communication. Serial ports transmit data bit by bit sequentially. Its advantages include simple communication lines; only a pair of transmission lines are needed for bidirectional communication, greatly reducing costs and making it particularly suitable for long-distance communication, but the transmission speed is relatively slow. When using a real serial port, the simulated serial port screen must be connected to the data exchange terminal via a transmission line to successfully transmit data between them. When using a virtual serial port, the connection between the simulated serial port screen and the data exchange terminal is achieved through software-simulated serial port protocols. Virtual serial ports should appear in pairs; another program needs to connect to the other virtual serial port to receive and send data.
[0094] Based on the above technical solutions, optionally, the data interaction terminal includes a physical lower-level machine and / or a virtual lower-level machine;
[0095] Accordingly, the serial port initialization code is run to connect the simulated serial port screen to the data interaction terminal via the serial port, including:
[0096] Run the serial port initialization code and display the serial port selection interface;
[0097] In response to a serial port selection operation, the simulated serial port screen is connected to the physical lower-level machine and / or the virtual lower-level machine based on the selected serial port.
[0098] The data interaction terminal includes a physical lower-level machine and / or a virtual lower-level machine;
[0099] Accordingly, the serial port initialization code is run to connect the simulated serial port screen to the data interaction terminal via the serial port, including:
[0100] Run the serial port initialization code and display the serial port selection interface;
[0101] In response to a serial port selection operation, the simulated serial port screen is connected to the physical lower-level machine and / or the virtual lower-level machine based on the selected serial port.
[0102] In this plan, Figure 3 This is a schematic diagram of the method for PC-side simulated serial port screen and lower-level machine interaction provided in Embodiment 1 of this application, as shown below. Figure 3 As shown, the physical lower-level machine can be a computer that directly controls the equipment and obtains the equipment status. Specifically, it can include external devices such as PLC, frequency converter, temperature control instrument and data acquisition module.
[0103] A virtual lower-level machine can also be run on a PC, simulating the actual operation of a physical lower-level machine. When connecting the simulated serial port screen to the virtual lower-level machine, the connection needs to be established using software to simulate the serial port protocol.
[0104] The serial port selection interface can be displayed on the PC, allowing the user to choose the serial port to connect to. Specifically, the serial ports can be pre-numbered and displayed on the selection interface, allowing the user to select the appropriate port. For example, the serial port numbers can be numerical, numbered sequentially as 01, 02, 03, etc.
[0105] After the serial port initialization code runs successfully, the PC will automatically display the serial port selection interface for the user to select the serial port to connect to.
[0106] When a user selects to connect to the serial port, the PC responds to the user's serial port selection and automatically opens the selected serial port. If the simulated serial port screen is a physical slave device, it can be connected to the physical serial port screen via the corresponding transmission line. If the simulated serial port screen is a virtual slave device, the software simulates the serial port protocol to connect the simulated serial port screen to the virtual slave device based on the selected serial port. Specifically, the code to open the serial port can be:
[0107]
[0108] This solution, by setting up both a physical and a virtual lower-level machine, enables the simulated serial port screen to interact with the lower-level machine product in real time during development, saving time and costs. It also allows the simulated serial port screen to communicate with the virtual lower-level machine, simplifying data transmission and facilitating debugging of the simulated serial port screen during development. This avoids the problem of reduced development efficiency caused by hardware failure and the additional time spent on data packaging and downloading.
[0109] Based on the above technical solutions, optionally, if it is the virtual lower-level machine, then before receiving the data to be parsed from the data interaction terminal through the serial port, the method further includes:
[0110] Configure the virtual lower-level machine with the data to be transmitted and parsed, and the transmission period for the data to be parsed.
[0111] In this solution, the transmission period can be the period for transmitting the data to be parsed. The transmission period can be set according to the functions of different modules in the simulated serial port screen. For example, if there is a module in the simulated serial port screen that collects device temperature data, and this module needs to obtain the device temperature every minute to monitor whether the device temperature is abnormal, then the data transmission period for the data to be parsed is one minute.
[0112] Since the virtual lower-level machine simulates the actual operating state of the physical lower-level machine, it needs to be configured according to the actual situation. Specifically, the data to be parsed and the transmission cycle of the data to be parsed need to be configured in advance in the corresponding functional modules of the virtual lower-level machine and the physical lower-level machine. This allows the simulated serial port screen to receive the data to be parsed once every equal transmission cycle and parse the data, thereby testing whether the simulated serial port screen can work as expected.
[0113] In this solution, by configuring the data to be parsed and the transmission cycle for the virtual lower-level machine, the time spent on communication testing with the lower-level machine by downloading firmware to the serial port screen hardware can be reduced, thereby improving the development and testing efficiency of the simulated serial port screen.
[0114] S104, receive the data to be parsed from the data interaction terminal through the serial port, store the data to be parsed in a temporary array; and run the serial port data parsing function in the simulated serial port screen to parse the data to be parsed, and update the display on the page of the simulated serial port screen.
[0115] The data to be parsed can be the data sent from the data interaction terminal to the simulated serial port screen. For example, when the data interaction terminal is a temperature control instrument, a button on the simulated serial port screen may be used to obtain the current device temperature. If this button is clicked on the simulated serial port screen, the temperature control instrument will return the device temperature data according to the instruction to obtain the current device temperature. This data is the data to be parsed.
[0116] When the data interaction terminal sends data to be parsed to the simulated serial port screen, if the serial port is a real serial port, the data to be parsed can be transmitted from the data interaction terminal to the simulated serial port screen through the transmission line, so that the simulated serial port screen can receive the data; if the serial port is a virtual serial port, the simulated serial port screen can receive the data to be parsed through the corresponding program and the virtual serial port.
[0117] The code that transmits the data to be parsed from the data interaction terminal to the simulated serial port screen via serial port can be:
[0118]
[0119]
[0120] Once the data to be parsed is obtained, it can first be stored in a temporary array. When the simulated serial port screen needs to process data, it can directly read the data from the temporary array and perform the corresponding processing. For example, the process of writing the data to be parsed into the temporary array can be to first input the value and then store it in the corresponding position of the array, that is, assign the value to the corresponding element.
[0121] Meanwhile, since different buttons on the simulated serial port screen correspond to different functions, different data parsing functions are included for each function. When the simulated serial port screen receives data to be parsed from the data interaction terminal, it automatically runs the serial port data parsing function to parse the data and obtain the required data. This can involve parsing the data into a uniform format or selecting the data required for a specific function from the data transmitted from the data interaction terminal. For example, if a button on the simulated serial port screen functions to obtain the device's temperature in Celsius, and the device temperature data transmitted from the data interaction terminal is in both Fahrenheit and Celsius formats, then the Celsius temperature can be selected using the data parsing function.
[0122] After the data to be parsed has been processed, the display on the simulated serial port screen can be updated by following these steps:
[0123] 1. First, you need to set up the page of the simulated serial port screen and determine the display position of the updated data;
[0124] 2. Then, format the processed data into a format supported by the simulated serial port screen;
[0125] 3. Finally, the processed formatted data is sent to the simulated serial port screen using a specific interface, thereby updating and displaying the data.
[0126] Based on the above technical solutions, optionally, the data to be parsed is received from the data interaction terminal via the serial port, and the data to be parsed is stored in a temporary array; and the serial port data parsing function is run in the simulated serial port screen to parse the data to be parsed, including:
[0127] The serial port receives the data to be parsed from the data interaction terminal and writes it into a temporary storage array.
[0128] The system identifies whether the temporary array is empty based on the callback instruction that runs on a timer.
[0129] If not empty, the serial port data parsing function is called to parse the data to be parsed in the temporary array one by one.
[0130] In this solution, if a callback instruction is pre-set to run every 10ms, the PC will automatically call the callback instruction every 10ms to identify whether there is data to be parsed in the temporary array. If there is data to be parsed, the temporary array will not be empty; if there is no data to be parsed, the temporary array will be empty.
[0131] If the PC detects that the temporary array is not empty, it automatically calls and runs the serial port data parsing function. The data to be parsed is processed one by one according to the function and requirements of the serial port data parsing function until all requirements are met.
[0132] This solution automatically checks for the existence of data to be parsed by setting a timed callback command. If data is found, it is processed accordingly. This avoids the previous problem of manually inputting data, which led to increased processing time and further improved data processing efficiency.
[0133] Based on the above technical solutions, optionally, after parsing the data to be parsed in the simulated serial port screen, the method further includes:
[0134] If parsing fails, a verification failure message is generated, and the serial port data parsing function in the basic data is redesigned based on the interactive interface.
[0135] In this solution, the verification failure message can be a prompt to developers indicating that an error occurred during the parsing of the data to be parsed, requiring them to redesign the operation based on the interactive interface and determine the serial port data parsing function in the underlying data. Since parsing the data may fail due to reasons such as not storing the data to be parsed in a temporary array, not executing the timed callback instruction, or errors in using the serial port data parsing function, a verification failure message needs to be generated to prompt testers to re-determine the serial port data parsing function in the underlying data and perform the test again.
[0136] A function can be defined to determine if parsing fails. If the function returns true, it indicates that parsing has failed. A variable can be set in the function to store the verification failure message. The information to be parsed transmitted from the data interaction terminal is parsed in the simulated serial port screen. If parsing fails, the message in the variable is output, and the serial port data parsing function in the basic data is redesigned based on the interactive interface.
[0137] In this solution, by generating a verification failure prompt instruction, the serial port data parsing function in the basic data can be re-determined after a parsing failure to complete the test of the simulated serial port screen. This ensures the accuracy and reliability of the simulated serial port screen, thereby improving the system's performance and stability.
[0138] S105, if the update display fails, it indicates that the simulated serial port screen test is abnormal.
[0139] Update failures can include the following two scenarios:
[0140] 1. Data cannot be displayed correctly; error codes are shown on the simulated serial port screen. For example, when needing to obtain transformer box temperature data, the simulated serial port screen does not display the temperature data transmitted from the data exchange terminal, but instead displays an error code. The reason for this failure to display data correctly may be that the serial port data parsing function has failed to parse the data to be parsed.
[0141] 2. The data displays correctly, but the simulated serial port screen does not update when the data changes. For example, when it is necessary to obtain the temperature data of a transformer substation, the serial port data parsing function can parse and process the data transmitted from the data exchange terminal and update the display on the simulated serial port screen normally. However, when the transformer substation temperature data is needed again, the simulated serial port screen does not update the temperature data transmitted from the data exchange terminal, and the displayed data is still the transformer substation temperature data obtained last time. The reason why the simulated serial port screen does not update after the data is updated may be that the temporary storage array does not store the updated data or the timed callback instruction has not been executed.
[0142] If either of the above two update display failures occurs, it can be determined that the simulated serial port screen test is abnormal. The technical solution provided in this embodiment responds to the interactive interface design operation of the simulated serial port screen, determines the format of the test data packet for the simulated serial port screen, and determines the basic running data of the simulated serial port screen. The basic running data includes: generating a temporary array, generating a callback instruction to run at a certain time, and generating a serial port data parsing function. Based on the basic running data, the simulated serial port screen is run locally; serial port initialization code is run to connect the simulated serial port screen to the data interaction terminal via the serial port; the data to be parsed from the data interaction terminal is received through the serial port, and the data to be parsed is stored in the temporary array; the serial port data parsing function is run in the simulated serial port screen to parse and process the data to be parsed, and the page of the simulated serial port screen is updated and displayed; if the update display fails, it is determined that the simulated serial port screen test is abnormal. Through the above PC-side simulated serial port screen testing method, the simulated serial port screen can be used to parse and display data in real time, allowing users to view the data more intuitively and to discover anomalies more quickly and accurately, thereby enabling better program debugging. Since no physical serial port screen device is required, the development efficiency of serial port screens is reduced due to hardware failure and the additional time spent on data packaging and downloading, thus saving time and costs.
[0143] Example 2
[0144] Figure 4 This is a flowchart illustrating the PC-side simulated serial port screen testing method provided in Embodiment 2 of this application. Figure 4 As shown, the specific steps include the following:
[0145] S201, in response to the interactive interface design operation of the simulated serial port screen, determine the format of the test data packet of the simulated serial port screen, and determine the basic running data of the simulated serial port screen; wherein, the basic running data includes: generating a temporary array, generating a callback instruction for running at a certain time, and generating a serial port data parsing function.
[0146] S202, Based on the aforementioned basic operating data, run a simulated serial port screen locally.
[0147] S203, run the serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port.
[0148] S204: Receive the data to be parsed from the data interaction terminal through the serial port, store the data to be parsed in a temporary array; run the serial port data parsing function in the simulated serial port screen to parse the data to be parsed, and update the display on the page of the simulated serial port screen.
[0149] S205, if the update display is successful, the operation command is received through the simulated serial port screen, and the command content is sent to the data interaction terminal through the serial port.
[0150] Operation commands can be instructions issued by the user through a simulated serial port screen to control the data interaction terminal. Specifically, the user can click the corresponding operation button on the simulated serial port screen using the mouse. After receiving the operation command, the simulated serial port screen sends the corresponding command content to the data interaction terminal via the serial port, thus communicating with the data interaction terminal. For example, when the data interaction terminal can control the engine speed, the simulated serial port screen can display a slider to control the engine speed. The user sliding this slider is considered to have issued an operation command to the data interaction terminal, and the command content is the engine speed corresponding to the slider. After receiving the command content, the data interaction terminal adjusts the engine speed accordingly.
[0151] S206, if no feedback information is received from the data interaction terminal, the simulated serial port screen test is determined to be abnormal.
[0152] The feedback information from the data interaction terminal can be the current working status of the data interaction terminal. After the data interaction terminal receives and executes the instruction, it needs to send the execution completion status to the simulated serial port screen so that the simulated serial port screen can confirm that the instruction was sent successfully and that the data interaction terminal successfully received and executed the instruction, thus confirming that the simulated serial port screen test is normal.
[0153] The following are possible reasons why the simulated serial port screen does not receive feedback information from the data exchange terminal:
[0154] 1. The command content was not successfully sent to the data interaction terminal via the serial port. When the command is not sent to the data interaction terminal, the terminal cannot respond to it and therefore will not transmit feedback information to the simulated serial port screen. The reason for this failure is likely a serial port malfunction. Specifically, if the serial port is virtual, malfunctions may be due to system driver issues, hardware problems, or device configuration issues; if the serial port is physical, malfunctions may be due to hardware failure or device configuration problems.
[0155] 2. The command was successfully sent to the data interaction terminal, but the terminal did not execute it. When the data interaction terminal does not respond to the command, no feedback information will be transmitted to the simulated serial port screen. This may be due to an anomaly on the data interaction terminal, requiring troubleshooting.
[0156] 3. The data interaction terminal successfully executed the command, but the feedback information was not transmitted to the simulated serial port screen. The reasons for this failure to transmit feedback information to the simulated serial port screen may be an anomaly on the data interaction terminal, preventing the feedback information from being sent normally; or an anomaly on the serial port, preventing the feedback information from being transmitted to the simulated serial port screen.
[0157] S207 If the update display fails, it indicates that the simulated serial port screen test is abnormal.
[0158] In this embodiment, by setting feedback information, normal communication between the simulated serial port screen and the data interaction terminal can be ensured, thereby improving the stability and reliability of the system. If no feedback information is received from the data interaction terminal, communication failures can be detected and handled in a timely manner, preventing system anomalies caused by communication problems. Simultaneously, testing the simulated serial port screen can effectively simulate the actual usage environment, allowing for the early detection and resolution of potential problems, thus reducing subsequent fault repair and testing costs.
[0159] Example 3
[0160] Figure 5 This is a schematic diagram of the test device for simulating a serial port screen on a PC provided in Embodiment 3 of this application. Figure 5 As shown, it specifically includes the following:
[0161] The basic data determination module 301 is used to respond to the interactive interface design operation of the simulated serial port screen, determine the format of the test data packet of the simulated serial port screen, and determine the basic running data of the simulated serial port screen; wherein, the basic running data includes: generating a temporary array, generating a callback instruction for running at a certain time, and generating a serial port data parsing function.
[0162] The simulated serial port screen operation module 302 is used to run a simulated serial port screen locally based on the aforementioned basic operation data.
[0163] The serial port connection module 303 is used to run serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port;
[0164] The data parsing module 304 is used to receive the data to be parsed from the data interaction terminal through the serial port, store the data to be parsed in a temporary array, and run the serial port data parsing function in the simulated serial port screen to parse the data to be parsed, and update the display on the page of the simulated serial port screen.
[0165] The test result determination module 305 is used to determine that the simulated serial port screen test is abnormal if the update display fails. Furthermore, the device also includes an instruction sending module, which is used to:
[0166] If the update is successful, the operation command is received through the simulated serial port screen, and the command content is sent to the data interaction terminal through the serial port.
[0167] If no feedback information is received from the data interaction terminal, the simulated serial port screen test is determined to be abnormal.
[0168] The technical solution provided in this embodiment includes a basic data determination module, which is used to determine the format of the test data packet of the simulated serial port screen and the basic running data of the simulated serial port screen in response to the interactive interface design operation of the simulated serial port screen; wherein, the basic running data includes: generating a temporary array, generating a callback instruction for running at a certain time, and generating a serial port data parsing function; a simulated serial port screen running module, which is used to run the simulated serial port screen locally based on the basic running data; and a serial port connection module, which is used to run serial port initialization code to connect the simulated serial port screen to the data interaction terminal through the serial port.
[0169] The data parsing module receives the data to be parsed from the data interaction terminal via the serial port, stores the data in a temporary array, and runs the serial port data parsing function in the simulated serial port screen to parse and process the data, updating the display on the simulated serial port screen page. The test result determination module determines that the simulated serial port screen test is abnormal if the update display fails. Through the above-mentioned PC-based simulated serial port screen testing device, data can be parsed and displayed in real time, allowing users to view the data more intuitively and identify anomalies more quickly and accurately, thus facilitating better program debugging. Since no physical serial port screen device is required, the development efficiency of the serial port screen is reduced due to hardware damage and the additional time spent on data packaging and downloading, saving time and costs.
[0170] The testing device for simulating a serial port screen on a PC in this application embodiment can be a device, or it can be a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. This application embodiment does not impose specific limitations.
[0171] The PC-based serial port simulation test device in this embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this embodiment does not impose specific limitations.
[0172] The PC-based simulated serial port screen testing device provided in this application embodiment can implement all the processes implemented in the above method embodiments. To avoid repetition, it will not be described again here.
[0173] Example 4
[0174] like Figure 6 As shown, this application embodiment also provides an electronic device 400, including a processor 401, a memory 402, and a program or instructions stored in the memory 402 and executable on the processor 401. When the program or instructions are executed by the processor 401, they implement the various processes of the above-described PC-side simulated serial port screen test method embodiment and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0175] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0176] Example 5
[0177] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described PC-side simulated serial port screen test method embodiment and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0178] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0179] Example 6
[0180] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described PC-side simulated serial port screen test method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0181] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0182] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0183] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0184] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0185] The above description is merely a preferred embodiment and the technical principles employed in this application. This application is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions that can be made by those skilled in the art will not depart from the scope of protection of this application. Therefore, although this application has been described in detail through the above embodiments, this application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of this application, the scope of which is determined by the scope of the claims.
Claims
1. A test method for simulating a serial port screen on a PC, characterized in that, The method is executed by a PC, and the method includes: In response to the interactive interface design operation of the simulated serial port screen, the format of the test data packet for the simulated serial port screen and the basic running data of the simulated serial port screen are determined. The basic running data includes: generating a temporary array, generating a callback instruction to run at a certain time, and generating a serial port data parsing function. The step of determining the format of the test data packet for the simulated serial port screen in response to the interactive interface design operation includes: designing a UI interface using a UI design tool and dragging and dropping buttons to create a UI thread and a main dialog box; setting the main dialog box of the UI thread as the main dialog box; sending a message to the main dialog box each time a button is dragged and dropped; and the main dialog box automatically generating the test data packet for the simulated serial port screen in response to the message to test whether the function corresponding to the button works as expected. Based on the aforementioned operational data, run a simulated serial port screen locally; Run the serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port; The system receives the data to be parsed from the data interaction terminal via the serial port and stores the data to be parsed in a temporary array. Based on the callback instruction of the timed operation, it identifies whether the temporary array is empty. If it is not empty, the serial port data parsing function is run in the simulated serial port screen to parse the data to be parsed in the temporary array one by one, and the page of the simulated serial port screen is updated and displayed. If the parsing fails, a verification failure prompt instruction is generated, and the serial port data parsing function in the basic data is re-determined based on the interactive interface design operation. If the update fails, it indicates an error in the simulated serial port screen test. If the update is successful, the operation command is received through the simulated serial port screen, and the command content is sent to the data interaction terminal through the serial port; if no feedback information is received from the data interaction terminal, the simulated serial port screen test is determined to be abnormal.
2. The method according to claim 1, characterized in that, The data interaction terminal includes a physical lower-level machine and / or a virtual lower-level machine; Accordingly, the serial port initialization code is run to connect the simulated serial port screen to the data interaction terminal via the serial port, including: Run the serial port initialization code and display the serial port selection interface; In response to a serial port selection operation, the simulated serial port screen is connected to the physical lower-level machine and / or the virtual lower-level machine based on the selected serial port.
3. The method according to claim 2, characterized in that, If it is the virtual lower-level machine, then before receiving the data to be parsed from the data interaction terminal through the serial port, the method further includes: Configure the virtual lower-level machine with the data to be transmitted and parsed, and the transmission period for the data to be parsed.
4. A testing device for simulating a serial port screen on a PC, characterized in that, The device is configured on a PC, and the device includes: The basic data determination module is used to determine the format of the test data packet for the simulated serial port screen and the basic running data for the simulated serial port screen in response to the interactive interface design operation. The basic running data includes: generating a temporary array, generating a callback instruction to run at a certain time, and generating a serial port data parsing function. The basic data determination module is also used to: design a UI interface using a UI design tool and drag and drop buttons to create a UI thread and a main dialog box; set the main dialog box of the UI thread as the main dialog box; send a message to the main dialog box each time a button is dragged and generated; and automatically generate a test data packet for the simulated serial port screen in response to the message to test whether the function corresponding to the button works as expected. A simulated serial port screen operation module is used to run a simulated serial port screen locally based on the aforementioned basic operation data; The serial port connection module is used to run serial port initialization code to connect the simulated serial port screen to the data interaction terminal via the serial port; The data parsing module is used to receive the data to be parsed from the data interaction terminal through the serial port, and store the data to be parsed in a temporary array; based on the callback instruction of the timed operation, it identifies whether the temporary array is empty. If it is not empty, the serial port data parsing function is run in the simulated serial port screen to parse the data to be parsed in the temporary array one by one, and the page of the simulated serial port screen is updated and displayed; if the parsing fails, a verification failure prompt instruction is generated, and the serial port data parsing function in the basic data is re-determined based on the interactive interface design operation. The test result determination module is used to determine that the simulated serial screen test is abnormal if the update display fails. It is also used to receive operation instructions through the simulated serial port screen if the update display is successful, and send the instruction content to the data interaction terminal through the serial port; if no feedback information is received from the data interaction terminal, it is determined that the simulated serial port screen test is abnormal.
5. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the test method for simulating a serial port screen on a PC as described in any one of claims 1-3.
6. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions, which, when executed by a processor, implement the steps of the test method for simulating a serial port screen on a PC as described in any one of claims 1-3.
