Flow meter communication method and device, computer equipment and storage medium
By obtaining and configuring the communication protocol parameters of the flow meter and generating a protocol parameter database, the problem of serial communication between flow meters and controllers by different manufacturers is solved, and communication can be achieved by implementing parameter configuration, saving labor time and cost.
Patent Information
- Application Number
- CN202510317023.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-18
- Publication Date
- 2025-04-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Due to the different serial port settings parameters, communication protocols and voltage requirements, the controller needs to frequently update the program to match each flowmeter model, resulting in increased working hours and costs, and complex version management.
By obtaining all communication protocols that match the flowmeter, perform protocol parameter configuration, and generate a protocol parameter database. When the controller needs to communicate serially with the specified flowmeter, serial communication between the controller and the flowmeter is performed based on the communication protocol type and protocol parameter database of the specified flowmeter.
The flow meter controller can communicate RS485 chip serially with the flow meter output from the MODBUS serial communication protocol of different manufacturers through parameter configuration, without changing or adding the program code of the original flow meter, saving labor time and cost and simplifying version management.
Smart Images

Figure CN119854390A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of intelligent instruments, and in particular to a communication method, device, computer equipment and storage medium of a flow meter. Background Art
[0002] With the gradual advancement of the application of the Internet of Things in the smart gas industry, there is an urgent need to transform or update the gas flow meter base meters that were previously running online by gas companies. Gas companies hope to realize the Internet of Things of the original online products by adding flow meter controllers. There are many manufacturers and varieties of flow meter online products. The installed controller obtains the flow meter data basically through RS485 chip serial communication, and the MODBUS communication mode is mostly used. When the RS485 chip communicates serially, the serial port setting parameters of each flow meter manufacturer may be different, the content of the read data command message and the response message are different, and the communication voltage required is also different. Generally, each time a new flow meter model is added, the controller program needs to be changed to match the communication. In actual applications, it is impossible to know all the flow meter protocol types that need to be matched, and the earliest way to deal with different communication voltages is to change the hardware components. The consequence of the traditional method is that the program needs to be constantly modified and updated. Each modified version needs to be tested, finalized, and archived, which requires a lot of repetitive work. There will be many program versions, and the more versions there are, the more subsequent maintenance problems there will be. The more flow meter protocol types that can be matched in one version of the program, the larger the program code will be, which is not conducive to serial communication between flow meters and controllers from different manufacturers via RS485. Summary of the invention
[0003] In view of this, the present invention provides a flow meter communication method, device, computer equipment and storage medium to solve the problem that flow meters from different manufacturers cannot communicate serially with a controller via RS485.
[0004] In a first aspect, the present invention provides a communication method for a flow meter, the method comprising: Get all communication protocols matching the flow meter; Perform protocol parameter configuration based on all communication protocols, and generate a protocol parameter database based on the protocol parameters; When the controller and the designated flow meter need to perform serial communication, the serial communication between the controller and the flow meter is performed based on the communication protocol type and protocol parameter database of the designated flow meter.
[0005] A communication method for a flow meter provided by the present invention obtains all communication protocols matching the flow meter; performs protocol parameter configuration based on all communication protocols, and generates a protocol parameter database based on the protocol parameters; when it is determined that a controller and a specified flow meter need to perform serial communication, serial communication between the controller and the flow meter is performed based on the communication protocol type and the protocol parameter database of the specified flow meter, thereby realizing that the flow meter controller can perform RS485 chip serial communication with flow meters of different manufacturers that output with the MODBUS serial communication protocol through parameter configuration, without changing or adding program codes of the new communication protocol of the flow meter, thus saving man-hours and costs, and solving the problem that flow meters of different manufacturers cannot perform serial communication with the controller through RS485.
[0006] In an optional implementation, protocol parameter configuration is performed based on all communication protocols, including: Configure the chip serial communication port parameters based on all communication protocols. The chip serial communication port parameters include baud rate, parity check, data bit and stop bit; Configure the flow meter hardware parameters based on all communication protocols, including communication voltage and delay time; Serial communication protocol command configuration is performed based on all communication protocols. The serial communication protocol command includes: communication address, function code, register start address and number of registers to be read; The response message data items are configured based on all communication protocols. The response message data items include relevant data offset address, data length, data type and abnormal flag data items.
[0007] In an optional implementation, generating a protocol parameter database based on the protocol parameters includes: The protocol parameter database software is used to store the newly added communication protocols and the corresponding protocol parameters in all communication protocols into the original protocol parameter database to generate a new protocol parameter database.
[0008] A communication method for a flow meter provided by the present invention performs chip serial communication port parameter configuration, flow meter hardware parameter configuration, serial communication protocol command configuration and response message data item configuration based on all communication protocols, and uses protocol parameter database software to store newly added communication protocols and corresponding protocol parameters in the original protocol parameter database to generate a new protocol parameter database, thereby realizing parameter configuration of flow meters with different communication protocols from different manufacturers and generating a new protocol parameter database, and providing conditions for subsequent serial communication between the flow meter and the controller.
[0009] In an optional implementation, the communication method of the flow meter further includes: When the communication between the controller and the designated flow meter is power-on communication, timing communication, key press communication and wireless remote connection communication, it is determined that the controller and the designated flow meter need to perform serial communication.
[0010] In an optional embodiment, before performing serial communication between the controller and the flow meter based on the communication protocol type and protocol parameter database of the specified flow meter, the communication method of the flow meter further includes: The communication protocol type of the specified flow meter is obtained, and the protocol-related parameters corresponding to the communication protocol type are obtained from the protocol parameter database and stored in the non-volatile memory of the controller.
[0011] In an optional implementation, the protocol-related parameters include baud rate, parity check, data bit, stop bit, communication voltage, delay time, communication address, function code, register start address, number of registers to read, and response message data items; Serial communication between the controller and the flow meter is based on the communication protocol type and protocol parameter database of the specified flow meter, including: Acquire protocol-related parameters corresponding to the communication protocol type of the specified flow meter from the non-volatile memory; Initialize the chip serial communication port based on baud rate, parity, data bits and stop bits; Based on the communication voltage, it is converted into a value corresponding to a preset electronic potentiometer, and the voltage used for the DC-DC boost chip output flow meter and chip serial communication is provided through the preset electronic potentiometer value; Set the serial communication port of the chip after initialization to the sending state and wait according to the delay time; When the delay time is over, the CRC checksum is calculated based on the communication address, function code, register start address and the number of registers to be read, and the message is assembled to send a read data command to the flow meter; Set the serial communication port of the chip to the receiving state, read the response message in the flow meter, filter out invalid data in the response data according to the communication address, function code, and data length, and obtain the CRC check code in the response message; The response message is checked by CRC based on the CRC check code. When the CRC check is legal, the response message is parsed based on the relevant data offset address, data length, data type and abnormal flag data items. The parsed response message data is converted into data in a preset format and stored in the controller as flow meter data.
[0012] A flow meter communication method provided by the present invention initializes the chip serial communication port and the flow meter hardware parameters based on the protocol related parameters in the protocol parameter database, and realizes the serial communication between the controller and the flow meters with different communication protocols, without modifying the original program code, thus saving work time and cost.
[0013] In an optional implementation, the relevant data offset address includes a high-order data offset address and a low-order data offset address of a specified response data item, the data length includes the number of high-order data bytes and the number of low-order data bytes, the data type includes the data type of the high-order data, the arrangement order of the high-order data, the magnification and reduction multiples of the high-order data, the data type of the low-order data, the arrangement order of the low-order data and the magnification and reduction multiples of the low-order data, and the abnormal flag bit data item includes the abnormal flag offset address and the abnormal flag BIT bit; Parsing the response message based on the relevant data offset address, data length, data type and abnormal flag data items, converting the parsed response message data into data in a preset format as flow meter data and storing it in the controller, including: Determine whether the high-order data offset address of the specified response data item is a preset value; if so, continue to determine whether the high-order data offset address of the next specified response data item is a preset value; if not, obtain the corresponding high-order received data in the response message according to the value of the high-order data offset address of the specified response data item and the number of high-order data bytes, and write the obtained high-order received data into the high-order array; Rearrange the high-order array sequence according to the arrangement sequence of the high-order data of the specified response data item, and convert the rearranged array into high-order data of a preset format according to the data type of the high-order data and the magnification / reduction multiple of the high-order data; Determine whether the low-order data offset address of the specified response data item in the response message is a preset value. If so, store the high-order data in the preset format as the final response data of the flow meter in the controller, and continue to execute the step of determining whether the high-order data offset address of the next specified response data item is a preset value; If not, obtain the corresponding low-order received data in the response message according to the low-order data offset address value and the number of low-order bytes, and write the low-order received data into the low-order array; Rearrange the low-order array sequence according to the arrangement sequence of the low-order data of the specified response data item, and convert the rearranged low-order array into low-order data of a preset format according to the data type of the low-order data and the magnification / reduction multiple of the low-order data; Add the high-order data and the low-order data as the final response data of the designated response data item and store them in the controller, designate the next response data item, and continue to execute the step of determining whether the high-order data offset address of the next designated response data item is a preset value; Determine whether the exception flag offset address in the specified exception flag data item is a preset value. If so, continue to execute the step of determining whether the exception flag offset address in the next specified exception flag data item is a preset value; if not, obtain the corresponding received data in the response message according to the value of the exception flag offset address, and determine whether the value of the exception flag BIT bit of the received data is valid according to the value of the exception flag BIT bit. If so, the corresponding exception state of the controller is set to valid; if not, the corresponding exception state of the controller is set to invalid, specify the next exception flag in the response data item, and continue to execute the step of determining whether the exception flag offset address in the next specified exception flag data item is a preset value.
[0014] A flow meter communication method provided by the present invention achieves the purpose of parsing the return message data items of different flow meter communication protocols into a unified data format through protocol-related parameters by specifying the offset, data type and abnormal flag bit address in the response data item, which is beneficial to the serial communication between the flow meter and the controller.
[0015] In a second aspect, the present invention provides a communication device for a flow meter, the device comprising: A communication protocol acquisition module is used to acquire all communication protocols matching the flow meter; The protocol parameter configuration and database generation module is used to configure the protocol parameters based on all communication protocols respectively, and generate a protocol parameter database based on the protocol parameters; The serial communication module is used for performing serial communication between the controller and the flow meter based on the communication protocol type and protocol parameter database of the specified flow meter when the controller and the specified flow meter need to perform serial communication.
[0016] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the communication method of the flow meter of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0017] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the flow meter communication method of the first aspect or any corresponding embodiment thereof.
[0018] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the flow meter communication method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 is a flow chart of a communication method of a flow meter according to an embodiment of the present invention; Figure 2 is a flow chart of another communication method of a flow meter according to an embodiment of the present invention; Figure 3 is a flow chart of another communication method of a flow meter according to an embodiment of the present invention; Figure 4 is a schematic diagram of a hardware circuit for outputting a corresponding voltage at VOUT according to a required flow meter communication voltage value according to an embodiment of the present invention; Figure 5 is a structural block diagram of a communication device of a flow meter according to an embodiment of the present invention; Figure 6 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0022] According to an embodiment of the present invention, a communication method embodiment of a flow meter is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0023] In this embodiment, a flow meter communication method is provided, which can be used in a computer terminal, such as a central processing unit, a server, etc. Figure 1 is a flow chart of a communication method of a flow meter according to an embodiment of the present invention, such as Figure 1 As shown, the process includes the following steps: Step S101, obtaining all communication protocols matching the flow meter.
[0024] Specifically, the flow meter is a smart instrument, which is an instrument used to measure the flow of fluid (gas or liquid). Its main task is to provide accurate flow data to support production monitoring and optimization.
[0025] All communication protocols that match the flowmeter, for example, Tianxin flowmeter MODBUS protocol, Cangnan flowmeter MODBUS protocol, Zhonghe Weisi flowmeter MODBUS protocol, Start flowmeter MODBUS protocol, etc. The original flowmeter database may also include other communication protocols, Tianxin flowmeter MODBUS protocol, Cangnan flowmeter MODBUS protocol, Zhonghe Weisi flowmeter MODBUS protocol, Start flowmeter MODBUS protocol can be understood as all newly added communication protocols that match the flowmeter.
[0026] Step S102, performing protocol parameter configuration based on all communication protocols, and generating a protocol parameter database based on the protocol parameters.
[0027] Specifically, based on the newly added communication protocol in step S101, protocol parameters are configured based on the newly added communication protocol, and a protocol parameter database is generated based on the newly configured protocol parameters. Before the newly added communication protocol, other communication protocols matching the flow meter have been configured with relevant protocol parameters.
[0028] Step S103: When the controller and the designated flow meter need to perform serial communication, serial communication between the controller and the flow meter is performed based on the communication protocol type and protocol parameter database of the designated flow meter.
[0029] Specifically, the serial communication in this embodiment adopts RS485 chip serial communication, that is, RS485 chip serial communication chip is adopted. The relationship between the controller and the flow meter is mainly reflected in the synergy in the industrial automation system. The controller integrates the automatic adjustment function, which can not only measure the flow rate of the flow meter in real time, but also accurately control the fluid flow rate by adjusting the valve according to the set value.
[0030] When the communication between the controller and the designated flow meter (any flow meter connected to the controller) is power-on communication, timed communication, button press communication and wireless remote connection communication, it is determined that the controller and the designated flow meter need to perform RS485 chip serial communication. When the controller and the designated flow meter need to perform RS485 chip serial communication, first obtain the communication protocol type of the designated flow meter, and then obtain the protocol-related parameters corresponding to the communication protocol type of the designated flow meter from the protocol parameter database, and based on the protocol-related parameters, serial communication is performed between the controller and the flow meter.
[0031] The communication method for the flow meter provided in this embodiment performs chip serial communication port parameter configuration, flow meter hardware parameter configuration, serial communication protocol command configuration and response message data item configuration based on all communication protocols, and uses protocol parameter database software to store newly added communication protocols and corresponding protocol parameters in the original protocol parameter database to generate a new protocol parameter database, thereby realizing parameter configuration of flow meters with different communication protocols from different manufacturers and generating a new protocol parameter database, and providing conditions for subsequent serial communication between the flow meter and the controller.
[0032] In this embodiment, a flow meter communication method is provided, which can be used in a computer terminal, such as a central processing unit, a server, etc. Figure 2 is a flow chart of a communication method of a flow meter according to an embodiment of the present invention, such as Figure 2 As shown, the process includes the following steps: Step S201, obtain all communication protocols that match the flow meter. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0033] Step S202, performing protocol parameter configuration based on all communication protocols, and generating a protocol parameter database based on the protocol parameters.
[0034] Specifically, the above step S202 includes: Step S2021, configure chip serial communication port parameters based on all communication protocols, the chip serial communication port parameters include baud rate, parity check, data bits and stop bits.
[0035] Specifically, the serial port of the RS485 chip serial communication chip is configured with parameters, including the baud rate, parity check, data bit and stop bit.
[0036] Step S2022, configure the flow meter hardware parameters based on all communication protocols, the flow meter hardware parameters include communication voltage and delay time.
[0037] Specifically, the delay time refers to the communication delay waiting time after power-on.
[0038] Step S2023, performing serial communication protocol command configuration based on all communication protocols, the serial communication protocol command includes: communication address, function code, register start address and read register quantity.
[0039] Specifically, the MODBUS serial communication protocol command configuration is read, including: communication address, register start address, function code and number of registers to be read.
[0040] Step S2024, configure the response message data items based on all communication protocols, and the response message data items include offset address, data length, data type and abnormal flag data items.
[0041] Specifically, the offset address is the initial position of the data address of the relevant data item data and the exception flag in the message response data frame.
[0042] The data type includes the high-order data type, the number of high-order data bytes, the high-order data arrangement order, the high-order data magnification or reduction multiple, the low-order data type, the number of low-order data bytes, the low-order data arrangement order, and the low-order data magnification or reduction multiple. If the data does not need to be combined with the high and low bits, only the high-order data type is used, and the low-order address offset is 0.
[0043] The exception flag bit data item includes an exception flag BIT bit, ranging from BIT0 to BIT7 corresponding to 0 to 7, which can be combined.
[0044] The new configuration protocol parameter table based on the communication protocol is shown in Table 1 below: Table 1 Protocol parameter configuration table
[0045] Step S2025, using protocol parameter database software to store the newly added communication protocol and the corresponding protocol parameters in all communication protocols into the original protocol parameter database to generate a new protocol parameter database.
[0046] Specifically, the database configuration operator adds new protocols by configuring the protocol parameter database software according to the table, such as the Tianxin flowmeter MODBUS protocol, Cangnan flowmeter MODBUS protocol, CNNC Weisi flowmeter MODBUS protocol, and Start flowmeter MODBUS protocol. The operator inputs the protocol parameters according to the flowmeter protocol parameter configuration table 1 to generate a protocol parameter database.
[0047] It should be noted that the application software (including serial communication application software, Bluetooth applet, wireless remote control system, etc.) obtains the new protocol parameter database by downloading or copying according to the needs; the application software obtains the protocol-related parameters from the protocol parameter database according to the communication protocol type input on the interface, forms a data frame according to the communication protocol related to each application software, and writes it into the controller through the corresponding software path. The path for writing data into the controller can be serial port, infrared, Bluetooth and / or wireless remote transmission.
[0048] Step S203, when the communication between the controller and the designated flow meter is power-on communication, timed communication, key-press communication, and wireless remote connection communication, it is determined that the controller and the designated flow meter need to perform serial communication.
[0049] The scheduled communication may be hourly communication.
[0050] Step S204, obtaining the communication protocol type of the specified flow meter, and obtaining protocol-related parameters corresponding to the communication protocol type from a protocol parameter database and storing them in a non-volatile memory of the controller.
[0051] Specifically, the communication protocol type of the specified flow meter is obtained, and the protocol-related parameters corresponding to the communication protocol type are obtained from the protocol parameter database. The controller stores the received protocol-related parameters in a non-volatile memory.
[0052] Step S205: When the controller and the designated flow meter need to perform serial communication, serial communication between the controller and the flow meter is performed based on the communication protocol type and protocol parameter database of the designated flow meter. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0053] The communication method for the flow meter provided in this embodiment performs chip serial communication port parameter configuration, flow meter hardware parameter configuration, serial communication protocol command configuration and response message data item configuration based on all communication protocols, and uses protocol parameter database software to store newly added communication protocols and corresponding protocol parameters in the original protocol parameter database to generate a new protocol parameter database, thereby realizing parameter configuration of flow meters with different communication protocols from different manufacturers and generating a new protocol parameter database, and providing conditions for subsequent serial communication between the flow meter and the controller.
[0054] In this embodiment, a flow meter communication method is provided, which can be used in a computer terminal, such as a central processing unit, a server, etc. Figure 3 is a flow chart of a communication method of a flow meter according to an embodiment of the present invention, such as Figure 3 As shown, the process includes the following steps: Step S301, obtain all communication protocols that match the flow meter. Figure 2 Step S201 of the illustrated embodiment will not be described in detail here.
[0055] Step S302: configure protocol parameters based on all communication protocols, and generate a protocol parameter database based on the protocol parameters. Figure 2 Step S202 of the illustrated embodiment will not be described in detail here.
[0056] Step S303: When it is determined that the controller and the designated flow meter need to perform serial communication, serial communication between the controller and the flow meter is performed based on the communication protocol type and protocol parameter database of the designated flow meter.
[0057] Specifically, the protocol related parameters include baud rate, parity check, data bit, stop bit, communication voltage, delay time, communication address, function code, register start address, number of registers to be read and response message data items; the above step S303 includes: Step S3031, obtaining protocol-related parameters corresponding to the communication protocol type of the specified flow meter from the non-volatile memory.
[0058] Step S3032, initializing the chip serial communication port based on the baud rate, parity, data bits and stop bits.
[0059] Specifically, turn on the RS485 chip serial communication power supply, and initialize the RS485 chip serial communication port according to the baud rate, data bit, stop bit and parity check in the protocol related parameters. For example, the baud rate is 9600, the parity check bit is none, the data bit is 8, and the stop bit is 1.
[0060] Step S3033, based on the communication voltage, the voltage is converted into a value corresponding to the preset electronic potentiometer, and the preset input electronic potentiometer value is used to output the voltage used by the DC-DC boost chip for flow meter and chip serial communication.
[0061] Specifically, the communication voltage value is converted into a corresponding value through the MCU of the controller, that is, the communication voltage value is converted into a corresponding value of the electronic potentiometer through a conversion algorithm, and the corresponding value is converted into a corresponding value through I 2 C is sent to the electronic potentiometer to turn on the input voltage of the boost chip, and the RS485 chip serial communication voltage is output through the electronic potentiometer, boost chip and related device circuits for flow meter communication.
[0062] Related conversion algorithms and hardware circuits such as Figure 4 As shown, Figure 4 middle, V is the flow meter communication voltage value VOUT, in mV. R62 for Figure 4 The resistance value of R62 in the circuit, unit Ω, R63 for Figure 4 The resistance value of R63 in the circuit, unit Ω, Rc is the unit resistance value of the electronic potentiometer U7 chip, in Ω, Vc The reference voltage of the boost chip U8, in mV. No The data written into the electronic potentiometer is calculated according to the following formula: No : (1); The data written to the electronic potentiometer No Through the SCL pin and SDA pin of U7 chip I 2C protocol is written into the electronic potentiometer U7 chip, the PW_485 terminal is set high, the input voltage V_DC is sent to the boost chip, and the boost chip U8 control terminal is turned on at the same time, and the RS485 chip serial communication voltage VOUT is output through the electronic potentiometer U7 chip, the boost chip U8 and related device circuits.
[0063] Figure 4 The main function of the circuit is to output the corresponding voltage at VOUT according to the required flowmeter communication voltage value. For example, if the communication voltage value is required to be 9 volts, 9 volts will be output at VOUT. If the communication voltage value is required to be 12 volts, 12 volts will be output at VOUT. In the circuit, V_DC is the voltage input, PW_485 is the voltage input control and chip enable control terminal of the boost chip U8, SCL1 and SDA1 are the data I terminals of the electronic potentiometer U7 chip. 2 C input terminal.
[0064] It should be noted that Figure 4 The circuit devices not described in the specification are mainly used to assist in calculating the electronic potentiometer U7 chip, the boost chip U8 and the related device circuit output RS485 chip serial communication voltage VOUT, and will not be described here.
[0065] Step S3034, setting the initialized chip serial communication port to a sending state, and waiting according to a delay time.
[0066] Specifically, because the RS485 chip serial communication chip is half-duplex, the RS485 is set to a sending state, and a delay wait is performed according to the configured delay time, for example, the delay time is 2s.
[0067] Step S3035, when the delay time ends, the CRC check code is calculated based on the communication address, function code, register start address and the number of registers to be read, and the message is assembled to send a read data command to the flow meter.
[0068] Specifically, when the delay time ends, the CRC checksum is calculated and the message is assembled according to the configured communication address, function code, register start address, and number of registers to be read, and then sent to the flow meter to read the data command.
[0069] For example, the configured communication address is 01, function code is 03, register starting address is 0000, and the number of registers to be read is 0010. The controller calculates the CRC check code of the data string 010300000010 as 4406 according to the ModbusCRC16 general algorithm program, and sends the read data command frame to the flow meter as: 0103000000104406.
[0070] Step S3036, set the serial communication port of the chip to the receiving state, read the response message in the flow meter, filter out invalid data in the response data according to the communication address, function code, and data length, and obtain the CRC check code in the response message.
[0071] Specifically, the RS485 chip serial communication chip is set to a receiving state, waiting to receive flow meter data, and filtering out invalid data operations on the received response message data according to the communication address, function code, and data length (number of bytes).
[0072] Step S3037, perform CRC check on the response message based on the CRC check code. When the CRC check is legal, parse the response message based on the relevant data offset address, data length, data type and abnormal flag data items, convert the parsed response message data into data in a preset format and use it as flow meter data and store it in the controller.
[0073] Specifically, the legal judgment includes whether the communication address is consistent, whether the CRC check is legal, etc. When the check is legal, the data is parsed according to the offset address, number of bytes, data type, and abnormal flag address, and converted into a fixed format as flow meter data and stored in the controller for other uses. For example, the standard total value of the flow meter data, the fixed format in the controller is a floating point number. First, the corresponding data is intercepted from the flow meter response message data string according to the offset address and number of bytes, converted into a floating point format according to the data type, and stored in the controller storage area.
[0074] In some optional implementations, as shown in Table 1, the relevant data offset address includes a high-order data offset address and a low-order data offset address of a specified response data item, the data length includes the number of high-order data bytes and the number of low-order data bytes, the data type includes the data type of the high-order data, the arrangement order of the high-order data, the magnification and reduction multiples of the high-order data, the data type of the low-order data, the arrangement order of the low-order data, and the magnification and reduction multiples of the low-order data, the abnormal flag bit data item includes the abnormal flag offset address and the abnormal flag BIT bit, and the above step S3037 includes: Step a1, determine whether the high-order data offset address of the specified response data item is a preset value; if so, continue to determine whether the high-order data offset address of the next specified response data item is a preset value; if not, obtain the corresponding high-order received data in the response message according to the value of the high-order data offset address of the specified response data item and the number of high-order data bytes, and write the obtained high-order received data into the high-order array.
[0075] Exemplarily, the preset value is set to 0. Parse the specified response data 1~N, and execute a1 to step a6 in a loop until the parsing of N data is completed. Determine whether the high-order data offset address addrhX of the specified response data X (X is 1~N) is 0. If not, obtain the corresponding received data revdata [addrhX] in the response data frame according to the value of the high-order data offset address addrhX and the number of bytes lenhX, and send lenhX bytes to the high-order array arrayh[lenhX], and execute step a2; if yes, add 1 to X and continue with step a1.
[0076] Step a2, rearrange the high-order array sequence according to the arrangement sequence of the high-order data of the specified response data item, and convert the rearranged array into high-order data of a preset format according to the data type of the high-order data and the magnification / reduction multiple of the high-order data.
[0077] Specifically, according to the data type typehX of the high-order data of the specified response data X, the arrangement order orderhX, and the data magnification or reduction multiple mulhX, the array order is rearranged, the data type is converted, and the data is magnified or reduced, and the high-order array arrayh[lenhX] is converted into controller fixed format data datahX, and step a3 is continued below.
[0078] Step a3, determine whether the low-order data offset address of the response data item specified in the response message is a preset value. If so, store the high-order data in the preset format as the final response data of the flow meter in the controller, and continue to execute the step of determining whether the high-order data offset address of the next specified response data item is a preset value.
[0079] Specifically, determine whether the low-order data offset addrlX of the designated response data item X is 0. If not, execute step a4. If so, datahX is used as the final data dataX of the designated response data item X, either stored or for standby use, X is increased by 1, and return to step a1.
[0080] Step a4, obtaining the corresponding low-order received data in the response message according to the low-order data offset address value and the number of low-order bytes, and writing the low-order received data into the low-order array.
[0081] Specifically, starting from obtaining the corresponding received data revdata [addrlX] in the response data frame according to the specified response data item X low-order data offset value addrlX and the number of bytes lenlX, lenlX bytes are sent to the array arrayl[lenlX], and step a5 is continued.
[0082] Step a5, rearrange the low-order array sequence according to the arrangement sequence of the low-order data of the specified response data item, and convert the rearranged low-order array into low-order data of a preset format according to the data type of the low-order data and the magnification / reduction multiple of the low-order data.
[0083] Specifically, according to the data type typelX, arrangement order orderlX, and data magnification / reduction multiple mullX of the low-order data of the designated response data item X, the low-order array sequence is rearranged, the data type is converted, and the data is magnified or reduced, and the low-order array arrayl[lenlX] is converted into controller fixed format data datalX, and then go to step a6.
[0084] Step a6, adding the high-order data and the low-order data as the final response data of the specified response data item is stored in the controller, and the next response data item is specified, and the step of determining whether the high-order data offset address of the next specified response data item is a preset value is continued.
[0085] Specifically, the high-order data and the low-order data datalX+datahX are taken as the final data dataX of the data item X, and are either stored or put on standby, X is increased by 1, and the process returns to step a1.
[0086] Step a7, determine whether the abnormal flag offset address in the specified abnormal flag data item is a preset value. If so, continue to execute the step of determining whether the abnormal flag offset address in the next specified abnormal flag data item is a preset value; if not, obtain the corresponding received data in the response message according to the value of the abnormal flag offset address, and determine whether the value of the abnormal flag BIT bit of the received data is valid according to the value of the abnormal flag BIT bit. If so, the corresponding abnormal state of the controller is set to valid; if not, the corresponding abnormal state of the controller is set to invalid, specify the next abnormal flag in the response data item, and continue to execute the step of determining whether the abnormal flag offset address in the next specified abnormal flag data item is a preset value.
[0087] In an optional implementation, step a7 includes: Step a71, analyze the exception flags 1 to N, and execute steps a71 to a72 in a loop until the conversion of N exception flag data is completed.
[0088] Step a72, determine whether the response data abnormal flag X (X is 1~N) offset address eaddrX is 0, if not, execute step a73, if yes, add 1 to X, and continue to execute step a72.
[0089] Step a73, obtain the corresponding received data revdata [eaddrX] in the response frame according to the data offset value eaddrX of the exception flag N, and determine whether the ebitXBIT bit of revdata [eaddrX] is valid according to the BIT bit ebitX value of the exception flag N. If so, the corresponding abnormal state of the controller is set to valid. If it is 0, the corresponding abnormal state of the controller is set to invalid, X is increased by 1, and the process returns to step a72.
[0090] After executing step S303, the chip serial communication port of the RS485 chip serial communication is closed, the chip power supply of the RS485 chip serial communication is closed, and the voltage output of the boost chip is closed.
[0091] The communication method for the flow meter provided in this embodiment achieves the purpose of parsing the return message data items of different flow meter communication protocols into a unified data format through protocol-related parameters by specifying the offset, data type and exception flag address in the response data item, which is beneficial to serial communication between the flow meter and the controller.
[0092] As one or more specific application embodiments of the embodiments of the present invention, the communication method of the flow meter provided by the present invention is further described in detail, specifically including: 1. According to market demand information, obtain the correct communication protocol for matching flow meters from the flow meter manufacturer.
[0093] 2. Professional technicians create a new protocol parameter configuration table 1 according to the protocol, and name and configure response data 1 to response data N and exception flag 1 to exception flag N according to actual applications.
[0094] 3. The technician enters the information into the flow meter protocol type database through the database generation software based on the table information.
[0095] 4. The application software equipment obtains the new protocol parameter database by remote downloading or copying according to the needs. The application software includes system software, applets, production configuration software, test tool software, etc., according to specific application requirements.
[0096] 5. The controller obtains the flow meter protocol type related parameters from the application software according to the needs and stores them in the non-volatile memory through different channels, including remote wireless, Bluetooth, infrared, serial port, etc.
[0097] 6. The controller MCU determines that RS485 chip serial communication is required, and the controller and flow meter communicate. The points that need to be communicated include timing (such as the hour), key pressing, power on, wireless remote transmission connection, etc. The communication steps are as follows: 6.1 Get the communication protocol type related parameters from the non-volatile memory.
[0098] 6.2 According to the communication voltage value, the value written into the electronic potentiometer U7 chip is calculated by the following formula (1). For the specific device circuit, see Figure 4 : Vo: Flow meter communication voltage value VOUT, unit: mV.
[0099] R62: Figure 4 The resistance value of R62 in the circuit, unit: Ω.
[0100] R63: Figure 4 The resistance value of R63 in the circuit, unit: Ω.
[0101] Rc: Unit resistance of electronic potentiometer U7 chip, unit Ω.
[0102] Vc: reference voltage of boost chip U8, unit: mV.
[0103] No: Write data to the electronic potentiometer.
[0104] (1); The data No written into the electronic potentiometer is transmitted through the SCL pin and SDA pin of the U7 chip 2 C protocol is written into the electronic potentiometer U7 chip, the PW_485 terminal is set high, the input voltage V_DC is sent to the boost chip, and the boost chip U8 control terminal is turned on at the same time, and the RS485 chip serial communication voltage VOUT is output through the electronic potentiometer U7 chip, the boost chip U8 and related device circuits.
[0105] 6.3 Turn on the power of the RS485 chip serial communication chip and initialize the RS485 chip serial communication port according to the baud rate, data bit, stop bit and parity check in the protocol related parameters.
[0106] 6.4 After initialization is completed, set RS485 to the sending state and wait according to the delay time in the configured data item. The purpose of the delay is that after the RS485 chip serial communication port is powered, the flow meter has a process of switching the power supply of the RS485 chip serial communication port. After the power switching is completed, the RS485 chip serial communication can be carried out, so a certain delay time is required.
[0107] 6.5 When the delay time is up, the CRC checksum is calculated based on the configured communication address, function code, register start address, and number of registers to be read, and a MODBUS read command frame message is formed and sent to the flow meter.
[0108] 6.6 After the transmission is successful, RS485 is set to receive state, and the delay waits for receiving data. The received data revdata[len], invalid data is filtered out, CRC check is performed, and the message data is judged to be legal. If it is legal, continue to execute the following steps.
[0109] 6.7 Analyze the response data 1 to N, and execute steps S1 to S7 in a loop until the analysis of N data is completed. The specific steps are as follows: Step S1: Determine whether the high-order data offset addrhX of the response data X (X is 1 to N) is 0. If not, execute step S2; if yes, add 1 to X and continue with step S1.
[0110] Step S2: start by obtaining the corresponding received data revdata [addrhX] in the response frame according to the high-order data offset value addrhX of the response data X and the number of bytes lenhX, send lenhX bytes into the array arrayh[lenhX], and execute step S3.
[0111] Step S3: According to the data type typehX, arrangement order orderhX, and data magnification / reduction multiple mulhX of the high-order data of the response data X, the array order is rearranged, the data type is converted, and the data is magnified or reduced, and the array arrayh[lenhX] is converted into controller fixed format data datahX, and step S4 is executed.
[0112] Step S4: Determine whether the low-order data offset addrlX of the response data X is 0. If not, execute step S5; if so, datahX is used as the final data dataX of the data item X, either stored or for standby, X is increased by 1, and return to step S1.
[0113] Step S5: starting from obtaining the corresponding received data revdata [addrlX] in the response frame according to the low-order data offset value addrlX of the response data X and the number of bytes lenlX, lenlX bytes are sent to the array arrayl[lenlX], and step S5 is executed.
[0114] Step S6: According to the data type typelX, arrangement order orderlX, and data magnification / reduction multiple mullX of the low-order data of the response data X, the array sequence is rearranged, the data type is converted, and the data is magnified or reduced, and the array arrayl[lenlX] is converted into controller fixed format data datalX, and then go to step S7.
[0115] Step S7: take datalX+datahX as the final data dataX of data item X, either for storage or standby, add 1 to X, and return to step S1.
[0116] 6.8 Analyze the abnormal flags 1 to N, and execute steps S8 and S9 in a loop until the conversion of N abnormal flag data is completed. The specific steps are as follows: Step S8: Determine whether the response data exception flag X (X is 1 to N) offset eaddrX is 0, if not, execute step S9; if yes, add 1 to X and continue to step S8.
[0117] Step S9: Obtain the corresponding received data revdata [eaddrX] in the response frame according to the data offset value eaddrX of the exception flag N, and determine whether the ebitXBIT bit of revdata [eaddrX] is valid according to the BIT bit ebitX value of the exception flag N; if so, the corresponding abnormal state of the controller is set to valid; if it is 0, the corresponding abnormal state of the controller is set to invalid, X is increased by 1, and the process returns to step S8.
[0118] 6.9 Close the R485 serial port, turn off the chip power supply of the RS485 chip serial communication, and turn off the voltage output of the boost chip.
[0119] The communication method for the flow meter provided in this embodiment obtains all communication protocols matching the flow meter; performs protocol parameter configuration based on all communication protocols, and generates a protocol parameter database based on the protocol parameters; when it is determined that the controller and the specified flow meter need to perform serial communication, serial communication between the controller and the flow meter is performed based on the communication protocol type and protocol parameter database of the specified flow meter, thereby realizing that the flow meter controller can perform RS485 chip serial communication with flow meters of different manufacturers that output with the MODBUS serial communication protocol through parameter configuration, without changing or adding the program code of the original flow meter, thus saving work time and cost, and solving the problem that the flow meter of the same manufacturer cannot perform serial communication with the controller through RS485.
[0120] In this embodiment, a communication device for a flow meter is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0121] This embodiment provides a communication device for a flow meter, such as Figure 5 As shown, including: The communication protocol acquisition module 501 is used to acquire all communication protocols matching the flow meter; The protocol parameter configuration and database generation module 502 is used to configure protocol parameters based on all communication protocols respectively, and generate a protocol parameter database based on the protocol parameters; The serial communication module 503 is used to perform serial communication between the controller and the flow meter based on the communication protocol type and protocol parameter database of the specified flow meter when the controller and the specified flow meter need to perform serial communication.
[0122] In some optional implementations, the protocol parameter configuration and database generation module 502 includes: The serial port parameter configuration unit is used to configure the chip serial communication port parameters based on all communication protocols. The chip serial communication port parameters include baud rate, parity, data bit and stop bit.
[0123] The hardware parameter configuration unit is used to configure the flow meter hardware parameters based on all communication protocols. The flow meter hardware parameters include communication voltage and delay time.
[0124] The protocol command configuration unit is used to configure serial communication protocol commands based on all communication protocols. The serial communication protocol commands include: communication address, function code, register start address and read register quantity.
[0125] The response message data item configuration unit is used to configure the response message data items based on all communication protocols. The response message data items include offset address, data length, data type and abnormal flag bit data items.
[0126] The protocol parameter database generating unit is used to store the newly added communication protocols and corresponding protocol parameters in all communication protocols into the original protocol parameter database by using the protocol parameter database software, so as to generate a new protocol parameter database.
[0127] In some optional implementations, the protocol-related parameters include baud rate, parity check, data bit, stop bit, communication voltage, delay time, communication address, function code, register start address, number of registers to read, and response message data items; the serial communication module 503 includes: A protocol-related parameter acquisition unit, used to acquire protocol-related parameters corresponding to the communication protocol type of the specified flow meter from the non-volatile memory; Initialization unit, used to initialize the chip serial communication port based on baud rate, parity, data bits and stop bits.
[0128] The output voltage unit is used to convert the communication voltage into a value corresponding to the preset electronic potentiometer, and provide the DC-DC boost chip with a voltage used for output flow meter and chip serial communication through the preset electronic potentiometer value.
[0129] The delay waiting unit is used to set the serial communication port of the chip after initialization to the sending state and wait according to the delay time; The CRC check code calculation and message group unit is used to calculate the CRC check code and group the message based on the communication address, function code, register start address and the number of registers to be read after the delay time ends, and send a read data command to the flow meter.
[0130] The CRC check code and message reading unit is used to set the chip serial communication port to the receiving state, read the response message in the flow meter, filter out invalid data in the response data according to the communication address, function code and data length, and obtain the CRC check code in the response message.
[0131] The serial communication unit is used to perform CRC check on the response message based on the CRC check code. When the CRC check is legal, the response message is parsed based on the relevant data offset address, data length, data type and abnormal flag data items, and the parsed response message data is converted into data in a preset format as flow meter data and stored in the controller.
[0132] In some optional implementations, the relevant data offset address includes a high-order data offset address and a low-order data offset address of a specified response data item, the data length includes the number of high-order data bytes and the number of low-order data bytes, the data type includes the data type of the high-order data, the arrangement order of the high-order data, the magnification and reduction multiples of the high-order data, the data type of the low-order data, the arrangement order of the low-order data and the magnification and reduction multiples of the low-order data, the abnormal flag bit data item includes the abnormal flag offset address and the abnormal flag BIT bit; the serial communication unit includes: The high-order array writing sub-unit is used to determine whether the high-order data offset address of the specified response data item is a preset value; if so, continue to determine whether the high-order data offset address of the next specified response data item is a preset value; if not, obtain the corresponding high-order received data in the response message according to the value of the high-order data offset address of the specified response data item and the number of high-order data bytes, and write the obtained high-order received data into the high-order array.
[0133] The high-order data conversion subunit is used to rearrange the high-order array sequence according to the arrangement sequence of the high-order data of the specified response data item, and convert the rearranged array into high-order data of a preset format according to the data type of the high-order data and the magnification and reduction multiple of the high-order data.
[0134] The first judgment subunit is used to judge whether the low-order data offset address of the response data item specified in the response message is a preset value. If so, the high-order data of the preset format is stored in the controller as the final response data of the flow meter, and the step of judging whether the high-order data offset address of the next specified response data item is a preset value is continued.
[0135] The low-order array writing subunit is used to obtain the corresponding low-order received data in the response message according to the low-order data offset address value and the number of low-order bytes, and write the low-order received data into the low-order array.
[0136] The low-order data conversion subunit is used to rearrange the low-order array sequence according to the arrangement sequence of the low-order data of the specified response data item, and convert the rearranged low-order array into low-order data of a preset format according to the data type of the low-order data and the magnification and reduction multiple of the low-order data.
[0137] The storage subunit is used to add the high-order data and the low-order data and store them in the controller as the final response data of the specified response data item, and specify the next response data item, and continue to execute the step of determining whether the high-order data offset address of the next specified response data item is a preset value.
[0138] The exception flag bit parsing subunit is used to determine whether the exception flag offset address in the specified exception flag bit data item is a preset value. If so, continue to execute the step of determining whether the exception flag offset address in the next specified exception flag bit data item is the preset value; if not, obtain the corresponding received data in the response message according to the value of the exception flag offset address, and determine whether the value of the exception flag BIT bit of the received data is valid according to the value of the exception flag BIT bit. If so, the corresponding exception state of the controller is set to valid; if not, the corresponding exception state of the controller is set to invalid, specify the next exception flag in the response data item, and continue to execute the step of determining whether the exception flag offset address in the next specified exception flag bit data item is the preset value.
[0139] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0140] The communication device of the flow meter in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0141] The embodiment of the present invention also provides a computer device having the above Figure 5 The communication device of the flow meter shown.
[0142] See also Figure 6 , Figure 6 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 6As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 6 A processor 10 is taken as an example.
[0143] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0144] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0145] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0146] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0147] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 6 The example of connecting through bus is taken in the following.
[0148] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device may be a touch screen.
[0149] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0150] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0151] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A communication method for a flow meter, characterized in that: The method comprises: Get all communication protocols matching the flow meter; Performing protocol parameter configuration based on all the communication protocols, and generating a protocol parameter database based on the protocol parameters; When the controller and the designated flow meter need to perform serial communication, the serial communication between the controller and the flow meter is performed based on the communication protocol type of the designated flow meter and the protocol parameter database.
2. The method according to claim 1, characterized in that Protocol parameter configuration based on all the communication protocols described, including: Configure chip serial communication port parameters based on all communication protocols, wherein the chip serial communication port parameters include baud rate, parity check, data bit and stop bit; Performing flow meter hardware parameter configuration based on all communication protocols, wherein the flow meter hardware parameters include communication voltage and delay time; Perform serial communication protocol command configuration based on all communication protocols, wherein the serial communication protocol command includes: communication address, function code, register start address and register number to be read; The response message data item configuration is performed based on all communication protocols, and the response message data item includes relevant data offset address, data length, data type and abnormal flag bit data item.
3. The method according to claim 1, characterized in that: The generating a protocol parameter database based on the protocol parameters comprises: The protocol parameter database software is used to store the newly added communication protocols and the corresponding protocol parameters in all communication protocols into the original protocol parameter database to generate a new protocol parameter database.
4. The method according to claim 1, characterized in that: The method further comprises: When the communication between the controller and the designated flow meter is power-on communication, timing communication, key press communication and wireless remote connection communication, it is determined that the controller and the designated flow meter need to perform serial communication.
5. The method according to claim 1, characterized in that Before performing serial communication between the controller and the flow meter based on the communication protocol type of the designated flow meter and the protocol parameter database, the method further includes: The communication protocol type of the specified flow meter is obtained, and protocol-related parameters corresponding to the communication protocol type are obtained from the protocol parameter database and stored in the non-volatile memory of the controller.
6. The method according to claim 5, characterized in that The protocol related parameters include baud rate, parity check, data bit, stop bit, communication voltage, delay time, communication address, function code, register start address, number of registers to read and response message data items; The serial communication between the controller and the flow meter based on the communication protocol type of the specified flow meter and the protocol parameter database includes: Acquire protocol-related parameters corresponding to the communication protocol type of the specified flow meter from the non-volatile memory; Initialize the chip serial communication port based on the baud rate, parity check, data bits and stop bits; Based on the communication voltage, the voltage is converted into a value corresponding to a preset electronic potentiometer, and the preset electronic potentiometer value is used to output the voltage used by the flow meter and chip serial communication of the DC-DC boost chip; Set the serial communication port of the initialized chip to the sending state and wait according to the delay time; When the delay time is over, the CRC check code is calculated based on the communication address, function code, register start address and the number of registers to be read, and a message is assembled, and a read data command is sent to the flow meter; Set the serial communication port of the chip to the receiving state, read the response message of the flow meter, filter out invalid data in the response data according to the communication address, function code, and data length, and obtain the CRC check code in the response message; The response message is subjected to CRC check based on the CRC check code. When the CRC check is legal, the response message is parsed based on the relevant data offset address, data length, data type and abnormal flag data items. The parsed response message data is converted into data in a preset format and then used as flow meter data and stored in the controller.
7. The method according to claim 6, characterized in that The relevant data offset address includes a high-order data offset address and a low-order data offset address of a specified response data item, the data length includes the number of high-order data bytes and the number of low-order data bytes of a specified response data item, the data type includes the data type of the high-order data of the specified response data item, the arrangement order of the high-order data, the magnification and reduction multiple of the high-order data, the data type of the low-order data, the arrangement order of the low-order data and the magnification and reduction multiple of the low-order data, and the abnormal flag bit data item includes an abnormal flag offset address and an abnormal flag BIT bit; The response message is parsed based on the relevant data offset address, data length, data type and abnormal flag data item, and the parsed response message data is converted into data in a preset format as flow meter data and stored in the controller, including: Determine whether the high-order data offset address of the specified response data item is a preset value; if so, continue to determine whether the high-order offset address of the next specified response data item is a preset value; if not, obtain the corresponding high-order received data in the response message according to the value of the high-order data offset address of the specified response data item and the number of high-order data bytes, and write the obtained high-order received data into the high-order array; Rearrange the high-order array sequence according to the arrangement sequence of the high-order data of the specified response data item, and convert the rearranged array into high-order data of a preset format according to the data type of the high-order data and the magnification / reduction multiple of the high-order data; Determine whether the low-order data offset address of the specified response data item is a preset value. If so, store the high-order data in the preset format as the final response data of the flow meter in the controller, and continue to execute the step of determining whether the high-order data offset address of the next specified response data item is a preset value; If not, obtain the corresponding low-order received data in the response message according to the low-order data offset address and the number of low-order data bytes of the specified response data item, and write the obtained low-order received data into the low-order array; Rearrange the low-order array sequence according to the arrangement sequence of the low-order data of the specified response data item, and convert the rearranged array into low-order data of a preset format according to the data type of the low-order data and the magnification / reduction multiple of the low-order data; Add the high-order data and the low-order data as the final response data of the designated response data item and store them in the controller, designate the next response data item, and continue to execute the step of determining whether the high-order data offset address of the next designated response data item is a preset value; Determine whether the abnormal flag offset address of the specified abnormal flag bit data item is a preset value. If so, continue to execute the step of determining whether the abnormal flag offset address in the next specified abnormal flag bit data item is the preset value; if not, obtain the corresponding received data in the response message according to the value of the abnormal flag offset address, and determine whether the value of the abnormal flag BIT bit of the received data is valid according to the value of the abnormal flag BIT bit. If so, the corresponding abnormal state of the controller is set to valid; if not, the corresponding abnormal state of the controller is set to invalid, specify the next abnormal flag bit data item, and continue to execute the step of determining whether the abnormal flag offset address in the next specified abnormal flag bit data item is the preset value.
8. A communication device for a flow meter, characterized in that: The device comprises: A communication protocol acquisition module is used to acquire all communication protocols matching the flow meter; A protocol parameter configuration and database generation module, used to configure protocol parameters based on all the communication protocols respectively, and generate a protocol parameter database based on the protocol parameters; The serial communication module is used to perform serial communication between the controller and the designated flow meter based on the communication protocol type of the designated flow meter and the protocol parameter database when the controller and the designated flow meter need to perform serial communication.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the communication method of the flow meter according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the communication method for a flow meter according to any one of claims 1 to 7.
Citation Information
Patent Citations
Data communication method based on Modbus protocol standard and related equipment
CN110474896A
Communication protocol adaptation method and device, equipment and storage medium
CN114827302A
Internet of Things meter reading method, system and device based on photovoltaic inverter
CN115175023A
Method for automatically identifying equipment communication protocol and information acquisition system
CN117768561A
Data transmission method and device
CN119025459A