SCPI communication implementation method and Android device
By implementing SCPI communication methods on Android devices, including receiving and parsing SCPI messages, and constructing hash table positioning methods and parameters, the problem of SCPI communication implementation on Android devices is solved, and efficient human-computer interaction and SCPI communication are achieved.
Patent Information
- Application Number
- CN202411493161.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-10-24
AI Technical Summary
The prior art is difficult to realize SCPI communication on Android devices, resulting in poor human-computer interaction experience of instrumentation and instrumentation equipment.
By implementing SCPI communication methods on Android devices, including receiving SCPI messages and stored to the cache area, using the fields in regular expressions to identify the message, analyze and mark the field type, build a hash table to position the method and parameters, and perform the corresponding correspondence method.
It realizes the execution of SCPI instructions on Android devices, which can not only obtain the excellent human-computer interaction experience of Android, but also realize SCPI communication between instrumentation devices.
Smart Images

Figure CN119356909A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of instruments and meters, and in particular, relates to a SCPI communication implementation method and an Android device. Background Art
[0002] Due to the design concept of automation and integration, there is often a need for interactive communication between instruments and equipment. At the same time, as the core link in production and research and development, people need a protocol that not only conforms to people's reading habits but also can realize communication between devices. Therefore, the SCPI communication protocol appeared.
[0003] SCPI (Standard Commands for Programmable Instruments) is a pure software standard that is independent of hardware. Strings can be transmitted through any instrument interface. It is a standardized instrument programming language based on the existing standards IEEE 488.1 and IEEE 488.2, and follows multiple standards such as floating-point arithmetic rules in IEEE 754 standard and 7-bit encoding symbols for information exchange in ISO646. It specifies the content and structure of information exchange layer messages between controller and instrument and between instrument and controller, so as to describe various instrument functions in a standard way, with the aim of reducing the program development time for automatic test equipment.
[0004] In the past, since instrumentation equipment usually used single-chip microcomputers to achieve control, human-computer interaction and external communication, and since these devices usually used C language as the main programming language, the SCPI communication function of these devices was also developed based on C language. With the rapid development of smart phones and tablets in society, users have gradually put forward higher and higher requirements for the human-computer interaction experience of instrumentation equipment. Therefore, it is an inevitable trend to use a smarter operating system as the interactive platform of the equipment.
[0005] The mainstream operating systems for smart devices are Android, IOS and Linux. IOS is not conducive to flexible development scenarios due to its closed ecosystem. Linux has a very flexible development method, but its human-computer interaction, UI and other design experiences are not as good as Android. Since the Android system itself inherits many advantages of the Linux system, devices equipped with the Android system (referred to as Android devices) have occupied the mainstream position of smart devices. Summary of the invention
[0006] The purpose of the present invention is to provide a SCPI communication implementation method also 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, so as to achieve both an excellent human-computer interaction experience of Android and the effect of SCPI communication between instrumentation devices.
[0007] The present invention is implemented by the following technical solutions: A SCPI communication implementation method is proposed, including: S1, receives SCPI messages and stores them in the buffer; S2, identifies the message segments through regular expressions, puts the identified fields into a list in order and marks the field types; S3, parse each field according to the field type, and put the parsed fields into the path and parameter list according to the type; S4, when parsing to the instruction end field, call the path and method Handle hash table to query the method corresponding to the path; S5, call the path and parameter hash table, query the parameter address, obtain the data under the parameter address and execute the corresponding method.
[0008] In some embodiments of the present invention, the regular expressions in step S2 are sorted according to priority, and include, from high to low, colon, semicolon, brackets, space, command class, data class, and line break; wherein the command class includes letters, numbers, asterisks, question marks, and decimal points; and the data class includes letters, numbers, and decimal points.
[0009] In some embodiments of the present invention, the method further comprises the step of constructing a short character hash table: Extract fields from the message; Extract the uppercase part of the field as short characters; Format the extracted fields to uppercase as long characters of the field; Bind short and long characters into the short character hash table.
[0010] In some embodiments of the present invention, the method further comprises the step of constructing a path and method Handle hash table: 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 through the interface type.
[0011] In some embodiments of the present invention, the method further comprises the step of constructing a path and parameter hash table: The path of the instruction and the address of the relevant parameters are bound to the path and parameter hash table; the address of the parameter is the specific address of the object to be set or queried in the end.
[0012] In some embodiments of the present invention, step S3 includes: For short characters, query the short character hash table to supplement them into long characters; Format all in uppercase; Add the uppercase field to the path.
[0013] In some embodiments of the present invention, step S3 further includes: Identify whether the field ends with a "?". If so, delete it first, then add it after the short characters are supplemented with long characters.
[0014] In some embodiments of the present invention, step S3 further includes: Place colon-type fields directly into the path as command field separators; when the first field is a colon, wrap around to the root of the path and clear the path.
[0015] In some embodiments of the present invention, the method further comprises: S6, returns the execution result; when the SCPI command is sent in a continuous frame, the execution result is spliced into a frame message with ";" and sent back.
[0016] An Android device is proposed, which is configured with the SCPI communication implementation method as described above.
[0017] Compared with the prior art, the advantages and positive effects of the present invention are as follows: the SCPI communication implementation method and Android device proposed in the present invention, when the Android device receives the SCPI message, firstly identifies the fields in the message by using a regular expression with a set priority, puts the identified fields into a list and marks the field type, parses each field according to the field type, and adds the parsed fields to the path and parameter list according to the type; when a message is parsed, the path and method Handle hash table is called, the method corresponding to the path is queried, and then the path and parameter hash table is called to query the parameter address, obtain the data under the parameter address and execute the corresponding method, so that the Android device can execute the SCPI instruction; the present invention constructs 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 the regular expression, parses each field in combination with the short character hash table, locates the method corresponding to the Android system by using the path and method Handle hash table, obtains the parameters required for the execution method by using the path and parameter hash table, and can quickly and orderly allow the Android device to run the SCPI instruction, so that both the excellent human-computer interaction experience of Android can be obtained and the SCPI communication between instrumentation equipment can be realized.
[0018] Other features and advantages of the present invention will become more apparent after reading the detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are part of the present invention and are used to provide a further understanding of the present invention. The exemplary embodiments and descriptions of the present invention are used to explain the present invention, but do not constitute an improper limitation of the present invention. Obviously, the accompanying drawings described below are only some embodiments. For those skilled in the art, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0020] Figure 1 The following is a schematic diagram of the execution steps of the SCPI communication implementation method proposed by the present invention; Figure 2 This is the execution flow of the SCPI communication implementation method proposed by the present invention.
[0021] It should be noted that these drawings and textual descriptions are not intended to limit the conceptual scope of the present invention in any way, but are intended to illustrate the concept of the present invention for those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0022] In order to make the purpose, 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 in conjunction with the drawings in the embodiments of the present invention. The following embodiments are used to illustrate the present invention but are not used to limit the scope of the present invention.
[0023] The prior art usually uses C language to implement SCPI communication on a platform based on MCU. However, the MCU platform has problems such as low operating efficiency, long development cycle, and rigid operation in terms of human-computer interaction optimization such as touch, UI, and color. The present invention aims to run a SCPI communication method on instrumentation equipment based on the Android system, such as Figure 1 and Figure 2 As shown, the following steps are included: S1: Receive SCPI messages and store them in the buffer.
[0024] The Android device receives messages and stores them in a message buffer. The program periodically checks the message buffer. When a carriage return or line feed character, i.e., \r and \n in ASCII code, is recognized, or other characters are received and there are no subsequent new messages after a certain period of time, the received message is read out and placed in a separate buffer.
[0025] S2: Use regular expressions to identify message segments, put the identified fields into a list in order and mark the field types.
[0026] In the embodiment of the present invention, regular expressions are divided into 7 priorities, from high to low: (1) colon ":", (2) semicolon ";", (3) brackets "[]", (4) space "\t", (5) command class, (6) data class, and (7) line feed "[\r\n]". 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\\.]+".
[0027] Based on the above regular expressions, each expression is matched with the input message according to its priority, the message is matched from left to right, and the successfully matched message is extracted.
[0028] Take the message instruction "CURR:STAT:L1 12" as an example. According to the priority of the above regular expression, each expression is matched with the instruction. 1-4 cannot be matched successfully. The 5th expression can be matched with "CURR" from left to right. Then "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 expression is used again to match the remaining messages according to the priority. At this time, the first character in ":STAT:L1 12" successfully matches the regular expression 1, and the colon ":" is successfully extracted. Since ":" and ";" are delimiters, in this embodiment, only the field type is retained when it is placed in the field list, and the content is represented by empty "null". The remaining messages are matched again by priority. Both "STAT" and "L1" are extracted and marked as command types. When the space position is matched, it matches regular expression 4 successfully, indicating that the subsequent content is a data type. The space is discarded and "12" is matched. Regular expression 5 matches successfully. Since a space parameter appears in front, "12" is put into the field list and marked as a data type.
[0029] After the entire message is matched, an instruction end symbol will be added to the end of the field list as the end, such as the semicolon ";" field. If the message comes with a ";", there is no need to add it.
[0030] After the message is matched and extracted by regular expressions, the entire message is divided into 7 fields, namely: "CURR", "null", "STAT", "null", "L1", "12" and ";".
[0031] In an embodiment of the present invention, in order to facilitate the rapid search for the method to be executed and the data to be processed after the SCPI instruction is parsed, and in order to be compatible with various combinations of full spelling, abbreviated spelling, uppercase and lowercase instructions, three hash tables are designed to achieve rapid matching of instructions, namely, a short character hash table, a path and method Handle (complete instruction-executable program handle) table and a path and parameter hash table.
[0032] In the short character hash table, short characters (abbreviations) are bound to long characters (full spelling); this is because the SCPI protocol allows abbreviations to be used instead of complete command spellings to reduce communication burden. The specific method of constructing the short character hash table takes the message "CONFigure: VOLTage: ON" as an example, including: (1) extracting the fields "CONFigure", "VOLTage" and "ON" from the message; (2) extracting the uppercase parts "CONF", "VOLT", "ON" in the fields as short characters; (3) formatting the fields extracted in (1) into uppercase as the long characters of the fields "CONFIGURE", "VOLTAGE", "ON"; (4) binding the short characters extracted in (2) and the long characters extracted in (3) into 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, the characters with long and short characters will be represented by different characters, and if there is no difference between long and short characters, the two bound words are the same.
[0033] In the path and method handle hash table, the complete instruction is bound to the handle of the corresponding method to be executed. The method handle is accessed through the interface type to access different methods using a unified interface; for example (CONFIGURE: VOLTAGE: ON, set).
[0034] In the path and parameter hash table, the path of the instruction is bound to the address of the relevant parameter. The parameter address is the specific address of the parameter object to be set or queried. This address is bound to the specific parameter through the hash table; for example (CONFIGURE: VOLTAGE: ON, 461).
[0035] The above paths include two 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?".
[0036] S3: Parse each field according to the field type, and put the parsed fields into the path and parameter list according to the type.
[0037] The process includes: (1) identifying whether the message ends with a “?”. If so, it indicates that the message is a query instruction; (2) if it is a short character, querying the short character hash table to supplement it with a long character; (3) formatting it in uppercase; and (4) adding the field to the path.
[0038] For example, in the embodiment of extracting the fields "CURR", "null", "STAT", "null", "L1", "12" and ";" in step S2, first read the first field "CURR" as a short character, then query the short character hash table, supplement the short character with the long character "CURRENT" and put it into the path, and then obtain the first element in the path; if the field itself contains "?", it is necessary to delete the "?" before searching, and add it after supplementing it with a long character; if the segment content is a long character, just keep the content of the field. The third field "STAT" is a short character, which is supplemented with the long character "STATIC" and put into the path as the third element in the path. The fifth field "L1" itself is a long character, so keep this field as the fifth element in the path.
[0039] The colon type field is used as a separator for the command field and is placed directly into the path. If the first field is a colon, it means to return to the root of the path and perform the path clearing operation.
[0040] Semicolon type field description This field has been parsed and the final instruction matching begins. The assembled path is matched in the path and method Handle hash table. If the match is successful, the query program or setting program bound in the hash table is executed.
[0041] The data type field "12" is added directly to the parameter list.
[0042] 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".
[0043] S4: When parsing to the instruction end field, call the path and method Handle hash table to query the method corresponding to the path.
[0044] Usually, a semicolon type field indicates that the field has been parsed, and the path and method Handle hash table is added and searched in it. For example, the method corresponding to "CURRENT:STATIC:L1" is found to be "set_CC".
[0045] S5: Retrieve the path and parameter hash table, query the parameter address, obtain the data under the parameter address and execute the corresponding method.
[0046] 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 from the parameter address, that is, the instruction parameter, and execute the method corresponding to the path. There are different methods for processing the corresponding query or setting instruction, which can be executed according to the existing processing method. After processing, execute step S6.
[0047] S6: Return the execution result.
[0048] In actual applications, SCPI commands are sent in continuous frames. For example, to continuously query the three parameters of voltage, current, and power, the execution program can concatenate the three queried parameters with ";" and combine them into a frame message to be sent back.
[0049] Based on the above-mentioned SCPI communication implementation method, the present invention also proposes an instrument device implemented by an Android system. The Android device is configured with the above-mentioned SCPI communication implementation method. After receiving the SCPI instruction, the method of the Android system is executed according to the above-mentioned SCPI communication implementation method, which can not only obtain the excellent human body interaction experience of Android, but also realize SCPI communication between instrument devices.
[0050] It should be pointed out that the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by ordinary technicians in this technical field within the essential 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, identifies the message segments through regular expressions, puts the identified fields into a list in order and marks the field types; S3, parse each field according to the field type, and put the parsed fields into the path and parameter list according to the type; S4, when parsing to the instruction end field, call the path and method Handle hash table to query the method corresponding to the path; S5, call the path and parameter hash table, query the parameter address, obtain the instruction parameters and execute the corresponding method.
2. The SCPI communication implementation method according to claim 1, characterized in that: The regular expressions in step S2 are sorted according to priority, and include, from high to low, colon, semicolon, brackets, space, command class, data class, and line break; wherein the command class includes letters, numbers, asterisks, question marks, and decimal points; and the data class includes letters, numbers, and decimal points.
3. The SCPI communication implementation method according to claim 1, characterized in that: The method also includes the step of constructing a short character hash table: Extract fields from the message; Extract the uppercase part of the field as short characters; Format the extracted fields to uppercase as long characters of the field; Bind short and long characters into the short character hash table.
4. The SCPI communication implementation method according to claim 1, characterized in that: The method also includes the step of constructing a path and method Handle hash table: 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 through the interface type.
5. The SCPI communication implementation method according to claim 1, characterized in that: The method also includes the step of constructing a path and parameter hash table: The path of the instruction and the address of the relevant parameters are bound to the path and parameter hash table; the address of the parameter is the specific address of the object to be set or queried in the end.
6. The SCPI communication implementation method according to claim 3, characterized in that: Step S3 includes: For short characters, query the short character hash table to supplement them into long characters; Format all in uppercase; Add the uppercase field to the path.
7. The SCPI communication implementation method according to claim 1, characterized in that: Step S3 also includes: Identify whether the field ends with a "?". If so, delete it first, then add it after the short characters are supplemented with long characters.
8. The SCPI communication implementation method according to claim 1, characterized in that: Step S3 also includes: Place colon-type fields directly into the path as command field separators; when the first field is a colon, wrap around to the root of the path and clear the path.
9. The SCPI communication implementation method according to claim 1, characterized in that: The method further comprises: S6, returns the execution result; when the SCPI command is sent in a continuous frame, the execution result is spliced into a frame message with ";" and sent back.
10. An Android device, characterized in that: The invention is configured with the SCPI communication implementation method as claimed in any one of claims 1 to 9.
Citation Information
Patent Citations
Implementation method of external key extension module of Android embedded equipment
CN111930646A
SCPI instruction management method for evaluating spacecraft power supply system
CN113703836A
Circuit and method for upgrading firmware, chip and electronic equipment
CN114721683A
Cited By
Method for efficiently executing SCPI program control instruction
CN121523732A