A General Method, Device, Medium and Product for Data Transmission of DCS Equipment in a Thermal Power Plant Machine Room
By defining configuration files and mapping tables, analyzing communication parameters to establish connections with DCS equipment in the thermal power plant room, setting up retransmission and error handling mechanisms, the problem of poor flexibility and scalability of communication protocols in the existing technology is solved, and the convenience and reliability of data transmission are achieved.
Patent Information
- Application Number
- CN202411336729.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2044-09-24
AI Technical Summary
The existing communication protocols have problems in the DCS equipment in the thermal power plant room, such as inability to flexibly specify data volume, limited bandwidth, high latency, low efficiency and data are susceptible to noise interference. Especially in multiple devices or different factory environments, communication logic needs to be reconstructed, resulting in poor reusability and scalability.
By defining configuration files and mapping tables, analyzing communication parameters to establish connections with the device, setting up retransmission mechanisms and error handling mechanisms, analyzing data structures and performing unit conversions, achieving flexible data acquisition and processing.
It improves the convenience and reliability of data transmission, solves the problems of latency and inefficiency, ensures data integrity, and supports the compatibility and scalability of multiple communication protocols.
Smart Images

Figure CN119232748B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data transmission, and in particular to a general thermal power plant machine room DCS equipment data transmission method, equipment, medium and product. Background Art
[0002] In a factory automation environment, the Distributed Control System (DCS) equipment in a general thermal power plant computer room and the computer room side typically communicate using a communication protocol (such as the Modbus protocol). Data such as the serial port and baud rate used for communication are generally fixed, and the data read by the DCS equipment in the general thermal power plant computer room is also fixed. This communication method is suitable for a single general thermal power plant computer room DCS device, but when multiple general thermal power plant computer room DCS devices are used or when different factory operating conditions are encountered, the overall communication logic needs to be restructured, resulting in poor scalability and reusability.
[0003] Existing technical solutions primarily rely on writing separate communication programs for each DCS device in a common thermal power plant computer room. This doesn't fully cover the diverse communication protocols required by different plants. For example, the Modbus TCP protocol and common big-endian and small-endian protocols require significant modifications to existing communication protocols.
[0004] Existing communication protocols have several limitations when processing large amounts of data. A major drawback is the inability to specify the amount of data to be acquired, which places significant constraints on processing large amounts of data. Furthermore, existing communication protocols typically utilize serial communication, which has limited bandwidth and speed, leading to delays and inefficiencies in large data transmission. Furthermore, existing communication protocols lack retransmission mechanisms and data integrity guarantees during transmission, making them susceptible to noise and interference, resulting in data loss or corruption. Summary of the Invention
[0005] In order to solve the above problems existing in the prior art, the present application provides a universal thermal power plant machine room DCS equipment data transmission method, equipment, medium and product.
[0006] To achieve the above objectives, this application provides the following solutions:
[0007] In a first aspect, the present application provides a general thermal power plant machine room DCS equipment data transmission method, comprising:
[0008] A configuration file is defined, in which a configuration block is defined for the communication program, and configuration content of the configuration block is set based on the YAML format; the configuration content includes: communication parameters and a list of data items to be obtained; the communication parameters include one or more of a serial port number, a baud rate, an IP address, data bits, a stop bit, a parity check, a slave address (device ID), a timeout period, an interframe period, a start character, an end character, an error check, an MBAP header, a data rate, a function code, a byte order, and a port number;
[0009] Define a mapping table and use a Mysql database to store and manage the various mapping relationships in the mapping table; the mapping table contains the following contents: protocol content mapping import module, connection error mapping, unit mapping conversion and data type mapping; the protocol content mapping import module is used to define the data mapping relationship between different communication protocols; the protocol content mapping import module includes the identification of the source protocol and the target protocol, as well as the data point mapping rules; the connection error mapping is used to standardize the handling methods of various connection errors; the connection error types are stored in the database, and each error has a corresponding error code, description text and severity level; the unit mapping conversion is used to define the conversion rules between different units of measurement; the database stores the source unit, target unit and the corresponding conversion formula or conversion factor; the data type mapping is used to define the data type of various data items, which is used to correctly handle the data type when transmitting data between different systems or protocols;
[0010] parsing the configuration file, establishing a connection with a universal thermal power plant computer room DCS device according to the communication parameters and the mapping table, reading data from the universal thermal power plant computer room DCS device according to a list of data items to be acquired based on a user request to obtain raw data, and processing the raw data based on provisions of the communication protocol to obtain a data reading result;
[0011] In the process of obtaining data reading results, set up a retransmission mechanism and error handling mechanism;
[0012] When no data read response is received within a set time, the retransmission mechanism is triggered;
[0013] When the data reading result obtained is abnormal, the error handling mechanism is triggered.
[0014] Optionally, processing the raw data based on a provision of a communication protocol to obtain a data reading result includes:
[0015] According to the data format of the original data, traverse and parse the data structure of each layer of the original data;
[0016] Defining data parsing logic, and based on the data parsing logic, locating the location of the data item corresponding to the user request in each layer of the data structure of the original data, and extracting the data item value;
[0017] For the data item value, according to the original unit and point situation of the data item value, query the rule base to obtain the conversion rule; the rule base definition is obtained;
[0018] The data item value is converted based on the conversion rule, and the data reading result is obtained based on the converted data item value.
[0019] Optionally, when no data read response is obtained within a set time, triggering the retransmission mechanism includes:
[0020] Resending the same request as the user request and determining whether a data read response is obtained within a set time;
[0021] If a data read response is obtained within the set time, the data read result is output;
[0022] If no data read response is obtained within the set time, the process returns to the step of resending the same request as the user request and determining whether a data read response is obtained within the set time, until the upper limit of request retransmission is reached, and a read failure message is returned; for each retransmission request, the set time is gradually increased.
[0023] Optionally, when the obtained data reading result is abnormal, triggering the error handling mechanism includes:
[0024] Performing an integrity check on the data reading result to obtain a test result;
[0025] When the inspection result shows that the data reading result is complete, outputting the data reading result;
[0026] When the inspection result shows that the data reading result is incomplete, it is determined that the data reading result is corrupted, the retransmission mechanism is triggered, and the process returns to the step of performing an integrity check on the data reading result to obtain the inspection result, until the requested retransmission limit is reached and the inspection result still shows that the data reading result is incomplete, and a read error message is returned.
[0027] Optionally, the configuration file is loaded and parsed using a PyYAML library.
[0028] Optionally, the process of parsing the configuration file and establishing a connection with a DCS device in a general thermal power plant machine room according to the communication parameters and the mapping table includes:
[0029] According to the protocol type of the DCS equipment in the general thermal power plant machine room, the corresponding module path and class name are found in the mapping table, and the module corresponding to the module path is dynamically imported using the Python importlib module to obtain a reference to the class;
[0030] Using the reflection mechanism, create the communication object of the class through the reference of the class;
[0031] Parsing the configuration file to obtain communication parameters of the DCS equipment in the general thermal power plant room;
[0032] The communication parameters of the universal thermal power plant machine room DCS device are passed to the communication object, and the corresponding initialization method is called according to different protocol types to establish a connection with the universal thermal power plant machine room DCS device.
[0033] Optionally, the process of setting the configuration content of the configuration block based on the YAML format includes:
[0034] An editing tool is used to set the configuration content of the configuration block based on the YAML format.
[0035] In a second aspect, the present application provides a computer device comprising: 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-mentioned general thermal power plant machine room DCS equipment data transmission method.
[0036] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-mentioned general thermal power plant machine room DCS equipment data transmission method.
[0037] In a fourth aspect, the present application provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the above-mentioned general thermal power plant machine room DCS equipment data transmission method.
[0038] According to the specific embodiments provided in this application, this application discloses the following technical effects:
[0039] The present application provides a general thermal power plant machine room DCS equipment data transmission method, equipment, medium and product. By defining a configuration file, the required data can be flexibly obtained, making the increase or decrease of data volume more convenient. Parse the configuration file, establish a connection with the general thermal power plant machine room DCS equipment (hereinafter referred to as the equipment) according to the communication parameters and mapping table, so that communication between devices is more convenient. At the same time, even when the equipment is replaced later, there is no need to make major adjustments to the communication program of the equipment. In addition, parse the configuration file, establish a connection with the general thermal power plant machine room DCS equipment (hereinafter referred to as the equipment) according to the communication parameters and mapping table, which can solve the delay and inefficiency problems that occur during large data transmission. By setting an error handling mechanism and a retransmission mechanism, the problem of data loss or damage due to noise and interference can be avoided. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0041] Figure 1 A flowchart of a general method for transmitting data from a DCS device in a thermal power plant machine room according to an embodiment of the present application is provided;
[0042] Figure 2 A schematic diagram of the structure of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0044] In order to make the purpose, features and advantages of this application more obvious and easy to understand, this application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0045] In the embodiment of this application, Figure 1 As shown, a general method for transmitting data of DCS equipment in a thermal power plant room is provided. The method is executed by a computer device, specifically, a computer device such as a terminal or a server, or a terminal and a server. In the embodiment of the present application, the method is described by taking the application of the method to an electronic device as an example, and includes the following steps 100 to 105. Among them:
[0046] Step 100: Define a configuration file. In the configuration file, define a configuration block for the communication program and set the configuration content of the configuration block based on the YAML format. The configuration content includes: communication parameters and a list of data items to be obtained. The communication parameters include one or more of the following: serial port number, baud rate, IP address, data bits, stop bits, parity, slave address (device ID), timeout, frame interval, start character, end character, error detection, MBAP header, data rate, function code, byte order, and port number. Among them, communication parameters refer to the communication parameters of a single device, and multiple devices have multiple communication parameters. The device refers to a DCS device or a PLC device. The IP address, port number, slave address, and MBAP header all belong to the Modbus TCP protocol and the Modbus UDP protocol. The serial port parameters, slave address: 1-247, start character: colon (:), end character: carriage return and line feed (CR / LF), error detection: LRC (longitudinal redundancy check) part belong to the Modbus ASCII protocol. Port number (COM port): Specifies the serial port used for communication. Baud rate: typically 9600, 19200, 38400, 57600, or 115200 bps. Data bits and stop bits: 1 or 2. Parity: None, odd, or even. Interframe interval. CRC checksum. These are part of the Modbus RTU protocol. Function codes and byte codes are common to all protocols.
[0047] Step 101: Define a mapping table and use a Mysql database to store and manage the various mapping relationships in the mapping table. The mapping table mainly includes the following aspects: (1) Protocol content mapping import module, which defines the data mapping relationship between different communication protocols. It includes the identification of the source protocol and the target protocol, as well as specific data point mapping rules; (2) Connection error mapping: used to standardize the handling of various connection errors. The possible types of connection errors are stored in the database, and each error has a corresponding error code, description text and severity level; (3) Unit mapping conversion: defines the conversion rules between different measurement units. The database stores the source unit, target unit and the corresponding conversion formula or conversion factor; (4) Data type mapping: defines the data type of various data items, which is used to ensure that the data type can be correctly handled when transmitting data between different systems or protocols.
[0048] Step 102: Parse the configuration file, establish a connection with the DCS device in the general thermal power plant computer room (hereinafter referred to as the device) based on the communication parameters and the mapping table, read data from the DCS device in the general thermal power plant computer room according to the list of data items to be obtained based on the user request, and obtain raw data. Process the raw data based on the provisions of the communication protocol to obtain a data reading result.
[0049] Step 103: In the process of obtaining the data reading result, a retransmission mechanism and an error handling mechanism are set.
[0050] Step 104: When no data read response is received within a set time, a retransmission mechanism is triggered.
[0051] Step 105: When the obtained data reading result is abnormal, an error handling mechanism is triggered.
[0052] Implementing steps 100 to 105 above makes it easier to increase or decrease the amount of data, solves the delay and inefficiency problems that occur during large data transmission, and avoids data loss or corruption due to noise and interference. In addition, this application is also compatible with common Modbus protocols on the market, including RTU, ASCII, and TCP, ensuring communication compatibility and scalability.
[0053] In another exemplary embodiment of the present application, a serial communication device (such as a USB to serial port adapter) is used to establish a connection with the device. These communication devices provide a reliable physical connection and are compatible with the computer system, facilitating data transmission and processing. In the specific implementation process, the communication connection and data transmission are mainly completed through the communication program. Based on this, in the above-mentioned steps 100 and 101, the configuration file is parsed and the connection is established with the DCS equipment of the general thermal power plant room according to the communication parameters and mapping table. The implementation process of the configuration file is as follows:
[0054] The configuration file uses the common YAML format, making it easy for users to edit and parse. Within the configuration file, you can define a configuration block for the communication program, which contains the device's communication parameters and a list of data items to be retrieved. Configuration content is set according to the standard YAML file format. Users can edit these configuration blocks using text document editing tools or other editing tools to customize the communication settings and data collection requirements for each device. Communication parameters include port (serial port name or TCP port number), baudrate (baud rate), and host (IP address or host name). For example, the Modbus protocol communication parameters include unit (slave address) and address (register starting address).
[0055] The communication program parses the configuration file to obtain the configuration information for each device. It then establishes a connection with the device (such as a programmable logic controller (PLC) or remote terminal unit (RTU)) based on the communication parameters. For example, Python serial communication libraries such as Pymodbus or pyModbusTCP can be used for this purpose.
[0056] Based on the description of this embodiment, the process of parsing the configuration file in step 101 and establishing a connection with the DCS equipment in the general thermal power plant room according to the communication parameters and the mapping table can be summarized as follows:
[0057] (1) According to the protocol type of the DCS equipment in the general thermal power plant room, the corresponding module path and class name are found from the mapping table. The Python importlib module is used to dynamically import the module corresponding to the module path to obtain the class reference.
[0058] (2) Using the reflection mechanism, create a communication object of the class through the reference of the class.
[0059] (3) Obtain the communication parameters of the DCS equipment in the general thermal power plant room from the configuration file.
[0060] (4) The communication parameters of the DCS equipment in the general thermal power plant room are passed to the communication object, and the corresponding initialization method is called according to different protocol types to establish a connection with the DCS equipment in the general thermal power plant room.
[0061] In another exemplary embodiment of the present application, in step 101, the process of processing the original data based on the provisions of the communication protocol to obtain the data reading result includes:
[0062] (1) According to the data format of the original data, traverse and parse the data structures of each layer of the original data.
[0063] (2) Define the data parsing logic, and based on the data parsing logic, locate the location of the data item corresponding to the user request in each layer of the data structure of the original data and extract the data item value.
[0064] (3) For the data item value, according to the original unit and point situation of the data item value, query the rule base to obtain the conversion rule. The rule base definition is obtained.
[0065] (4) Convert the data item value based on the conversion rule, and obtain the data reading result based on the converted data item value.
[0066] In another exemplary embodiment of the present application, in step 101, based on a user request and according to a list of data items to be obtained, data is read from a DCS device in a general thermal power plant computer room to obtain raw data, and the raw data is processed according to the provisions of the communication protocol to obtain the data reading result, including:
[0067] First, the communication program sends a request to the DCS or PLC device to obtain the required communication protocol (for example, Modbus RTU) raw data based on the list of data items required by each device in the configuration file. The program then parses and extracts the specified data items. The obtained data then undergoes unit conversion. The raw data from the communication protocol typically consists of the format ([start bit][slave address][function code][data][CRC checksum]).
[0068] Next, parse and extract the specified data items. Based on the original data format (JSON, YAML format) returned by the device, traverse and parse the data structure of each layer to locate the location of the data item that needs to be extracted. For each data item that needs to be extracted, write the corresponding data parsing logic to accurately extract the value of the data item from the original data. Considering that the data formats returned by different devices may be different, different data parsing logic needs to be written for different device types and models. For example, the data parsing logic of the Transmission Control Protocol (TCP) is used for the Siemens S7-1200 PLC, the data parsing logic of the RTU is used for the Schneider Modicon M241 PLC, the ABB ACS880 inverter and the Rosemount 3051S pressure transmitter, and the data parsing logic of the American Standard Code for Information Interchange (ASCII) is used for the Anderson-Jaeger EJA110E pressure transmitter.
[0069] The process for writing the corresponding data parsing logic to accurately extract the value of a data item from the raw data is as follows: First, import the necessary modules from the pymodbus library, such as Modbus TCP Client, Modbus Serial Client, Binary Payload Decoder, and Endian. Next, create a base class, ModbusDeviceBase, which contains methods for initialization, reading data, parsing data, and retrieving the parsed data. Next, create subclasses for each device, inheriting from the base class, and define device-specific initialization, data reading, and data parsing methods in each subclass. For example, the Siemens S71200 class initializes the Modbus TCP client using the IP address, reads holding registers, and uses the Binary Payload Decoder to parse register data and convert it into specific measurement values (such as temperature, pressure, and flow). Other device classes, such as the Schneider M241 and ABB ACS880, follow similar logic. The parsing logic needs to be fault-tolerant and able to handle exceptions (such as incorrect data format or missing key fields) to avoid data loss due to parsing failures. The parsed data item value needs to be converted to ensure that it matches the expected data type.
[0070] The units of the same data item in the raw data returned by different devices may vary, requiring unified unit conversion. Unit conversion is mainly achieved by maintaining a unit conversion rule library, clarifying the standard unit for each data item, and the conversion formula from different source units to the standard unit. For example:
[0071] (1) Temperature conversion:
[0072] The conversion formula from Celsius (°C) to Fahrenheit (°F) is: °F = (°C × 9 / 5) + 3.
[0073] The conversion formula from Fahrenheit (°F) to Celsius (℃) is: ℃ = (°F - 32) × 5 / 9.
[0074] The conversion formula from Kelvin (K) to Celsius (°C) is: °C = K - 273.15.
[0075] (2) Pressure conversion:
[0076] The conversion formula from bar to kilopascals (kPa) is: kPa = bar × 100.
[0077] The conversion formula from pounds per square inch (psi) to kilopascals (kPa) is: kPa = psi × 6.89476.
[0078] The conversion formula from megapascal (MPa) to kilopascal (kPa) is: kPa = MPa × 1000.
[0079] (4) Traffic conversion:
[0080] Cubic meters / hour (m 3 The conversion formula from liters per minute (L / min) to liters per minute (L / h) is: L / min = (m 3 / h×1000) / 60.
[0081] Gallons per minute (gpm) to cubic meters per hour (m 3 / h) is converted into: m 3 / h=gpm×0.227124.
[0082] (5) Power conversion:
[0083] The conversion formula from kilowatt (kW) to megawatt (MW) is: MW = kW / 1000.
[0084] The conversion formula from horsepower (hp) to kilowatts (kW) is: kW = hp × 0.745699.
[0085] (6) Heat conversion:
[0086] The conversion formula from kilocalorie (kcal) to kilojoule (kJ) is: kJ = kcal × 4.184.
[0087] The conversion formula from British thermal units (BTU) to kilojoules (kJ) is: kJ = BTU × 1.055056.
[0088] (7) Voltage conversion:
[0089] The conversion formula from kilovolts (kV) to volts (V) is: V = kV × 1000.
[0090] (8) Current conversion:
[0091] The conversion formula from ampere (A) to milliampere (mA) is: mA = A × 1000.
[0092] (9) Frequency conversion:
[0093] The conversion formula from Hertz (Hz) to kilohertz (kHz) is: kHz = Hz / 1000.
[0094] In addition, other conversion formulas are included, which will not be described in detail here.
[0095] For each parsed data item value, the rule library is queried to obtain the corresponding conversion formula based on its original unit and point location. Unit conversion calculations are used to convert the data item value from the original unit to the standard unit. The converted data must be processed without loss of precision, and rounding errors must be considered for floating-point calculations. If a unit conversion rule cannot be found for a data item, the original value and unit are retained, and a warning message is recorded in the log. The processed data is stored in files or databases, and visualization libraries can also be used to display the data in charts or other formats.
[0096] During the entire process, the communication program will record relevant log information for debugging and tracing, and will handle and report any abnormal situations that may occur (such as communication errors, data format errors, etc.) appropriately.
[0097] In another exemplary embodiment of the present application, the implementation process of step 103 includes:
[0098] (1) Resend the same request as the user request and determine whether a data read response is received within the set time.
[0099] (2) If a data read response is received within the set time, the data read result is output.
[0100] (3) If no data read response is received within the set time, the process returns to the step of resending the same request as the user request and determining whether a data read response is received within the set time. This process continues until the upper limit of request resends is reached, at which point a read failure message is returned. The set time is gradually increased for each resend request.
[0101] In another exemplary embodiment of the present application, the implementation process of step 104 includes:
[0102] (1) Perform integrity check on the data reading result to obtain the test result.
[0103] (2) When the inspection result shows that the data reading result is complete, the data reading result is output.
[0104] (3) When the inspection result shows that the data reading result is incomplete, it is determined that the data reading result is damaged, the retransmission mechanism is triggered, and the process returns to the step of performing an integrity check on the data reading result to obtain the inspection result, until the requested retransmission limit is reached and the inspection result still shows that the data reading result is incomplete, and a read error message is returned.
[0105] In another exemplary embodiment of the present application, in the general thermal power plant machine room DCS equipment data transmission method provided by the present application, the data acquisition and processing process can be described as follows:
[0106] The communication program establishes a connection with the device based on the communication parameters defined in the configuration file and reads data from the device according to the user-specified list of data items. The data read is raw data, which is processed according to the provisions of the Modbus RTU protocol or other protocols such as TCP and ASCII to convert it into normal read data. Taking the Modbus RTU protocol as an example, the process of converting the raw data a and b read from the Modbus protocol into normal floating-point values is as follows:
[0107] First, use the hex() function to convert a and b into hexadecimal strings. After removing the "0x" prefix, use the zfill(4) method to pad the strings to 4 characters. Then, concatenate the two padded hexadecimal strings according to the IEEE 754 floating-point format, with the high byte first and the low byte last. Use the bytes.fromhex() method to convert the concatenated strings into a byte sequence. Finally, use the unpack() function of the struct module to unpack the byte sequence into network byte order and floating-point format. The first element of the returned tuple is the converted floating-point value.
[0108] When reading data, a resend mechanism and error handling are set up to ensure data integrity and reliability. The resend mechanism starts a timer after sending a request. If no response is received within the timeout period, the same request is resent. The number of retries is capped, and the timeout period is appropriately increased before each resend.
[0109] Error handling will check the integrity of the response data. After receiving the original data returned by the device, the data needs to be checked for integrity. According to the Modbus protocol, the last two bytes of the data returned by the device are checksums [such as cyclic redundancy check (CRC), checksum, etc.], which are used to verify whether the data has been tampered with during transmission. Get the checksum field in the original data and recalculate the checksum value of the data based on the checksum algorithm (such as CRC16, CRC32, etc.). Taking the CRC16 algorithm as an example, for the Modbus protocol, there is an initialization CRC value of 0xFFFF and a 16-bit polynomial value of 0xA001. The following processing is performed on each data byte:
[0110] Perform an exclusive-OR (XOR) operation on the data byte with the lower 8 bits of the CRC. Repeat the following operation multiple times (for example, 8 times) (corresponding to the 8 bits of a byte): Check the lowest bit of the CRC (the first bit on the right). If it is 1, shift the CRC value right by one bit and then perform an exclusive-OR operation with the polynomial value (0xA001). If it is 0, shift the CRC value right by one bit only. Repeat the previous steps until all data bytes have been processed. The resulting 16-bit value is the CRC checksum. In the Modbus protocol, this value is usually appended to the end of the message with the least significant byte first (little endian).
[0111] The recalculated checksum is compared with the checksum in the original data to ensure it is consistent. If they are inconsistent, the data is considered corrupted. For recoverable errors such as checksum errors, the request is resent and the retransmission mechanism is initiated. If a checksum error is found, it is generally believed that the data was contaminated during transmission, but the device itself is operating normally. In this case, you can try to request the data again to give the device a chance to retransmit. Implement a retry mechanism and set a maximum number of retries (such as 3). If the number is exceeded, communication is terminated. Set a reasonable waiting interval before each retry to avoid excessive requests that overload the device. If response data with the correct checksum is received within the specified number of retries, the recoverable error is considered resolved and subsequent processing can continue.
[0112] For unrecoverable errors, such as device-returned exception codes (e.g., Modbus IOException for I / O-related errors, Modbus Exception for Modbus protocol-related exceptions, and Connection Exception for connection-related exceptions), these exceptions are captured to determine whether an exception response has been received. This indicates a device failure or abnormal state. An exception code mapping table is maintained, creating a dictionary to map exception codes and descriptions, such as exception_codes = {1: "Illegal Function", 2: "Illegal Data Address", 3: "Illegal Data Value", 4: "Device Failure", 5: "Confirm", 6: "Device Busy"}. This maps the exception code returned by the device to the specific error message. The data returned by the device is parsed to check whether it contains an exception code field. If so, the mapping table is queried to obtain the corresponding error message. After obtaining the error message, detailed information is recorded in the log. The error information includes a timestamp, device ID, error code, and description. The error is then classified as recoverable or unrecoverable based on its nature, and relevant personnel are promptly notified through various channels (such as control room alarms and text messages). The monitoring interface also updates in real time to display error status. Recoverable errors include brief communication interruptions caused by network congestion or temporary interference. Data checksum errors, such as CRC check failures, may be caused by noise interference during transmission. Device busy status: The device is temporarily unable to respond to requests but is expected to resume normal operation later. The system will attempt to automatically recover, such as resending commands or restarting communication. For unrecoverable errors, certain exception codes may indicate serious problems. Communication with the device is usually terminated, and a corresponding error message is output in the log or UI to facilitate subsequent troubleshooting. The error message should include sufficient context, such as the device ID, error code, and error description, to quickly locate the problem. The program also handles communication-level exceptions, such as serial port opening failures and connection interruptions. Reconnection attempts will be made, and if failure persists, a hardware check prompt will be prompted. Unrecoverable errors include ConnectionException, which indicates an inability to establish or maintain a connection to the device. Specific Modbus exception codes indicate device malfunctions, such as Code 4, which indicates an unrecoverable error within the device. Code 5 (Confirmation) indicates a prolonged state, which may indicate a device freeze. Code 6 (Device Busy) indicates that if it occurs repeatedly, it may indicate a serious problem with the device. Repeated failure means that if an operation fails more than a predetermined number of times in a row, it can be considered an unrecoverable error. Custom serious errors refer to device characteristics.
[0113] In another exemplary embodiment of the present application, the communication program implements compatibility with different Modbus protocols (such as RTU, ASCII, and TCP). Based on the device definition in the configuration file, the appropriate protocol is dynamically selected to communicate with the device. In this way, users can flexibly switch and use different communication protocols in different industrial environments without having to modify or recompile the program. The specific implementation process is:
[0114] First, we load and parse the YAML-formatted configuration file using the PyYAML library to obtain the Modbus protocol type used by each device. The configuration file defines an entry for each device, including information such as the device ID, protocol type, and communication parameters (such as serial port number, baud rate, IP address, and port number).
[0115] Secondly, maintain a protocol type mapping table that maps different protocol type strings (such as "RTU" and "TCP") to corresponding Python module paths and class names. The mapping table acts as a lookup table to facilitate finding the modules and classes that need to be dynamically imported based on the protocol type strings read from the configuration file.
[0116] Then, for each device, the corresponding module path and class name are found in the mapping table based on its protocol type. The specified module is dynamically imported using Python's importlib module to obtain a class reference. Using reflection, an instance object of the class is created from the class reference, i.e., a communication host object of the corresponding protocol type.
[0117] Next, read the specific communication parameters of the device from the configuration file, such as serial port number, baud rate, IP address, port number, etc., pass these parameters to the communication object created earlier, call the corresponding initialization method according to different protocol types, and establish a connection with the device.
[0118] To unify the interaction between upper-level business logic and underlying communication objects, a general communication interface class is defined, with specific communication objects as attributes of this interface class. Data read and write methods are implemented in the interface class, which internally calls the corresponding read and write methods of the underlying communication objects. This allows the upper-level logic to interact only with this unified interface, regardless of the specific protocol used by the underlying layer. Finally, during system initialization, all devices in the configuration file are traversed, and corresponding communication objects are dynamically created for each device based on its protocol type. These created objects are encapsulated in instances of the communication interface class and stored as attributes. When the upper-level logic needs to communicate with a device, it retrieves the corresponding instance from the interface class and calls its read and write methods, allowing it to interact with the device without having to worry about the underlying protocol. This dynamic loading method enhances scalability.
[0119] When supporting a new protocol type, simply add a new protocol type entry to the mapping table and implement the corresponding module and class, without modifying the main logic code. Furthermore, because communication objects for different protocol types implement similar read and write interfaces, changes to the upper-layer business logic are minimal, making it easy to integrate new protocol support. Other communication parameters are then set in the object, and object methods are called to establish a connection with the device according to the protocol. Data is then read and written from the communication object using a unified interface, and data is exchanged with the device using the appropriate method based on the protocol. Finally, the connection is closed.
[0120] Through this dynamic switching process, you only need to specify the protocol type in the configuration file, without modifying the program, to switch to different Modbus protocols in different industrial environments, reducing development and maintenance costs. You can further use design patterns to optimize the code and support more protocol variants to meet the needs of more scenarios.
[0121] In summary, this application addresses the limitations of the Modbus protocol in transmitting large amounts of data. By flexibly accessing the required data through configuration files, it makes it easier to increase or decrease the amount of data. Furthermore, configuration files are also used to process parameters such as the serial port name and baud rate used in serial communication, making communication between devices more convenient. Even when replacing devices later, there is no need to make significant program adjustments.
[0122] Furthermore, the general thermal power plant machine room DCS equipment data transmission method provided by this application has the following advantages over the prior art:
[0123] 1) Unified management: This application manages communications and data through configuration files, eliminating the need to write separate communication programs for each device, simplifying maintenance and management.
[0124] 2) Full protocol coverage: The dynamic protocol switching method provided by this application can support common Modbus protocols such as TCP, RTU, and ASCII, without the need for large-scale communication modifications, thereby improving communication compatibility and flexibility.
[0125] In addition, during the specific implementation process, you can also use the existing communication library and Modbus protocol stack to write communication programs for different devices, or use specialized communication devices and protocol converters, such as gateway devices, to achieve communication conversion between different protocols.
[0126] In an exemplary embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Figure 2As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, abbreviated as I / O) and a communication interface. The processor, memory and input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store data transmitted by a general thermal power plant machine room DCS device. The input / output interface of the computer device is used to exchange information between the processor and external devices. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a general thermal power plant machine room DCS device data transmission method is implemented.
[0127] Those skilled in the art will understand that Figure 2 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present application and does not constitute a limitation on the computer device to which the solution of the present application is applied. A specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement. In an exemplary embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps of the above-mentioned method embodiments when executing the computer program.
[0128] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0129] In an exemplary embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0130] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0131] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0132] The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processors involved in the various embodiments provided herein may include, but are not limited to, general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic units, data processing logic units based on quantum computing, and the like.
[0133] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0134] This document uses specific examples to illustrate the principles and implementation methods of this application. The description of the above examples is only intended to help understand the method and core concept of this application. At the same time, for those skilled in the art, based on the concept of this application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.
Claims
1. A general thermal power plant DCS equipment data transmission method, characterized in that: The general thermal power plant machine room DCS equipment data transmission method includes: A configuration file is defined, in which a configuration block is defined for the communication program, and configuration content of the configuration block is set based on the YAML format; the configuration content includes: communication parameters and a list of data items to be obtained; the communication parameters include one or more of a serial port number, a baud rate, an IP address, data bits, a stop bit, a parity check, a slave address (device ID), a timeout period, an interframe period, a start character, an end character, an error check, an MBAP header, a data rate, a function code, a byte order, and a port number; Define a mapping table and use a Mysql database to store and manage the various mapping relationships in the mapping table; the mapping table contains the following contents: protocol content mapping import module, connection error mapping, unit mapping conversion and data type mapping; the protocol content mapping import module is used to define the data mapping relationship between different communication protocols; the protocol content mapping import module includes the identification of the source protocol and the target protocol, as well as the data point mapping rules; the connection error mapping is used to standardize the handling methods of various connection errors; the connection error types are stored in the database, and each error has a corresponding error code, description text and severity level; the unit mapping conversion is used to define the conversion rules between different units of measurement; the database stores the source unit, target unit and the corresponding conversion formula or conversion factor; the data type mapping is used to define the data type of various data items, which is used to correctly handle the data type when transmitting data between different systems or protocols; parsing the configuration file, establishing a connection with a universal thermal power plant computer room DCS device according to the communication parameters and the mapping table, reading data from the universal thermal power plant computer room DCS device according to a list of data items to be acquired based on a user request to obtain raw data, and processing the raw data based on provisions of the communication protocol to obtain a data reading result; In the process of obtaining data reading results, set up a retransmission mechanism and error handling mechanism; When no data read response is received within a set time, the retransmission mechanism is triggered; When the data reading result obtained is abnormal, triggering the error handling mechanism; The process of parsing the configuration file and establishing a connection with a DCS device in a general thermal power plant machine room according to the communication parameters and the mapping table includes: For each device, find the corresponding module path and class name from the mapping table according to its protocol type, use Python's importlib module to dynamically import the specified module and obtain the class reference; Using the reflection mechanism, create the communication object of the class through the reference of the class; Read the device's communication parameters from the configuration file, pass them to the created communication object, call the corresponding initialization method according to the different protocol types, and establish a connection with the device; To unify the interaction between upper-layer business logic and underlying communication objects, a universal communication interface class is defined, with communication objects as attributes of the interface class. Data read and write methods are implemented in the interface class, which internally calls the corresponding read and write methods of the underlying communication objects. This allows the upper-layer logic to interact only with the unified interface, regardless of the specific protocol used by the underlying layer. During system initialization, all devices in the configuration file are traversed, and corresponding communication objects are dynamically created for each device based on its protocol type. The created objects are encapsulated in instances of the communication interface class and stored as attributes. When the upper-layer logic needs to communicate with a device, it obtains the corresponding instance of the device from the interface class and calls its read and write methods to interact with the device. When a new protocol type needs to be supported, a new protocol type entry is added to the mapping table and the corresponding modules and classes are implemented without modifying the main logic code; a unified interface is used to read and write data from the communication object, and data is exchanged with the device in an appropriate manner according to the protocol, and finally the connection is closed.
2. The method for transmitting data of DCS equipment in a general thermal power plant room according to claim 1, characterized in that: The raw data is processed based on the provisions of the communication protocol to obtain a data reading result, including: According to the data format of the original data, traverse and parse the data structure of each layer of the original data; Defining data parsing logic, and based on the data parsing logic, locating the location of the data item corresponding to the user request in each layer of the data structure of the original data, and extracting the data item value; For the data item value, according to the original unit and point situation of the data item value, query the rule base to obtain the conversion rule; the rule base definition is obtained; The data item value is converted based on the conversion rule, and the data reading result is obtained based on the converted data item value.
3. The method for transmitting data of DCS equipment in a general thermal power plant machine room according to claim 1, characterized in that: When no data read response is received within a set time, the retransmission mechanism is triggered, including: Resending the same request as the user request and determining whether a data read response is obtained within a set time; If a data read response is obtained within the set time, the data read result is output; If no data read response is obtained within the set time, the process returns to the step of resending the same request as the user request and determining whether a data read response is obtained within the set time, until the upper limit of request retransmission is reached, and a read failure message is returned; for each retransmission request, the set time is gradually increased.
4. The method for transmitting data of DCS equipment in a general thermal power plant room according to claim 1, characterized in that: When the data reading result is abnormal, the error handling mechanism is triggered, including: Performing an integrity check on the data reading result to obtain a test result; When the inspection result shows that the data reading result is complete, outputting the data reading result; When the inspection result shows that the data reading result is incomplete, it is determined that the data reading result is corrupted, the retransmission mechanism is triggered, and the process returns to the step of performing an integrity check on the data reading result to obtain the inspection result, until the requested retransmission limit is reached and the inspection result still shows that the data reading result is incomplete, and a read error message is returned.
5. The method for transmitting data of DCS equipment in a general thermal power plant machine room according to claim 1, characterized in that: The configuration file is loaded and parsed through the PyYAML library.
6. The method for transmitting data of DCS equipment in a general thermal power plant machine room according to claim 1, characterized in that: The process of setting the configuration content of the configuration block based on the YAML format includes: An editing tool is used to set the configuration content of the configuration block based on the YAML format.
7. A computer device comprising: 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 universal thermal power plant machine room DCS equipment data transmission method according to any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the universal thermal power plant machine room DCS equipment data transmission method according to any one of claims 1 to 6 is implemented.
9. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the universal thermal power plant machine room DCS equipment data transmission method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Template-based easy-to-expand data analysis method and system
CN117435653A