SCPI communication implementation method and Android device

By building a hash table on the Android device to parse SCPI messages, efficient SCPI communication and human-computer interaction experience are achieved, solving the problem of low human-computer interaction efficiency on the MCU platform.

CN119356909BActive Publication Date: 2026-03-24青岛艾诺仪器有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-24
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing technologies for instruments and meters based on MCU platforms suffer from poor human-computer interaction, long development cycles, and rigid operation, making it difficult to implement SCPI communication on Android devices.

Method used

Regular expressions are used to segment and identify SCPI messages. Short character hash tables, path and method hash tables, and path and parameter hash tables are constructed. These tables are used to quickly parse SCPI instructions and execute corresponding methods to realize SCPI communication on Android devices.

Benefits of technology

It implements efficient SCPI communication on Android devices, with excellent human-computer interaction experience, and solves the problem of low human-computer interaction efficiency on MCU platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119356909B_ABST
    Figure CN119356909B_ABST
Patent Text Reader

Abstract

The application discloses an SCPI communication implementation method and an Android device, when the Android device receives an SCPI message, fields in the message are identified first, the identified fields are put into a list and are marked with types, each field is parsed according to the field type, the parsed fields and data are added to a path and a parameter list respectively, when a message is parsed, a method corresponding to the path is queried by calling a path and method Handle hash table, then a parameter address is obtained by calling a path and parameter hash table, data under the parameter address is acquired and a corresponding method is executed, so that the Android device can execute SCPI instructions; the application can quickly and orderly make the Android device run SCPI instructions, so that excellent man-machine interaction experience of the Android device can be obtained, and SCPI communication between instrument and meter devices can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of instrumentation technology, specifically, it relates to an SCPI communication implementation method and an Android device. Background Technology

[0002] Driven by the design principles of automation and integration, there is a frequent need for interactive communication between instruments and equipment. Meanwhile, as humans are a core element in production and R&D, a protocol is required that both conforms to human reading habits and enables communication between devices. Therefore, the SCPI communication protocol emerged.

[0003] SCPI (Standard Commands for Programmable Instruments) is a hardware-independent, purely software standard that allows strings to be transmitted through any instrument interface. It is a standardized instrument programming language built upon existing standards IEEE 488.1 and IEEE 488.2, and conforms to floating-point arithmetic rules in IEEE 754, ISO 646 7-bit encoding symbols for information exchange, and other standards. It specifies the content and structure of messages at the controller-to-instrument and instrument-to-controller information exchange layer, thereby describing a wide variety of instrument functions in a standardized way, with the aim of reducing program development time for automated test equipment.

[0004] In the past, instrumentation equipment typically used microcontrollers for control, human-computer interaction, and external communication. Since these devices usually used C as their primary programming language, their SCPI communication functions were also developed using C. However, with the rapid development of smartphones and tablets, users have increasingly higher demands for the human-computer interaction experience of instrumentation equipment. Therefore, using a more intelligent operating system as the interaction platform for these devices is an inevitable trend.

[0005] Currently, the mainstream operating systems for smart devices are Android, iOS, and Linux. iOS, due to its closed ecosystem, is not conducive to flexible development scenarios. Linux offers a very flexible development approach, but its human-computer interaction and UI design experience are not as good as Android. Because Android inherits many advantages from Linux, devices running Android have become the mainstream in the smart device market. Summary of the Invention

[0006] The purpose of this invention is to provide an SCPI communication implementation method for Android devices and an Android device configured with the SCPI communication implementation method, so as to run the SCPI communication method on the Android device and achieve the effect of obtaining the excellent human-computer interaction experience of Android and realizing SCPI communication between instruments and meters.

[0007] The present invention is implemented using the following technical solutions:

[0008] A method for implementing SCPI communication is proposed, including:

[0009] S1 receives SCPI messages and stores them in the buffer.

[0010] S2 uses regular expressions to segment and identify messages, and puts the identified fields into a list in order and labels the field types;

[0011] S3, parse each field according to its type, and put the parsed fields into the path and parameter list according to their type;

[0012] S4, when parsing the instruction end field, retrieve the path and method hash table to query the method corresponding to the path;

[0013] S5 retrieves the path and parameter hash table, queries the parameter address, obtains the data under the parameter address, and executes the corresponding method.

[0014] In some embodiments of the present invention, the regular expressions in step S2 are sorted according to priority, from high to low, including: colon, semicolon, square brackets, space, command type, data type and newline; wherein, the command type includes letters, numbers, asterisks, question marks and decimal points; the data type includes letters, numbers and decimal points.

[0015] In some embodiments of the present invention, the method further includes the step of constructing a short character hash table:

[0016] Extract fields from the message;

[0017] Extract the uppercase portion of the field as a short character;

[0018] The extracted fields are formatted into uppercase and used as the long characters of the fields;

[0019] Bind short characters and long characters to the short character hash table.

[0020] In some embodiments of the present invention, the method further includes the step of constructing a path and method Handle hash table:

[0021] The complete instruction and the handle of the corresponding method to be executed are bound to the path and method Handle hash table; the method Handle is accessed by passing through the interface type.

[0022] In some embodiments of the present invention, the method further includes the step of constructing a path and parameter hash table:

[0023] The path of the instruction is bound to the address of the relevant parameter to the path and parameter hash table; the address of the parameter is the specific address of the object to be set or queried.

[0024] In some embodiments of the present invention, step S3 includes:

[0025] For short characters, query the short character hash table to pave them into long characters;

[0026] Format all letters to uppercase;

[0027] Add the uppercase version of the field to the path.

[0028] In some embodiments of the present invention, step S3 further includes:

[0029] The system identifies whether the field ends with a "?". If a "?" is found, it is deleted first, and then the short character is padded to a long character before being added after the long character.

[0030] In some embodiments of the present invention, step S3 further includes:

[0031] Fields of type colon are directly inserted into the path as delimiters for command fields; when the first field is a colon, the path is returned to the root and the path is cleared.

[0032] In some embodiments of the present invention, the method further includes:

[0033] S6 returns the execution result; when the SCPI command is sent in frames, the execution result is concatenated into a single frame using semicolons and sent back.

[0034] An Android device is proposed, configured with the SCPI communication implementation method described above.

[0035] Compared with existing technologies, the advantages and positive effects of this invention are as follows: The SCPI communication implementation method and Android device proposed in this invention, when the Android device receives an SCPI message, first identifies the fields in the message using regular expressions with set priorities, puts the identified fields into a list and labels the field types, parses each field according to the field type, and adds the parsed fields to the path and parameter lists according to their types. When a message is parsed, the path and method Handle hash table is retrieved to look up the method corresponding to the path, and then the path and parameter hash table is retrieved to obtain the parameter address, retrieve the data under the parameter address, and execute the corresponding method, enabling the Android device to execute SCPI instructions. This invention, by constructing a short character hash table, a path and method Handle hash table, and a path and parameter hash table, after identifying the fields in the message based on regular expressions, combines the short character hash table to parse each field, locates the corresponding method in the Android system through the path and method Handle hash table, and obtains the parameters required to execute the method through the path and parameter hash table. This enables the Android device to run SCPI instructions quickly and orderly, thus achieving both an excellent human-computer interaction experience on Android and SCPI communication between instruments and equipment.

[0036] Other features and advantages of the present invention will become clearer after reading the detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. Attached Figure Description

[0037] The accompanying drawings, as part of this invention, are provided to further illustrate the invention. The illustrative embodiments and descriptions are used to explain the invention but do not constitute an undue limitation thereof. Clearly, the drawings described below are merely some embodiments; those skilled in the art can obtain other drawings based on these drawings without creative effort.

[0038] Figure 1 This diagram illustrates the execution steps of the SCPI communication implementation method proposed in this invention.

[0039] Figure 2 This is the execution flow of the SCPI communication implementation method proposed in this invention.

[0040] It should be noted that these accompanying drawings and textual descriptions are not intended to limit the scope of the invention in any way, but rather to illustrate the concept of the invention to those skilled in the art by referring to specific embodiments. Detailed Implementation

[0041] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments will be clearly and completely described below with reference to the accompanying drawings. The following embodiments are used to illustrate the present invention, but are not intended to limit the scope of the present invention.

[0042] Existing technologies typically implement SCPI communication using C language on MCU-based platforms. However, MCU platforms suffer from low operating efficiency, long development cycles, and rigid operation due to limitations in human-computer interaction optimization for touch, UI, and color design. This invention aims to implement an SCPI communication method for instrumentation equipment based on the Android system. Figure 1 and Figure 2 As shown, it includes the following steps:

[0043] S1: Receive SCPI messages and store them in the buffer.

[0044] Android devices receive messages and store them in a message buffer. The program periodically checks the message buffer. When it detects a carriage return or newline character (i.e., \r and \n in ASCII code), or receives other characters and no new messages are received after a certain period of time, it reads the received message and puts it into a separate buffer.

[0045] S2: Use regular expressions to segment and identify the message, and put the identified fields into a list in order and label the field types.

[0046] In this embodiment of the invention, regular expressions are divided into 7 priorities, from highest to lowest: (1) colon ":", (2) semicolon ";", (3) square brackets "[]", (4) space "\t", (5) command class, (6) data class, and (7) newline "[\r\n]". Among them, the command class includes: letters, numbers, asterisks, question marks, and decimal points "[a-zA-z0-9*_?\\.]+", and the data class includes: letters, numbers, and decimal points "[a-zA-z0-9\\.]+".

[0047] Based on the above regular expressions, each expression is matched against the input message according to its priority. The messages are matched from left to right, and the successfully matched messages are extracted.

[0048] Taking the message command "CURR:STAT:L1 12" as an example, according to the priority of the regular expressions mentioned above, each expression is matched against the command. Expressions 1-4 cannot be matched successfully. Expression 5 matches "CURR" from left to right. Therefore, "CURR" is the first field of this message. "CURR" is placed in the field list, and the field type is marked as command type. Then, the regular expressions are used again to match the remaining messages according to priority. At this time, the first character in ":STAT:L1 12" matches regular expression 1 successfully, so the colon ":" is successfully extracted. Since ":" and ";" are delimiters, in this embodiment, only the field type is retained when placing it in the field list, and the content is represented by an empty "null". The remaining messages are then matched again according to priority. "STAT" and "L1" are extracted and marked as command types. When a space is matched, it matches regular expression 4, indicating that the following content is a data type. The space is discarded and the matching of "12" continues. Regular expression 5 matches successfully. Since there is a space parameter, "12" is added to the field list and marked as a data type.

[0049] After the entire message has been matched, an instruction end symbol will be added to the end of the field list as the end, such as the semicolon ";". If the message already has a ";" when it is sent, then no additional symbol is needed.

[0050] After matching and extracting the message using regular expressions, the entire message is divided into 7 fields: "CURR", "null", "STAT", "null", "L1", "12", and ";".

[0051] In this embodiment of the invention, in order to facilitate the quick search for the method to be executed and the data to be processed after SCPI instruction parsing, and to be compatible with various combinations of full spelling, abbreviation, uppercase and lowercase instructions, three hash tables are designed to achieve fast instruction matching: a short character hash table, a path and method Handle (complete instruction - handle of executable program) table, and a path and parameter hash table.

[0052] In the short character hash table, short characters (abbreviations) are bound to long characters (full spellings). This is because the SCPI protocol allows the use of abbreviations to replace the complete spelling of instructions, in order to reduce the communication burden. Specifically, the construction method of the short character hash table, taking the message "CONFigure:VOLTage:ON" as an example, includes: (1) extracting the fields "CONFigure", "VOLTage" and "ON" from the message; (2) extracting the uppercase parts "CONF", "VOLT" and "ON" from the fields as short characters; (3) formatting the fields extracted in (1) into uppercase as the long characters "CONFIGURE", "VOLTAGE" and "ON"; (4) binding the short characters extracted in (2) and the long characters extracted in (3) to the short character hash table, for example, (CONF, CONFIGURE), (VOLT, VOLTAGE) and (ON, ON). As shown in the example, in the short character hash table, if there is a distinction between long and short characters, different characters will be represented. If there is no distinction between long and short characters, the two bound words will be the same.

[0053] The path and method handle hash table binds the complete instruction to the handle of the corresponding method to be executed. Method handles are accessed by passing an interface type to access different methods using a unified interface; for example (CONFIGURE: VOLTAGE: ON, set).

[0054] The path and parameter hash table binds the instruction path with the address of the related parameter. The parameter address is the specific address of the parameter object to be set or queried, and this address is bound to the specific parameter through the hash table; for example (CONFIGURE: VOLTAGE: ON, 461).

[0055] The above paths fall into two main categories: one is a setting type, such as "CONFigure:VOLTage:ON", and the other is a query type with a question mark at the end, such as "CONFigure:VOLTage:ON?".

[0056] S3: Parse each field according to its type, and put the parsed fields into the path and parameter list according to their type.

[0057] This includes: (1) identifying whether the message ends with a "?". If it does, it means that the message is a query instruction; (2) if it is a short character, query the short character hash table to supplement it into a long character; (3) formatting it to uppercase; (4) adding the field to the path.

[0058] For example, in step S2, where the fields "CURR", "null", "STAT", "null", "L1", "12", and ";" are extracted, the first field "CURR" is read as a short character. The short character hash table is consulted, and the short character is padded to the long character "CURRENT" before being added to the path. At this point, the first element in the path is obtained. If the field itself contains "?", the "?" needs to be removed before the search, and the padded character is appended to the long character. If the segment content is a long character, the field content is retained. The third field "STAT" is a short character, padded to the long character "STATIC" before being added to the path, becoming the third element in the path. The fifth field "L1" is itself a long character, and this field is retained as the fifth element in the path.

[0059] Fields of type colon are used as separators for command fields and are directly placed in the path. If the first field is a colon, it indicates that you need to return to the root of the path and perform a path clearing operation.

[0060] Semicolon type field description: This field has been parsed and the final instruction matching will begin. The path will be matched against the constructed path in the Path and Method Handle hash table. If the match is successful, the query program or setting program bound in the hash table will be executed.

[0061] The data field "12" was directly added to the parameter list.

[0062] At this point in the program's execution, the "CURR:STAT:L1 12" message has been parsed into two parts: the path "CURRENT:STATIC:L1" and the parameter "12".

[0063] S4: When the instruction end field is parsed, retrieve the path and method hash table and look up the method corresponding to the path.

[0064] Typically, a semicolon-type field indicates that this field has been parsed. Add a path and method hash table and search within it. For example, find that the method corresponding to "CURRENT:STATIC:L1" is "set_CC".

[0065] S5: Retrieve the path and parameter hash table, query the parameter address, obtain the data under the parameter address, and execute the corresponding method.

[0066] From the path and parameter hash table, query the parameter address corresponding to the path, read the data stored in the parameter list in step S4 (i.e., the instruction parameters) from that parameter address, and execute the method corresponding to the path. Different methods are used to process different query or set instructions; execute them according to the existing methods. After processing, proceed to step S6.

[0067] S6: Returns the execution result.

[0068] In practical applications, SCPI commands are sent in frames. For example, if the three parameters of voltage, current and power are queried consecutively, the executing program can concatenate the three parameters with ";" to form a single message frame and send it back.

[0069] Based on the SCPI communication implementation method proposed above, this invention also proposes an instrumentation device implemented using the Android system. The Android device is configured with the above-mentioned SCPI communication implementation method. After receiving the SCPI instruction, it executes the Android system's method according to the above-mentioned SCPI communication implementation method. This not only obtains the excellent human interaction experience of Android, but also realizes SCPI communication between instrumentsation devices.

[0070] It should be noted that the above description is not intended to limit the present invention, and the present invention is not limited to the examples given above. Any changes, modifications, additions or substitutions made by those skilled in the art within the scope of the present invention should also fall within the protection scope of the present invention.

Claims

1. A method for implementing SCPI communication, characterized in that, include: S1 receives SCPI messages and stores them in the buffer. S2 uses regular expressions to segment and identify messages, and puts the identified fields into a list in order and labels the field types; S3, parse each field according to its type, and put the parsed fields into the path and parameter list according to their type; S4, when parsing the instruction end field, retrieve the path and method hash table to query the method corresponding to the path; S5, retrieve the path and parameter hash table, look up the parameter address, obtain the instruction parameters, and execute the corresponding method; The method also includes the step of constructing a short character hash table: extracting fields from the message; Extract the uppercase portion of the field as the short character; format the extracted field to uppercase as the long character; bind the short character and the long character to the short character hash table; The method further includes the step of constructing a path and method Handle hash table: binding the complete instruction and the handle of the corresponding method to be executed to the path and method Handle hash table; the method Handle is accessed by passing through an interface type; The method further includes the step of constructing a path and parameter hash table: binding the path of the instruction and the address of the related parameters to the path and parameter hash table; The address of the parameter is the specific address of the object to be set or queried. Then step S3 includes: For short characters, query the short character hash table to pave them into long characters; format them uniformly to uppercase; add the uppercase field to the path; If a field ends with a "?", delete it first, then append the short character to the long character and add it after the long character. Fields of type colon are directly inserted into the path as delimiters for command fields; when the first field is a colon, the path is returned to the root and the path is cleared.

2. The SCPI communication implementation method according to claim 1, characterized in that, The regular expressions in step S2 are sorted by priority from highest to lowest as follows: colon, semicolon, square brackets, space, command type, data type, and newline; among them, the command type includes letters, numbers, asterisks, question marks, and decimal points; the data type includes letters, numbers, and decimal points.

3. The SCPI communication implementation method according to claim 1, characterized in that, The method further includes: S6 returns the execution result; when the SCPI command is sent in frames, the execution result is concatenated into a single frame using ";" and sent back.

4. An Android device, characterized in that, It is configured with the SCPI communication implementation method as described in any one of claims 1-3.

Citation Information

Patent Citations

  • Implementation method of external key extension module of Android embedded equipment

    CN111930646A

  • Circuit and method for upgrading firmware, chip and electronic equipment

    CN114721683A