A command processing method, device and equipment of an industrial communication adapter and a medium

By constructing a command dependency graph and topological sorting, the command execution sequence is dynamically generated, solving the communication failure problem caused by hard coding, improving the reliability and flexibility of industrial communication, and reducing maintenance costs.

CN123177883APending Publication Date: 2026-11-27CHONGQING CHUANYI AUTOMATION CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611312050.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing industrial communication adapters, when processing multiple command combinations, use hard-coding, which makes it easy for the command execution order to be incorrect, for pre-commands to be missed, for being difficult to adapt flexibly to changes in equipment, for having high maintenance costs, and for having a high probability of communication failure.

Method used

By constructing a command dependency graph, traversing backwards to generate the smallest command subgraph, performing topological sorting, dynamically generating command execution sequences, explicitly modeling data dependencies, ensuring strict dependency constraints on command execution, and optimizing command execution by combining caching strategies.

Benefits of technology

It reduces the probability of communication failure, improves the reliability and flexibility of industrial communication, reduces maintenance costs, and adapts to changes in equipment and protocols.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123177883A_ABST
    Figure CN123177883A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of industrial communication, and discloses a command dynamic aggregation method and device of an industrial communication adapter and a medium. The method comprises the following steps: receiving and analyzing an application program interface request to obtain a data field set to be acquired; determining a candidate command node from a command dependency relationship graph and reversely traversing to obtain a preceding command node; generating a minimum command subgraph based on the nodes and directed edges; performing topological sorting on the minimum command subgraph to generate a command execution sequence; sequentially executing the commands in the command execution sequence, extracting data to generate an intermediate result according to a parsing rule; and extracting an effective data value sequence from the intermediate result and serializing the effective data value sequence into a response body to return. The application explicitly models the data dependency relationship between the commands, dynamically generates an execution sequence that strictly satisfies the dependency constraint, reduces the probability of communication failure caused by the omission or execution sequence error of the preceding command, and improves the reliability of industrial communication.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of industrial communication technology, specifically to a command processing method, apparatus, device, and medium for an industrial communication adapter. Background Technology

[0002] With the development of Industrial Internet of Things (IIoT) and edge computing technologies, industrial communication adapters are playing an increasingly important role in industrial sites such as water conservancy and water management. In practical industrial applications, upper-layer applications typically need to use industrial communication adapters to obtain real-time data and operating status from lower-level field instruments in order to achieve remote monitoring and automated management of industrial production processes.

[0003] In the field of industrial process automation, the HART (Highway Addressable Remote Transducer) protocol is widely used. There are two common physical layer implementations of the HART protocol: one is based on a 4-20 mA analog loop using HART FSK (Frequency Shift Keying), and the other is based on Ethernet using HART-IP. Industrial communication adapters need to be compatible with both physical layers and provide a unified data access interface for upper-layer applications. However, the application layer command interaction of the HART protocol is relatively complex. For example, obtaining a complete device status often requires the coordinated operation of multiple low-level HART commands, and the response formats of instruments from different manufacturers to the same command may differ.

[0004] In related technologies, current industrial gateway products on the market generally adopt a fixed command sequence and fixed parsing logic when handling multiple command combinations. For each business function, the order of command calls is hard-coded in the code.

[0005] However, the aforementioned technologies suffer from the following technical drawbacks: Because they employ hard-coding to handle protocol command calls, they fail to explicitly model the data dependencies between underlying commands at the system level. This results in a situation where it may work when the device model is simple and the protocol is stable, but as the number of device types increases and protocols evolve, the combinations of hard-coded command sequences grow exponentially, leading to extremely high development and maintenance costs. More seriously, this lack of explicit data dependency modeling makes it prone to errors in command execution order, and prerequisite commands are easily overlooked, causing communication failures and hindering flexible adaptation to changes in field equipment. Summary of the Invention

[0006] In view of the above-mentioned shortcomings of the prior art, the purpose of this application is to provide a command processing method, apparatus, device and medium for an industrial communication adapter to solve at least one of the above-mentioned defects.

[0007] Firstly, this application provides a command processing method for an industrial communication adapter, comprising: Receive and parse the application programming interface (API) request initiated by the upper-layer application to obtain the set of data fields to be retrieved; From the constructed command dependency graph, determine the candidate command node that provides any field in the set of data fields to be obtained, and traverse backwards based on the candidate command node to obtain the predecessor command node associated with the candidate command node; Based on the candidate command node, the predecessor command node, the directed edges between the candidate command node and the predecessor command node, and the directed edges between the predecessor command nodes, generate the minimum command subgraph. Perform a topological sort on the smallest command subgraph to generate a command execution sequence, so that each command is executed after the commands it depends on have been executed. Each command in the command execution sequence is executed sequentially, and data is extracted from the response according to the parsing rules corresponding to the command to obtain intermediate results; wherein, the response is generated by the associated system of the industrial communication adapter based on the command; After all commands have been executed, the set of data fields to be retrieved is traversed, and the valid data values ​​corresponding to each field are extracted one by one from the intermediate results. The valid data values ​​are then serialized into a response body and sent back to the upper-layer application.

[0008] In one embodiment of this application, after generating the minimum command subgraph, the method further includes: Check if the fields in the set of fields to be retrieved are already cached in the local cache, and if the cached fields are valid; if the fields in the set of fields to be retrieved are already cached in the local cache, and if the cached fields are valid, then remove the cached fields from the set of fields to be retrieved. Remove command nodes from the minimum command subgraph that are only used to provide the fields that have been removed, and remove the preceding command nodes that only provide preceding inputs to the removed command nodes and have no other downstream dependencies.

[0009] In one embodiment of this application, topological sorting of the minimum command subgraph is performed to generate a command execution sequence, including: Calculate the in-degree of each command node in the minimum command subgraph. The in-degree is the number of directed edges pointing to the command node. Remove the command node with an in-degree of 0 from the minimum command subgraph, add it to the command execution sequence, and update the in-degree of the remaining command nodes; If, during the generation of the command execution sequence, there are still nodes in the minimum command subgraph that have not been removed, and none of the nodes that have not been removed are command nodes with an in-degree of 0, then a circular dependency is determined to exist, an error message is generated, and the execution of the command execution sequence is terminated.

[0010] In one embodiment of this application, the parsing rules include field names, data location expressions, and data type conversion rules; The data location expression type includes at least one of the following types: Byte offset positioning, used to start reading from the specified offset byte in the response; Value range positioning is used to read bytes of a specified length starting from the set start byte in the response; Bit positioning is used to read a specified bit of a set byte in the response; Data type conversion rules include at least one of the following types: Basic data type conversion, including unsigned integers, unsigned floating-point numbers, strings, and bits; Enumeration mapping conversion is used to map enumeration values ​​to readable strings.

[0011] In one embodiment of this application, the parsing rules are organized according to a three-level directory structure, which includes: The device rules directory stores the parsing rules for a given device model; The vendor-wide rules directory stores common parsing rules for devices from the same vendor. The default rules directory is used to store the default parsing rules defined according to the protocol specifications.

[0012] In one embodiment of this application, the method for determining the parsing rules includes: The parsing rules are determined by searching through the priority order of device rules, manufacturer-wide rules, and default rules. If no corresponding rule is detected in the device rules, manufacturer general rules, and default rules, a request to the cloud server to resolve the rule is triggered.

[0013] In one embodiment of this application, triggering a request to the cloud server for a parsing rule includes: Send a request to the cloud server to resolve the rules; The system receives the parsing rules issued by the cloud server, persists the parsing rules to the corresponding directory of the non-volatile memory, and loads them into the two-level hash table without restarting the industrial communication adapter, so as to query the parsing rules when the command is executed. When the cloud server issues an update to the parsing rules, an isolated update mechanism is used to replace the parsing rules in the local memory.

[0014] Secondly, this application provides a command processing device for an industrial communication adapter, comprising: The request parsing module is used to receive and parse the application programming interface requests initiated by the upper-layer application to obtain the set of data fields to be retrieved. The node filtering module is used to determine candidate command nodes that provide any field in the set of data fields to be obtained from the constructed command dependency graph, and to traverse backwards based on the candidate command nodes to obtain the predecessor command nodes associated with the candidate command nodes. The subgraph generation module is used to generate a minimum command subgraph based on candidate command nodes, predecessor command nodes, directed edges between candidate command nodes and predecessor command nodes, and directed edges between predecessor command nodes. The subgraph sorting module is used to perform topological sorting on the smallest command subgraph, generate a command execution sequence, and ensure that each command is executed after the commands it depends on have been executed. The command execution module is used to execute each command in the command execution sequence in sequence and extract data from the response according to the parsing rules corresponding to the command to obtain intermediate results; wherein, the response is generated by the industrial communication adapter's associated system based on the command; The data extraction module is used to traverse the set of data fields to be acquired after all commands have been executed, extract the valid data values ​​corresponding to each field from the intermediate results, serialize the valid data values ​​into a response body, and send it back to the upper layer application.

[0015] Thirdly, the electronic device provided in this application includes: One or more processors; and Memory is used to store one or more programs, which, when executed by one or more processors, enable the processors to implement certain methods.

[0016] Fourthly, this application provides a machine-readable medium having instructions stored thereon that, when executed by one or more processors, cause the processor to perform a method.

[0017] Beneficial Technical Effects: This application discloses a dynamic command aggregation method for an industrial communication adapter, comprising: receiving and parsing an application programming interface (API) request to obtain a set of data fields to be acquired; determining candidate command nodes from a command dependency graph and reversing to obtain preceding command nodes; generating a minimal command subgraph based on the aforementioned nodes and directed edges; performing topological sorting on the minimal command subgraph to generate a command execution sequence; sequentially executing commands in the command execution sequence, extracting data according to parsing rules to generate intermediate results; and extracting valid data values ​​from the intermediate results, serializing them into a response body, and sending it back. This application, by explicitly modeling the data dependencies between commands, dynamically generates execution sequences that strictly satisfy dependency constraints, reducing the probability of communication failures due to missing preceding commands or incorrect execution order, and improving the reliability of industrial communication.

[0018] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a flowchart illustrating a command processing method for an industrial communication adapter, as described in an exemplary embodiment of this application. Figure 2 This is a schematic flowchart illustrating the topological sorting of a minimum command subgraph, as an exemplary embodiment of this application. Figure 3 This is a schematic diagram of the command processing device of an industrial communication adapter according to an exemplary embodiment of this application; Figure 4 A schematic diagram of the structure of a computer system suitable for implementing embodiments of this application is shown. Detailed Implementation

[0021] The embodiments of this application will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be understood that the preferred embodiments are only for illustrating this application and are not intended to limit the scope of protection of this application.

[0022] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. Therefore, the drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0023] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the present application. However, it will be apparent to those skilled in the art that embodiments of the present application may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the present application.

[0024] First, the technical terms and custom concepts involved in this application will be explained in detail.

[0025] HART protocol: Highway Addressable Remote Transducer, is a hybrid analog / digital communication protocol widely used in the field of industrial process automation.

[0026] HART FSK: A HART implementation based on a 4-20mA analog loop, which transmits digital signals by superimposing them onto analog signals using frequency shift keying.

[0027] HART-IP: An Ethernet-based implementation of the HART protocol, transmitting HART commands and responses via TCP / UDP, supporting device network discovery and remote access.

[0028] Kahn's algorithm: a classic algorithm for topological sorting that generates an ordered sequence by repeatedly removing nodes with an in-degree of 0. In this paper, it is used for topological sorting of directed acyclic graphs.

[0029] A Directed Acyclic Graph (DAG) is a graph structure consisting of vertices and directed edges, in which there is no cycle that starts from a vertex, traverses several edges, and returns to that vertex. In this paper, it is used to model data dependencies between HART commands, ensuring that the command execution order is free of cyclic dependencies.

[0030] Command dependency graph: A model that describes the data dependencies between HART commands in the form of a directed acyclic graph, where nodes represent commands and edges represent dependencies.

[0031] It should be noted that the command dependency graph is constructed in the non-volatile storage module of the industrial communication adapter. The command dependency graph is defined as a directed acyclic graph G=(N,E). Here, node n∈N represents a low-level protocol command, and each node contains the following attributes: command number (e.g., 9, 48, 0, etc.), used to uniquely identify a command; parameter list required_params, recording the parameters required to execute the command, such as the device address; output field set provided, recording the set of data fields returned by the command, such as vendor ID, long tag; caching policy cache_policy, which can be static, quasi-static, or dynamic; and parsing rule identifier parser_rule, pointing to the dynamic parsing rule corresponding to the command. It should be noted that the low-level protocol command in this application is a higher-level concept. In practical applications, the low-level protocol command can be a HART protocol command, a Modbus protocol command, or a command of other industrial fieldbus protocols. This embodiment uses a HART protocol command as an example for illustration.

[0032] In a command dependency graph, a directed edge e=(u,v) indicates that command v depends on the execution result of command u. That is, command u must be executed before command v can be executed, and the directed edge points from the dependent command u to the dependent command v. The attributes of the directed edge can also include data mapping (data_mapping), which describes which output fields of command u serve as input parameters for command v, thus enabling automatic transfer of preceding command outputs to subsequent command inputs during command execution. For example, in the HART protocol, command 1 (reading main variables) depends on the output results of command 0 (reading device unique identifier), command 20 (reading long tags), and command 520 (reading process unit tags). In the command dependency graph, there are three directed edges: one from the node corresponding to command 0 to the node corresponding to command 1, one from the node corresponding to command 20 to the node corresponding to command 1, and one from the node corresponding to command 520 to the node corresponding to command 1.

[0033] Taking the HART protocol as an example, the dependency relationships of some commands in the command dependency diagram can be represented as follows: Command 0 does not depend on other commands, and its output data includes vendor ID, device type, device ID, and extended device status bits, serving to read the device's unique identifier; Command 20 depends on Command 0, and its output data is a long tag, used to concatenate the hostname in the HART-IP link; Command 520 depends on Command 0, and its output data is a process unit tag, used to concatenate the hostname in the HART-IP link; Command 1 depends on Command 0, Command 20, and Command 520, and its output data is the main variable, used for routine data acquisition; Command... Command 2 depends on commands 0, 20, and 520, and outputs the main variable loop current; Command 3 depends on commands 0, 20, and 520, and outputs the main variable, second main variable, third main variable, and fourth main variable; Command 9 depends on commands 0, 20, and 520, and outputs the first to ninth variables; Command 33 depends on commands 0, 20, and 520, and outputs the first to fourth variables; Command 48 depends on commands 0, 20, and 520, and outputs the additional device status bit, extended device status bit, and device operation mode, used for alarm status reading.

[0034] In some embodiments, the command dependency graph can be stored in non-volatile memory in JSON format. The JSON-formatted command dependency graph contains an array of nodes and an array of directed edges. Each node element in the nodes array contains an id (node ​​identifier), a command number, an array of provided output fields, a list of required params, a cache policy, and a parser rule identifier. For example, The node elements corresponding to command 0 can be recorded as follows: "id" is 0, "command" is 0, "provides" is ["manufacturer_id","device_type","device_id","ext_status_pos"], "required_params" is ["device_address"], "cache_policy" is "static", and "parser_rule" is "cmd0_default"; The node elements corresponding to command 20 can be recorded as follows: "id" is 20, "command" is 20, "provides" is ["long_tag"], "required_params" is ["device_address"], "cache_policy" is "static", and "parser_rule" is "cmd20_default"; The node elements corresponding to command 520 can be recorded as follows: "id" is 520, "command" is 520, "provides" is ["process_unit_tag"], "required_params" is ["device_address"], "cache_policy" is "static", and "parser_rule" is "cmd520_default"; The node elements corresponding to command 1 can be recorded as follows: "id" is 1, "command" is 1, "provides" is ["primary_variable"], "required_params" is ["device_address"], "cache_policy" is "dynamic", and "parser_rule" is "cmd1_default"; The node elements corresponding to command 2 can be recorded as follows: "id" is 2, "command" is 2, "provides" is ["loop_current"], "required_params" is ["device_address"], "cache_policy" is "dynamic", and "parser_rule" is "cmd2_default"; The node elements corresponding to command 3 can be recorded as follows: "id" is 3, "command" is 3, "provides" is ["pv","sv","tv","qv"], "required_params" is ["device_address"], "cache_policy" is "dynamic", and "parser_rule" is "cmd3_default"; The node elements corresponding to command 9 can be recorded as follows: "id" is 9, "command" is 9, "provides" is ["var1","var2","var3","var4","var5","var6","var7","var8","var9"], "required_params" is ["device_address","slot"], "cache_policy" is "dynamic", and "parser_rule" is "cmd9_default"; The node elements corresponding to command 33 can be recorded as follows: "id" is 33, "command" is 33, "provides" is ["var1","var2","var3","var4"], "required_params" is ["device_address","slot"], "cache_policy" is "dynamic", and "parser_rule" is "cmd33_default"; The node elements corresponding to command 48 can be recorded as follows: "id" is 48, "command" is 48, "provides" is ["additional_status", "extended_status", "device_mode"], "required_params" is ["device_address"], "cache_policy" is "dynamic", and "parser_rule" is "cmd48_default".

[0035] Each edge element in the directed edge array `edges` contains a source node identifier (`from`) and a target node identifier (`to`), indicating that the command corresponding to the target node depends on the execution result of the command corresponding to the source node. For example, The edge element { "from": 0, "to": 20} indicates that command 20 depends on command 0; The edge element { "from": 0, "to": 520} indicates that command 520 depends on command 0; The edge elements { "from": 0, "to": 1}, { "from": 20, "to": 1}, and { "from": 520, "to": 1} indicate that command 1 depends on command 0, command 20, and command 520. The edge elements { "from": 0, "to": 2}, { "from": 20, "to": 2}, and { "from": 520, "to": 2} indicate that command 2 depends on command 0, command 20, and command 520. The edge elements { "from": 0, "to": 3}, { "from": 20, "to": 3}, and { "from": 520, "to": 3} indicate that command 3 depends on command 0, command 20, and command 520. The edge elements { "from": 0, "to": 9}, { "from": 20, "to": 9}, and { "from": 520, "to": 9} indicate that command 9 depends on command 0, command 20, and command 520. The edge elements { "from": 0, "to": 33}, { "from": 20, "to": 33}, and { "from": 520,"to": 33} indicate that command 33 depends on command 0, command 20, and command 520. The edge elements { "from": 0, "to": 48}, { "from": 20, "to": 48}, and { "from": 520,"to": 48} indicate that command 48 depends on command 0, command 20, and command 520.

[0036] Please see Figure 1 , Figure 1 This is a schematic flowchart of a command processing method for an industrial communication adapter according to an exemplary embodiment of this application. The command processing method for the industrial communication adapter includes at least steps S110 to S160, which are described in detail below: Step S110: Receive and parse the application programming interface request initiated by the upper-layer application to obtain the set of data fields to be acquired; Specifically, the industrial communication adapter receives API call requests initiated by upper-layer applications (such as cloud server software) through its communication module. These API call requests contain at least a target device identifier parameter (which identifies the target device and allows for the acquisition of data about it). The adapter parses the API call request parameters, extracting the target device identifier parameter as the target device identifier and extracting the list of data fields requested by the API call request as a set of data fields to be acquired, R. For example, when an upper-layer application initiates a request to obtain device status, the request may include the target device identifier. The industrial communication adapter receives the API call GetDeviceStatus(deviceID) request, parses it, and obtains the target device identifier deviceID and the corresponding set of data fields to be acquired, R, which includes {Manufacturer ID, Device Type, Device ID, Extended Device Status Bits, Additional Device Status Bits}.

[0037] The upper-layer application can be cloud server software or a monitoring application deployed in an industrial field. The associated system of the industrial communication adapter can be a HART FSK field instrument or a HART-IP field instrument. The upper-layer application sends data requests at the business semantic layer to the industrial communication adapter, which then translates these requests into a set of underlying commands that satisfy dependencies.

[0038] It should be noted that there are various types of upper-level API requests, and different API requests correspond to different sets of data fields.

[0039] Step S120: Determine candidate command nodes that provide any field from the set of data fields to be acquired from the constructed command dependency graph, and traverse backwards based on the candidate command nodes to obtain the predecessor command nodes associated with the candidate command nodes; wherein, the command dependency graph includes command nodes and directed edges, the command node represents the underlying protocol command, including the output field set and the parsing rule identifier (the corresponding parsing rule can be determined through the parsing rule identifier), and the directed edges point from the dependent command to the dependent command; In this step, the set of fields that can provide the data to be retrieved is determined from the command dependency graph. R Find all candidate command nodes for any field, and traverse backwards along the directed edges from the candidate command nodes to obtain all their predecessor command nodes.

[0040] Specifically, each node in the command dependency graph is traversed, and the output field set `provides` of each node is compared with the data field set to be retrieved. R If the output field set `provides` of a node contains the set of data fields to be retrieved, then... RIf any data field in the node is selected, the node is marked as a candidate command node, and the data field is marked as "to be retrieved". Then, starting from the candidate command node, the traversal is performed in the opposite direction to the directed edge. Since the directed edge points from the dependent command to the dependent command, the reverse traversal can find the direct predecessor command node that the current candidate command node depends on layer by layer, and continue to find the upstream predecessor command node that the direct predecessor command node depends on, until a node with no incoming edges is reached.

[0041] Step S130: Generate a minimum command subgraph based on candidate command nodes, predecessor command nodes, directed edges between candidate command nodes and predecessor command nodes, and directed edges between predecessor command nodes. Specifically, after the reverse traversal, a minimum command subgraph is generated based on the candidate command node, the predecessor command node, the directed edges between the candidate command node and the predecessor command node, and the directed edges between different predecessor command nodes. Other command nodes that do not provide execution conditions for the candidate command and are not candidates are not included in this minimum command subgraph.

[0042] The minimum command subgraph is denoted as G R , where subscript R This indicates that the minimal command subgraph is generated for the current set of data fields to be retrieved. Here, "minimal" means that, given the given command dependency graph and the current field requirements, the subgraph retains candidate commands and the dependency paths that enable the candidate commands to meet the execution conditions, rather than representing a mathematical optimization of the number of nodes that is detached from the command semantics.

[0043] For example, if the set of data fields to be acquired only includes the additional device status bit, the command 48 node that provides that field can be located. For a HART-IP link, traversing backwards from the command 48 node, preceding command nodes such as command 0, command 20, and command 520 can be extracted. Compared to other command nodes that do not provide additional device status bits or execution conditions for command 48, commands 1, 2, 3, 9, and 33 do not enter the current minimum command subgraph. Finally, after the reverse traversal, commands 0, 20, 520, and 48 together constitute the minimum command subgraph. G R .

[0044] Step S140: Perform topological sorting on the minimum command subgraph to generate a command execution sequence, so that each command is executed after the commands it depends on have been executed. Specifically, compute the minimum command subgraph. G R The in-degree of each node is calculated, where in-degree is the number of directed edges pointing to that node; nodes with an in-degree of zero are removed in a loop, and the commands corresponding to the removed nodes are added to the command execution sequence in turn. After removing a node, decrement the in-degree of all its successors by one; repeat this process until all nodes have been processed. If there are still unremoved nodes before the end of the traversal, and the in-degree of the remaining nodes is not zero, then the node is considered a minimum command subgraph. G R A circular dependency exists, causing an error and termination of execution.

[0045] Topological sorting ensures that each command follows its dependent commands. When there are no direct or indirect dependencies between command nodes, their relative order in the command execution sequence can be determined by the traversal order. Regardless of the relative order among undependent nodes, the dependent command always enters the execution sequence before its dependent commands.

[0046] Step S150: Execute each command in the command execution sequence in sequence, and extract data from the response according to the parsing rules corresponding to the command to obtain intermediate results; wherein, the response is generated by the associated system of the industrial communication adapter based on the command; In this step, each command in the command execution sequence is executed sequentially. For each command in the sequence, parameters are first obtained from the context or the execution result of the preceding node command based on the required_params parameter list of the command. For example, the device address can come from the context of the API request, and the variable slots can come from the output of the preceding command. After the parameters are prepared, the current command is sent to the associated system (target device) through the communication module. The associated system generates a response based on the received command and returns the response to the industrial communication adapter. The industrial communication adapter looks up the corresponding parsing rule based on the parsing rule identifier parser_rule corresponding to the current command node, then parses the response based on the parsing rule, extracts the data defined in the output field set provided from the response, and uses this data as an intermediate result.

[0047] The response to the current command can include a protocol response header and response data. Parsing rules define field positions and type conversion methods for the response data. Based on the parsing rules, field location, raw byte reading, and data type conversion are performed, and then the converted fields are written to a temporary data pool. The temporary data pool serves as an intermediate result of the current application interface request.

[0048] Step S160: After all commands have been executed, iterate through the set of data fields to be acquired, extract the valid data values ​​corresponding to each field from the intermediate results, serialize the valid data values ​​into a response body, and send it back to the upper layer application.

[0049] After the command execution sequence is traversed, the set of data fields to be retrieved is traversed. For each field in the set, the corresponding valid data value is extracted from the intermediate results by field name, and serialized according to the field names and organizational hierarchy defined by the application interface to obtain the response body. The response body can be a JSON object. The serialization process converts fields from multiple underlying commands into a business response corresponding to the upper-layer application, so that the upper-layer application does not need to identify which HART protocol command each field comes from. After serialization is completed, the response body is sent back to the upper-layer application that initiated the request through the communication module.

[0050] This application expresses the constraints between commands through a command dependency graph, derives the actual required nodes from the current field requirements through reverse traversal, and converts the dependency subgraph into an executable sequence through topological sorting. Field requirements, graph traversal results, and sorting results are progressively passed along the same data link, reducing the probability of missing preceding commands and mismatched execution order when maintaining multiple sets of command sequences in a fixed business function.

[0051] In one embodiment, after generating the minimum command subgraph, the method further includes: Check if the fields in the set of fields to be retrieved are already cached in the local cache, and if the cached fields are valid; if the fields in the set of fields to be retrieved are already cached in the local cache, and if the cached fields are valid, then remove the cached fields from the set of fields to be retrieved. Remove command nodes from the minimum command subgraph that are only used to provide the fields that have been removed, and remove the preceding command nodes that only provide preceding inputs to the removed command nodes and have no other downstream dependencies.

[0052] Specifically, after a command is executed, the industrial communication adapter writes to or updates the local cache according to the caching strategy.

[0053] Caching strategies can include static, quasi-static, and dynamic. Static strategies are suitable for fields that typically remain unchanged throughout the device's lifecycle, such as the vendor identifier, device type, and device identifier returned by command 0, the long label returned by command 20, and the process unit label returned by command 520. Dynamic strategies are suitable for fields that need to be refreshed or periodically refreshed based on the device's operating status, such as master variables, variable values, and device status. Quasi-static strategies can be used for fields that remain stable for a relatively long period but may be updated after configuration changes. Static, quasi-static, and dynamic strategies are used to distinguish the refresh method for cached fields and do not require all output fields from different commands to use the same expiration criteria. The expiration status of a field can be determined based on the caching strategy associated with the command node.

[0054] During cache lookup, each field in the set of data fields to be retrieved is checked to see if it already exists in the local cache. If the corresponding field exists in the local cache and is still valid according to the caching strategy, the field is marked as a cache hit and removed from the set of data fields to be retrieved. After removing cache hit fields from the set of data fields to be retrieved, candidate command nodes in the minimal command subgraph are checked. If a command node is only used to provide a field that has been removed and does not provide any other fields yet to be retrieved, the command node and the edges associated with it are pruned from the minimal command subgraph.

[0055] After pruning a command node, the preceding command nodes of that node are checked. If a preceding command node only provides preceding input to the pruned node, and no other downstream command nodes in the minimum command subgraph depend on that preceding command node, the preceding command node is removed in a coordinated manner. This coordinated removal can continue upstream along the dependency direction. For each preceding command node removed, it is checked again whether the node's upstream nodes still have other downstream dependencies. If the upstream nodes are still depended on by other retained command nodes, the coordinated removal for that path is stopped to maintain the execution conditions of the remaining command nodes.

[0056] For example, if the current request only retrieves long tags, and the long tags are already effectively cached, the long tags are removed from the set of fields to be retrieved, and the command 20 node is pruned from the minimum command subgraph. If the command 0 node only provides input to command 20, and no other downstream nodes in the current minimum command subgraph depend on the command 0 node, then the command 0 node can also be removed in conjunction.

[0057] Please see Figure 2 , Figure 2 This is a schematic flowchart illustrating a topological sorting of a minimal command subgraph according to an exemplary embodiment of this application. The topological sorting of the minimal command subgraph includes at least steps S210 to S230, which are described in detail below: Step S210: Calculate the in-degree of each command node in the minimum command subgraph. The in-degree is the number of directed edges pointing to the command node. Specifically, traverse all directed edges in the minimum command subgraph. For each directed edge pointing to the current node found, the in-degree of the current node increases. The in-degree value represents the number of unresolved prerequisite dependencies of the current node within the subgraph.

[0058] Step S220: Remove the command node with an in-degree of 0 from the minimum command subgraph, add it to the command execution sequence, and update the in-degree of the remaining command nodes; Specifically, after calculating the in-degree, we find command nodes with an in-degree of 0. An in-degree of 0 indicates that the node has no prerequisites in the current minimum command subgraph, or that all prerequisites have been processed in previous loops. We remove the found nodes with an in-degree of 0 from the subgraph to be processed and append the command corresponding to the node to the command execution sequence.

[0059] After a command node is removed, traverse the downstream nodes pointed to by that node and decrease the in-degree of each downstream node accordingly. If the updated in-degree of a downstream node is 0, that downstream node enters the range of subsequent nodes to be processed. Repeat node removal, sequence appending, and in-degree updating until all command nodes have been processed, or no more nodes with an in-degree of 0 can be found.

[0060] If multiple command nodes with an in-degree of 0 exist in the same round, these nodes can be added to the command execution sequence sequentially. Since there are no unresolved pre-dependencies between these nodes, their relative order does not change the dependency constraints expressed by other directed edges. Alternatively, the processing order of these nodes can be determined according to their storage order in the graph.

[0061] In step S230, if there are still nodes that have not been removed in the minimum command subgraph during the generation of the command execution sequence, and there are no command nodes with an in-degree of 0 among the nodes that have not been removed, then it is determined that there is a circular dependency, an error message is generated, and the execution of the command execution sequence is terminated.

[0062] If the command execution sequence does not yet contain all command nodes in the minimum command subgraph, and none of the remaining nodes have an in-degree of 0, then an unresolved circular dependency exists between the remaining nodes. In this case, the command dependency configuration is deemed abnormal, an error message is generated, and the execution of the currently requested command is terminated. The error message can indicate that a circular dependency has been detected and can carry the command number of the unprocessed command node to help locate the configuration problem in the command dependency graph.

[0063] In one embodiment, the parsing rules include field names, data location expressions, and data type conversion rules. The data location expressions include at least one of the following types: byte offset location, used to read from a set offset byte in the response; value range location, used to read bytes of a specified length starting from a set start byte in the response; bit location, used to read a specified bit of a set byte in the response. The data type conversion rules include at least one of the following types: basic data type conversion, where the basic data types include unsigned integers, unsigned floating-point numbers, strings, and bits; and enumeration mapping conversion, used to map enumeration values ​​to readable strings.

[0064] Specifically, the parsing rules are defined in JSON format. The parsing rules include field names, data location expressions, and data type conversion rules. The field names match the field names in the output field set of the command node, enabling the parsing results to be written to a temporary data pool according to the field names and used for indexing the data field set to be retrieved.

[0065] Data location expressions must support at least one of the following: byte offset location, range slice location, and bit location. Parsing rules can contain only one of these location methods, or different location methods can be used for different fields within the same parsing rule object. Raw data is read from the response data according to the location expression corresponding to each field.

[0066] Byte offset positioning uses the form response.data[offset], indicating that reading starts from the offset-th byte of the response data. This method is suitable for data located at a specific byte position. For example, when the manufacturer identifier is located at byte 0 of the response data, the field name can be set to manufacturer_id, and the data positioning expression can be set to response.data[0].

[0067] Range slicing positioning uses the format `response.data[start-length]`, indicating that a continuous sequence of bytes of length `length` is read starting from the `start`th byte. This method is suitable for data consisting of multiple consecutive bytes, such as device identifiers, floating-point numbers, and strings. For example, if the device identifier occupies three bytes starting from the second byte, the original byte sequence can be extracted using the corresponding range slicing positioning.

[0068] Bit positioning uses the format `response.data[byte:bit]`, indicating that the bit in the byte-th byte of the response data is read. This method is suitable for bit-level fields such as extended status bits, alarm bits, and device operation flags. When different manufacturers use different layouts for alarm bits in command 48, the bit positioning expression can be changed to adapt to the corresponding position without changing the command execution code.

[0069] Data type conversion rules must support at least one of the following: basic data type conversion and enumeration mapping conversion. Basic data types can include unsigned 8-bit integers (uint8), unsigned 16-bit integers (uint16), unsigned 32-bit integers (uint32), 32-bit floating-point numbers (float32), 64-bit floating-point numbers (float64), strings, and bits.

[0070] Enumeration mapping conversion is used to convert enumeration values ​​in a response into readable strings. For example, an enumeration conversion rule can map the value 0 to "normal" and the value 1 to "alarm".

[0071] As a specific implementation, taking the default parsing rule cmd0_default for command 0 (reading the device's unique identifier) ​​as an example, its JSON format definition can include the following parsing entries: The field `manufacturer_id` has the location expression `response.data[0]`, the conversion rule is `uint8`, and the description is the manufacturer ID. The field device_type has the location expression response.data[1], the conversion rule is uint8, and the description is the device type; The field device_id has the location expression response.data[2-3], the conversion rule is uint16, and the description is device ID; The field `ext_status_pos` uses the location expressions `response.data[6:0]`, `response.data[6:1]`, `response.data[6:2]`, and `response.data[6:3]`, respectively, and is converted to bits. Their descriptions are, in order, Maintenance Required, Device Variable Alert, CriticalPower Failure, and Failure. This example demonstrates that multiple fields or even multiple bits within the same byte in the same command response can be independently defined through declarative parsing entries, without requiring any parsing code.

[0072] In one embodiment, the parsing rules are organized according to a three-level directory structure, which includes: a device rules directory for storing parsing rules for a specified device model; a manufacturer-wide rules directory for storing parsing rules common to devices from the same manufacturer; and a default rules directory for storing default parsing rules defined according to the protocol specification.

[0073] Specifically, three subdirectories are set up under the root directory / parser_rules / : The protocol default rules directory / parser_rules / default / is used to store parsing rule files that conform to the default behavior of the protocol specification, such as cmd0_default.json, cmd1_default.json, etc. The vendor-specific rules directory / parser_rules / vendor / is named after the vendor identifier and is used to store general parsing rule files for all models of devices from a specific vendor. For example, the rule with vendor ID 0xD4 is stored in the / parser_rules / vendor / 0xD4 / directory, and the rule with vendor ID 0x56 is stored in the / parser_rules / vendor / 0x56 / directory. The device rules directory / parser_rules / device / is named after the device model identifier and is used to store parsing rule files for specific device models. For example, the rules for a device with a vendor ID of 0xD4 and a device type of 0x81 are stored in the / parser_rules / device / 0xD481 / directory.

[0074] When the industrial communication adapter starts up, it reads the rule file in the three-level directory, parses the rule text into in-memory rule objects, and constructs a two-level hash table (a queryable data structure). The first-level hash table uses the command number as the key, and the corresponding value points to the second-level hash table; the second-level hash table uses the field name as the key, and the corresponding value points to the specific parsing rule structure.

[0075] For example, command number 0 corresponds to the command 0 rule set in the first-level hash table. The second-level hash table in the command 0 rule set can contain field keys such as manufacturer identifier, device type, device identifier, and extended device status bits. By locating the rule set by command number and then locating the parsed rule structure by field name, the process of traversing the rule file one by one is reduced.

[0076] In one embodiment, the method for determining the parsing rules includes: The parsing rules are determined by searching through the priority order of device rules, manufacturer-specific rules, and default rules. If no corresponding rule is detected in the device rules, manufacturer general rules, and default rules, a request to the cloud server to resolve the rule is triggered.

[0077] The matching priority of parsing rules is as follows: device-specific rules, vendor-specific rules, and protocol default rules. After determining the matching order, device rule matching is performed first, prioritizing the matching of rule files corresponding to the device model in the device rule directory. For example, for a device with vendor ID 0xD4 and device type 0x81, the rule file for the corresponding command is searched first in the ` / parser_rules / device / 0xD481 / ` directory. If not found, vendor-specific rule matching is performed, falling back to the rule file corresponding to the vendor identifier in the vendor-specific rule directory, such as searching in the ` / parser_rules / vendor / 0xD4 / ` directory. If still not found, protocol default rule matching is performed, falling back to the default rule file in the protocol default rule directory, such as searching in the ` / parser_rules / default / ` directory. During the matching process, if a corresponding rule file is found, data is extracted according to the parsing rules. If no matching is found in device rules, vendor-specific rules, or protocol default rules, a request for parsing rules is triggered from the cloud server.

[0078] In one embodiment, triggering a request to the cloud server to resolve rules includes: Send a request to the cloud server to resolve the rules; It receives the parsing rules from the cloud server, persists the parsing rules to the corresponding directory of non-volatile memory, and loads them into a two-level hash table without restarting the industrial communication adapter, so as to query the parsing rules when the command is executed; When the cloud server issues an update to the parsing rules, an isolated update mechanism is used to replace the parsing rules in the local memory.

[0079] Specifically, when no matching rules exist locally, the communication module establishes or uses a communication connection with the cloud server and sends a rule request to the cloud server. The industrial communication adapter determines the corresponding third-level directory location based on the device model or manufacturer identifier in the request, and then writes the parsed rule text to non-volatile memory. After persistent storage is complete, the new rule text is parsed without restarting the industrial communication adapter, the corresponding parsed rule structure is constructed, and the new rule is added to a two-level hash table in memory. The rule file in the non-volatile memory can also be reloaded when the industrial communication adapter restarts.

[0080] Furthermore, if the cloud server issues rule updates, an isolation update mechanism (double buffering or read-write locks) is used to ensure that the command execution thread is not disturbed by rule updates during the parsing process. Taking the double buffering mechanism as an example, the update operation is first written to a backup buffer, where the parsing and complete construction of the new rule object are performed. After the rule object is fully constructed, the replacement is completed through atomic pointer switching, so that the rule pointers in the two-level hash tables in memory are switched from the old rule object to the new rule object in a single atomic operation. The old rule object is released after it is no longer referenced. Since the pointer switching is an atomic operation, the rule object read by the command execution thread at any time is a complete and consistent version. The intermediate state during the rule update process is not visible to the execution thread, realizing non-blocking hot-swappable updates. As an alternative implementation, read-write locks can also be used to protect the rule object: the update thread acquires the write lock to complete the rule replacement, and the command execution thread holds the read lock for parsing, which can also ensure the integrity of the rule object read during the parsing process.

[0081] In one embodiment, the extraction of each field is further encapsulated into a metadata structure, which includes at least a data value field, a data length field, an acquisition timestamp field, a source command number field, and a cache flag field.

[0082] The data value field stores the actual field value obtained through parsing. In one implementation, the data value field can use a generic pointer to the field data to accommodate different data types such as unsigned integers, floating-point numbers, strings, and bits.

[0083] The data length field is used to record the length of the field data, so that the subsequent serialization process can read the data value according to the field length.

[0084] The timestamp field is used to record the time the field was acquired. When the field is obtained by parsing the current command response, the timestamp records the time corresponding to the current collection. When the field is reused from the local cache, the timestamp can record the original acquisition time of the cached data, allowing upper-layer applications to determine the freshness of the field by combining the timestamp.

[0085] The Source Command Number field records the HART protocol command number from which the current field was parsed. For example, if the vendor identifier comes from command 0, the Source Command Number field records command 0; if the additional device status bit comes from command 48, the Source Command Number field records command 48. This field allows the semantically fused data to still be traced back to the underlying command source.

[0086] The cache flag field identifies whether the current field comes from the local cache. When the field is obtained through physical communication triggered by the current request, the cache flag can be set to an uncached source; when the field is written to the temporary data pool during the cache query phase, the cache flag is set to a cached source. The cache flag, combined with the retrieval timestamp, allows upper-layer applications to distinguish between real-time collected data and cached reused data.

[0087] As a specific implementation, the data value field in the metadata structure uses `void* value`, the data length field uses `uint8_t length`, the timestamp field uses `time_t timestamp`, the source command number field uses `uint8_t source_cmd`, and the cache flag field uses `bool is_cached`. The above types are used to illustrate one feasible data organization method and do not limit other data types that can express the same field meanings.

[0088] In some embodiments, the physical layer implementation of the HART protocol includes at least a HART FSK link and an Ethernet-based HART-IP link. The command dependency graph sets different prerequisite command dependencies based on the device addressing and network access procedures of the physical links.

[0089] Under HART-IP links, commands 0, 20, and 520 constitute the pre-command sequence for device network access. Command 0 returns the device's unique identifier, command 20 returns the long label, and command 520 returns the process unit label. The outputs of commands 20 and 520 are used to concatenate and generate hostnames for DNS service discovery.

[0090] In a HART FSK link, the unique device identifier returned by command 0 can be used for device addressing; commands 20 and 520 are not required prerequisite commands for data acquisition commands. The command dependency graph established for this link can retain the directed edge from command 0 to the data acquisition command, without setting dependency edges from commands 20 and 520 for each data acquisition command.

[0091] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0092] Figure 3 This is a schematic diagram of the command processing device of an industrial communication adapter according to an exemplary embodiment of this application. Figure 3 As shown, a command processing device for an industrial communication adapter includes: The request parsing module 310 is used to receive and parse the application programming interface request initiated by the upper layer application to obtain the set of data fields to be obtained. The node filtering module 320 is used to determine the candidate command node that provides any field in the set of data fields to be obtained from the constructed command dependency graph, and to traverse backwards based on the candidate command node to obtain the predecessor command node associated with the candidate command node. The subgraph generation module 330 is used to generate a minimum command subgraph based on candidate command nodes, predecessor command nodes, directed edges between candidate command nodes and predecessor command nodes, and directed edges between predecessor command nodes. The subgraph sorting module 340 is used to perform topological sorting on the smallest command subgraph to generate a command execution sequence, so that each command is executed after the commands it depends on have been executed. The command execution module 350 is used to execute each command in the command execution sequence in sequence and extract data from the response according to the parsing rules corresponding to the command to obtain intermediate results; wherein, the response is generated by the associated system of the industrial communication adapter based on the command; The data extraction module 360 ​​is used to traverse the data field set after all commands have been executed, extract the valid data values ​​corresponding to each field from the intermediate results, serialize the valid data values ​​into a response body, and send it back to the upper layer application.

[0093] It should be noted that the command processing device for the industrial communication adapter provided in the above embodiments and the command processing method for the industrial communication adapter provided in the above embodiments belong to the same concept. The specific ways in which each module and unit performs operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the command processing device for the industrial communication adapter provided in the above embodiments can allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not a limitation here.

[0094] Embodiments of this application also provide an electronic device, including: one or more processors; and a memory for storing one or more programs, which, when executed by one or more processors, cause the memory to implement the command processing method of the industrial communication adapter in the above embodiments.

[0095] Embodiments of this application also provide a machine-readable medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the command processing method of the industrial communication adapter described in the above embodiments.

[0096] Figure 4A schematic diagram of a computer system suitable for implementing embodiments of this application is shown. It should be noted that... Figure 4 The computer system shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0097] like Figure 4 As shown, the computer system 400 includes a Central Processing Unit (CPU) 410, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on a program stored in Read-Only Memory (ROM) 420 or a program loaded from storage into Random Access Memory (RAM) 430. The RAM also stores various programs and data required for system operation. The CPU, ROM, and RAM are interconnected via a bus. An Input / Output (I / O) interface 450 is also connected to the bus 440.

[0098] The following components are connected to the I / O interface: an input section 460 including a keyboard, mouse, etc.; an output section 470 including a cathode ray tube (CRT), liquid crystal display (LCD), and speakers, etc.; a storage section 480 including a hard disk, etc.; and a communication section 490 including a network interface card such as a LAN (Local Area Network) card and a modem, etc. The communication section performs communication processing via a network such as the Internet. A drive 4100 is also connected to the I / O interface as needed. Removable media, such as disks, optical disks, magneto-optical disks, semiconductor memories, etc., are installed on the drive as needed so that computer programs read from them can be installed into the storage section as needed.

[0099] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including methods for performing processes. Figure 1 A computer program for a command processing method of the industrial communication adapter shown. In such an embodiment, the computer program can be downloaded and installed from a network via a communication section, and / or installed from removable media 4110. When the computer program is executed by a central processing unit (CPU), it performs various functions defined in the system of this application.

[0100] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0101] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0102] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.

[0103] Another aspect of this application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a computer's processor, causes the computer to perform the command processing method of the aforementioned industrial communication adapter. This computer-readable storage medium may be included in the memory described in the above embodiments, or it may exist independently and not incorporated into that memory.

[0104] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the command processing method of the industrial communication adapter provided in the various embodiments described above.

[0105] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.

Claims

1. A command processing method for an industrial communication adapter, characterized in that, The method includes: Receive and parse the application programming interface (API) request initiated by the upper-layer application to obtain the set of data fields to be retrieved; From the constructed command dependency graph, determine the candidate command node that provides any field in the set of data fields to be obtained, and traverse backwards based on the candidate command node to obtain the predecessor command node associated with the candidate command node; Based on the candidate command node, the preceding command node, the directed edge between the candidate command node and the preceding command node, and the directed edge between the preceding command nodes, a minimum command subgraph is generated; Perform topological sorting on the minimum command subgraph to generate a command execution sequence; Each command in the command execution sequence is executed sequentially, and data is extracted from the response according to the parsing rules corresponding to the command to obtain an intermediate result; wherein, the response is generated by the industrial communication adapter's associated system based on the command; After all commands have been executed, the set of data fields to be acquired is traversed, and the valid data values ​​corresponding to each field are extracted one by one from the intermediate results. The valid data values ​​are then serialized into a response body and sent back to the upper-layer application.

2. The method according to claim 1, characterized in that, After generating the minimum command subgraph, the method further includes: Check if the fields in the set of fields to be retrieved are already cached in the local cache, and if the cached fields are valid; if the fields in the set of fields to be retrieved are already cached in the local cache, and if the cached fields are valid, then remove the cached fields from the set of fields to be retrieved. Remove command nodes from the minimum command subgraph that are only used to provide the fields that have been removed, and remove the preceding command nodes that only provide preceding inputs to the removed command nodes and have no other downstream dependencies.

3. The method according to claim 1, characterized in that, The step of performing topological sorting on the minimum command subgraph to generate a command execution sequence includes: Calculate the in-degree of each command node in the minimum command subgraph, where the in-degree is the number of directed edges pointing to the command node; Remove command nodes with an in-degree of 0 from the minimum command subgraph and add them to the command execution sequence; If, during the generation of the command execution sequence, there are still nodes in the minimum command subgraph that have not been removed, and none of the nodes that have not been removed are command nodes with an in-degree of 0, then a circular dependency is determined to exist, an error message is generated, and the execution of the command execution sequence is terminated.

4. The method according to claim 1, characterized in that, The parsing rules include field names, data location expressions, and data type conversion rules; The data location expression includes at least one of the following types: Byte offset positioning, used to start reading from the specified offset byte in the response; Value range positioning is used to read bytes of a specified length starting from the set start byte in the response; Bit positioning is used to read a specified bit of a set byte in the response; The data type conversion rules include at least one of the following types: Basic data type conversion, where the basic data types include unsigned integers, unsigned floating-point numbers, strings, and bits; Enumeration mapping conversion is used to map enumeration values ​​to readable strings.

5. The method according to claim 4, characterized in that, The parsing rules are organized according to a three-level directory structure, which includes: The device rules directory stores the parsing rules for a given device model; The vendor-wide rules directory stores common parsing rules for devices from the same vendor. The default rules directory is used to store the default parsing rules defined according to the protocol specifications.

6. The method according to claim 5, characterized in that, The method for determining the parsing rules includes: The parsing rules are determined by searching through the priority order of device rules, manufacturer-specific rules, and default rules. If no corresponding rule is detected in the device rules, manufacturer general rules, and default rules, a request to the cloud server to resolve the rule is triggered.

7. The method according to claim 2, characterized in that, The rules for triggering a request to the cloud server for parsing include: Send a request to the cloud server to resolve the rules; The system receives the parsing rules issued by the cloud server, persists the parsing rules to the three-level directory structure corresponding to the non-volatile memory, and loads them into the two-level hash table in memory without restarting the industrial communication adapter, so as to query the parsing rules when the command is executed. When the cloud server issues an update to the parsing rules, an isolated update mechanism is used to replace the parsing rules in the local memory.

8. A command processing device for an industrial communication adapter, characterized in that, include: The request parsing module is used to receive and parse the application interface requests initiated by the upper-layer application to obtain the set of data fields to be retrieved. The node filtering module is used to determine candidate command nodes that provide any field in the set of data fields to be obtained from the constructed command dependency graph, and to traverse backwards based on the candidate command nodes to obtain the predecessor command nodes associated with the candidate command nodes. The subgraph generation module is used to generate a minimum command subgraph based on the candidate command node, the preceding command node, the directed edge between the candidate command node and the preceding command node, and the directed edge between the preceding command nodes. The subgraph sorting module is used to perform topological sorting on the minimum command subgraph to generate a command execution sequence, so that each command is executed after the commands it depends on have been executed. The command execution module is used to execute each command in the command execution sequence in sequence, and extract data from the response according to the parsing rules corresponding to the command to obtain intermediate results; wherein, the response is generated by the industrial communication adapter's association system based on the command; The data extraction module is used to traverse the set of data fields to be acquired after all commands have been executed, extract the valid data values ​​corresponding to each field from the intermediate results, serialize the valid data values ​​into a response body, and send it back to the upper layer application.

9. An electronic device, characterized in that, include: One or more processors; and A memory for storing one or more programs, which, when executed by one or more processors, cause the processors to implement the method as described in any one of claims 1 to 7.

10. A machine-readable medium, characterized in that, It stores instructions that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1 to 7.