A device control method, apparatus, storage medium, and computer device
By establishing a communication link between the managing device and the managed device through a serial port management library, and automating the transmission and execution of scripts, the problems of network dependence and manual operation in existing technologies are solved, and automated remote management and efficient operation and maintenance are realized in network-free environments.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU DPTECH TECH
- Filing Date
- 2026-04-08
- Publication Date
- 2026-07-31
AI Technical Summary
Existing remote management solutions cannot effectively manage devices that are not connected to the network, have abnormal network connections, or do not have SSH service pre-installed. Furthermore, solutions based on physical serial ports rely on manual operation, which is inefficient and cannot meet the needs of large-scale automated operation and maintenance.
By establishing a communication link between the management device and the managed device through a serial port management library, the script content is automatically transmitted and instructions are executed, realizing full automation from script transmission to result collection, avoiding network dependence and manual operation.
It enables automated remote management of managed devices in a network-free environment, improving management efficiency, meeting the needs of large-scale automated operation and maintenance, and avoiding the limitations of network configuration and manual operation.
Smart Images

Figure CN122489202A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a device control method, apparatus, storage medium, and computer device. Background Technology
[0002] In scenarios such as industrial control, embedded device control, and edge computing, controlling a large number of deployed managed devices (such as Linux devices, Windows devices, etc.) in ways such as maintenance, batch configuration, and status acquisition is a basic but critical requirement. The prerequisite for meeting this requirement is the ability to remotely manage the managed devices, such as remotely executing commands on the managed devices and obtaining feedback.
[0003] Current remote management solutions generally fall into two categories: network protocol-based solutions and physical serial port-based interactive terminal solutions. While network protocol-based solutions are powerful, they require the managed device to be pre-configured for the network and have the corresponding control processes running. This makes them completely ineffective in situations such as the managed device not being connected to the network, the management device and the managed device being in the network initialization phase, or service crashes. They are significantly invasive and dependent on network configuration. On the other hand, physical serial port-based interactive terminal solutions, although not network-dependent, require technicians to manually input interactive commands on the terminal for remote management, resulting in inefficiency and a high risk of errors.
[0004] Therefore, it is evident that current remote management solutions all have significant drawbacks and cannot effectively meet the needs of remotely managing managed devices. Summary of the Invention
[0005] In view of this, this application provides a device control method, apparatus, storage medium, and computer device to achieve automated remote management of the managed device without relying on a network.
[0006] Specifically, this application is implemented through the following technical solution: In a first aspect, embodiments of this disclosure provide a device control method applied to managing devices, comprising: Using the serial port management library, determine the second serial port on the management device that is physically connected to the first serial port of the managed device, and establish a communication link between the second serial port and the first serial port; The pre-written script content is converted into at least one text string and sent to the managed device through the communication link; Upon completion of sending each of the text strings, an execution instruction is sent to the managed device via the communication link; the managed device receives and responds to the execution instruction, executes the script command corresponding to each of the text strings, and obtains an execution result file. In response to the triggering of the result reading condition, a result reading command is sent to the managed device through the communication link to obtain the execution result file in the managed device.
[0007] Secondly, embodiments of this disclosure also provide a device control apparatus for managing equipment, the apparatus comprising: A module is established to use a serial port management library to determine a second serial port on the management device that is physically connected to a first serial port on the managed device, and to establish a communication link between the second serial port and the first serial port. The first sending module is used to convert the pre-written script content into at least one text string and send it to the managed device through the communication link; The second sending module is used to send an execution instruction to the managed device through the communication link in response to the completion of sending each of the text strings; the managed device is used to receive and respond to the execution instruction, execute the script command corresponding to each of the text strings, and obtain an execution result file. The acquisition module is used to send a result reading command to the managed device through the communication link in response to a trigger result reading condition, and to acquire the execution result file in the managed device.
[0008] Thirdly, an optional implementation of this disclosure also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the steps in the first aspect described above.
[0009] Fourthly, an optional implementation of this disclosure also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps in the first aspect described above.
[0010] The device control method, apparatus, storage medium, and computer device provided in this disclosure allow the management device to actively discover a second serial port physically connected to the first serial port of the managed device using a serial port management library, and establish a communication link between the two serial ports. This enables interaction with the managed device using the two serial ports without relying on a network, thus avoiding the strong reliance on network configuration and service pre-installation issues inherent in existing network protocol-based solutions, and overcoming network constraints on remote management. Furthermore, the management device can automate the entire process from script transmission to trigger execution and result collection based on the communication link, overcoming the reliance on manual intervention in existing physical serial port-based interactive terminal solutions, and improving the efficiency of remote management. Moreover, since the entire management and control process for the managed devices is automated, this application can achieve automated batch remote management of a large number of managed devices, effectively meeting the needs for large-scale, automated operation and maintenance of managed devices.
[0011] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0012] Figure 1 This is a flowchart illustrating a device control method according to an exemplary embodiment of this application; Figure 2 This is an interactive schematic diagram illustrating a device control process according to an exemplary embodiment of this application; Figure 3 This is a schematic diagram of a device control apparatus shown in an exemplary embodiment of this application; Figure 4 This is a schematic diagram of the structure of a computer device shown in an exemplary embodiment of this application. Detailed Implementation
[0013] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0014] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0015] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0016] Research has revealed that for remote management of managed devices, network protocol-based solutions require a pre-established network connection between the managed and managing devices. For example, a Secure Shell (SSH)-based solution relies on the managing device using an SSH client to establish an encrypted Transmission Control Protocol (TCP) session with the managed device, which has an SSH server installed and running. After successful session establishment and authentication, the managing device can encapsulate the command to be executed into an SSH protocol data packet and send it to the managed device through an encrypted channel. The managed device's SSH server can then create a shell process locally to execute the command and return the execution result to the managing device through the same encrypted channel. However, the core limitation of this type of solution lies in its stringent prerequisites. Specifically, it heavily relies on the managed device having a usable network connection and correct network configuration (such as Internet Protocol Address (IP address), routing information, and firewall rules). This means that if the managed device is not network-ready, experiences network failure, or is isolated, this solution cannot be used for remote management. Furthermore, due to its significant intrusiveness, this solution requires the managed device to pre-install and continuously maintain the availability of SSH services, increasing deployment complexity and resource consumption, and introducing additional security maintenance burdens. Therefore, these two drawbacks make this type of solution unsuitable for embedded devices in environments without network access, with highly limited resources (such as limited network resources), or for rapid deployment scenarios requiring zero pre-configuration of the managed device. While interactive terminal solutions based on physical serial ports do not rely on a network, they are essentially a continuous interactive process where operators manually input commands, observe the screen output of the management device in real time, and input commands again based on the output. This fails to enable automated control of the managed device, resulting in low management efficiency and susceptibility to human error, making it difficult to meet the management needs of large-scale, automated operations and maintenance. For example, a common interactive terminal solution involves directly connecting the management device and the managed device via a serial cable. On the management device side, the user needs to run terminal emulation software (such as Minicom, PuTTY, etc.) to establish a bidirectional character stream communication channel between the management device and the text console of the managed device.The entire management process is entirely manual and interactive: the user manually enters commands on the running terminal emulation software, which then sends the commands to the managed device via a serial port. The managed device's shell processes the commands and sends the output text back to the terminal emulation software via the same serial port, where it is presented to the user in real time. The user can then enter commands again based on the presented results for further control. The most significant drawback of this approach is that its interactive operation mode hinders process automation. Specifically, every step—from command input and execution to result acquisition—requires manual, real-time operation via the terminal emulation software. This high dependence on manual intervention leads to low management efficiency and poor fault tolerance, making it unsuitable for scenarios requiring automation, such as batch device management, scheduled tasks, or integration with modern maintenance systems.
[0017] In summary, existing remote management technologies either have a strong dependence on the pre-configuration of the managed devices (such as the pre-configuration of network and SSH services) or a strong dependence on manual operation, which cannot efficiently meet the remote management needs of large-scale, automated operation and maintenance.
[0018] Based on the above research, this disclosure provides a device control method, apparatus, storage medium, and computer device. Utilizing an automated program based on a serial port management library, it controls the serial communication link between the managing device and the managed device, constructing a complete automated management process. This achieves full automation from script transmission to trigger execution and result collection, fundamentally replacing the interactive terminal mode that relies on manual operation in existing technologies. In summary, this application not only overcomes the limitations of manual operation in traditional serial port management but also overcomes the environmental constraints of network-dependent solutions by eliminating the need for pre-configuration of network and SSH services on the managed device. This enables zero-configuration management of the managed device, effectively meeting the needs for large-scale, automated management of managed devices.
[0019] The shortcomings of the above solutions are the result of the inventor's practical experience and careful research. Therefore, the discovery process of the above problems and the solutions proposed in this disclosure below should be considered as the inventor's contribution to this disclosure.
[0020] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0021] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0022] It should be noted that the specific terms mentioned in the embodiments of this disclosure include: Serial port: The full name is serial communication interface. It specifically refers to the physical communication interface that conforms to standards such as RS-232. The serial port can be used as a physical layer data transmission channel between the management device and the managed device. It is responsible for transmitting raw byte streams and is the basis for realizing zero-configuration management on the managed device.
[0023] To facilitate understanding of this embodiment, a device control method disclosed in this disclosure will first be described in detail. The device control method provided in this disclosure is generally executed by a terminal device or other processing device with certain computing capabilities. The terminal device may be a user equipment (UE), a mobile device, a terminal, a personal digital assistant (PDA), a handheld device, a computer device, etc. In some possible implementations, the device control method can be implemented by the processor calling computer-readable instructions stored in the memory.
[0024] The following describes the device control method provided in this disclosure embodiment, taking the management device as the executing entity as an example.
[0025] like Figure 1 The flowchart shown is a device control method provided in an embodiment of this disclosure, which may include the following steps: S101: Using the serial port management library, determine the second serial port on the management device that is physically connected to the first serial port of the managed device, and establish a communication link between the second serial port and the first serial port.
[0026] Here, the managing device can be any computer device with a usable serial port, such as industrial control equipment, embedded devices, or edge computing devices. The managed device can be a computer device that supports remote control of the managing device and also has a usable serial port; for example, the managed device can be an industrial control device, embedded device, or edge computing device. The operating system used by the managed device can be Linux, and no network configuration or installation of any additional services is required.
[0027] A serial port management library is a function library that provides serial port discovery, configuration, and read / write functions for managed devices. The serial port management library can be determined based on the programming languages supported by the managed device. For example, if the managed device supports Java, the serial port management library could be the jSerialComm library; if the managed device supports C / C++, the serial port management library could be a Windows Application Programming Interface (API) serial port function library.
[0028] The device control method provided in this application can be encapsulated as a target program generated based on a serial port management library, such as a JAVA program based on the jSerialComm library. The target program can be automatically executed by the management device, thereby achieving automated management of the managed device.
[0029] The first serial port is located on the managed device, and the second serial port is located on the management device. The management device and the managed device can be pre-connected through the first and second serial ports. Therefore, the device control method provided in this application presupposes that the management device and the managed device are already connected via serial ports.
[0030] A communication link is a link actively established by the management device to the managed device, which can then manage the managed device.
[0031] In practice, the management device can be a computer running the target program, equipped with a usable second serial port; the managed device can be any standard Linux device equipped with a usable first serial port, and the managed device does not require any prior network configuration or installation of any additional services. The management device and the managed device can be pre-connected via the first and second serial ports.
[0032] After deploying the target program on the management device, the management device can first initialize the serial port connection. Specifically, the target program in the management device can use a serial port management library to discover the physical serial ports connecting itself and the managed devices. The serial port on its own device can be defined as the second serial port, and the serial port on the managed device can be defined as the first serial port. Then, the management device can use the serial port management library to configure the second serial port, thereby establishing a communication link between the second serial port and the first serial port.
[0033] In one embodiment, the step of "establishing a communication link between the second serial port and the first serial port" in S101 above can be implemented according to the following steps 1 to 2: Step 1: Obtain the serial port configuration information of the first serial port; the serial port configuration information includes at least the baud rate, data bits, stop bits, and parity bits.
[0034] Here, the baud rate indicates the data transmission rate of the serial port, specifically the number of symbols that the serial port can transmit per second. The data bits indicate the number of bits of valid information in a data frame. The stop bits mark the end of a data frame. The check bits are used to verify the correctness of the data frame.
[0035] In practice, the management device can use the serial port management library to obtain serial port configuration information such as baud rate, data bits, stop bits, and parity bits of the first serial port of the managed device.
[0036] Step 2: Configure the second serial port according to the serial port configuration information, and after the configuration is completed, start the second serial port to establish a communication link.
[0037] In practical implementation, to ensure consistent data parsing between the managing and managed devices, it's necessary to guarantee that the serial ports connected to both devices have the same configuration. Therefore, after obtaining the serial port configuration information of the first serial port, a serial port management library can be used to configure the second serial port based on this information, thus ensuring that the second serial port has the same configuration as the first. After successful configuration, the target program can open the second serial port, thereby establishing a communication link between the second and first serial ports.
[0038] Optionally, after configuration is complete and the second serial port is opened, the management device can forward configuration signals to the managed device via the communication link. After receiving the configuration signal, the managed device can send feedback to the management device indicating that the communication connection is ready, thereby informing the management device that the communication link between the second and first serial ports has been successfully established.
[0039] S102: Convert the pre-written script content into at least one text string and send it to the managed device via the communication link.
[0040] Here, the script content can be a pre-written command script, which includes at least one script command to control the managed device. Different script commands can have different control functions; for example, a script command can be a command to query device information of the managed device, or it can be a calculation command, a data processing command, a control command, etc. Understandably, the specific script commands can be set according to the actual application scenario, and this application does not impose specific limitations.
[0041] In practice, the management device can use the target program to automatically acquire pre-written script content and convert it into one or more text strings. Then, the target program can output each text string to the first serial port of the managed device via the established communication link, through the second serial port, as an output stream, thereby automatically sending the script content to the managed device.
[0042] Understandably, when data is transmitted between the first and second serial ports, since the serial port configuration information of the two serial ports is already consistent, data can be transmitted between the two serial ports based on the configured serial port configuration information.
[0043] In one embodiment, the above-described S102 can be implemented according to the following steps: S102-1: Parse the script content to determine the individual script commands to be executed.
[0044] Here, the script command to be executed is the script command that the managed device needs to execute, and the script content may include at least one pre-written script command.
[0045] In practice, the management device can use the target program to obtain the script content, then parse the script content to determine the script commands included in the script content, and use these script commands as the script commands to be executed by the managed device.
[0046] S102-2: Convert each script command into a text string and set a command separator at the end of the text string.
[0047] In practice, the management device can use the target program to convert each script command into a text string according to the order of the commands within the script content, thus obtaining the text string corresponding to each script command. Simultaneously, to distinguish between different script commands, a command separator can be set at the end of the text string corresponding to each script command. The command separator can be, for example, a newline character.
[0048] S102-3: Send each text string with a command delimiter to the managed device via the communication link as an output stream.
[0049] In practice, the management device can use the target program to send each text string containing a command delimiter sequentially to the managed device via an established serial port connection as an output stream. In this way, each script command's corresponding text string ends with a newline character during transmission, effectively simulating user command input on the management device without requiring actual manual input from the user.
[0050] In one embodiment, to ensure that the script content is completely written to the managed device in step S102 above, this application embodiment also provides a script content writing mechanism. Specifically, the script content writing can be implemented according to the following steps A1~A2: A1: Sends a file initialization command to the managed device via the communication link; the managed device receives and responds to the initialization command, initializing an empty command file.
[0051] Here, the file initialization command is used to instruct the managed device to create a blank command file.
[0052] In practice, after confirming the successful establishment of the communication link, the management device can use the target program to send a file initialization command to the managed device via the communication link. Upon receiving the file initialization command, the managed device can use a shell process to execute the command, creating a blank command file. After the command file is created, the managed device can send a file creation completion feedback to the management device via the communication link. Upon receiving the file creation completion feedback, the management device executes step A2 as described below.
[0053] A2: Convert the pre-written script content into at least one text string, and write the text string into the command file in the managed device via the communication link.
[0054] In practice, the management device can use the target program to convert the pre-written script commands into text strings with command delimiters at the end. Then, in the form of an output stream, each text string with a command delimiter is sequentially written to a command file initialized in the managed device for storage via a communication link.
[0055] S103: In response to the completion of sending each text string, an execution command is sent to the managed device through the communication link; the managed device is used to receive and respond to the execution command, execute the script command corresponding to each text string, and obtain the execution result file.
[0056] Here, the execution instruction is used to trigger the managed device to execute the script command corresponding to the script content.
[0057] In practice, the management device can use the target program to detect whether the text strings corresponding to each script command in the acquired script content have been written to the managed device. If not, it continues to wait for the script commands to be written until all are written. Then, in response to the completion of sending each text string, it generates an execution instruction for each script command based on the command content corresponding to each script command and sends the execution instruction to the managed device through the communication link. The execution instruction can include a command execution indication and a permission change indication for changing the permissions corresponding to the script command. The permissions corresponding to the script command can be determined based on the device permissions required for the script command to execute. For example, when the script command is a content read / write instruction, the corresponding permission can be read / write permission; when the script command is a control command, the corresponding permission can be root permission. After receiving the execution instruction, the managed device can respond to the execution instruction, change the permissions of each script content according to the permissions indicated by the execution instruction, and execute the script command to obtain the execution result of the script command corresponding to each text string. Simultaneously, the managed device can generate a temporary execution result file and store the execution results corresponding to each script command in this file. For example, a temporary execution result file could be / tmp / result.txt.
[0058] In this way, the management device can actively send specific execution instructions to the managed device through the target program and serial port, which can change the permissions of the temporary script content in the managed device and trigger the managed device to actively execute the script content, thereby realizing automatic control of the automatic execution of the script content in the managed device.
[0059] In one embodiment, to avoid the problem that the script command cannot be fully executed because the script content is not completely written to the managed device before the execution command is sent, this application also provides a checking mechanism. Specifically, for the above S103, it can be implemented according to the following steps: S103-1: Send a first file check instruction to the managed device through the communication link; the managed device is used to receive and respond to the first file check instruction, perform content integrity checks on the command file, and obtain the first check result.
[0060] Here, the first file check instruction is used to instruct the command file in the managed device to perform a file integrity check. The first check result is used to indicate whether the script content in the command file is complete, that is, to indicate whether each script command in the script content has been written into the command file.
[0061] In practice, the management device can use the target program to send a first file check command to the managed device via a communication link. The timing of sending the first file check command can be a target duration after sending the text string to the managed device, or it can be sent periodically. The target duration can be a preset duration, or it can be dynamically determined based on the serial port configuration information of the first serial port and the size of the script content.
[0062] Furthermore, after receiving the first file check instruction, the managed device can use the Shell process to respond to the instruction and perform a content integrity check on the command file to determine whether the command file has completely stored the text strings corresponding to each script command in the script content, obtain the first check result, and feed it back to the management device through the communication link.
[0063] S103-2: Receive the first check result sent by the managed device through the communication link, and if the first check result indicates that the command file content is complete, determine that the text string has been sent, and send the execution command to the managed device through the communication link.
[0064] In practice, the management device can receive the first check result sent by the managed device and parse it using the target program to determine whether the first check result indicates that the command file content is complete. If not, it means that the script content has not been completely written into the command file. In this case, after waiting for a set time, the process can return to the step of sending the first file check instruction to the managed device until the obtained first check result indicates that the command file content is complete. If yes, it means that the script content has been completely written into the command file, which means that all text strings corresponding to the script content have been sent. Then, an execution instruction for the script content can be generated and sent to the managed device via the communication link to trigger the managed device to execute the command.
[0065] S104: In response to the triggering result reading condition, send a result reading command to the managed device through the communication link to obtain the execution result file in the managed device.
[0066] Here, the result reading condition can be a condition indicating the reading of command execution results from the managed device. The result reading command is used to read the execution result file from the managed device.
[0067] In practice, the management device can use the target program to detect whether a result reading condition has been triggered. If not, it can continue detecting until it is triggered. If so, in response to the triggered result reading condition, the management device can use the target program to send a result reading command to the managed device via a communication link. The managed device can receive the result reading command and execute it using a shell, reading its own stored execution result file and sending it back to the management device via the communication link. Furthermore, the management device can receive the execution result file from the managed device via the communication link.
[0068] In this way, connecting the managing device and the managed device via a serial port and managing the managed device using the serial port not only avoids network dependence on the managed device but also eliminates the need for pre-installing any management services on the managed device. Automated management can be achieved solely using the most basic "command line" functions (such as Linux command line) inherent in all managed devices. Thus, the device control method provided in this application enables zero-configuration remote script execution of managed devices based on serial communication. Furthermore, by encoding the process of "sending script content – triggering script execution – reading execution results" into a repeatable and schedulable automated program, this application achieves automated management of the managed device, avoiding the inefficiency and error-prone nature of manual operation.
[0069] In one embodiment, the result reading condition can be triggered by at least one of the following two methods: Method 1: The result reading condition is triggered when the duration of the executed instruction reaches the first target duration.
[0070] Here, the first target duration can be a preset duration, which can be set based on experience, and this embodiment does not impose specific limitations. Understandably, the first target duration can be a relatively large duration to ensure that each script command has sufficient execution time. The sent duration is used to record the time elapsed since the execution command was sent to the managed device. For example, if the execution command was sent at 0:00:00 and the current time is 0:00:06, then the sent duration corresponding to the execution command at the current time is 6 seconds. In method 1, the result reading condition can be that the sent duration after the execution command was sent to the managed device reaches the first target duration.
[0071] In practice, after the management device sends the execution command to the managed device, it can use the target program to start a timer, count the duration of the execution command, and continuously check whether the duration has reached the first target duration. If not, it continues to record the duration. If so, it can determine the trigger condition for reading the result and use the target program to send a result reading command to the managed device.
[0072] Method 2: According to the scheduled check interval, a second file check instruction is sent to the managed device through the communication link; the managed device is used to receive and respond to the second file check instruction, check the execution result file, and obtain the second check result; the second check result is used to indicate whether the execution result file is complete; the second check result is received, and if the second check result indicates that the execution result file is incomplete, the process returns to the step of sending the second file check instruction to the managed device through the communication link according to the scheduled check interval, until the second check result indicates that the execution result file is complete, triggering the result reading condition.
[0073] Here, the interval for periodic checks can be set based on experience, and this embodiment does not impose specific limitations. The second file check instruction is used to instruct the execution result file in the managed device to perform a file integrity check. The second check result is used to indicate whether the content of the execution result file is complete, that is, to indicate whether all script commands in the script content have been executed.
[0074] In practice, after sending the execution command to the managed device, the management device can use the target program to periodically send a second file check command to the managed device via the communication link according to a preset timed check interval. Upon receiving the second file check command, the managed device can respond to and execute the command using its shell to perform an integrity check on its local execution result file. This determines whether the execution result file has completely stored the execution results corresponding to each script command in the script content, and the second check result is fed back to the management device via the communication link. Furthermore, the management device can receive the second check result from the managed device, parse it, and determine whether the second check result indicates that the content of the execution result file is complete. If not, it can be determined that not all script commands in the script content have been executed completely. Therefore, it can return to the step of sending the second file check command to the managed device via the communication link according to the timed check interval, waiting for the managed device to continue executing the unprocessed script commands until the latest second check result indicates that the content of the execution result file is complete, confirming that all script content has been completely executed, thus triggering the result reading condition. In this way, by performing regular, continuous checks, we can obtain information that the script has finished executing in a timely manner, and then trigger the result reading condition to read the execution result file, which can ensure that the complete execution result file can be read.
[0075] Optionally, if the second check result indicates that the result file content is complete, the result reading condition can be triggered after a short third target duration. This way, if the result file content is complete, a short delay can further ensure that all script commands have been executed.
[0076] Understandably, methods 1 and 2 can be used individually or in combination, and this application embodiment does not impose specific limitations. When using both methods in combination, a consistency comparison can be performed on the execution result files read under the two methods to improve the accuracy of the obtained execution result files. If the execution result files read under the two methods are inconsistent, the execution result file read under method 2 can be used as the final execution result file, and the first target duration can be adjusted according to the difference between the two methods. For example, if the difference between the execution result files read under the two methods is large, the first target duration can be increased by a larger amount; if the difference between the execution result files read under the two methods is small, the first target duration can be increased by a smaller amount. Alternatively, the increase ratio of the first target duration can be determined based on the difference between the execution result files read under the two methods, and the first target duration can be increased according to this ratio.
[0077] For example, after detecting that the script content has finished executing, a short delay can be used to ensure that the script content has completed execution. Then, the target program on the management device can send a result read command via serial port to read the contents of the execution result file. (For example, the result read command could be `cat / tmp / result.txt`. After receiving the result read command, the managed device's shell performs the corresponding file read operation and sends the read execution result file back to the management device via the same serial port channel.)
[0078] In one embodiment, the step of "obtaining the execution result file in the managed device" in S104 above can be implemented through the following steps B1 to B3: B1: Continuously acquire the result byte stream sent by the managed device through the input stream of the serial port management library.
[0079] Here, the result byte stream carries the file contents of the execution result file.
[0080] In practice, when communicating between the management device and the managed device using a serial port, data is transmitted between the two devices via byte streams. Therefore, the managed device can send the execution result file back to the management device as an output stream through the first serial port. The management device can then use the target program to continuously listen for and receive the result byte stream from the first serial port via the input stream of the serial port management library.
[0081] B2: In response to receiving a result byte stream indicating the end and / or not receiving a new result byte stream within the second target duration, convert each currently received result byte stream into an execution result file.
[0082] Here, the first target duration is a preset duration, which can be set based on experience, and this embodiment does not impose a specific limitation. The result byte stream indicating the end can be, for example, a byte stream carrying an end-of-byte character.
[0083] In practice, the management device can continuously acquire the result byte stream sent by the managed device through the input stream. Simultaneously, the management device can use the target program to monitor each received result byte stream, determining whether it indicates the end of the result byte stream, and / or whether no new result byte stream transmitted from the first serial port has been received within the second target duration since the last received result byte stream. If a result byte stream indicating the end is detected, and / or no new result byte stream transmitted from the first serial port has been received within the second target duration, it can be determined that the first serial port transmission has been completed. The management device can then use the target program to convert each result byte stream received from the first serial port into individual result strings, and combine these result strings into an execution result file.
[0084] B3: Based on the script content, parse the execution result file to obtain the file parsing result, and store the file parsing result and the execution result file.
[0085] In practical implementation, after the management device converts the execution result file using the target program, it can parse the execution result file according to the specific command content of each script command in the script content to determine the file parsing result. The file parsing result indicates whether the execution result of each script command matches the script command, that is, whether each script command was executed correctly. For example, when the script command is to query the hardware type of the managed device, the file parsing result can be used to determine whether the execution result matches the script command by checking if it contains keywords matching the hardware type. For example, when querying the Central Processing Unit (CPU) model of the managed device, if keywords related to the CPU model are parsed from the execution result file, it can be determined that the execution result matches the script command; conversely, if no keywords related to the CPU model are parsed, it can be determined that the execution result does not match the script command. In this way, this application can realize the automatic acquisition and parsing of script execution results between the management device and the managed device using the same serial communication channel.
[0086] Then, the management device can use the target program to store the file parsing results and execution result files in a local file or database for subsequent analysis and processing by maintenance personnel.
[0087] Optionally, after the management device converts the result file into an execution file, it may not parse it but instead store it directly in a local file or database for subsequent analysis and processing by maintenance personnel.
[0088] Thus, in this application, the management device utilizes a target program based on a serial port management library to achieve a fully automated process from script content conversion to triggering script execution and obtaining execution results, thereby completing remote automatic management of the managed device.
[0089] like Figure 2 The diagram illustrates an interactive process for device control provided in this application, where a management device and a managed device are pre-connected physically via a serial port. The management device then uses a target program to perform connection initialization, specifically by using a serial port management library to discover, configure, and open a serial port (such as the second serial port mentioned above) to establish a serial communication link with the managed device. It forwards configuration signals to the managed device via this communication link and, upon receiving connection-ready information from the managed device, determines that the communication link has been established. Next, the management device uses the target program to transmit and execute scripts, specifically by converting pre-written script content into at least one text string and sending it to the managed device via the communication link. After receiving confirmation from the managed device that the script content has been saved, it sends an execution command to the managed device via the communication link. Upon receiving the execution command, the managed device can execute the script commands in the text string using a shell to obtain an execution result file. Finally, the management device uses the target program to retrieve the results, specifically by sending a result read command to the managed device via the communication link. The managed device can respond to the result read command, read the execution result file, and send the execution result file back to the management device in the form of a result byte stream via the communication link. Finally, the management device can use the target program to process the results, specifically by converting the received result byte streams into an execution result file, parsing it to obtain the file parsing result, and then storing the file parsing result and the execution result file.
[0090] Thus, this application provides an automated process for automatically sending, triggering execution, and obtaining results of scripts based on serial communication. This fundamentally solves the problems of strong dependence on network configuration and pre-installation of services in technical solutions based on network protocols such as SSH, and also solves the problem of the inability to automate processes in interactive terminal solutions based on physical serial ports. This effectively improves the flexibility and efficiency of remote device management.
[0091] The specific interaction process between the management device and the managed device can be referred to the descriptions of the above embodiments, and will not be repeated here.
[0092] Furthermore, embodiments of this application also provide a device control system, which includes a management device and a managed device with zero pre-configuration. A second serial port on the management device is physically connected to a first serial port on the managed device. The management device can utilize the device control method provided in embodiments of this application to achieve remote automated management of the managed device.
[0093] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0094] Based on the same inventive concept, this disclosure also provides a device control apparatus corresponding to the device control method. Since the principle of the device in this disclosure for solving the problem is similar to that of the device control method described above, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0095] like Figure 3 The diagram shown is a schematic representation of a device control apparatus provided in an embodiment of this disclosure, comprising: Module 301 is used to determine, using a serial port management library, a second serial port on the management device that is physically connected to the first serial port of the managed device, and to establish a communication link between the second serial port and the first serial port. The first sending module 302 is used to convert pre-written script content into at least one text string and send it to the managed device through the communication link; The second sending module 303 is used to send an execution instruction to the managed device through the communication link in response to the completion of sending each of the text strings; the managed device is used to receive and respond to the execution instruction, execute the script command corresponding to each of the text strings, and obtain an execution result file. The acquisition module 304 is used to send a result reading command to the managed device through the communication link in response to a trigger result reading condition, and to acquire the execution result file in the managed device.
[0096] In one possible implementation, the establishment module 301, when establishing the communication link between the second serial port and the first serial port, is used to: Obtain the serial port configuration information of the first serial port; the serial port configuration information includes at least the baud rate, data bits, stop bits, and parity bits; The second serial port is configured according to the serial port configuration information, and after the configuration is completed, the second serial port is opened to establish the communication link.
[0097] In one possible implementation, the first sending module 302, when converting the pre-written script content into at least one text string and sending it to the managed device via the communication link, is used to: The script content is parsed to determine the individual script commands to be executed. Each script command is converted into a text string and a command separator is set at the end of the text string; Each text string containing the command delimiter is sent to the managed device via the communication link as an output stream.
[0098] In one possible implementation, the first sending module 302, when converting the pre-written script content into at least one text string and sending it to the managed device via the communication link, is used to: A file initialization command is sent to the managed device via the communication link; the managed device receives and responds to the initialization command, and initializes an empty command file; The pre-written script content is converted into at least one text string, and the text string is written into the command file in the managed device through the communication link.
[0099] In one possible implementation, the second sending module 303, when sending an execution command to the managed device via the communication link in response to the completion of sending each of the text strings, is configured to: A first file check instruction is sent to the managed device via the communication link; the managed device receives and responds to the first file check instruction, performs a content integrity check on the command file, and obtains a first check result. The system receives a first check result sent by the managed device through the communication link, and if the first check result indicates that the command file content is complete, it determines that the text string has been sent and sends an execution command to the managed device through the communication link.
[0100] In one possible implementation, the acquisition module 304 is configured to trigger the result reading condition through the following steps: In response to the execution instruction's sent duration reaching a first target duration, the result reading condition is triggered; and / or, According to the scheduled check interval, a second file check instruction is sent to the managed device through the communication link; the managed device is used to receive and respond to the second file check instruction, check the execution result file, and obtain a second check result; the second check result is used to indicate whether the execution result file is complete. Receive the second check result, and if the second check result indicates that the content of the execution result file is incomplete, return to the step of sending the second file check instruction to the managed device through the communication link according to the timed check interval, until the second check result indicates that the content of the execution result file is complete, triggering the result reading condition.
[0101] In one possible implementation, the acquisition module 304, when acquiring the execution result file in the managed device, is used to: The system continuously acquires the result byte stream sent by the managed device through the input stream of the serial port management library. In response to receiving a result byte stream indicating the end and / or not receiving a new result byte stream within the second target duration, convert each currently received result byte stream into an execution result file; Based on the script content, the execution result file is parsed to obtain the parsing result, and the parsing result and the execution result file are stored.
[0102] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0103] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0104] Based on the same technical concept, embodiments of this application also provide a computer device. (Refer to...) Figure 4 The diagram shown is a structural schematic of a computer device provided in an embodiment of this application, comprising: The system comprises a processor 401, a memory 402, and a bus 403. The memory 402 stores machine-readable instructions executable by the processor 401. The processor 401 executes these machine-readable instructions, performing the following steps: S101: Using a serial port management library, the processor determines a second serial port on the management device that is physically connected to a first serial port on the managed device, and establishes a communication link between the second serial port and the first serial port; S102: The processor converts a pre-written script into at least one text string and sends it to the managed device via the communication link; S103: In response to the completion of sending each text string, the processor sends an execution command to the managed device via the communication link; the managed device receives and responds to the execution command, executes the script command corresponding to each text string, and obtains an execution result file; and S104: In response to triggering a result reading condition, the processor sends a result reading command to the managed device via the communication link to obtain the execution result file from the managed device.
[0105] The aforementioned memory 402 includes a main memory 4021 and an external memory 4022. The main memory 4021, also known as internal memory, is used to temporarily store the computational data in the processor 401, as well as the data exchanged with external memory such as a hard disk 4022. The processor 401 exchanges data with the external memory 4022 through the main memory 4021. When the computer device is running, the processor 401 and the memory 402 communicate through the bus 403, so that the processor 401 executes the execution instructions mentioned in the above method embodiments.
[0106] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the device control method described in the above-described method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
[0107] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the device control method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0108] The computer program product can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0109] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0110] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0111] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0112] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0113] If the technical solution of this application involves personal information, the product using this technical solution has clearly informed the user of the personal information processing rules and obtained the user's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using this technical solution has obtained the user's separate consent before processing the sensitive personal information, and also meets the requirement of "express consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set up to inform users that they have entered the scope of personal information collection and that personal information will be collected. If an individual voluntarily enters the collection scope, it is deemed that they have agreed to the collection of their personal information; or on the personal information processing device, with clear signs / information informing users of the personal information processing rules, authorization is obtained from the individual through pop-up information or by asking the individual to upload their personal information; wherein, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the types of personal information processed.
[0114] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A device control method characterized by, Applied to the management of equipment, the method includes: Using the serial port management library, determine the second serial port on the management device that is physically connected to the first serial port of the managed device, and establish a communication link between the second serial port and the first serial port; The pre-written script content is converted into at least one text string and sent to the managed device through the communication link; Upon completion of sending each of the text strings, an execution instruction is sent to the managed device via the communication link; the managed device receives and responds to the execution instruction, executes the script command corresponding to each of the text strings, and obtains an execution result file. In response to the triggering of the result reading condition, a result reading command is sent to the managed device through the communication link to obtain the execution result file in the managed device.
2. The method of claim 1, wherein, Establishing a communication link between the second serial port and the first serial port includes: Obtain the serial port configuration information of the first serial port; the serial port configuration information includes at least the baud rate, data bits, stop bits, and parity bits; The second serial port is configured according to the serial port configuration information, and after the configuration is completed, the second serial port is opened to establish the communication link.
3. The method of claim 1, wherein, The step of converting pre-written script content into at least one text string and sending it to the managed device via the communication link includes: The script content is parsed to determine the individual script commands to be executed. Each script command is converted into a text string and a command separator is set at the end of the text string; Each text string containing the command delimiter is sent to the managed device via the communication link as an output stream.
4. The method of claim 1, wherein, The step of converting pre-written script content into at least one text string and sending it to the managed device via the communication link includes: A file initialization command is sent to the managed device via the communication link; the managed device receives and responds to the initialization command, and initializes an empty command file; The pre-written script content is converted into at least one text string, and the text string is written into the command file in the managed device through the communication link.
5. The method according to claim 4, characterized in that, The response, upon completion of sending each of the text strings, involves sending an execution command to the managed device via the communication link, including: A first file check instruction is sent to the managed device via the communication link; the managed device receives and responds to the first file check instruction, performs a content integrity check on the command file, and obtains a first check result. The system receives a first check result sent by the managed device through the communication link, and if the first check result indicates that the command file content is complete, it determines that the text string has been sent and sends an execution instruction to the managed device through the communication link.
6. The method according to claim 1, characterized in that, The result reading conditions are triggered through the following steps: In response to the execution instruction's sent duration reaching a first target duration, the result reading condition is triggered; and / or, According to the scheduled check interval, a second file check instruction is sent to the managed device through the communication link; the managed device is used to receive and respond to the second file check instruction, check the execution result file, and obtain a second check result; the second check result is used to indicate whether the execution result file is complete. Receive the second check result, and if the second check result indicates that the content of the execution result file is incomplete, return to the step of sending the second file check instruction to the managed device through the communication link according to the timed check interval, until the second check result indicates that the content of the execution result file is complete, triggering the result reading condition.
7. The method according to claim 1, characterized in that, The step of obtaining the execution result file from the managed device includes: The system continuously acquires the result byte stream sent by the managed device through the input stream of the serial port management library. In response to receiving a result byte stream indicating the end and / or not receiving a new result byte stream within the second target duration, convert each currently received result byte stream into an execution result file; Based on the script content, the execution result file is parsed to obtain the parsing result, and the parsing result and the execution result file are stored.
8. A device control apparatus, characterized in that, Applied to management equipment, the device includes: A module is established to use a serial port management library to determine a second serial port on the management device that is physically connected to a first serial port on the managed device, and to establish a communication link between the second serial port and the first serial port. The first sending module is used to convert the pre-written script content into at least one text string and send it to the managed device through the communication link; The second sending module is used to send an execution instruction to the managed device through the communication link in response to the completion of sending each of the text strings; the managed device is used to receive and respond to the execution instruction, execute the script command corresponding to each of the text strings, and obtain an execution result file. The acquisition module is used to send a result reading command to the managed device through the communication link in response to a trigger result reading condition, and to acquire the execution result file in the managed device.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.
10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method as described in any one of claims 1 to 7.