Method for efficiently executing SCPI program control instruction
By simultaneously comparing and splitting the keywords and parameters of SCPI instructions, the instruction parsing process is optimized, solving the problem of excessively long execution time in existing technologies and achieving the effect of efficient execution of SCPI instructions.
Patent Information
- Application Number
- CN202511717806.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-02-13
AI Technical Summary
Existing technologies involve a cumbersome parsing process when executing SCPI instructions, resulting in excessively long execution times, making them unsuitable for applications with high real-time requirements.
通过匹配IP地址建立上位机与服务器的通信,使用‘ ’字符拆分指令数据包,空格和逗号分隔关键字和参数,并根据指令类型进行特定处理,优化指令解析过程。
It achieves efficient parsing of multiple SCPI instructions, improving instruction execution speed and enhancing user experience.
Smart Images

Figure CN121523732A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of SCPI programmable instruction technology, specifically a method for efficiently executing SCPI programmable instructions. Background Technology
[0002] Standard Commands for Programmable Instruments (SCPI) is a set of instructions used to control programmable measuring instruments. For example, patent application CN202411493161.9 describes an SCPI communication implementation method and an Android device. When the Android device receives an SCPI message, it first identifies the fields in the message, places the identified fields in a list and labels their types, parses each field according to its type, and adds the parsed fields and data to the path and parameter lists respectively. When a message is parsed, it retrieves the method corresponding to the path from the path and method hash table, then retrieves the parameter address from the path and parameter hash table, obtains the data at the parameter address, and executes the corresponding method, enabling the Android device to execute SCPI instructions.
[0003] Currently, most measuring instruments on the market use VISA library functions to read, write, and parse SCPI commands. This method compares multi-level command keywords sequentially, which is too cumbersome and increases execution time, making it unsuitable for applications with high real-time requirements.
[0004] Therefore, existing technologies can no longer meet people's current needs, and based on the current situation, there is an urgent need to improve existing technologies. Summary of the Invention
[0005] The purpose of this invention is to provide a method for efficiently executing SCPI programmable instructions, so as to solve the problems mentioned in the background art.
[0006] This invention provides a method for efficiently executing SCPI programmable instructions, the specific steps of which include: Step S100: Match IP addresses to enable communication between the host computer and the server.
[0007] Step S200: The host computer sends SCPI commands: function query command, file transfer command, and function setting command; each command ends with the '\n' character; and the keywords of the SCPI commands are separated by ':'. In step S200, if the SCPI instruction is a function query instruction, a question mark '?' is added to the end of the keyword.
[0008] In step S300, the server receives the instruction data packet and reads all the data. If multiple SCPI instructions are in the same instruction data packet, the instruction data packet is split into multiple SCPI instructions by using the '\n' character. If the last instruction does not end with the '\n' character, the data after the last '\n' character of the instruction data packet is merged with the data before the first '\n' character of the next instruction data packet.
[0009] Step S400: Parse the keyword and parameter for each SCPI instruction, and separate the keyword and parameter by a space; separate the keyword and the first parameter by a space; separate the parameters by commas; and end the SCPI instruction with '\n'.
[0010] In step S500, if the instruction in the parsed instruction data packet is a function setting instruction, after the parameters of the instruction are parsed, the parameters are set to the corresponding function.
[0011] Step S600: If the instruction in the parsed instruction data packet is a function query instruction, then reply to the host computer in the format of #9#9 + data byte length + instruction identifier + data; where #9#9 is fixed data, representing the start byte of the reply instruction; data byte length represents the length of the data content; instruction identifier represents the identifier corresponding to the function queried by the instruction; and data represents the content queried.
[0012] Step S700: If the instruction in the parsed instruction data packet is a file transfer instruction, then parse the file length and file content contained in the parameters of the file transfer instruction; and, when parsing the file content of the file in the parameters of the file transfer instruction, extract the data from the instruction data packet according to the file length.
[0013] The present invention has the following beneficial effects: This invention enables the reading of files of any file type by simultaneously comparing multiple SCPI command keywords. It optimizes the cumbersome command parsing process, increases command execution speed, and improves the user experience. Attached Figure Description
[0014] Figure 1 This is a schematic diagram illustrating the execution steps of the present invention; Figure 2 This is a schematic diagram of the structure when the file length of this invention is less than the instruction data packet length; Figure 3 This is a schematic diagram of the structure when the file length of this invention is greater than the instruction data packet length. Detailed Implementation
[0015] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the present invention without creative effort are within the scope of protection of the present invention.
[0016] refer to Figure 1 The present invention provides a method for efficiently executing SCPI programmable instructions, comprising: Step S100: Match IP addresses to enable communication between the host computer and the server; SCPI commands have multiple communication methods. In this embodiment, network communication is taken as an example. The server is a programmable instrument, the host computer is the client, and the server's IP address is set to 192.168.1.127. The host computer uses a network debugging assistant to connect to the remote host with the IP address 192.168.1.127 and the listening port number 5025.
[0017] In step S100, the server implements TCP / IP communication based on QT software under the Linux system. When the client sends a connection request, the server creates a network socket by rewriting virtual functions and binds data reading and signal reception under network disconnection conditions.
[0018] Step S200: The host computer sends SCPI commands: function query command, file transfer command, and function setting command; each command ends with a '\n' character; and the keywords of the SCPI commands are separated by ':' in their names; among them, The function query command is used to query the parameter values of the function corresponding to the command. The file transfer instruction is used to transfer files. The function setting command is used to set the parameter values of the function corresponding to the command.
[0019] In step S200, if the SCPI instruction is a function query instruction, a question mark '?' is added to the end of the keyword.
[0020] In step S200, the host computer sends SCPI instructions in the form of instruction data packets. The SCPI instructions sent may be a single instruction or multiple instructions.
[0021] In step S300, the server receives the instruction data packet and reads all the data. If multiple SCPI instructions are in the same instruction packet, the instruction packet is split into multiple SCPI instructions using the '\n' character; If the last instruction does not end with the '\n' character, then the data after the last '\n' character in the instruction data packet is merged with the data before the first '\n' character in the next instruction data packet.
[0022] Step S400: Parse the keywords and parameters for each SCPI instruction, and separate the keywords and parameters by spaces; Separate the keyword from the first parameter with a space; separate parameters with commas; and end the SCPI command with \n.
[0023] Step S500: If the instruction in the parsed instruction data packet is a function setting instruction, after the parameters of the instruction are parsed, the parameters are set to the corresponding function. In this embodiment, for example, the function setting instruction is: HISTory:WRECord val1,val2\n, where HISTory is the first keyword, WRECord is the second keyword, val1 is the first parameter, and val2 is the second parameter.
[0024] Step S600: If the instruction in the parsed instruction data packet is a function query instruction, then reply to the host computer in the format of #9#9 + data byte length + instruction identifier + data; where #9#9 is fixed data, representing the start byte of the reply instruction; data byte length represents the length of the data content; instruction identifier represents the identifier corresponding to the function queried by the instruction; and data represents the content queried. In this embodiment, for example, the function query command is: HISTory:WRECord?\n, where HISTory is the first keyword and WRECord is the second keyword.
[0025] Step S700: If the instruction in the parsed instruction data packet is a file transfer instruction, then the file length and file content contained in the parameters of the file transfer instruction are parsed sequentially; and when parsing the file content of the file in the parameters of the file transfer instruction, the data is extracted from the instruction data packet according to the file length. In this embodiment, because the file may contain characters used for delimiters such as spaces, '\n', ',', etc., which may cause SCPI instruction parsing errors, data is extracted from the instruction data packet according to the length of the file when parsing the file content.
[0026] refer to Figure 2 In step S701, when parsing the file length of the file transmission command parameters, if the file length is less than the command data packet length, the file is first removed from the command data packet, and then the remaining data is returned to step 400 for further parsing.
[0027] refer to Figure 3In step S702, when parsing the file length of the file transmission command parameters, if the file length is greater than the command data packet length, the file part of the command data packet is cached first. When the data of the next command data packet arrives, the keywords and parameters of the file transmission command are concatenated with the cached data, and the process returns to step 400 to continue parsing.
[0028] In step S703, if there is still remaining data in the current instruction data packet, return to step 400 to continue parsing until all the data in the instruction data packet has been read.
[0029] Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for efficiently executing SCPI programmable instructions, characterized in that, The specific steps include: Step S100: Match IP addresses to enable communication between the host computer and the server; Step S200: The host computer sends SCPI commands: function query command, file transfer command, and function setting command; each command ends with the '\n' character; and the keywords of the SCPI commands are separated by ':'. In step S200, if the SCPI instruction is a function query instruction, a question mark '?' is added to the end of the keyword for naming; In step S300, the server receives the instruction data packet and reads all the data. If multiple SCPI instructions are in the same instruction packet, the instruction packet is split into multiple SCPI instructions using the '\n' character; If the last instruction does not end with the '\n' character, then the data after the last '\n' character in the instruction data packet will be merged with the data before the first '\n' character in the next instruction data packet; Step S400: Parse the keywords and parameters for each SCPI instruction, and separate the keywords and parameters using spaces; and, Separate the keyword from the first parameter using a space; and, Separate the parameters with commas; and, End SCPI commands with '\n' at the end; Step S500: If the instruction in the parsed instruction data packet is a function setting instruction, after the parameters of the instruction are parsed, the parameters are set to the corresponding function. Step S600: If the instruction in the parsed instruction data packet is a function query instruction, then reply to the host computer in the format of #9#9 + data byte length + instruction identifier + data; where, #9 is a fixed number, representing the start byte of the reply instruction; the data byte length represents the length of the data content; the instruction identifier represents the identifier corresponding to the function of the instruction query; and the data represents the content of the query. Step S700: If the instruction in the parsed instruction data packet is a file transfer instruction, then parse the file length and file content contained in the parameters of the file transfer instruction; and, When parsing the file content of the file containing the file transfer command parameters, data is extracted from the command data packet based on the file length.
2. The method for efficiently executing SCPI programmable instructions according to claim 1, characterized in that: In step S100, when the client sends a connection request, the server creates a network socket by overriding a virtual function and binds it for data reading and signal reception under network disconnection conditions.
3. The method for efficiently executing SCPI programmable instructions according to claim 1, characterized in that: The function query command is an instruction that queries the parameter value of the function corresponding to the command. The file transfer instruction is an instruction for transferring files; The function setting command is a command that sets the parameter value of the function corresponding to the command.
4. The method for efficiently executing SCPI programmable instructions according to claim 1, characterized in that: In step S200, the host computer sends SCPI instructions in the form of instruction data packets. The sent SCPI instructions may be a single instruction or multiple instructions.
5. The method for efficiently executing SCPI programmable instructions according to claim 1, characterized in that: When parsing the file length of the file transfer command parameters, if the file length is less than the command data packet length, the file is first extracted from the command data packet, and then the remaining data is returned to step 400 for further parsing.
6. The method for efficiently executing SCPI programmable instructions according to claim 1, characterized in that: When parsing the file length of the file transfer command parameters, if the file length is greater than the command data packet length, the file portion of the command data packet is cached first. When the data of the next command data packet arrives, the keywords and parameters of the file transfer command are concatenated with the cached data, and the process returns to step 400 to continue parsing.
7. The method for efficiently executing SCPI programmable instructions according to claim 1, characterized in that: After step S700 is completed, if there is still data remaining in the current instruction data packet, the process returns to step 400 to continue parsing until all data in the instruction data packet has been read.
Citation Information
Patent Citations
SCPI communication implementation method and Android device
CN119356909A