A communication method and device based on a command-response protocol
By adopting a command-response protocol communication method in industrial gateways, and utilizing command-response log tables and parallel sending threads, the problems of real-time communication and configuration complexity of existing industrial gateways are solved, achieving efficient and reliable adaptive communication and reducing maintenance costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- DONGTU TECH (YICHANG) CO LTD
- Filing Date
- 2026-03-18
- Publication Date
- 2026-06-05
AI Technical Summary
Existing command-response protocols for industrial gateways suffer from poor real-time communication, complex configuration, and inability to adapt to changes in topology, resulting in high system reliability and maintenance costs.
A communication method based on a command-response protocol is adopted. By querying the command-response record table, real-time response and dynamic channel allocation are achieved to avoid communication blockage. Furthermore, communication efficiency and adaptability are optimized through parallel sending threads and a fault identification mechanism.
It improves the real-time performance and reliability of communication, reduces system configuration and maintenance costs, enables adaptive capabilities to topology changes, and ensures communication continuity in industrial scenarios.
Smart Images

Figure CN122160280A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of industrial gateway technology, and in particular to a communication method and apparatus based on a command-response protocol. Background Technology
[0002] In industrial automation and control systems, communication gateways serve as hubs connecting different devices, protocols, and networks, and the efficiency, reliability, and ease of use of their data forwarding mechanisms are crucial. Currently, there are two main implementation modes for command-response data communication methods commonly used in industrial gateways.
[0003] The first type is the transparent transmission mode. In this mode, the gateway essentially acts as a transparent channel, directly forwarding command messages received from the input channels to the preset output channels; correspondingly, response messages received from the output channels are directly transmitted back to the corresponding input channels. This mode is simple to implement, but it has significant drawbacks: on the one hand, if a device connected to an output channel fails or a response times out, subsequent commands and responses on that channel will be blocked, severely affecting the real-time performance and reliability of the overall communication; on the other hand, this mode requires administrators to precisely configure the static mapping relationship between each input channel and output channel, which is a large and inflexible configuration task.
[0004] The second type is the proxy mode. To overcome the timeliness issues of the pass-through mode, the proxy mode caches and matches commands and responses internally within the gateway. This typically requires pre-configuring a series of commands to be sent for the output channel in the gateway. The gateway actively polls and sends these commands, storing the response results in its internal cache. When the input channel receives a command request from the host computer, the gateway does not forward it in real time, but instead retrieves the pre-configured corresponding response data from its internal cache and returns it. While this mode avoids channel-level blocking due to device failure, its configuration process is extremely cumbersome: it requires not only pre-defining the command sequence on the output side but also precisely configuring the mapping relationship between commands and cached data on the input side, resulting in high system deployment and maintenance costs.
[0005] In summary, both the transparent transmission mode and the proxy mode have significant limitations. The transparent transmission mode is subject to channel congestion risks and complex static configurations, while the proxy mode sacrifices reliability for high configuration complexity. More importantly, when the topology of field devices changes (such as device replacement, address adjustment, or channel addition or removal), both modes require manual reconfiguration, resulting in a lack of adaptive capabilities and difficulty in adapting to the flexible and ever-changing application requirements of modern industrial environments. Therefore, there is an urgent need for a communication method that can balance high efficiency, reliability, ease of configuration, and adaptive capabilities. Summary of the Invention
[0006] In view of this, this application proposes a communication method, apparatus, and computing device based on a command-response protocol, which effectively improves the real-time performance and reliability of communication, and significantly reduces the configuration and maintenance costs of the system.
[0007] In a first aspect, this application provides a communication method based on a command-response protocol, applied to a communication device including at least one input channel and at least one output channel, comprising:
[0008] Receive external commands through the input channel;
[0009] Check if a response record corresponding to the external command exists in the command response record table; if it exists, return the response data in the response record through the input channel; if it does not exist, write the external command into a newly created response record and return a no-response indication.
[0010] Based on the response records in the command response record table, an output channel is allocated for the external command, and the external command is sent to the allocated output channel according to preset rules;
[0011] Receive response data from the output channel, update the response data to the response record in the command response record table, and return the response data through the input channel.
[0012] As described above, the communication method based on a command-response protocol provided in this application utilizes a query-and-return mechanism. When an external command is received, it first queries an internally stored record table. If a valid response exists in the record table, it returns immediately, avoiding the problem in the pass-through mode where a single command timeout can block all subsequent commands. If no valid response is found, a no-response indication is returned, and the external command is sent through the allocated output channel. The received response data is then updated in the record table for return through the input channel. This application achieves "returning response data when a response record exists" and "creating a new response record and returning response data when no response record exists" through the command-response record table. In other words, it automatically reassigns channels when there is no response and automatically associates with a valid channel when a response record is found, eliminating the need for manual configuration of the output channel. This application significantly reduces response latency and improves communication efficiency through the query record table and instant feedback mechanism. Furthermore, it eliminates the need for pre-configuring fixed mapping relationships between input / output channels, simplifying the configuration process. It also achieves adaptive updates to channel status and topology changes, eliminating the need for manual reconfiguration and ensuring communication continuity in industrial scenarios.
[0013] Optionally, each response record in the command response record table includes at least one of the following fields:
[0014] Command content, response content, input time, input interval, output time, output channel identifier, and number of no-response instances.
[0015] As described above, the structured field design (input / output time, interval, number of no-response times, etc.) provides complete data support for subsequent command queries, channel allocation, transmission frequency control, fault identification and other logic.
[0016] Optional, also includes:
[0017] If a response record corresponding to the external command exists in the command response record table, then the input interval and input time in the response record are updated according to the current time and the input time in the response record.
[0018] If there is no response record corresponding to the external command in the command response record table, the command content and input time of the external command are written into the newly created response record.
[0019] As described above, by dynamically updating the input time and input interval of the response record, it is possible to perceive changes in the receiving frequency of the same command in real time. The real-time update of the input interval provides a precise basis for adjusting the sending frequency of the subsequent output channel, allowing the sending rhythm of external commands to dynamically match the actual needs, avoiding resource waste or response lag caused by fixed sending frequency, and improving the dynamic adaptability of communication.
[0020] Optionally, allocating an output channel for the external command specifically includes:
[0021] If the response record contains the output channel identifier of the external command, then the external command is assigned to the output channel corresponding to the output channel identifier;
[0022] If the response record does not contain the output channel identifier of the external command, then the external command is assigned to any idle or polled output channel.
[0023] As described above, by defining two logics for route allocation, for external commands that have been bound to an output channel, the system can identify and reuse known valid paths, ensuring the determinism and efficiency of communication. For new commands or commands that have been unbound, the system can use a polling / idle channel probing mechanism to automatically allocate them to an available channel for testing, realizing the dynamic utilization of output channels, avoiding resource idleness caused by single channel occupancy, and providing logical support for subsequent fault channel switching and adaptive topology changes.
[0024] Optionally, sending external commands to the allocated output channel according to preset rules specifically includes:
[0025] Establish a parallel sending thread for each output channel;
[0026] Each sending thread controls the frequency at which it sends external commands to the output channel corresponding to it, based on the input interval of the external commands in the response record; the input interval is the time difference between two consecutive receptions of the same external command.
[0027] As described above, by adopting a parallel sending thread design, multiple output channels can work independently, avoiding the impact of single-channel failure on overall communication efficiency and improving the system's concurrent processing capability. Based on input interval control of the sending frequency, the command sending can be adjusted on demand. Commands received at high frequencies correspond to high-frequency sending, while commands received at low frequencies have fewer sending attempts. This ensures real-time response to critical commands, reduces resource consumption caused by invalid sending, and optimizes communication bandwidth and device performance.
[0028] Optionally, after assigning an external command to the output channel corresponding to the output channel identifier, updating the response data to the response record in the command response record table specifically includes:
[0029] If a valid response is received, the response data is written to the response content field of the response record, the output time in the response record is updated, and the number of no responses in the response record is cleared to zero.
[0030] If no valid response is received or the response times out, the response content field of the response record is cleared, the number of no responses in the response record is incremented by one, and the output time in the response record is updated. When the number of no responses exceeds a preset threshold, the output channel identifier in the response record is deleted.
[0031] Based on the above, an automatic identification and unbinding mechanism for faulty channels was established. By accumulating the number of unresponsive events and triggering the deletion of channel identifiers, the automatic troubleshooting of faulty output channels was achieved. The binding between faulty channels and commands can be removed without manual intervention, creating conditions for the system to reallocate effective channels. This improves the system's self-repair capability and anti-interference ability for channel faults, ensures the continuity of communication, and avoids communication failures caused by faulty channels occupying commands for a long time.
[0032] Optionally, after assigning an external command to any idle or polled output channel, updating the response data to the response record in the command response record table specifically includes:
[0033] If a valid response is received, the response data is written to the response content field of the response record, the output time in the response record is updated, the number of no responses in the response record is cleared to zero, and the output channel identifier of the response data returned this time is written to the output channel identifier of the corresponding response record.
[0034] If no valid response is received or the response times out, the external command will be reassigned to any other available or polled output channel.
[0035] As described above, automatic discovery and binding of output channels are achieved. Commands that are not bound to a channel are sent through multiple channels. Once a valid channel is found, it is automatically associated, completely eliminating the need for manual configuration of channel mapping relationships. When there is no response, the channel is automatically reassigned to ensure that the command can complete communication through other valid channels, thereby improving the success rate of command sending.
[0036] Optional, also includes:
[0037] Periodically check each response record in the command response record table and delete response records whose current time differs from the input time by more than a preset lifespan.
[0038] As described above, by regularly cleaning up response records that have exceeded their preset lifespan, invalid data (such as command records that have not been received for a long time) is prevented from accumulating in the record table, reducing storage resource consumption; the operating efficiency of the command response record table is optimized, avoiding a decrease in query and update speed due to data redundancy, and ensuring the long-term stable and efficient operation of the communication device.
[0039] Secondly, this application provides a communication device based on a command-response protocol, including at least one input channel and at least one output channel, and further comprising:
[0040] The command input module is used to receive external commands through the input channel;
[0041] The command response storage module is used to query whether there is a response record corresponding to the external command in the command response record table; if it exists, the response data in the response record is returned through the input channel; if it does not exist, the external command is written to a newly created response record and a no-response indication is returned.
[0042] The response output module is used to allocate an output channel for the external command according to the response record in the command response record table, and send the external command to the allocated output channel according to a preset rule; receive response data from the output channel, update the response data to the response record in the command response record table, and return the response data through the input channel.
[0043] Thirdly, this application provides a computing device, the computing device comprising:
[0044] processor;
[0045] Memory, used to store one or more programs;
[0046] When the processor executes one or more programs, it enables the processor to implement the above-described communication method based on a command-response protocol.
[0047] These and other aspects of this application will become more apparent in the description of the following embodiments(s). Attached Figure Description
[0048] Figure 1 A flowchart illustrating a communication method based on a command-response protocol provided in an embodiment of this application;
[0049] Figure 2 This is a schematic diagram of the format of a command response record table according to an embodiment of this application;
[0050] Figure 3 A block diagram of a communication device based on a command-response protocol provided in an embodiment of this application;
[0051] Figure 4 This is a schematic diagram illustrating the interaction between the command input module and the command response storage module in an embodiment of this application.
[0052] Figure 5 This is a schematic diagram illustrating the interaction between the command response storage module and the response output module in an embodiment of this application.
[0053] Figure 6 This is a structural diagram of a computing device provided in an embodiment of this application.
[0054] It should be understood that the dimensions and shapes of the block diagrams in the above structural diagrams are for reference only and should not constitute an exclusive interpretation of the embodiments of this application. The relative positions and inclusion relationships between the block diagrams presented in the structural diagrams are only schematic representations of the structural relationships between the block diagrams, and are not intended to limit the physical connection methods of the embodiments of this application. Detailed Implementation
[0055] The technical solutions provided in this application will be further described below with reference to the accompanying drawings and embodiments. It should be understood that the system architecture and business scenarios provided in the embodiments of this application are mainly for illustrating possible implementations of the technical solutions of this application and should not be construed as the sole limitation on the technical solutions of this application. Those skilled in the art will recognize that the technical solutions provided in this application are equally applicable to similar technical problems as system architectures evolve and new business scenarios emerge.
[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. In case of any inconsistency, the meaning set forth in this specification or derived from the content described herein shall prevail. Furthermore, the terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit the scope of this application.
[0057] The solutions provided in this application will now be described in detail with reference to the accompanying drawings and embodiments.
[0058] This application proposes a communication method and apparatus based on a command-response protocol, relating to the field of industrial gateway protocol data communication technology. Specifically, it is applied to industrial gateways with complex heterogeneous equipment, suitable for communication scenarios in industrial settings with multiple input / output channels and frequent changes in response devices. This application uses an intelligent command-response record table as a central hub to decouple the two pairs of processes: command reception and response return, and physical transmission and response waiting. This allows for immediate responses to the input side, while time-consuming physical device communication is processed asynchronously in the background. This fundamentally solves the problems of poor communication efficiency, cumbersome configuration, and inability to adapt to topology changes inherent in existing transparent transmission and proxy modes, meeting the core requirements of industrial sites for high reliability, ease of maintenance, and adaptability in communication systems.
[0059] Figure 1 The diagram shows a flowchart of a communication method based on a command-response protocol provided in an embodiment of this application. This communication method is applied to a communication device including at least one input channel (for connecting to a host computer, such as a SCADA system) and at least one output channel (for connecting to field devices, such as a PLC or sensor). (Refer to...) Figure 1 As shown, the communication method includes:
[0060] S110: Receive external commands through the input channel.
[0061] In this step, external commands sent by the host computer can be received through the input channel, and the command response record can be queried in the pre-stored command response record table according to the external command.
[0062] S120: Query the command response record table to see if there is a response record corresponding to the external command.
[0063] In this embodiment, the command response record table can be pre-configured and stored in the system, as shown in the reference. Figure 2 As shown, the command response record table contains multiple response records corresponding to different external commands. Each response record contains the following key fields:
[0064] Command content, used to store external commands received from the input channel;
[0065] Response content, used to store response data received from the output channel;
[0066] Enter the time, which will be used to store the time when this command was last received;
[0067] Input interval, used to store the time interval between the two most recent receipts of the same command;
[0068] Output time is used to store the time of the most recent command issued in the output channel;
[0069] Output channel identifier, used to store the output channel identifier corresponding to the external command.
[0070] Based on the key fields in the command response record table, a query is performed to check if a response record corresponding to the external command exists. If a corresponding response record exists, the response data in the response record is returned through the input channel, and the input time in the response record is updated according to the current time. If the current input time and the previous input time exist, the input interval in the response record can also be updated according to the time difference between the two adjacent input times. If no corresponding response record exists, a no-response indication is returned, a new response record is created in the command response record table, and the command content and input time of the external command are written into the newly created response record.
[0071] S130: Based on the response records in the command response record table, allocate an output channel for the external command and send the external command to the allocated output channel according to preset rules.
[0072] In this step, if the response record in the command response record table contains the output channel identifier of the external command, then the external command is assigned to the output channel corresponding to the output channel identifier; if the response record in the command response record table does not contain the output channel identifier of the external command, then a polling / idle channel probing mechanism is used to assign the external command to any idle or polled output channel.
[0073] After the output channels are allocated, external commands can be sent to the allocated output channels according to preset rules. Specifically, multiple parallel sending threads can be created based on the number of output channels, with each sending thread independently managing a physical output channel. During transmission, each sending thread can control the frequency of sending external commands to its corresponding output channel based on the input interval in the response record of the external command. This achieves on-demand adjustment of external command transmission, with high-frequency received external commands corresponding to high-frequency transmission, and low-frequency received external commands receiving fewer transmissions. This ensures real-time response to critical commands while reducing resource consumption caused by invalid transmissions.
[0074] S140: Receive response data from the output channel, update the response data to the response record in the command response record table, and return the response data through the input channel.
[0075] In this step, after assigning an external command to the output channel corresponding to the output channel identifier, if a valid response is received, the response data is written to the response content field of the response record, the output time in the response record is updated, and the no-response count in the response record is cleared to zero. If no valid response is received or the response times out, the response content field of the response record is cleared, the no-response count in the response record is incremented by one, and the output time in the response record is updated. When the no-response count exceeds a preset threshold, the output channel identifier in the response record is deleted. By updating the output time in the response record and controlling the sending frequency of external commands based on the time difference between the current time and the output time, high-frequency repeated sending is avoided from consuming communication bandwidth and channel resources.
[0076] In some embodiments, when an external command is assigned to any idle or polled output channel using a polling / idle channel probing mechanism, if a valid response is received, the response data is written to the response content field of the response record, the output time in the response record is updated, the number of no-response counts in the response record is cleared, and the output channel identifier that returned the response data this time is written to the output channel identifier of the corresponding response record; if no valid response is received or the response times out, the external command is reassigned to any other idle or polled output channel until a valid response data is received.
[0077] It should be noted that in this embodiment, the external command is used to query its pre-stored command response record table to see if a corresponding response record exists. The query result can be divided into three cases: First, if a corresponding response record exists in the command response record table and the response record stores response data, then the response data is returned to the host computer through the input channel. Second, if a corresponding response record exists in the command response record table but the response record does not store response data (this may be due to various reasons, such as a new command being accessed for the first time and not yet completing a full send-response loop, or a response record being created and forwarded to the external command but the response timed out / no response was received), then a no-response indication is returned to the host computer through the input channel. Simultaneously, an output channel is allocated to the external command according to the response record. If the response record contains the output channel identifier of the external command, then... The external command is assigned to the output channel corresponding to the output channel identifier. If the response record does not contain the output channel identifier of the external command, a polling / idle channel probing mechanism is used to assign the external command to any idle or polled output channel. Third, if there is no corresponding response record in the command response record table, a no-response indication is returned to the host computer through the input channel, and a new response record is created in the command response record table. At the same time, an output channel is assigned to the external command according to the newly created response record. Similarly, if the newly created response record contains the output channel identifier of the external command, the external command is assigned to the output channel corresponding to the output channel identifier. If the newly created response record does not contain the output channel identifier of the external command, a polling / idle channel probing mechanism is used to assign the external command to any idle or polled output channel.
[0078] In some embodiments, a background task can also be created in the system to periodically check each response record in the command response record table and delete response records whose difference between the current time and the input time exceeds a preset lifespan (e.g., 30 minutes). This avoids the accumulation of invalid data (e.g., command records that have not been received for a long time) in the record table, avoids the decrease in query and update speed due to data redundancy, and ensures the long-term stable and efficient operation of the communication device.
[0079] like Figure 3 As shown, this application embodiment also provides a communication device based on a command-response protocol, which includes at least one input channel and at least one output channel. (Refer to...) Figure 3 As shown, the communication device also includes a command input module 210, a command response storage module 220, and a response output module 230.
[0080] The command input module 210 receives external commands through an input channel, and the command response storage module 220 queries the command response record table to see if a response record corresponding to the external command exists. If it exists, the response data in the response record is returned through the input channel; if it does not exist, the external command is written to a newly created response record, and a no-response indication is returned. The response output module 230 allocates an output channel for the external command according to the response record in the command response record table, and sends the external command to the allocated output channel according to a preset rule; it receives response data from the output channel, updates the response data to the response record in the command response record table, and returns the response data through the input channel.
[0081] The following reference Figures 4-5 The workflow of the three modules of the communication device provided in this embodiment will be described in detail.
[0082] like Figure 4 The diagram illustrates the interaction process between the command input module and the command response storage module. The command input module 210 receives external commands sent by the host computer through the input channel and sends the external commands to the command response storage module 220 for querying and responding.
[0083] The command response storage module 220 queries its pre-stored command response record table to see if there is a response record corresponding to the external command. If there is a corresponding response record and the response record stores response data, the response data is returned to the command input module 210 so that it can return to the host computer through the input channel. The input time in the response record is updated according to the current time. When the current input time and the previous input time exist, the input interval in the response record can also be updated according to the time difference between the two adjacent input times. If there is no response data stored in the response record, a no-response indication is returned to the command input module 210 so that it can return to the host computer through the input channel. If no corresponding response record exists in the record table, a no-response indication is returned to the command input module 210 so that it can return to the host computer through the input channel. At the same time, it is determined whether the number of response records in the record table has exceeded the maximum number of records. If it has not exceeded the maximum number, a new response record is created in the command response record table, and the command content and input time of the external command are written into the new response record. If it has exceeded the maximum number, a new response record cannot be created immediately. At least one response record must be deleted (such as deleting a response record that has exceeded the preset lifespan) before a new response record can be created in the command response record table.
[0084] It should be noted that in this embodiment, the command response storage module 220 receives external commands sent by the host computer through the input channel and queries its pre-stored command response record table to see if there is a corresponding response record. The query result can be divided into three cases: First, if there is a corresponding response record in the command response record table and the response record stores response data, the response data is returned to the command input module 210 so that it can return to the host computer through the input channel; Second, if there is a corresponding response record in the command response record table but the response record does not store response data (which may be caused by various reasons, such as a new command being accessed for the first time and not yet completing a complete send-response closed loop, or a response record being created and forwarded to the external command but the response timed out / no response was received), a no-response indication is returned to the command input module 210 so that it can return to the host computer through the input channel. At the same time, the response output module 230 allocates an output channel for the external command according to the response record. If the response record contains the output channel identifier of the external command, the external command is assigned to the output channel corresponding to the output channel identifier. If the response record does not contain the output channel identifier of the external command, a polling / idle channel probing mechanism is used to assign the external command to any idle or polled output channel. Third, if there is no corresponding response record in the command response record table, a no-response indication is returned to the command input module 210 so that it can return to the host computer through the input channel and create a new response record in the command response record table. At the same time, the response output module 230 assigns an output channel to the external command according to the newly created response record. Similarly, if the newly created response record contains the output channel identifier of the external command, the external command is assigned to the output channel corresponding to the output channel identifier. If the newly created response record does not contain the output channel identifier of the external command, a polling / idle channel probing mechanism is used to assign the external command to any idle or polled output channel.
[0085] In some embodiments, the command response storage module 220 also runs a background task to periodically check each response record in the command response record table and delete response records whose difference between the current time and the input time exceeds a preset lifespan (e.g., 30 minutes), thereby preventing invalid data from accumulating in the record table.
[0086] like Figure 5The diagram illustrates the interaction between the command response storage module and the response output module. The response output module 230 manages multiple output channels. Specifically, it can create N parallel sending threads based on the number of output channels N. Each sending thread independently manages a physical output channel and requests tasks from the command response storage module 220 according to the request rules. The request rules are: obtain all external commands whose output channels are identified as being managed by the sending thread or whose output channels are identified as empty.
[0087] For external commands whose output channel is identified as an output channel managed by this sending thread, the sending thread of the response output module 230 can first determine whether to send the command to the corresponding output channel based on the output time and input interval of the external command. If the time difference between the current time and the output time is lower than a preset time (e.g., input interval), the command is not sent to avoid the external command being forwarded repeatedly at high frequency. If the time difference between the current time and the output time is higher than a preset time (e.g., input interval), the external command is sent through the corresponding output channel, and the response data returned by the output channel is awaited. If a valid response is received within the preset time, the response data is written to the response content field of the response record, the output time in the response record is updated, and the number of no-response events in the response record is cleared. If no valid response is received or the response times out, the response content field of the response record is cleared, the output time in the response record is updated, and the number of no-response events in the response record is incremented. When the number of no-response events exceeds a preset threshold (e.g., three times), the output channel identifier in the response record is deleted, meaning that the output channel needs to be reassigned for the external command.
[0088] For external commands with an empty output channel identifier, the sending thread of the response output module 230 can use a polling / idle channel probing mechanism to assign the external command to any idle or polled output channel and wait for the response data returned by that output channel. If a valid response is received within a preset time, the response data is written to the response content field of the response record, the output time in the response record is updated, the number of no-response counts in the response record is cleared to zero, and the output channel identifier of the returned response data is written to the corresponding output channel identifier of the response record; if no valid response is received or the response times out, the external command is reassigned to any other idle or polled output channel until a valid response data is received.
[0089] In some embodiments, each sending thread is also configured with a sleep parameter, which allows the sending thread to sleep for a period of time after completing the sending of the current external command, and then re-execute the sending task of other external commands.
[0090] In summary, this application provides a communication method and apparatus based on a command-response protocol. Employing a query-and-return mechanism, when an external command is received, it first queries an internally stored record table. If a valid response exists in the record table, it returns immediately, avoiding the problem of subsequent commands being blocked due to a single command timeout in the transparent transmission mode. If no valid response is found, a no-response indication is returned, and the external command is sent through the allocated output channel. The received response data is updated in the record table to facilitate a return through the input channel. This application constructs a communication system with a command-response record table at its core, featuring decoupled and collaborative modules. It effectively solves the blocking problem of the transparent transmission mode and the cumbersome configuration problem of the proxy mode, and introduces self-learning, self-adaptation, and self-maintenance capabilities, significantly improving the communication efficiency, reliability, and maintainability of industrial gateways in complex and dynamic environments.
[0091] Figure 6 This is a structural diagram of a computing device 1000 provided in an embodiment of this application. The computing device 1000 includes: a processor 1010, a memory 1020, a communication interface 1030, and a bus 1040.
[0092] It should be understood that Figure 6 The communication interface 1030 in the computing device 1000 shown can be used to communicate with other devices.
[0093] The processor 1010 can be connected to the memory 1020. The memory 1020 can be used to store the program code and data. Therefore, the memory 1020 can be a storage unit inside the processor 1010, an external storage unit independent of the processor 1010, or a component that includes both the storage unit inside the processor 1010 and the external storage unit independent of the processor 1010.
[0094] Optionally, the computing device 1000 may also include a bus 1040. The memory 1020 and communication interface 1030 can be connected to the processor 1010 via the bus 1040. The bus 1040 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus 1040 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.
[0095] It should be understood that in the embodiments of this application, the processor 1010 may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor. Alternatively, the processor 1010 may employ one or more integrated circuits to execute relevant programs to implement the technical solutions provided in the embodiments of this application.
[0096] The memory 1020 may include read-only memory and random access memory, and provides instructions and data to the processor 1010. A portion of the processor 1010 may also include non-volatile random access memory. For example, the processor 1010 may also store device type information.
[0097] When the computing device 1000 is running, the processor 1010 executes the computer execution instructions in the memory 1020 to perform the operation steps of the above method.
[0098] It should be understood that the computing device 1000 according to the embodiments of this application can correspond to the corresponding subject in executing the methods according to the various embodiments of this application, and the other operations and / or functions of each module in the computing device 1000 are respectively for implementing the corresponding processes of the methods of this embodiment. For the sake of brevity, they will not be described in detail here.
[0099] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0100] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0101] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0102] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0103] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0104] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0105] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is used to perform the above-described method, which includes at least one of the schemes described in the above embodiments.
[0106] The computer storage medium in this application embodiment can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. For example, a computer-readable storage medium can be, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: 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 or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0107] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0108] The program code contained on a computer-readable medium may be transmitted using any suitable medium, including, but not limited to, wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0109] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0110] It should be noted that the embodiments described in this application are merely some embodiments, not all embodiments. The components of the embodiments of this application typically described and shown in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the above detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0111] The terms "first, second, third, etc." or similar terms such as module A, module B, module C, etc., used in the specification and claims are only used to distinguish similar objects and do not represent a specific ordering of objects. It is understood that a specific order or sequence may be interchanged where permitted so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0112] In the above description, the labels indicating the steps do not necessarily mean that the steps will be executed. They may include intermediate steps or be replaced by other steps. Where permissible, the order of the steps may be interchanged or executed simultaneously.
[0113] The term "comprising" as used in the specification and claims should not be construed as limiting itself to what follows; it does not exclude other elements or steps. Therefore, it should be interpreted as specifying the presence of the mentioned feature, integral, step, or component, but does not exclude the presence or addition of one or more other features, integrals, steps, or components, or groups thereof. Thus, the statement "device comprising means A and B" should not be limited to a device consisting solely of components A and B.
[0114] The terms "an embodiment" or "an embodiment" as used in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in at least one embodiment of this application. Therefore, the terms "in one embodiment" or "in an embodiment" appearing throughout this specification do not necessarily refer to the same embodiment, but may refer to the same embodiment. Furthermore, in the various embodiments of this application, unless otherwise specified or in case of logical conflict, the terminology and / or descriptions between different embodiments are consistent and can be mutually referenced. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships.
[0115] Note that the above are merely preferred embodiments and the technical principles employed in this application. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present application has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, all of which fall within the scope of protection of the present invention.
Claims
1. A communication method based on a command-response protocol, applied to a communication device including at least one input channel and at least one output channel, characterized in that, include: Receive external commands through the input channel; Check if a response record corresponding to the external command exists in the command response record table; If it exists, the response data in the response record will be returned through the input channel; If it does not exist, the external command is written to the newly created response record, and a no-response indication is returned; Based on the response records in the command response record table, an output channel is allocated for the external command, and the external command is sent to the allocated output channel according to preset rules; Receive response data from the output channel, update the response data to the response record in the command response record table, and return the response data through the input channel.
2. The method according to claim 1, characterized in that, Each response record in the command response record table includes at least one of the following fields: Command content, response content, input time, input interval, output time, output channel identifier, and number of no-response instances.
3. The method according to claim 2, characterized in that, Also includes: If a response record corresponding to the external command exists in the command response record table, then the input interval and input time in the response record are updated according to the current time and the input time in the response record. If there is no response record corresponding to the external command in the command response record table, the command content and input time of the external command are written into the newly created response record.
4. The method according to claim 2, characterized in that, The allocation of an output channel for the external command specifically includes: If the response record contains the output channel identifier of the external command, then the external command is assigned to the output channel corresponding to the output channel identifier; If the response record does not contain the output channel identifier of the external command, then the external command is assigned to any idle or polled output channel.
5. The method according to claim 1, characterized in that, The step of sending external commands to the allocated output channel according to preset rules specifically includes: Establish a parallel sending thread for each output channel; Each sending thread controls the frequency at which it sends external commands to the output channel corresponding to it, based on the input interval of the external commands in the response record; the input interval is the time difference between two consecutive receptions of the same external command.
6. The method according to claim 4, characterized in that, After assigning an external command to the output channel corresponding to the output channel identifier, updating the response data to the response record in the command response record table specifically includes: If a valid response is received, the response data is written to the response content field of the response record, the output time in the response record is updated, and the number of no responses in the response record is cleared to zero. If no valid response is received or the response times out, the response content field of the response record is cleared, the number of no responses in the response record is incremented by one, and the output time in the response record is updated. When the number of no responses exceeds a preset threshold, the output channel identifier in the response record is deleted.
7. The method according to claim 4, characterized in that, After assigning an external command to any idle or polled output channel, updating the response data to the response record in the command response record table specifically includes: If a valid response is received, the response data is written to the response content field of the response record, the output time in the response record is updated, the number of no responses in the response record is cleared to zero, and the output channel identifier of the response data returned this time is written to the output channel identifier of the corresponding response record. If no valid response is received or the response times out, the external command will be reassigned to any other available or polled output channel.
8. The method according to claim 2, characterized in that, Also includes: Periodically check each response record in the command response record table and delete response records whose current time differs from the input time by more than a preset lifespan.
9. A communication device based on a command-response protocol, comprising at least one input channel and at least one output channel, characterized in that, Also includes: The command input module is used to receive external commands through the input channel; The command response storage module is used to query the command response record table to see if there is a response record corresponding to the external command. If it exists, the response data in the response record will be returned through the input channel; If it does not exist, the external command is written to the newly created response record, and a no-response indication is returned; The response output module is used to allocate an output channel for the external command according to the response record in the command response record table, and send the external command to the allocated output channel according to a preset rule; Receive response data from the output channel, update the response data to the response record in the command response record table, and return the response data through the input channel.
10. A computing device, characterized in that, include: processor; Memory, used to store one or more programs; When the processor executes the one or more programs, the processor implements a communication method based on a command-response protocol as described in any one of claims 1 to 7.