A floating point low-loss encoding method for data exchange of intelligent instruments
By using floating-point low-loss encoding method in intelligent instrument data interaction, floating-point numbers are encoded into four bytes visible strings, which solves the problem of inefficient data interaction caused by SCPI protocol, and achieves efficient data interaction and comparison High accuracy reserved.
Patent Information
- Application Number
- CN202210401173.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-18
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2042-04-18
AI Technical Summary
The existing SCPI protocols lead to excessive data volume and low throughput in smart instrument data interaction, and inefficiency in redundant coding.
A floating point low loss encoding method is used to format the floating point number into a string, extract the sign bit, mantissa and exponent bit, and encode it separately to generate four bytes of visible string encoding to ensure that each byte is in The ASCII code table is visible characters.
By reducing the amount of encoded data, the readability of the original communication method is maintained, the data interaction efficiency between the upper and lower computers of the intelligent instrument is improved, and the effective accuracy of at least 6-bit decimal is retained after decoding.
Smart Images

Figure FDA0005183477300000011 
Figure GDA0005183477310000021 
Figure GDA0005183477310000041
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of electronic measurement, and in particular to a floating point low-loss encoding method for intelligent instrument data interaction. Background Art
[0002] For modern intelligent instruments, especially electronic measuring instruments, the data exchange between the host computer and the slave computer generally adopts the SCPI protocol. This protocol is to send the data to be exchanged directly from the slave computer to the host computer through the communication interface in the form of string encoding. Its advantages are that the communication content is clear and easy to program; but its disadvantages are that the data volume is too large and the throughput is low. For example: if the measurement reading is 1.23456, the floating point number is encoded as a string as "+1.23456E+0" with a total of 10 bytes. The total information volume of a single-precision floating point number is originally only 4 bytes. It can be seen that the encoding of the measurement reading by the SCPI protocol is very redundant. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a floating point low-loss encoding method for intelligent instrument data interaction, which can greatly improve the data interaction efficiency between the host computer and the slave computer of the intelligent instrument without violating the SCPI protocol.
[0004] The technical solution adopted by the present invention to solve the technical problem is: a floating point low-loss encoding method for intelligent instrument data interaction, comprising the following steps:
[0005] S1. Format the floating point number into a string, retaining 6 decimal digits;
[0006] S2, extracting numerical information ranging from 0 to 255 from the character string in sequence, and obtaining three parts of information: the sign bit, the mantissa bit, and the exponent bit;
[0007] S3, splitting the mantissa information and encoding the split digits respectively to obtain three code elements;
[0008] S4, append the information of the sign bit to the first code element;
[0009] S5, encoding the information of the exponent bit separately into the last code element;
[0010] S6, using three code elements to represent the mantissa and the sign bit, and one code element to represent the exponent bit, each code element occupies one byte, and all of them are visible strings in the ASCII code table, and a four-byte string encoding is obtained;
[0011] S7, send to the host computer to read and decode through SCPI protocol to complete the data exchange.
[0012] Furthermore, in step S3 of the present invention, when the code element is an invisible character string, a certain value is uniformly increased on the original basis to convert the code element into a visible character.
[0013] Furthermore, in step S6 of the present invention, the four encoded symbols are assumed to be x[0], x[1], x[2], and x[3]; the sign bit is assumed to be s, and the three bytes of data bits from high to low are assumed to be N h 、N m 、N l ; The exponent bit is e; then the encoding algorithm is expressed as follows:
[0014]
[0015] Wherein, the value of s is 0 or 1; if the sign bit is positive, then s=0; if the sign bit is negative, then s=1.
[0016] Furthermore, in step S7 of the present invention, in the data interaction system of the intelligent instrument, the lower computer encodes the measurement reading and sends it to the upper computer. After receiving the data encoding in the form of a string, the upper computer decodes it to obtain the measurement reading in the form of a floating point number.
[0017] Furthermore, the decoding method described in the present invention is the inverse process of the encoding method.
[0018] The beneficial effects of the present invention are that the defects existing in the background technology are solved, and in view of the weaknesses of the SCPI protocol, the measurement reading is encoded from a floating point number to a visible character string within 4 bytes, avoiding the first 32 invisible control characters of ASCII, and each byte of the encoded output is a visible character in the ASCII code table; the encoded output is no more than 4 bytes, and at least 6 decimal effective precision is retained after decoding; while reducing the encoded data, the principle of the SCPI protocol based on a readable character string is still followed, and the original communication mode is maintained. DETAILED DESCRIPTION
[0019] The present invention will now be further described in detail with reference to embodiments.
[0020] A floating point number low-loss encoding method for intelligent instrument data interaction performs low-loss encoding on the floating point number on the basis of retaining at least 6 decimal digits of precision and outputs the result in the form of a visible character string.
[0021] First, the floating point number is formatted as a string; then the numerical information in the range of 0 to 255 is extracted from the string in sequence; finally, three code elements are used to represent the mantissa and the sign, and one code element is used to represent the exponent bit, thus obtaining a four-byte string encoding.
[0022] Taking the floating point number -123.456789 as an example, the encoding process is as follows:
[0023] 1. First, convert the floating point number into a string in scientific notation, retaining 6 decimal digits, and get "-1.23456E+02".
[0024] 2. Extract three pieces of information from the string "-1.23456E+02", which are ① the sign bit, ② the mantissa bit, and ③ the exponent bit. In this example, the sign is negative, the mantissa is 123456, and the exponent is +2.
[0025] 3. Encode the three parts of information in the previous step into visible strings. The specific method is:
[0026] ⑴ Encode the last digits 123456 as 0x0C, 0x22, and 0x38, respectively, each occupying one byte. The corresponding decimal ASCII codes are 12, 34, and 56. At this time, the first code 0x0C is an invisible string.
[0027] ⑵ To avoid the first 32 invisible characters in the ASCII code table, add 50 to the three code units obtained in the previous step. Because the maximum value of a two-digit decimal number is 99, adding 50 to it is 149, which is far less than the maximum decimal number 255 that can be represented by a byte. In this example, the three code units after adding 50 are: 0x3E, 0x54, and 0x6A, which are all visible characters in the ASCII code table.
[0028] 4. If the sign bit is a negative number, add 100 to the first code. In this example, the first code element becomes 0xA2 after adding 100. It is still a visible character in the ASCII code table.
[0029] 5. Finally, encode the exponent. The exponent is usually within the range of ±50. For the measurement readings of intelligent instruments, when the exponent is less than -50 or greater than +50, the data has lost its practical meaning. Add 128 to the exponent as the fourth code element, which must be a visible character in the ASCII table. In this example, the exponent is +2, and after adding 128, the code element 0x82 is obtained. So far, all four code elements of the floating point encoding are obtained, and the final encoding result is: 0x3E 0x54 0x6A 0x82.
[0030] In summary, let the four encoded code elements be x[0], x[1], x[2], x[3]; let the sign bit be s, and the three bytes of data bits from high to low be N h 、N m 、N l ; The exponent bit is e. Then the encoding algorithm can be expressed as follows:
[0031]
[0032] Where s is either 0 or 1. If the sign is positive, s = 0; if the sign is negative, s = 1.
[0033] In the data exchange system of intelligent instruments, the lower computer encodes the measurement readings and sends them to the upper computer. The upper computer receives the data encoding in the form of a string and decodes it to obtain the measurement readings in the form of floating point numbers. The decoding method is the reverse process of the encoding method.
[0034] Continuing with the previous example, assuming the code is 0x3E 0x54 0x6A 0x82, the decoding process is as follows:
[0035] 1. First, determine whether the first code element is greater than 150. If so, the sign bit is negative, otherwise the sign bit is positive.
[0036] The sign bit is y1, and its value is ±1. The value is determined as follows:
[0037]
[0038] 2. Calculate the mantissa of a floating point number according to the following formula:
[0039]
[0040] Where y2 is the decoded mantissa, and x[0], x[1], and x[2] are the first, second, and third code elements after encoding, respectively.
[0041] 3. Subtract 128 from the fourth codeword of the encoding result to get the exponent. The exponent is y3 and is calculated as follows:
[0042] y3=x[3]-128
[0043] Where x[3] is the fourth code element.
[0044] 4. Multiply the mantissa, exponent, and sign number to get the final decoding result. The calculation method is as follows:
[0045] y4=y1*y2-y3
[0046] Substituting the code 0x 3E 0x54 0x6A 0x82, the decoded floating point number is -12.3456.
[0047] The above description only describes the specific implementation mode of the present invention. Various examples do not limit the essential content of the present invention. After reading the description, ordinary technicians in the relevant technical field can modify or deform the specific implementation modes described above without departing from the essence and scope of the invention.
Claims
1. A floating point low-loss encoding method for intelligent instrument data interaction, characterized in that: The following steps are involved: S1. Format the floating point number into a string, retaining 6 decimal digits; S2, extracting numerical information ranging from 0 to 255 from the character string in sequence, and obtaining three parts of information: the sign bit, the mantissa bit, and the exponent bit; S3, splitting the mantissa information and encoding the split digits respectively to obtain three code elements; S4, append the information of the sign bit to the first code element; S5, encoding the information of the exponent bit separately into the last code element; S6, using three code elements to represent the mantissa and the sign bit, and one code element to represent the exponent bit, each code element occupies one byte, and all of them are visible strings in the ASCII code table, and a four-byte string encoding is obtained; In step S6, the four encoded symbols are set to be x[0], x[1], x[2], and x[3]; the sign bit is set to be s, and the three bytes of data bits from high to low are set to be N h 、N m 、N l ; The exponent bit is e; then the encoding algorithm is expressed as follows: Where s is 0 or 1. If the sign bit is positive, s = 0; if the sign bit is negative, s = 1. S7, send to the host computer to read and decode through SCPI protocol to complete the data exchange.
2. The floating point low-loss encoding method for intelligent instrument data interaction according to claim 1, characterized in that: In the step S3, when the code element is an invisible character string, a certain value is uniformly increased on the original basis to turn the code element into a visible character.
3. The floating point low-loss encoding method for intelligent instrument data interaction according to claim 1, characterized in that: In the step S7, in the data interaction system of the intelligent instrument, the lower computer encodes the measurement reading and sends it to the upper computer. After receiving the data encoding in the form of a character string, the upper computer decodes it to obtain the measurement reading in the form of a floating point number.
4. The floating point low-loss encoding method for intelligent instrument data interaction according to claim 3, characterized in that: The decoding method is the inverse process of the encoding method.
Citation Information
Patent Citations
Method and system for string representation of floating point numbers
US20030088597A1
Conversion of floating-point numbers from binary into string format
US20070203965A1