Natural gas flowmeter parameterized data acquisition method, device and equipment and medium
By acquiring the protocol configuration file and constructing and adjusting the acquisition request frame of the natural gas flow meter, the problems of complex adaptation and parsing errors caused by differences in communication protocols between different manufacturers and models of equipment are solved, and cross-protocol compatibility and high-precision data acquisition are achieved.
Patent Information
- Application Number
- CN202511744614.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-25
- Publication Date
- 2026-02-03
AI Technical Summary
The differences in communication protocols between natural gas flow meters from different manufacturers and models lead to complex adaptation, difficult maintenance, and resolution errors.
By obtaining the protocol configuration file, the frame category, field type, field position, field length, end order, verification algorithm and data type are uniformly described. The acquisition request frame is constructed and dynamically adjusted to ensure the integrity and consistency of the data frame, and to achieve cross-protocol compatibility and rapid configuration.
It improves the flexibility, reliability and scalability of natural gas flow meter data acquisition, solves the problems of complex adaptation and parsing errors caused by differences in communication protocols, and realizes high-precision data acquisition in a multi-protocol environment.
Smart Images

Figure CN121462684A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data acquisition and processing, and in particular to a method, apparatus, equipment, and medium for parametric data acquisition from a natural gas flow meter. Background Technology
[0002] Natural gas, as an important clean energy source, is widely used in urban pipeline networks, industrial gas supply, and power generation. To ensure the accuracy of natural gas measurement during production, transmission, distribution, and metering, natural gas flow meters are used to measure gas flow rate and cumulative total volume in real time. However, different manufacturers and models of natural gas flow meters often use significantly different communication protocol formats, with inconsistent frame structure definitions, field layouts, verification methods, and endpoint order rules. This necessitates separate adaptation and program development for each protocol when the host computer or centralized data acquisition equipment interfaces with different flow meters. Summary of the Invention
[0003] To improve the adaptability of natural gas flow meter data acquisition, this application provides a method, apparatus, equipment, and medium for parametric data acquisition of natural gas flow meters.
[0004] The above-mentioned method for acquiring parameterized data of a natural gas flow meter according to this application includes: Obtain the protocol configuration file, which includes frame type, field type, field position, field length, end order, verification algorithm, and data type; Based on the field position and field length in the protocol configuration file, the order of each field in the acquisition request frame is determined sequentially to obtain the field sorting result. Based on the field sorting result, the field content is filled in according to the field type to obtain frame structure data containing the original content of each field. The field content in the frame structure data is adjusted byte order according to end-order to obtain formatted frame data. Based on the formatted frame data, the checksum is calculated for the specified check interval using a checksum algorithm, and the checksum is written to the corresponding field position to obtain complete acquisition request frame data. The acquisition request frame data is sent to the natural gas flow meter, and the response frame data returned by the natural gas flow meter is received. Field extraction operations are performed on the response frame data according to the protocol configuration file to obtain the raw measurement data. Based on the original measurement data and data type, data parsing operations are performed to obtain structured measurement data. Standard condition total volume data and standard condition flow rate data are extracted from the measurement data to obtain the flow meter measurement results, which are then output to a host computer or display terminal. The first objective is achieved through the following technical solution: By adopting the above technical solution, the versatility and adaptability of the natural gas flow meter data acquisition process can be significantly improved, effectively solving the problems of complex adaptation, difficult maintenance, and parsing errors caused by differences in communication protocols between different manufacturers and models of equipment in existing technologies. This method obtains the protocol configuration file, uniformly describing frame category, field type, field position, field length, end-order method, verification algorithm, and data type in a parameterized form. This allows the acquisition logic to automatically construct acquisition request frames and dynamically adjust them based on the configuration content during execution, avoiding a fixed program dependency on specific protocol formats. By determining the field order, adjusting the end-order, and calculating the checksum of the frame structure data, the integrity and consistency of the communication data frames are ensured, enabling correct parsing of both request and response data under multi-protocol conditions. By performing structured parsing and standard condition data extraction based on data type, high-precision output and unified format representation of measurement results are achieved. This enables the natural gas flow meter to achieve cross-protocol compatibility, rapid configuration, and accurate parsing in a multi-protocol environment, comprehensively improving the flexibility, reliability, and scalability of the data acquisition method.
[0005] In a preferred embodiment, this application can be further configured as follows: Based on the field position and field length in the protocol configuration file, the order of each field in the acquisition request frame is determined sequentially to obtain a field sorting result; based on the field sorting result, the field content is filled according to the field type to obtain frame structure data containing the original content of each field, including: Based on the field position and field length, calculate the starting offset position of each field in the acquisition request frame, and sort the fields according to the order of the starting offset positions to obtain the field sorting result; Based on the field sorting results, read the field type corresponding to each field in sequence, and determine the field content filling method according to the field type; Based on the field content filling method, the filling value corresponding to the field is extracted from the protocol configuration file, and the content of each field is written to the corresponding starting offset position to obtain the frame structure data containing the original content of each field. After determining the content of each field, the field content is written into the acquisition request frame according to the starting offset position corresponding to the field sorting result, thus obtaining frame structure data containing the original content of each field.
[0006] By adopting the above technical solution, precise mapping and dynamic filling of field positions and field content can be achieved during the acquisition request frame construction phase. By calculating the starting offset position of each field based on its position and length, and sorting them according to the order of offsets, the consistency and logical order of field arrangement within the frame structure can be guaranteed. By determining the field content filling method based on the field type and extracting the corresponding filling values from the protocol configuration file, the field content can be automatically written during the construction process. By writing the filled field content into the acquisition request frame according to the starting offset position corresponding to the field sorting result, a complete frame structure data with clearly defined fields can be formed. This enables the acquisition request frame to have unified construction rules in a multi-protocol environment, improving the accuracy and scalability of the frame construction process.
[0007] In a preferred embodiment, this application can be further configured as follows: adjusting the byte order of the field content in the frame structure data according to endianness to obtain formatted frame data includes: Read the content of each field in the frame structure data to obtain the endianness of each field. Endianness includes big-endian and little-endian. In big-endian, the most significant byte is arranged first, and in little-endian, the least significant byte is arranged first. Based on the endianness, determine the byte order in the field content to obtain the field content after adjusting the byte order; The adjusted byte order field content is used to replace the corresponding field content in the frame structure data to obtain the formatted frame data.
[0008] By adopting the above technical solution, the byte order can be uniformly adjusted and the data format standardized during the construction of the acquisition request frame, avoiding parsing errors caused by differences in end-order between different communication protocols. By reading the content of each field in the frame structure data and identifying the corresponding end-order method, the arrangement requirements of high-order byte first or low-order byte first can be accurately distinguished. By redetermining the byte order of each field content according to the end-order method, the byte logic of the data can be kept consistent during the transmission and parsing stages. The adjusted field content is then replaced in the corresponding position in the frame structure data to form formatted frame data. This enables the acquisition request frame to achieve byte order consistency and data format standardization in a multi-protocol environment, thereby improving the accuracy and stability of data interaction.
[0009] In a preferred embodiment, this application can be further configured as follows: based on the formatted frame data, a checksum is calculated on a specified check interval using a verification algorithm, and the checksum is written into the corresponding field position to obtain complete acquisition request frame data, including: Read the verification algorithm and verification range from the protocol configuration file. The verification range includes the position of the verification start field and the position of the verification end field. In the formatted frame data, extract the content of the fields located between the start and end fields of the validation process, and use them as the validation input data. The verification input data is processed according to the verification algorithm to calculate the verification code; Write the checksum into the specified field position in the formatted frame data to form a complete acquisition request frame data.
[0010] By adopting the above technical solution, data integrity and transmission reliability verification and control can be implemented during the construction of the acquisition request frame, ensuring the consistency of frame data during generation and interaction. By reading the verification algorithm and verification range in the protocol configuration file, the verification calculation range can be flexibly determined under different communication protocols. By extracting the field content within the corresponding range from the formatted frame data as verification input data, the range of bytes participating in the verification can be precisely locked. By performing checksum calculation according to the verification algorithm and writing the checksum to the specified field position, the integrity identification of the frame data can be completed. This enables the acquisition request frame to have error resistance and data consistency verification functions before transmission, thereby improving the stability and security of communication interaction with the natural gas flow meter.
[0011] In a preferred embodiment, this application can be further configured to: process the verification input data according to the verification algorithm to calculate the verification code, including: For each byte in the verification input data, a weighted perturbation operation is performed according to the corresponding byte index value and the preset perturbation coefficient to construct a perturbation verification vector; Using the perturbation verification vector as input data, and combining the initialization value, operation bit width parameter and nonlinear operation function defined in the verification algorithm, multiple rounds of modulus addition and displacement mapping operations are performed to generate a sequence of intermediate verification results. The calculation results in the intermediate result sequence are subjected to bit-width compression and format standardization to obtain the check code.
[0012] By adopting the above technical solution, a dynamic verification mechanism integrating multi-dimensional perturbation weighting and nonlinear operation can be realized in the check code generation process, improving the anti-interference and uniqueness of the verification results. By performing weighted perturbation operation on each byte in the verification input data according to the byte index value and the preset perturbation coefficient, position-sensitive change characteristics can be introduced into the verification process. By combining the perturbation verification vector with the initialization value, operation bit width parameter and nonlinear operation function defined in the verification algorithm to perform multi-round modulo addition operation and displacement mapping, a more complex verification path generation can be achieved. Finally, by performing bit width compression and format standardization on the intermediate verification result sequence, a unique and verifiable check code is obtained, thereby ensuring the integrity and reliable transmission of frame data in different communication scenarios.
[0013] In a preferred embodiment, this application can be further configured to: send acquisition request frame data to the natural gas flow meter, receive response frame data returned by the natural gas flow meter, and perform field extraction operations on the response frame data according to the protocol configuration file to obtain the raw measurement data, including: Based on the field positions and lengths configured in the protocol configuration file, locate the starting offset position of each field in the response frame data, parse the original byte data of each field in offset order, and obtain the response frame structure data containing the original content of each field. Based on the field types and end-order settings configured in the protocol configuration file, the original byte order of each field in the response frame structure data is adjusted to construct formatted response frame data. Extract the raw measurement data field content from the formatted response frame data, perform type conversion and numerical parsing on the raw measurement data field content according to the corresponding data type in the protocol configuration file, and generate the raw measurement data.
[0014] By adopting the above technical solutions, precise positioning, standardized adjustment, and unified parsing of multi-protocol response frames can be achieved during the response data parsing process, avoiding parsing errors caused by differences in field definitions, inconsistent end-order, or mismatched data types. By locating the starting offset of each field according to the field position and length defined in the protocol configuration file, accurate extraction of the corresponding raw byte data under different protocol frame structures can be ensured. By adjusting the byte order based on field type and end-order method, the format and byte logic of the response frame data can be unified. By performing type conversion and numerical parsing on the raw measurement data field content according to data type, raw measurement data with a unified format can be generated, thereby ensuring the accuracy and compatibility of the data parsing process in a multi-protocol environment.
[0015] In a preferred embodiment, this application can be further configured as follows: based on the original measurement data and data type, the data parsing operation is completed to obtain structured measurement data; standard condition total data and standard condition flow data are extracted from the measurement data to obtain the flow meter measurement results, including: Based on the data type, perform data format conversion on the original measurement data to construct structured measurement data with a unified data format and field semantics; Based on the field identification information configured in the protocol configuration file, locate the standard condition total data field and the standard condition flow data field in the structured measurement data, and extract the corresponding numerical information of the fields; The numerical information corresponding to the standard condition total data field and the numerical information corresponding to the standard condition flow data field are aggregated to obtain the flow meter measurement result.
[0016] By adopting the above technical solution, standardized conversion and multi-field aggregation processing of measurement data can be achieved during the data parsing stage, ensuring consistency in format and semantics of measurement results from different protocol sources. By performing data format conversion on the original measurement data according to data type, data under different encoding rules can be unified into a standard structural form, constructing structured measurement data with a unified data format and field semantics. By locating the standard condition total data field and standard condition flow data field based on the field identifier information configured in the protocol configuration file, the corresponding numerical information can be accurately extracted while maintaining consistent field meaning. By aggregating the two types of numerical information, a unified format of flowmeter measurement results can be obtained, achieving centralized parsing and consistent output of measurement data under cross-protocol conditions, thereby improving the accuracy and versatility of data processing.
[0017] The second objective of this invention is achieved through the following technical solution: A parameterized data acquisition device for a natural gas flow meter, the natural gas flow meter parameterized data acquisition device comprising: The protocol configuration parsing module is used to obtain the protocol configuration file, which includes frame type, field type, field position, field length, end order, verification algorithm, and data type. The acquisition request frame construction module is used to determine the order of each field in the acquisition request frame according to the field position and field length in the protocol configuration file, obtain the field sorting result, and fill the field content according to the field type based on the field sorting result to obtain frame structure data containing the original content of each field. The formatting and verification processing module is used to adjust the byte order of the field content in the frame structure data according to the end-order method to obtain formatted frame data. Based on the formatted frame data, the verification algorithm is used to calculate the check code for the specified verification interval and write the check code into the corresponding field position to obtain the complete acquisition request frame data. The response data extraction module is used to send the acquisition request frame data to the natural gas flow meter and receive the response frame data returned by the natural gas flow meter. According to the protocol configuration file, the response frame data is used to extract fields to obtain the raw measurement data. The data parsing and result output module is used to perform data parsing operations based on the original measurement data and data type to obtain structured measurement data, extract standard condition total data and standard condition flow data from the measurement data, obtain the flow meter measurement results, and output the flow meter measurement results to the host computer or display terminal.
[0018] By adopting the above technical solution, the versatility and adaptability of the natural gas flow meter data acquisition process can be significantly improved, effectively solving the problems of complex adaptation, difficult maintenance, and parsing errors caused by differences in communication protocols between different manufacturers and models of equipment in existing technologies. This method obtains the protocol configuration file, uniformly describing frame category, field type, field position, field length, end-order method, verification algorithm, and data type in a parameterized form. This allows the acquisition logic to automatically construct acquisition request frames and dynamically adjust them based on the configuration content during execution, avoiding a fixed program dependency on specific protocol formats. By determining the field order, adjusting the end-order, and calculating the checksum of the frame structure data, the integrity and consistency of the communication data frames are ensured, enabling correct parsing of both request and response data under multi-protocol conditions. By performing structured parsing and standard condition data extraction based on data type, high-precision output and unified format representation of measurement results are achieved. This enables the natural gas flow meter to achieve cross-protocol compatibility, rapid configuration, and accurate parsing in a multi-protocol environment, comprehensively improving the flexibility, reliability, and scalability of the data acquisition method.
[0019] The above-mentioned objective three of this application is achieved through the following technical solution: A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described natural gas flow meter parameterized data acquisition method.
[0020] The fourth objective of this application is achieved through the following technical solution: A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method for parameterized data acquisition of a natural gas flow meter.
[0021] In summary, this application includes at least one of the following beneficial technical effects: 1. This method significantly improves the versatility and adaptability of natural gas flow meter data acquisition, effectively solving the problems of complex adaptation, difficult maintenance, and parsing errors caused by differences in communication protocols between different manufacturers and models of equipment in existing technologies. By acquiring the protocol configuration file, this method uniformly describes frame category, field type, field position, field length, end-order method, verification algorithm, and data type in a parameterized form. This allows the acquisition logic to automatically construct acquisition request frames and dynamically adjust them based on the configuration content during execution, avoiding rigid program dependencies on specific protocol formats. By determining the field order, adjusting the end-order, and calculating the checksum of the frame structure data, the integrity and consistency of the communication data frames are ensured, enabling correct parsing of both request and response data under multi-protocol conditions. Through structured parsing and standard condition data extraction based on data type, high-precision output and unified format representation of measurement results are achieved. This enables natural gas flow meters to achieve cross-protocol compatibility, rapid configuration, and accurate parsing in multi-protocol environments, comprehensively improving the flexibility, reliability, and scalability of the data acquisition method. Attached Figure Description
[0022] Figure 1 This is a flowchart of a method for parameterized data acquisition of a natural gas flow meter according to an embodiment of this application.
[0023] Figure 2 This is a flowchart illustrating the implementation of step S10 in a method for acquiring parameterized data of a natural gas flow meter according to an embodiment of this application. Figure 3 This is a flowchart of step S30 in a method for parameterized data acquisition of a natural gas flow meter according to an embodiment of this application; Figure 4 This is another implementation flowchart of step S30 in a natural gas flow meter parameterized data acquisition method according to one embodiment of this application; Figure 5 This is a flowchart of step S306 in a method for parameterized data acquisition of a natural gas flow meter according to an embodiment of this application; Figure 6 This is a flowchart illustrating the implementation of step S40 in a method for acquiring parameterized data of a natural gas flow meter according to an embodiment of this application. Figure 7 This is a flowchart illustrating the implementation of step S50 in a method for parameterized data acquisition of a natural gas flow meter according to an embodiment of this application. Figure 8 This is a schematic diagram of a parameterized data acquisition device for a natural gas flow meter according to one embodiment of this application. Detailed Implementation
[0024] The present application will be further described in detail below with reference to the accompanying drawings.
[0025] In one embodiment, such as Figure 1 As shown, this application discloses a method for parameterized data acquisition from a natural gas flow meter, which specifically includes the following steps: S10: Obtain the protocol configuration file, which includes frame type, field type, field position, field length, end order, verification algorithm, and data type.
[0026] In this embodiment, frame category refers to the classification identifier used to identify the functional attributes of various data frames during communication, including different frame types such as acquisition request frames and response frames, used for matching parsing logic. Field type refers to the functional definition of each field in the frame, such as attribute tags representing device address, command code, or data content. Field position refers to the relative starting offset position of the field in the frame structure, usually located in bytes. Field length refers to the number of consecutive bytes occupied by the field, used to extract the complete field content from the frame. Endianness refers to the byte arrangement order when multi-byte fields are stored in the frame, commonly including "big-endian" with the high byte first and "little-endian" with the low byte first. Verification algorithm refers to the operation logic used to calculate the checksum of the content in a specific frame interval, used to ensure the integrity of frame data, commonly including methods such as CRC16 and checksum. Data type refers to the parsing method used to indicate the parsing method to be used when parsing field content, including type mapping rules such as integer, floating-point, or string.
[0027] Specifically, by reading the configuration file content from the preset storage path, parsing the structured format information of the configuration file, and extracting parameters such as frame category, field type, field position, field length, end order, verification algorithm, and data type, the parsed parameters are loaded into the internal parameter mapping structure in key-value pairs for subsequent data frame construction, formatting processing, verification calculation, and field parsing operations. This ensures that the loaded parameter structure is complete and consistent, avoiding failure of the acquisition process due to missing parameters.
[0028] S20: Based on the field position and field length in the protocol configuration file, determine the order of each field in the acquisition request frame to obtain the field sorting result. Based on the field sorting result, fill in the field content according to the field type to obtain frame structure data containing the original content of each field.
[0029] In this embodiment, the field sorting result refers to the field arrangement order formed by the field positions in the protocol configuration file from smallest to largest according to the byte offset. The field content refers to the original data value that needs to be filled in for each field in the acquisition request frame. This data value is parsed by the natural gas flow meter during subsequent data transmission.
[0030] Specifically, by extracting the field positions and lengths from the protocol configuration file, the field position parameter of each field is read sequentially as the byte start index, and the field length parameter is read as the byte span value. All fields are arranged in ascending order of the field position parameters to obtain the field sorting result. After the field sorting result is constructed, the content of each field in the sorted list is processed sequentially. First, the field type information is read. When the field type is integer, the corresponding integer encoding method is selected according to the field length parameter. For example, when the field length is 2 bytes, 16-bit two's complement is used. The target integer value is converted into two bytes and written to the starting byte specified by the field position parameter and the subsequent consecutive bytes. When the field type is floating-point, single-precision or double-precision floating-point encoding rules are selected according to the field length parameter, and the target floating-point value is encoded according to IEEE... The 754 floating-point number representation is converted into binary data of the corresponding length and written to the starting byte and its continuous range identified by the field position parameter. When the field type is string, the target string is encoded character by character, for example, by using ASCII or UTF-8 to obtain the encoding value of each character. Then, the maximum number of characters that can be written is determined according to the field length parameter. The character encoding values are written to the byte range corresponding to the field position parameter in sequence. After all field contents have been filled, all field byte sequences are concatenated into a continuous byte sequence according to the field sorting result to form frame structure data containing the original contents of all fields.
[0031] S30: Adjust the byte order of the field content in the frame structure data according to the end-order method to obtain formatted frame data. Based on the formatted frame data, use the verification algorithm to calculate the check code for the specified verification interval, and write the check code into the corresponding field position to obtain the complete acquisition request frame data.
[0032] In this embodiment, end-order refers to the arrangement direction of the high-order and low-order bytes in the byte sequence, and the verification algorithm refers to the mathematical calculation method used to detect the integrity of data during transmission or storage.
[0033] Specifically, for each field in the frame structure data, the corresponding endianness parameter in the protocol configuration file is first read. The byte adjustment direction is determined based on the endianness parameter value. When the endianness parameter is big-endian, each byte is moved sequentially to the beginning of the field content, starting from the most significant byte. When the endianness parameter is little-endian, each byte is moved sequentially to the beginning of the field content, starting from the least significant byte. After adjusting the byte order of all fields, the formatted frame data is obtained. After obtaining the formatted frame data, the verification algorithm type and verification interval information are read from the protocol configuration file. The byte range required for verification calculation is determined by the start and end field positions of the verification interval. The formatted frame... The continuous byte sequence corresponding to the verification interval is extracted from the data as the verification input data. The byte-by-byte calculation operation is performed according to the verification algorithm. When the verification algorithm is of type CRC16, the XOR operation and shift operation are performed on each input byte by using a generator polynomial and shift register. After all bytes are calculated, a 16-bit verification result is output as the check code. When the verification algorithm is of type summation, the value of each byte in the verification interval is weighted and summed according to the byte order. Finally, the least significant byte of the summation result is taken to obtain the check code. The calculated check code is written to the verification field position marked in the protocol configuration file, and the corresponding byte content in the formatted frame data is updated. After the writing operation is completed, a complete acquisition request frame data is formed.
[0034] S40: Send the acquisition request frame data to the natural gas flow meter and receive the response frame data returned by the natural gas flow meter. Perform field extraction operations on the response frame data according to the protocol configuration file to obtain the raw measurement data.
[0035] In this embodiment, response frame data refers to the byte sequence information generated and returned by the natural gas flow meter after receiving the acquisition request frame data, based on the internally set measurement parameters and feedback protocol format. Field extraction operation refers to locating and reading the corresponding byte content from the response frame data according to the field position and field length specified in the protocol configuration file. Raw measurement data refers to numerical information that has not undergone further parsing or conversion, including but not limited to instantaneous flow rate, cumulative gas volume, measurement timestamp, etc.
[0036] Specifically, the request frame data is sent to the natural gas flow meter via a serial communication interface or an industrial Ethernet communication interface. After the communication interface establishes a connection and confirms that the data transmission is completed, the serial port or Ethernet receive buffer is continuously monitored. When a return data is detected, the received data stream is read in byte order. After the frame length and start and end flags defined in the protocol configuration file are met, the complete response frame data is separated from the receive buffer. Then, according to the field position and field length of each field recorded in the protocol configuration file, the original byte content of each field is read one by one from the response frame data in a sequential positioning manner. The starting position of each field is calculated using the offset information in the protocol configuration file. That is, with the frame start position as the reference, the first byte address of the target field is calculated by the field sorting result and offset rules. The number of bytes corresponding to the field length is read sequentially. After all fields are extracted, the byte content of each field is combined in order to form the original measurement data.
[0037] S50: Based on the original measurement data and data type, complete the data parsing operation to obtain structured measurement data, extract standard condition total data and standard condition flow data from the measurement data, obtain the flow meter measurement results, and output the flow meter measurement results to the host computer or display terminal.
[0038] In this embodiment, the data parsing operation refers to the process of semantically transforming the content of each measurement field in the original measurement data according to the data types defined in the protocol configuration file. The data types include integer, floating-point, and string types. Structured measurement data refers to a set of key-value pairs indexed by field names and containing the parsed numerical values. The structured measurement data includes at least the following fields: standard condition total data field, standard condition flow rate data field, operating condition total data field, operating condition flow rate data field, pressure data field, temperature data field, and instrument status word field. Standard condition total data refers to the cumulative volume of natural gas under standard operating conditions. Total volume, standard condition flow rate data refers to the volume change of natural gas per unit time under standard operating conditions; operating condition total volume data refers to the cumulative total volume of natural gas under operating conditions; operating condition flow rate data refers to the volume change of natural gas per unit time under operating conditions; pressure data refers to the pressure value at the flowmeter measurement point; temperature data refers to the temperature value at the flowmeter measurement point; instrument status word refers to the coded information used to characterize the current operating status and fault indications of the flowmeter; flowmeter measurement result refers to the set of values formed by combining standard condition total volume data and standard condition flow rate data to represent the cumulative flow and instantaneous flow rate under standard operating conditions.
[0039] Specifically, based on the data type of each field in the original measurement data, the system first determines whether the current field's data type is integer, floating-point, or string. If the field corresponds to an integer type, the byte sequence of the field in the original measurement data is expanded and combined into an integer value according to big-endian or little-endian order. If the field corresponds to a floating-point type, the byte sequence of the field is expanded and combined according to IEEE 1000- ... The 754 floating-point encoding rule parses the sign bit, exponent bit, and mantissa bit to restore the floating-point value. When the field corresponds to a string type, the field byte sequence is converted into the corresponding character sequence according to the character encoding rule specified in the protocol configuration file. After completing the type identification and value conversion of each measurement field, the field name of each field is bound to the parsed value. Structured measurement data is generated according to the field order specified in the protocol configuration file. After obtaining the structured measurement data, based on the predefined identifier field in the protocol configuration file, the standard condition total data field and standard condition flow data field are located from the structured measurement data and the corresponding values are extracted. The values of the standard condition total data field and the standard condition flow data field are combined in a preset order to form the flow meter measurement result. Finally, the flow meter measurement result is encoded according to the data format required by the host computer or display terminal and output to the host computer interface or field display terminal for display.
[0040] In one embodiment, such as Figure 2 As shown, in step S10, the order of each field in the acquisition request frame is determined according to the field position and field length in the protocol configuration file, resulting in a field sorting result. Based on the field sorting result, the field content is filled in according to the field type to obtain frame structure data containing the original content of each field, including: S101: Based on the field position and field length, calculate the starting offset position of each field in the acquisition request frame, and sort the fields according to the order of the starting offset positions to obtain the field sorting result.
[0041] In this embodiment, the starting offset position refers to the relative position of the first byte of a certain field in the acquisition request frame, and the field sorting result refers to the ordered field sequence generated based on the starting offset position of each field, which represents the order of the fields.
[0042] Specifically, according to the field position information defined for each field in the protocol configuration file, the field position is directly used as the starting offset position of the field in the acquisition request frame. Then, the field length information of the corresponding field is read, and it is determined whether the field length is non-zero. If the field length is non-zero, the field is confirmed to be valid. Next, the starting offset positions of all fields are sorted in ascending order, that is, the fields that appear first are placed first, and the fields that appear later are placed last. During the sorting process, a comparison-based stable sorting algorithm is used to ensure that fields with the same starting offset position are retained in their original order. After the sorting is completed, the field sorting result is generated. The field sorting result is represented in the form of an ordered mapping set consisting of field name as index and starting offset position as value.
[0043] S102: Based on the field sorting results, read the field type corresponding to each field in sequence, and determine the field content filling method according to the field type.
[0044] In this embodiment, the field type refers to the type identifier marked for each field in the protocol configuration file to indicate the data format of that field. Field types include integer, floating-point, and string types, and different field types determine different ways of filling field content.
[0045] Specifically, according to the field sorting order defined by the field sorting results, each field name is read sequentially, and the field type information corresponding to the field name is obtained from the protocol configuration file. If the field type is integer, the target data is converted into a fixed-length zero-padded format and then converted into a hexadecimal byte stream with the corresponding endianness according to the protocol requirements. If the field type is floating-point, the target data is converted into a four-byte or eight-byte format and processed into a byte sequence with the specified endianness according to the IEEE 754 representation rules of floating-point numbers in memory. If the field type is string, the target string is directly encoded into an ASCII or UTF-8 byte stream, and truncated or padded with whitespace characters according to the field length to meet the fixed length requirement. After the field content is filled, the field content order is kept consistent with the field sorting results, and each field is written to the corresponding position in the frame structure data to construct the complete frame structure data.
[0046] S103: Based on the field content filling method, extract the corresponding filling value of the field from the protocol configuration file, write the content of each field to the corresponding starting offset position, and obtain the frame structure data containing the original content of each field.
[0047] In this embodiment, the padding value refers to the original data value preset for each field in the protocol configuration file. It is usually recorded in hexadecimal, string or numerical form and is used as the data source for the actual content written into the frame during the construction of the frame structure data.
[0048] Specifically, based on the field name recorded in the field sorting results and the field content padding method, the corresponding field padding value is first retrieved from the protocol configuration file. If the field content padding method is integer padding, the numeric data is read from the padding value and converted into a hexadecimal byte stream that matches the endianness. If the field content padding method is floating-point padding, the padding value is converted into the byte stream format required for floating-point representation according to the floating-point standard conversion rules (such as the IEEE 754 standard), and the endianness is handled uniformly. If the field content padding method is string padding, the padding value is converted into a byte stream of the corresponding encoding format, and whitespace characters are truncated or padded according to the field length. Then, based on the starting offset position of the field, the content of each field is written to the corresponding byte range of the frame structure data in sequence using memory write operations, ensuring that the content of each field corresponds one-to-one with its offset position without overlap or omission, and finally completing the construction of the frame structure data containing the original content of all fields.
[0049] S104: After determining the content of each field, write the field content into the acquisition request frame according to the starting offset position corresponding to the field sorting result, and obtain frame structure data containing the original content of each field.
[0050] Specifically, after determining the field content, based on the starting offset position of each field recorded in the field sorting result and combined with the field length information, the write position range of each field in the acquisition request frame is determined. Then, according to the arrangement order of each field in the field sorting result, the corresponding field content is written to the corresponding starting offset position in the acquisition request frame in sequence. The write operation adopts a byte-by-byte copy method, that is, according to the byte sequence of the field content, it is written one byte at a time from the first byte to the memory address in the acquisition request frame corresponding to the starting offset position of the field. The number of bytes written does not exceed the field length, ensuring that the field content is completely and accurately filled into the specified position in the frame structure data. After completing the write operation of all field content, the frame structure data containing the original content of each field is constructed.
[0051] In one embodiment, such as Figure 3 As shown, in step S30, the field content in the frame structure data is adjusted byte order according to endianness to obtain formatted frame data, including: S301: Read the content of each field in the frame structure data to obtain the endianness of each field. Endianness includes big-endian and little-endian. In big-endian, the most significant byte is arranged first, and in little-endian, the least significant byte is arranged first.
[0052] Specifically, for each field in the frame structure data, the original content of the field is first read based on the field order recorded in the field sorting result. Then, the endianness of the field in the protocol configuration file is used for judgment. If the endianness is big-endian, the byte sequence of the field content is reordered by arranging the most significant byte first and the least significant byte last. If the endianness is little-endian, the least significant byte is arranged first and the most significant byte last. The byte sequence of the field content is adjusted in this order. The above byte order adjustment operations are all completed by remapping the byte position in the buffer. That is, after reading the original field byte sequence, it is written into a new buffer in sequence according to the target endianness to form the adjusted field byte sequence, and the corresponding field content in the original frame structure data is replaced.
[0053] S302: Determine the byte order in the field content according to the end-order method, and obtain the field content after adjusting the byte order.
[0054] Specifically, according to the endianness specified for each field in the protocol configuration file, the content of each field in the frame structure data is processed sequentially. When the endianness is big-endian, the byte sequence of the field content is rearranged in order from the most significant byte to the least significant byte, that is, the most significant byte is read first, and then the remaining bytes are arranged in order. After completion, the field content with the adjusted byte order is obtained. When the endianness is little-endian, the byte sequence of the field content is rearranged in order from the least significant byte to the most significant byte, that is, the least significant byte is read first, and then the remaining bytes are arranged in order. After completion, the field content with the adjusted byte order is obtained.
[0055] S303: Replace the corresponding field content in the frame structure data with the field content after adjusting the byte order to obtain the formatted frame data.
[0056] Specifically, the field content after adjusting the byte order is written to the specified position of the frame structure data according to the starting offset position of the corresponding field in the protocol configuration file. When performing the replacement operation, the starting offset position and field length of the field to be replaced in the frame structure data are first determined according to the field position. Then, the original field content byte sequence is deleted at that position, and the field content after adjusting the byte order is written to the corresponding offset interval one by one according to the byte order. After the replacement of all field content is completed, each field in the frame structure data maintains the same arrangement order as specified in the protocol configuration file, thus forming formatted frame data.
[0057] In one embodiment, such as Figure 4As shown, in step S30, based on the formatted frame data, a checksum is calculated for the specified check interval using a verification algorithm, and the checksum is written into the corresponding field position to obtain the complete acquisition request frame data, including: S304: Read the verification algorithm and verification range from the protocol configuration file. The verification range includes the position of the verification start field and the position of the verification end field.
[0058] Specifically, by parsing the preset configuration information in the protocol configuration file, the configuration content of the verification algorithm field and the verification interval field is read. The verification algorithm field is used to define the algorithm type and calculation parameters used to perform the check code calculation, and the verification interval field is used to define the frame data range covered by the verification operation. When reading the verification interval field, the marked verification start field position and verification end field position are extracted and used as the boundary to determine the data boundary required for the verification operation. By calculating the byte span between the verification start field position and the verification end field position, the number of bytes participating in the verification operation is determined, thus establishing the data range for subsequent verification input data extraction and check code calculation.
[0059] S305: In the formatted frame data, extract the field content located between the start field position and the end field position of the verification as the verification input data.
[0060] In this embodiment, the verification input data refers to the continuous byte sequence formed in the formatted frame data, starting from the position of the verification start field and ending at the position of the verification end field, which is the original byte set used for subsequent verification code calculation.
[0061] Specifically, the start byte index corresponding to the start field position and the end byte index corresponding to the end field position in the formatted frame data are read. A continuous byte interval is determined in the order from the start byte index to the end byte index. Based on this continuous byte interval, the value of each byte is obtained in sequence and recorded as a continuous byte sequence in the order of acquisition. This continuous byte sequence is defined as the verification input data.
[0062] S306: Process the verification input data according to the verification algorithm and calculate the verification code.
[0063] In this embodiment, the check code refers to the result value obtained after performing operations on the check input data according to the check algorithm. The check input data is a continuous byte sequence determined according to the position of the check start field and the position of the check end field.
[0064] Specifically, firstly, the type identifier and calculation parameters of the verification algorithm are read, the current verification value is established as an intermediate result variable and an initial value is set. When the verification algorithm is CRC16, the current verification value is set to the initial value and the verification input data is processed byte by byte. For each byte processed, the current verification value is first XORed with the byte value, and then the shift operation is performed 8 times in a loop. Each time, it is checked whether the least significant bit of the current verification value is 1. If the least significant bit is 1, the current verification value is shifted right by one bit and then XORed with the generator polynomial. If the least significant bit is 0, the current verification value is shifted right by only one bit. This process continues until all bytes are processed. The current verification value is truncated according to the operation bit width parameter and output in two positions according to the endianness. The checksum is composed of bytes. When the checksum algorithm is an additive type, the current checksum is set to zero and the checksum input data is added in byte order. After each addition, modulo operation or low-order truncation is performed according to the operation bit width parameter. After all bytes are calculated, one or two bytes are output as the checksum according to the endianness. When the checksum algorithm includes an initialization value, operation bit width parameter and nonlinear operation function, the weight is calculated according to the byte index and perturbation coefficient and a perturbation sequence is generated. The perturbation sequence and the checksum input data are subjected to modulo addition and shift mapping operation in each iteration to update the current checksum. After reaching the preset number of iterations, the current checksum is compressed and format standardized, and a fixed-length result is output as the checksum according to the endianness.
[0065] S307: Write the checksum into the specified field position in the formatted frame data to form a complete acquisition request frame data.
[0066] In this embodiment, the specified field position is configured as the starting byte index and field length defined for the verification field in the protocol configuration file, which is used to locate the verification code writing range within the formatted frame data.
[0067] Specifically, firstly, the field positions specified in the configuration are read from the formatted frame data to determine the starting byte index and field length. Then, the byte length of the checksum is compared with the field length. If they match, the original bytes at the corresponding positions are overwritten sequentially according to the starting byte index using a byte-by-byte writing method. If they do not match, the checksum is truncated according to the field length or padded with zero-value bytes at the end to meet the fixed-length requirement. Subsequently, the overwrite is completed while keeping the contents of other fields in the formatted frame data, except for the checksum field, unchanged. After completing the above writing operation, a byte sequence containing the checksum is obtained, and the byte sequence is used as the acquisition request frame data for subsequent transmission.
[0068] In one embodiment, such as Figure 5 As shown, in step S306, the verification input data is processed according to the verification algorithm to calculate the verification code, including: S3061: For each byte in the verification input data, perform a weighted perturbation operation according to the corresponding byte index value and the preset perturbation coefficient to construct a perturbation verification vector.
[0069] In this embodiment, the perturbation coefficient is a numerical parameter pre-set in the protocol configuration file to enhance the randomness of the verification. Each perturbation coefficient corresponds one-to-one with a byte index value and is used to introduce a weighting factor in the calculation process to increase the anti-interference ability of the verification process.
[0070] Specifically, for each byte in the verification input data, the byte index value of the current byte in the data sequence is first read. Then, the perturbation coefficient table stored in the protocol configuration file is called to obtain the perturbation coefficient corresponding to the index value. Next, the value of the byte is multiplied by the perturbation coefficient to obtain the weighted result. Then, according to the preset operation rules, the weighted result is subjected to an XOR operation or a modulo addition operation to form a perturbed single-byte result. After all bytes have been weighted and perturbed, each perturbation result is combined in the order of the byte index to generate a perturbation verification vector.
[0071] S3062: Using the perturbation verification vector as input data, and combining the initialization value, operation bit width parameter and nonlinear operation function defined in the verification algorithm, perform multiple rounds of modulus addition and displacement mapping operations to generate a sequence of intermediate verification results.
[0072] In this embodiment, the initialization value refers to the initial cumulative value defined by the verification algorithm at the start of the calculation, which is used to determine the starting state of the first round of modular addition operation. The operation bit width parameter refers to the binary bit width range limited in the modular addition operation, which is used to constrain the numerical range of the calculation result each time. The nonlinear operation function refers to the function that performs a nonlinear mapping transformation on the result after each round of operation, which is used to increase the complexity of the result distribution.
[0073] Specifically, after the perturbation check vector is input into the calculation process, the initialization value and the first byte value in the perturbation check vector are read and a modular addition operation is performed. The modular addition operation is performed by adding the two operands and taking the modulo of the result to obtain the first round of calculation result. Then, the result is truncated in binary according to the operation bit width parameter to keep the result within the specified bit width range. On this basis, the current result is added to the next byte value in the perturbation check vector and the modular addition operation is performed again. After each modular addition operation, a nonlinear operation function is called to perform a shift mapping operation. The shift mapping operation is performed by cyclically shifting or bitwise XORing the binary bit order of the result according to the preset offset, thereby generating a new result that has a nonlinear relationship with the original input. This process is repeated until all bytes in the perturbation check vector have been processed, and finally a sequence of intermediate verification results containing the results of multiple rounds of calculation is formed.
[0074] S3062: Perform bit-width compression and format standardization on each calculation result in the intermediate result sequence to obtain the check code.
[0075] In this embodiment, bit width compression refers to truncating or folding each calculation result in the intermediate result sequence of the verification according to a preset target bit width, so that the result retains valid information and removes redundant bit information within the limited bit width range. Format standardization processing refers to converting the bit width compressed numerical result into a unified output format that conforms to the requirements of the protocol configuration file.
[0076] Specifically, for each calculation result in the intermediate result sequence, the target bit width range is first determined according to the operation bit width parameter. When the binary length of the calculation result exceeds the target bit width, compression is performed by discarding high bits or folding low bits to keep the result within the target bit width range. Folding is achieved by performing an XOR operation on the binary bits that exceed the bit width to form new low-bit information. After the bit width compression is completed, the compressed result is converted into hexadecimal, binary, or ASCII code representation according to the check code format type specified in the protocol configuration file, and rearranged according to the byte order defined in the protocol to ensure that the format-standardized numerical content is consistent with the check field definition in the formatted frame data. After all calculation results have completed bit width compression and format standardization, the results are concatenated and truncated to generate a check code that conforms to the format specified in the protocol.
[0077] In one embodiment, such as Figure 6 As shown, in step S40, the request frame data is sent to the natural gas flow meter, and the response frame data returned by the natural gas flow meter is received. Field extraction is performed on the response frame data according to the protocol configuration file to obtain the raw measurement data, including: S401: Based on the field positions and lengths configured in the protocol configuration file, locate the starting offset position of each field in the response frame data, parse the original byte data of each field in offset order, and obtain the response frame structure data containing the original content of each field.
[0078] In this embodiment, the response frame structure data refers to the ordered organization of the original byte data of each field extracted from the response frame data in offset order according to the field position and field length in the protocol configuration file.
[0079] Specifically, the field positions and lengths recorded in the protocol configuration file are read. Taking the first byte of the response frame data as a reference, the field positions are used as the starting offset positions to determine the parsing order. Each field is processed sequentially in ascending order of the starting offset positions. For each field, the first byte is located in the response frame data with the starting offset position, and a number of bytes equal to the field length are read continuously as raw byte data. After all fields have been read, the raw byte data of each field obtained in the offset order are merged sequentially to form response frame structure data containing the original content of each field.
[0080] S402: Based on the field types and end-order settings configured in the protocol configuration file, perform byte order adjustment on the original byte content of each field in the response frame structure data to construct formatted response frame data.
[0081] In this embodiment, formatted response frame data refers to a set of byte sequences organized by field position after adjusting the byte order of the original byte content in the response frame structure data according to the field types and end-order methods configured in the protocol configuration file.
[0082] Specifically, the original byte content of each field in the response frame structure data is processed sequentially according to the field order recorded in the protocol configuration file. First, the field type and endianness of the corresponding field are read. When the field type corresponds to multi-byte data and the endianness is big-endian, the original byte content of the field is rearranged from the most significant byte to the least significant byte. When the field type corresponds to multi-byte data and the endianness is little-endian, the original byte content of the field is rearranged from the least significant byte to the most significant byte. After the byte order of the current field is adjusted, the adjusted byte order is written as the byte content of the field into the same position in the response frame structure data. This process is repeated until all fields are processed and the formatted response frame data is constructed accordingly.
[0083] S403: Extract the raw measurement data field content from the formatted response frame data, perform type conversion and numerical parsing on the raw measurement data field content according to the corresponding data type in the protocol configuration file, and generate the raw measurement data.
[0084] In this embodiment, the original measurement data refers to the set of values obtained after locating the original measurement data field content in the formatted response frame data according to the protocol configuration file and completing type conversion and numerical parsing.
[0085] Specifically, firstly, based on the field position and length corresponding to the original measurement data field content in the protocol configuration file, the byte sequence of each original measurement data field content is read sequentially from the formatted response frame data. Then, according to the data type configured for the original measurement data field content in the protocol configuration file, type conversion and numerical parsing are performed. When the data type is integer, the byte sequence is combined into an integer value according to the bit weight expansion method. When the data type is floating-point, the sign bit, exponent field, and mantissa field are parsed according to the floating-point encoding rules and restored to a floating-point value. When the data type is string, the byte sequence is mapped word by word into a readable character sequence according to the character encoding rules. After completing the type conversion and numerical parsing of all original measurement data field content, the parsed values are recorded in the reading order to generate the original measurement data.
[0086] In one embodiment, such as Figure 7 As shown, in step S50, based on the original measurement data and data type, the data parsing operation is completed to obtain structured measurement data. Standard condition total volume data and standard condition flow rate data are extracted from the measurement data to obtain the flow meter measurement results, including: S501: Based on the data type, perform data format conversion on the original measurement data to construct structured measurement data with a unified data format and field semantics.
[0087] In this embodiment, data format conversion refers to the process of unifying the original measurement data according to the data type, which is used to construct structured measurement data with a unified data format and field semantics.
[0088] Specifically, the system first reads the data type corresponding to each raw measurement data field defined in the protocol configuration file. Data types include integer, floating-point, and string types. When the data type is integer, the system performs bit-weighted expansion calculations on the byte content in the raw measurement data, accumulating each byte content in order from the high bit to the low bit to convert it into a decimal integer. When the data type is floating-point, the system parses the byte content according to the IEEE 754 floating-point encoding rules, combining the sign bit, exponent bit, and mantissa bit to calculate the floating-point value. When the data type is string, the system converts the byte content word by word into a recognizable character sequence according to the character encoding method specified in the protocol configuration file (such as UTF-8 or ASCII). After completing the type conversion of each field content, the converted data is combined in a unified data structure according to the field arrangement order in the protocol configuration file, establishing the correspondence between field names and values, and finally constructing structured measurement data with a unified data format and field semantics.
[0089] S502: Based on the field identification information configured in the protocol configuration file, locate the standard condition total data field and the standard condition flow data field in the structured measurement data, and extract the corresponding numerical information of the fields.
[0090] In this embodiment, field identification information refers to the annotation information in the protocol configuration file used to uniquely identify the location and name of each field in the structured measurement data. The standard condition total data field refers to the field in the structured measurement data used to represent the cumulative total volume under standard operating conditions. The standard condition flow data field refers to the field in the structured measurement data used to represent the volume change per unit time under standard operating conditions. The numerical information refers to the specific numerical value read from the structured measurement data according to the field identification information.
[0091] Specifically, the field identifier information in the protocol configuration file is read, and the field identifiers corresponding to the standard condition total data field and the standard condition flow data field are obtained respectively. In the structured measurement data, precise matching and positioning are performed according to the field identifiers to determine the location and name of the two target fields. Then, a reading operation is performed on the location of the standard condition total data field to obtain the corresponding numerical information, and a reading operation is performed on the location of the standard condition flow data field to obtain the corresponding numerical information. Finally, the two reading results are recorded as the numerical information of the standard condition total data field and the numerical information of the standard condition flow data field, respectively.
[0092] S503: Aggregate the numerical information corresponding to the standard condition total data field and the numerical information corresponding to the standard condition flow data field to obtain the flow meter measurement result.
[0093] In this embodiment, the numerical information corresponding to the standard condition total data field refers to the value obtained by location extraction, which represents the cumulative flow of natural gas under standard operating conditions. The numerical information corresponding to the standard condition flow data field refers to the value obtained by location extraction, which represents the change in flow of natural gas per unit time under standard operating conditions. The flow meter measurement result refers to the final measurement output result formed after aggregating the above two numerical information.
[0094] Specifically, the numerical information corresponding to the standard condition total data field and the standard condition flow data field are read. First, a unified numerical accuracy calibration operation is performed on both according to their data types to ensure that they are calculated under the same unit of measurement. Then, according to the time synchronization rules, the historical cumulative value of the standard condition total data field and the instantaneous change of the standard condition flow data field are aggregated. The aggregation calculation includes combining the cumulative amount and instantaneous flow information in a weighted manner to generate a comprehensive measurement value. If necessary, data alignment and smoothing operations are performed according to the timestamp order to finally obtain the flow meter measurement result representing the current operating status of the natural gas flow meter.
[0095] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0096] In one embodiment, a natural gas flow meter parameterized data acquisition device is provided, which corresponds one-to-one with the natural gas flow meter parameterized data acquisition method described in the above embodiments. For example... Figure 8 As shown, the parameterized data acquisition device for a natural gas flow meter includes a protocol configuration parsing module, an acquisition request frame construction module, a formatting and verification processing module, a response data extraction module, and a data parsing and result output module.
[0097] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A method for acquiring parameterized data from a natural gas flow meter, characterized in that, The method for acquiring parameterized data from a natural gas flow meter includes: Obtain the protocol configuration file, which includes frame type, field type, field position, field length, end order, verification algorithm, and data type; Based on the field position and field length in the protocol configuration file, the order of each field in the acquisition request frame is determined sequentially to obtain the field sorting result. Based on the field sorting result, the field content is filled in according to the field type to obtain frame structure data containing the original content of each field. The field content in the frame structure data is adjusted byte order according to end-order to obtain formatted frame data. Based on the formatted frame data, the checksum is calculated for the specified check interval using a checksum algorithm, and the checksum is written to the corresponding field position to obtain complete acquisition request frame data. The acquisition request frame data is sent to the natural gas flow meter, and the response frame data returned by the natural gas flow meter is received. Field extraction operations are performed on the response frame data according to the protocol configuration file to obtain the raw measurement data. Based on the original measurement data and data type, the data parsing operation is completed to obtain structured measurement data. Standard condition total data and standard condition flow data are extracted from the measurement data to obtain the flow meter measurement results, which are then output to the host computer or display terminal.
2. The method for parameterized data acquisition of a natural gas flow meter according to claim 1, characterized in that, The process involves determining the order of each field in the acquisition request frame based on its position and length in the protocol configuration file, obtaining a field sorting result, and then filling in the field content according to the field type based on the sorting result to obtain frame structure data containing the original content of each field, including: Based on the field position and field length, calculate the starting offset position of each field in the acquisition request frame, and sort the fields according to the order of the starting offset positions to obtain the field sorting result; Based on the field sorting results, read the field type corresponding to each field in sequence, and determine the field content filling method according to the field type; Based on the field content filling method, the filling value corresponding to the field is extracted from the protocol configuration file, and the content of each field is written to the corresponding starting offset position to obtain the frame structure data containing the original content of each field. After determining the content of each field, the field content is written into the acquisition request frame according to the starting offset position corresponding to the field sorting result, thus obtaining frame structure data containing the original content of each field.
3. The method for acquiring parameterized data of a natural gas flow meter according to claim 1, characterized in that, The process of adjusting the byte order of the fields in the frame structure data according to endianness to obtain formatted frame data includes: Read the content of each field in the frame structure data to obtain the endianness of each field. Endianness includes big-endian and little-endian. In big-endian, the most significant byte is arranged first, and in little-endian, the least significant byte is arranged first. Based on the endianness, determine the byte order in the field content to obtain the field content after adjusting the byte order; The adjusted byte order field content is used to replace the corresponding field content in the frame structure data to obtain the formatted frame data.
4. The method for parameterized data acquisition of a natural gas flow meter according to claim 1, characterized in that, The process involves using a verification algorithm to calculate a checksum for a specified verification interval based on formatted frame data, and then writing the checksum into the corresponding field position to obtain complete acquisition request frame data, including: Read the verification algorithm and verification range from the protocol configuration file. The verification range includes the position of the verification start field and the position of the verification end field. In the formatted frame data, extract the content of the fields located between the start and end fields of the validation process, and use them as the validation input data. The verification input data is processed according to the verification algorithm to calculate the verification code; Write the checksum into the specified field position in the formatted frame data to form a complete acquisition request frame data.
5. The method for acquiring parameterized data of a natural gas flow meter according to claim 4, characterized in that, The step of processing the verification input data according to the verification algorithm and calculating the verification code includes: For each byte in the verification input data, a weighted perturbation operation is performed according to the corresponding byte index value and the preset perturbation coefficient to construct a perturbation verification vector; Using the perturbation verification vector as input data, and combining the initialization value, operation bit width parameter and nonlinear operation function defined in the verification algorithm, multiple rounds of modulus addition and displacement mapping operations are performed to generate a sequence of intermediate verification results. The calculation results in the intermediate result sequence are subjected to bit-width compression and format standardization to obtain the check code.
6. The method for acquiring parameterized data of a natural gas flow meter according to claim 1, characterized in that, The process involves sending the acquisition request frame data to the natural gas flow meter and receiving the response frame data returned by the natural gas flow meter. According to the protocol configuration file, field extraction operations are performed on the response frame data to obtain the raw measurement data, including: Based on the field positions and lengths configured in the protocol configuration file, locate the starting offset position of each field in the response frame data, parse the original byte data of each field in offset order, and obtain the response frame structure data containing the original content of each field. Based on the field types and end-order settings configured in the protocol configuration file, the original byte order of each field in the response frame structure data is adjusted to construct formatted response frame data. Extract the raw measurement data field content from the formatted response frame data, perform type conversion and numerical parsing on the raw measurement data field content according to the corresponding data type in the protocol configuration file, and generate the raw measurement data.
7. The method for acquiring parameterized data of a natural gas flow meter according to claim 1, characterized in that, Based on the original measurement data and data type, a data parsing operation is performed to obtain structured measurement data. Standard condition total volume data and standard condition flow rate data are extracted from the measurement data to obtain the flow meter measurement results, including: Based on the data type, perform data format conversion on the original measurement data to construct structured measurement data with a unified data format and field semantics; Based on the field identification information configured in the protocol configuration file, locate the standard condition total data field and the standard condition flow data field in the structured measurement data, and extract the corresponding numerical information of the fields; The numerical information corresponding to the standard condition total data field and the numerical information corresponding to the standard condition flow data field are aggregated to obtain the flow meter measurement result.
8. A parameterized data acquisition device for a natural gas flow meter, characterized in that, The natural gas flow meter parameterized data acquisition device includes: The protocol configuration parsing module is used to obtain the protocol configuration file, which includes frame type, field type, field position, field length, end order, verification algorithm, and data type. The acquisition request frame construction module is used to determine the order of each field in the acquisition request frame according to the field position and field length in the protocol configuration file, obtain the field sorting result, and fill the field content according to the field type based on the field sorting result to obtain frame structure data containing the original content of each field. The formatting and verification processing module is used to adjust the byte order of the field content in the frame structure data according to the end-order method to obtain formatted frame data. Based on the formatted frame data, the verification algorithm is used to calculate the check code for the specified verification interval and write the check code into the corresponding field position to obtain the complete acquisition request frame data. The response data extraction module is used to send the acquisition request frame data to the natural gas flow meter and receive the response frame data returned by the natural gas flow meter. According to the protocol configuration file, the response frame data is used to extract fields to obtain the raw measurement data. The data parsing and result output module is used to perform data parsing operations based on the original measurement data and data type to obtain structured measurement data, extract standard condition total data and standard condition flow data from the measurement data, obtain the flow meter measurement results, and output the flow meter measurement results to the host computer or display terminal.
9. 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 computer program, it implements the steps of the parameterized data acquisition method for a natural gas flow meter as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the parameterized data acquisition method for a natural gas flow meter as described in any one of claims 1 to 7.