Data access method, serial port communication parameter configuration method and data access system
By creating a mapped memory in the gateway and parsing the data access request message, matching the mapped memory address of the slave station identifier, and directly returning the data, the communication anomaly caused by multiple master stations making simultaneous requests is resolved, thereby improving the communication efficiency and data access speed of the automated control system.
Patent Information
- Application Number
- CN202410735129.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2025-12-09
AI Technical Summary
In automated control systems, when multiple master stations simultaneously request data from slave devices, communication anomalies can occur due to gateways waiting for messages from other master stations to arrive. This is especially true under the Modbus protocol, where master stations may trigger retransmission mechanisms due to timeouts, leading to low communication efficiency.
By creating mapped memory in the gateway, slave data is cached, and the mapping table is used to quickly match master requests, thus implementing data access and parsing methods. The data access method is implemented by parsing the master's data access request message, matching the mapped memory address corresponding to the slave identifier, and directly returning the mapped memory data. This decouples the master query and slave response process, reducing waiting time.
It improves communication efficiency, enabling efficient response to master station data requests even when multiple master stations are simultaneously querying slave station data, reducing waiting time and enhancing the response speed and accuracy of data access.
Smart Images

Figure CN121098653A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and more specifically, to a data access method, a serial communication parameter configuration method, and a data access system. Background Technology
[0002] In automated control systems, the master station, slave stations, and gateway together form an efficient communication network. The master station, as the central controller, is responsible for issuing commands and collecting status information from the entire system, and typically possesses strong processing capabilities. Slave stations are controlled units, such as sensors or actuators, that receive commands from the master station and execute corresponding operations, such as data acquisition or mechanical control. The gateway acts as a bridge between different network protocols, responsible for protocol conversion and data forwarding, ensuring effective communication between the master station and slave stations, thereby achieving coordinated operation of the entire system.
[0003] In related technologies, after receiving data access requests from multiple master stations, the gateway combines the data access messages from the different master stations into a new data access request message before requesting data from the slave devices. Because the arrival times of the request messages from different master stations are inconsistent, while waiting for other master station messages to arrive, the master station that initiated the request message may experience a timeout, leading to communication abnormalities. Summary of the Invention
[0004] This application provides a data access method, a serial communication parameter configuration method, and a data access system to improve communication efficiency.
[0005] In a first aspect, embodiments of this application provide a data access method, including:
[0006] Parse the data access request message sent by the master station to obtain parsing information; the parsing information includes at least the identifier of the slave station requested by the master station.
[0007] The slave identifier is matched with the first mapped memory address corresponding to the slave identifier from a preset mapping table; the first mapped memory address is a memory area mapped with slave data, and the mapping table includes at least the association between the slave identifier and the mapped memory address;
[0008] If the first mapped memory address is matched, the first mapped memory data is returned to the main station.
[0009] In the above technical solution, a mapped memory is created to cache slave data. Upon receiving a data request from the master station, the mapping table can quickly determine whether the slave data to be accessed by the master station exists in the mapped memory. If the slave data to be accessed by the master station exists in the mapped memory, the mapped memory data is returned to the master station. In this way, the process of master station query and slave station response is decoupled, reducing the waiting time of the master station after initiating a data access request. Even when multiple master stations query slave data simultaneously, the master station's data requests can be responded to efficiently, thereby improving communication efficiency.
[0010] In some embodiments, the method further includes:
[0011] A first data request is sent to the slave station mapped by the first mapped memory at preset intervals, so that the slave station can return the first slave station data corresponding to the first data request;
[0012] The first mapped memory data is updated based on the first slave station data.
[0013] In the above technical solution, by periodically sending data requests to the slave station and updating the data in the mapped memory, the timeliness of the data is improved, enabling the master station to access new slave station data and to capture and reflect changes in the slave station's status in a timely manner, thereby reducing the operational risks caused by operation delays or omissions.
[0014] In some embodiments, returning the first mapped memory data to the main station includes:
[0015] Determine the last update time of the first mapped memory;
[0016] If the time since the last update is less than a preset threshold, the first mapped memory data is returned to the main station.
[0017] In the above technical solution, by introducing an update time check mechanism, the data obtained by the main station is reliable data within a preset time threshold, thereby enhancing the consistency and accuracy of the data.
[0018] In some embodiments, the method further includes:
[0019] If the first mapped memory address is not matched, a second mapped memory address is created based on the parsed information;
[0020] Based on the second mapped memory address, a second data request is sent to the slave station corresponding to the slave station identifier, so that the slave station can return the second slave station data corresponding to the second data request;
[0021] After storing the second slave station data in the second mapped memory associated with the second mapped memory address, the second mapped memory data is returned to the master station.
[0022] In the above technical solution, when the master station's request cannot find a matching mapped memory address in the existing mapping table, a new mapped memory address is created, and a data request is actively sent to the corresponding slave station to obtain the required slave station data. This enables timely response and accurate data provision even when facing unknown or newly added slave station access requests, thereby improving the overall data access response speed.
[0023] In some embodiments, the parsed information further includes register information;
[0024] Matching the slave identifier with the first mapped memory address corresponding to the slave identifier from a preset mapping table, including:
[0025] The first mapped memory address is matched from the mapping table according to the slave identifier and the register information; wherein, the mapping table also includes the association between register information and mapped memory address.
[0026] In the above technical solution, register information clearly defines the master station's access requirements. Furthermore, by matching the mapped memory address based on the register information, the required data from the master station can be accurately returned. Even when multiple master stations simultaneously query slave station data, if the accessed register information is the same, the same mapped memory data can be returned without re-matching the mapped memory address. This achieves deduplication of requests from multiple master stations, reduces communication bandwidth consumption, and further improves communication efficiency.
[0027] In some embodiments, the register information includes the register length;
[0028] The step of returning the first mapped memory data to the main station when the first mapped memory address is matched includes:
[0029] If the first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address can cover the register length, the first mapped memory data is returned to the master station.
[0030] In the above technical solution, by determining whether the mapped memory has sufficient capacity to cover the requested register length, if the mapped memory is large enough to contain the requested data range, it means that the main station can provide complete data, which can effectively avoid missing data errors during data reading.
[0031] In some embodiments, the method further includes:
[0032] If the first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address cannot cover the register length, the first mapped memory is expanded according to the register length to obtain the third mapped memory.
[0033] Based on the third mapped memory address corresponding to the third mapped memory, a third data request is sent to the slave station corresponding to the slave station identifier, so that the slave station can return the third slave station data corresponding to the third data request;
[0034] After storing the third slave station data in the third mapped memory, the third mapped memory data is returned to the master station.
[0035] In the above technical solution, when the existing mapped memory is insufficient to cover the requested register length, the mapped memory is expanded to create a larger mapped memory. This allows the expanded mapped memory to have enough space to store the data returned by the slave station, reducing communication failures caused by missing mapped memory data. This enables the master station to successfully access the required slave station data and improves communication efficiency.
[0036] Secondly, embodiments of this application provide a method for configuring serial communication parameters, including:
[0037] Receive query messages sent by the master station based on the target communication protocol via the uplink serial port;
[0038] Adjust the serial communication parameters to parse the query message and obtain the parsed message;
[0039] If the parsed message conforms to the format specified by the target communication protocol, the downlink serial port is configured according to the target serial port communication parameters used in the parsed message.
[0040] In the above technical solution, by using the uplink serial port to receive and adjust the serial communication parameters to parse the query messages sent by the master station, the communication protocol used by the master station can be automatically identified and adapted. When the query message is successfully parsed and the format meets the requirements of the target communication protocol, the corresponding serial communication parameters will be automatically used to configure the downlink serial port, without the need for tedious manual parameter configuration, thereby improving the configuration efficiency of serial communication parameters.
[0041] Thirdly, embodiments of this application provide a data access device, including:
[0042] The parsing module is used to parse the data access request message sent by the master station to obtain parsing information; the parsing information includes at least the slave station identifier requested by the master station.
[0043] The matching module is used to match the first mapped memory address corresponding to the slave identifier from a preset mapping table according to the slave identifier; the first mapped memory address is a memory area mapped with slave data, and the mapping table includes at least the association relationship between the slave identifier and the mapped memory address;
[0044] The return module is used to return the first mapped memory data to the main station if the first mapped memory address is matched.
[0045] In the above technical solution, a mapped memory is created to cache slave data. Upon receiving a data request from the master station, the mapping table can quickly determine whether the slave data to be accessed by the master station exists in the mapped memory. If the slave data to be accessed by the master station exists in the mapped memory, the mapped memory data is returned to the master station. In this way, the process of master station query and slave station response is decoupled, reducing the waiting time of the master station after initiating a data access request. Even when multiple master stations query slave data simultaneously, the master station's data requests can be responded to efficiently, thereby improving communication efficiency.
[0046] Fourthly, embodiments of this application provide a serial communication parameter configuration device, including:
[0047] The receiving module is used to receive query messages sent by the master station based on the target communication protocol via the uplink serial port;
[0048] An adjustment module is used to adjust serial communication parameters to parse the query message and obtain the parsed message.
[0049] The configuration module is used to configure the downlink serial port according to the target serial port communication parameters used in the parsed message when the parsed message conforms to the format agreed upon by the target communication protocol.
[0050] In the above technical solution, by using the uplink serial port to receive and adjust the serial communication parameters to parse the query messages sent by the master station, the communication protocol used by the master station can be automatically identified and adapted. When the query message is successfully parsed and the format meets the requirements of the target communication protocol, the corresponding serial communication parameters will be automatically used to configure the downlink serial port, without the need for tedious manual parameter configuration, thereby improving the configuration efficiency of serial communication parameters.
[0051] Fifthly, embodiments of this application provide a data access system, characterized in that it includes: a master station, a slave station, and a gateway;
[0052] The gateway is connected to the master station via an uplink serial port and to the slave station via a downlink serial port;
[0053] The gateway is used to implement the data access method as described in the first aspect or the serial communication parameter configuration method as described in the second aspect.
[0054] In a sixth aspect, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the data access method as described in the first aspect or the serial communication parameter configuration method as described in the second aspect.
[0055] In a seventh aspect, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the data access method as described in the first aspect or the serial communication parameter configuration method as described in the second aspect.
[0056] Eighthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the data access method as described in the first aspect or the serial communication parameter configuration method as described in the second aspect.
[0057] Ninthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the data access method as described in the first aspect or the serial communication parameter configuration method as described in the second aspect. Attached Figure Description
[0058] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 This is a schematic diagram of the architecture of the data access system provided in the embodiments of this application;
[0060] Figure 2 This is a flowchart illustrating the data access method provided in an embodiment of this application;
[0061] Figure 3 This is a schematic diagram of a scenario illustrating the data access method provided in an embodiment of this application;
[0062] Figure 4 This is a flowchart illustrating the serial communication parameter configuration method provided in an embodiment of this application;
[0063] Figure 5 This is a schematic diagram of the structure of the data access device provided in the embodiments of this application;
[0064] Figure 6This is a schematic diagram of the serial communication parameter configuration device provided in the embodiments of this application;
[0065] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0066] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0067] Unless otherwise defined, all technical and scientific terms used in this application have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used in the description of this application is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms "comprising" and "having," and any variations thereof, in the description, claims, and accompanying drawings of this application are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the description, claims, or accompanying drawings of this application are used to distinguish different objects, not to describe a specific order or hierarchy.
[0068] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this application can be combined with other embodiments.
[0069] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," "linking," and "attachment" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal communication between two components. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.
[0070] In this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, in this application, the character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0071] In this application, "multiple" refers to two or more (including two), and similarly, "multiple groups" refers to two or more (including two), and "multiple pieces" refers to two or more (including two).
[0072] In the embodiments of this application, the master station, slave station, and gateway can be three distinct components, each playing a unique role. The master station is typically the core of the control network, possessing strong processing capabilities, responsible for initiating communication and control operations, and executing complex logic and decisions. The master station is responsible for monitoring the status of the entire system, sending instructions to slave stations, and collecting data from slave stations. The master station can be a central monitoring system, a human-machine interface (HMI), a programmable logic controller (PLC), or other types of control systems.
[0073] A slave station is a controlled unit in a network. Its computing and processing capabilities are typically weaker than those of the master station. It is responsible for receiving instructions from the master station and executing operations, such as responding to queries, sending data, or receiving commands. Slave stations can be sensors, actuators, remote terminal units (RTUs), Supervisory Control and Data Acquisition (SCADA) system components, etc.
[0074] A gateway is a device that connects different networks or uses different protocols, allowing them to communicate. Gateways perform necessary protocol conversions during data transmission, enabling different systems to understand each other's information. Of course, gateways can also provide other functions, such as data filtering, routing, address translation, and security control.
[0075] In automated control systems, these three components typically work together as follows: The master station initiates a request: the master station needs data from the slave station or wants to send control commands to it; the gateway intervenes: if the slave and master stations use different communication protocols, the gateway converts the master station's request into a format the slave station can understand, or vice versa; the slave station responds: upon receiving the request, the slave station performs the corresponding operation, such as sending data or executing commands, and returns the response to the gateway; the gateway forwards the response: upon receiving the slave station's response, the gateway converts it back into a format the master station can understand and then forwards it to the master station. In this way, the master station can effectively manage and monitor the slave stations in the network, even if they use different communication protocols. The presence of the gateway greatly enhances the system's scalability and flexibility, while also simplifying the integration between different systems.
[0076] Modbus is a serial communication protocol that supports various communication media and electrical interfaces, such as RS-232, RS-485, and Ethernet, and can be transmitted over various physical media. A Modbus gateway is a network hub communication protocol conversion device. Modbus masters communicate with the Modbus gateway via a network, while the Modbus gateway communicates with Modbus slaves via a serial port. In industrial environments, multiple Modbus masters may access Modbus slaves on a single serial communication bus. If multiple Modbus masters send request commands within a certain time period, due to the query-response nature of the Modbus protocol, the Modbus gateway needs to forward the commands to the slaves via the serial port and wait for a response before issuing the next command. However, when there are too many request commands, processing them sequentially according to the Modbus master connection order can result in significant delays or no response.
[0077] To address this issue, in related technologies, after receiving data access requests from multiple master stations, the Modbus gateway combines the data access messages (first request messages) from different Modbus master stations into a new data access request message (second request message) within the Modbus gateway, and uses the second request message to request data from the Modbus slave device. When the Modbus slave returns data to the Modbus gateway based on the second request message, the Modbus gateway splits the data according to the request range of the first request message, reassembles the data, and returns it to the corresponding data-requesting Modbus master station.
[0078] The inventors discovered that, due to the question-and-answer nature of the Modbus protocol, the master station typically sets a request waiting time after requesting data and begins waiting for a response from the slave station. If the slave station times out and does not respond, a retransmission mechanism is triggered. Because the arrival times of the first request messages from different master stations are inconsistent, while waiting for messages from other master stations to arrive, the master station that initiated the first request message may time out, leading to communication anomalies.
[0079] Based on the above considerations, in order to solve the problem of abnormal communication response caused by multiple master stations requesting data from slave devices, the inventors, after in-depth research, designed a data access method, including: parsing the data access request message sent by the master station to obtain parsing information; the parsing information includes at least the slave identifier requested by the master station; matching the first mapped memory address corresponding to the slave identifier from a preset mapping table according to the slave identifier; the first mapped memory address is a memory area mapped with slave data, and the mapping table includes at least the association between the slave identifier and the mapped memory address; if the first mapped memory address is matched, returning the first mapped memory data to the master station.
[0080] This data access method caches slave data by creating mapped memory. Upon receiving a data request from the master station, it can quickly determine whether the requested slave data exists in the mapped memory using a mapping table. If the data exists, it is returned to the master station. This decouples the master station's query and slave station's response process, reducing the master station's waiting time after initiating a data access request. Even when multiple master stations simultaneously query slave data, it can efficiently respond to master station data requests, thereby improving communication efficiency.
[0081] The data access method disclosed in this application can be used, but is not limited to, in control systems for industrial automation, smart grids, vehicles, smart homes, aerospace, etc. The architecture of this control system can be established using the data access method, apparatus, and system disclosed in this application, which helps improve the communication efficiency within the control system.
[0082] Taking the data access method of one embodiment of this application applied to an electric vehicle as an example, the master station can be various control units in the vehicle, responsible for monitoring battery status, energy distribution, and overall system health, while providing key information to the user. The slave stations act as actuators; they can be units that directly interact with the battery and electrical devices, responsible for collecting battery performance data and executing control commands issued by the master station. The gateway acts as a data transmission hub in this process, ensuring unimpeded information flow between the master and slave stations, and may also be responsible for encrypting, decrypting, or converting data to adapt to different communication media and security requirements.
[0083] The data access method, serial communication parameter configuration method, and data access system provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0084] First, the data access system provided in the embodiments of this application is introduced. The data access system may include a master station, a slave station, and a gateway. The gateway is connected to the master station through an uplink serial port and to the slave station through a downlink serial port.
[0085] like Figure 1 As shown, the data access system can be formed by connecting a gateway to an existing industrial site, or by rebuilding the master station, slave station, and gateway.
[0086] In this embodiment, the data access system may include one master station or multiple master stations. If there is one master station, its serial port can be connected to the gateway's uplink serial port. If the data access system includes multiple master stations, one master station's serial port can be connected to the gateway's uplink serial port, while other master stations can connect to the gateway's available network ports and / or serial ports. The data access system may also include one slave station or multiple slave stations, which can connect to the gateway's downlink serial port.
[0087] In this embodiment, the master station, slave stations, and gateway in the data access system can communicate based on the Modbus protocol. When the data access system includes multiple slave stations, since RS-485 and RS-422 support point-to-many bidirectional communication, the slave stations can be mounted on the RS-485 or RS-422 bus.
[0088] In this application embodiment, the serial communication parameter configuration method of the master station, slave station and gateway in the data access system can refer to the following introduction on the serial communication parameter configuration method provided in this application embodiment; the data interaction process of the master station, slave station and gateway in the data access system can refer to the following introduction on the data access method provided in this application embodiment.
[0089] The data access method provided in the embodiments of this application is described below. This data access method can be applied to a terminal, and can be executed by hardware or software within the terminal.
[0090] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads). It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads).
[0091] The following embodiments describe a terminal including a display and a touch-sensitive surface. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and joystick.
[0092] The data access method provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the data access method. The electronic device has the function of a gateway device. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The data access method provided in this application embodiment is described below using an electronic device as the execution subject as an example.
[0093] like Figure 2As shown, the data access method includes steps 210, 220 and 230.
[0094] Step 210: Parse the data access request message sent by the master station to obtain the parsing information; the parsing information shall include at least the identifier of the slave station requested by the master station.
[0095] Parsing data access request messages typically involves parsing communication protocols, such as Modbus, PROFIBUS, and CANopen, which are common in industrial automation. Before initiating a data access request message, the master station usually generates the message according to a specific communication protocol, taking into account the access requirements. This message typically includes the identifier of the slave station to be accessed, indicating the target slave station.
[0096] Upon receiving a data access request message, it needs to be parsed to understand the master station's requirements. Specifically, the format of the data access request message can be checked. If the format conforms to the agreed communication protocol, the data access request message is considered valid and can be parsed according to the agreed communication protocol.
[0097] Step 220: Match the first mapped memory address corresponding to the slave identifier from the preset mapping table according to the slave identifier; the first mapped memory address is the memory area mapped with slave data, and the mapping table includes at least the association between the slave identifier and the mapped memory address.
[0098] In the embodiments of this application, slave data can be data stored on the slave station. For example, for some slave stations, data may be stored in registers, so slave data can be register data; for other slave stations, data may be stored in a file system, so slave data can be data in the file system; and for some slave stations, data may be stored in a database, so slave data can be data in the database; of course, for distributed systems, some slave station data may be stored in the cloud, so slave data can be data stored in the cloud.
[0099] In this embodiment of the application, slave data can be mapped to a memory area inside the gateway. Specifically, a memory area can be initialized inside the gateway, then slave data can be requested from the slave, and then the slave data can be mapped to the memory area inside the gateway to realize a one-to-one correspondence between the storage address of the slave data and the mapped memory address of the memory area. This memory area is the mapped memory.
[0100] In the process of mapping slave data, a mapping table can be established to represent the association between slaves and mapped memory addresses. For example, one column of the mapping table stores slave identifiers, and another column stores mapped memory addresses. The slave identifier is used to uniquely identify the slave, and slave identifiers and mapped memory addresses with a mapping relationship are in the same row. Alternatively, the slave identifier can be associated with the index of the mapped memory address. For example, a set of mapped memory addresses can be stored in a local database, and each mapped memory address in the set can be assigned a number, which is the index of the corresponding mapped memory address. The corresponding mapped memory address can be uniquely identified through this index, and the slave identifier and the index of the mapped memory address are associated and stored in the mapping table. Of course, the form of the mapping table is not limited to the above examples. Those skilled in the art may make other changes based on the essence of the technology in this application, but as long as the function and effect implemented are the same as or similar to that of this application, they should be covered within the scope of protection of this application.
[0101] In this embodiment of the application, after obtaining the parsed information, the first mapped memory address corresponding to the slave identifier can be matched from the mapping table according to the slave identifier in the parsed information.
[0102] Step 230: If the first mapped memory address is matched, return the first mapped memory data to the main station.
[0103] In this embodiment, the first mapped memory data represents the data stored in the memory region corresponding to the first mapped memory address. If a first mapped memory address is matched, it indicates that the data required by the master station exists in the memory region. In this case, the first mapped memory data can be returned to the master station without needing to retrieve data from the slave station.
[0104] In the above technical solution, a mapped memory is created to cache slave data. Upon receiving a data request from the master station, the mapping table can quickly determine whether the slave data to be accessed by the master station exists in the mapped memory. If the slave data to be accessed by the master station exists in the mapped memory, the mapped memory data is returned to the master station. In this way, the process of master station query and slave station response is decoupled, reducing the waiting time of the master station after initiating a data access request. Even when multiple master stations query slave data simultaneously, the master station's data requests can be responded to efficiently, thereby improving communication efficiency.
[0105] In some embodiments, the method further includes:
[0106] A first data request is sent to the slave station mapped by the first mapped memory at preset intervals so that the slave station can return the first slave station data corresponding to the first data request;
[0107] The first mapped memory data is updated based on the data from the first slave station.
[0108] In this embodiment, a periodic data update mechanism is set to ensure that the data in the mapped memory is as consistent as possible with the data stored on the slave station.
[0109] Specifically, a preset time interval can be set, which can be adjusted according to actual needs. For example, for scenarios where the data from the slave station changes rapidly, a shorter time interval can be set, such as 0.5s, 1s, or 5s. For scenarios where the data from the slave station changes slowly, a longer time interval can be set, such as 10min, 30min, or 60min. Of course, the time interval can also be set to other values, such as 30s or 120min, but this embodiment does not limit this.
[0110] At each preset time interval, a data request can be sent to the slave station. This data request may contain information about the need to retrieve data from the slave station. Upon receiving the data request, the slave station reads the corresponding data from its storage location based on the request information and returns the read data to the gateway. After receiving the slave station's data, the gateway can write the slave station's data to the corresponding mapped memory address, for example, it can overwrite the slave station's data previously stored at the corresponding mapped memory address.
[0111] In the above technical solution, by periodically sending data requests to the slave station and updating the data in the mapped memory, the timeliness of the data is improved, enabling the master station to access new slave station data and to capture and reflect changes in the slave station's status in a timely manner, thereby reducing the operational risks caused by operation delays or omissions.
[0112] In some embodiments, returning the first mapped memory data to the master station includes:
[0113] Determine the last update time of the first mapped memory;
[0114] If the time since the last update is less than a preset threshold, the first mapped memory data is returned to the main station.
[0115] In this embodiment, in order to improve the real-time performance of the returned data, when the mapped memory is updated, the timestamp of the update can be recorded. Then, before the mapped memory address needs to be returned to the master station, the last update time of the mapped memory is determined based on the timestamp, and the time difference between the current time and the last update time is calculated. If the time difference between the current time and the last update time is less than a preset time threshold, the slave data in the mapped memory can still be considered to be real-time, and the mapped memory address can be returned to the master station.
[0116] If the time difference exceeds the preset time threshold, the slave data in the mapped memory can be considered not to be real-time. In this case, the mapped memory address will not be returned temporarily, but will wait for the next update before returning, or a new update process will be triggered.
[0117] In the above technical solution, by introducing an update time check mechanism, the data obtained by the main station is reliable data within a preset time threshold, thereby enhancing the consistency and accuracy of the data.
[0118] In some embodiments, the method further includes:
[0119] If the first mapped memory address is not matched, a second mapped memory address is created based on the parsed information;
[0120] A second data request is sent to the slave station corresponding to the slave station identifier based on the second mapped memory address, so that the slave station can return the second slave station data corresponding to the second data request;
[0121] After storing the second slave station data in the second mapped memory associated with the second mapped memory address, the second mapped memory data is returned to the master station.
[0122] In this embodiment, if the first mapped memory address is not matched, it means that there is no mapped slave data that the master station needs to access in memory. In this case, the mapped memory corresponding to the slave data that the master station needs to access can be created.
[0123] Specifically, the slave identifier is first confirmed. Then, a new memory space is allocated in the gateway's memory management unit as the second mapped memory, and this second mapped memory is initialized. If the slave data is register data, the size of this memory space should match the register length to ensure proper mapping of the slave's register data. Next, a unique second mapped memory address is generated; this address can be a physical address or a virtual address. Then, based on the slave data to be mapped at the second mapped memory address, a second data request is constructed according to the communication protocol used between the gateway and the slave. This second data request may include information such as the slave identifier, function code, and data type. After receiving the second data request, the slave returns the second slave data based on the information in the request. After receiving the second slave data, the gateway stores the second slave data in the mapped memory associated with the newly created second mapped memory address, and then returns the second mapped memory data to the master station.
[0124] Furthermore, after creating the second mapped memory address, the mapping table can be updated to associate the newly created second mapped memory address with the slave identifier, so that when the master station sends the same or similar data access requests, it can find the corresponding mapped memory address based on the updated mapping table.
[0125] In the above technical solution, when the master station's request cannot find a matching mapped memory address in the existing mapping table, a new mapped memory address is created, and a data request is actively sent to the corresponding slave station to obtain the required slave station data. This enables timely response and accurate data provision even when facing unknown or newly added slave station access requests, thereby improving the overall data access response speed.
[0126] In some embodiments, the parsed information also includes register information;
[0127] Based on the slave identifier, the first mapped memory address corresponding to the slave identifier is matched from a preset mapping table, including:
[0128] The first mapped memory address is matched from the mapping table based on the slave identifier and register information; the mapping table also includes the association between register information and mapped memory addresses.
[0129] Depending on the communication protocol between the master station and the gateway, the content of the data access request message sent by the master station and the parsed information obtained from parsing the data access request message can also be different. Taking the Modbus protocol as an example, a Modbus RTU (serial communication) format data access request message can include information such as slave station identifier, function code, register address, register type, and checksum. Parsing a request message sent by a master station typically involves the following steps: 1. Identify the message format: Determine whether the data access request message conforms to the format requirements of the Modbus protocol; 2. Check message integrity; 3. Parse the function code: By parsing the function code, understand the type of operation requested; 4. Parse the register type: Understand whether the requested access is to a holding register or an input register, etc.; 5. Parse the register address: Understand the starting address of the register to be accessed.
[0130] In this embodiment, register information represents information related to the register, such as register address, register type, etc. If the slave station's data is stored through registers, the slave station's register data can be mapped to a memory area inside the gateway. Specifically, a memory area can be initialized inside the gateway, then register data can be requested from the slave station, and then the register data can be mapped to the memory area inside the gateway, realizing a one-to-one correspondence between the slave station's register address and the mapped memory address of the memory area. This memory area is called the mapped memory.
[0131] When register information includes register addresses, a mapping table can be established during the mapping of slave register data to represent the association between slave register addresses and mapped memory addresses. For example, one column of the mapping table stores the slave identifier, one column stores the register address, and one column stores the mapped memory address. The slave identifier is used to uniquely identify the slave, and slave identifiers, register addresses, and mapped memory addresses with mapping relationships are in the same row. Alternatively, the slave identifier, register address, and the index of the mapped memory address can be stored together. For instance, a set of mapped memory addresses can be stored in a local database, and each mapped memory address in the set can be assigned a number, which serves as the index of the corresponding mapped memory address. This index uniquely identifies the corresponding mapped memory address, and the slave identifier, register address, and the index of the mapped memory address are stored together in the mapping table. Of course, the form of the mapping table is not limited to the examples above. Those skilled in the art may make other modifications based on the essence of this application, but as long as the functionality and effect achieved are the same as or similar to this application, they should be covered within the scope of protection of this application.
[0132] If the register information includes the register type, the register type identifier can be added to the mapping table to establish a correspondence between the slave identifier, register address, register type, and mapped memory address. This allows matching the corresponding mapped memory address of a register based on its slave identifier, register address, and register type.
[0133] In the above technical solution, register information clearly defines the master station's access requirements. Furthermore, by matching the mapped memory address based on the register information, the required data from the master station can be accurately returned. Even when multiple master stations simultaneously query slave station data, if the accessed register information is the same, the same mapped memory data can be returned without re-matching the mapped memory address. This achieves deduplication of requests from multiple master stations, reduces communication bandwidth consumption, and further improves communication efficiency.
[0134] In some embodiments, register information includes register length;
[0135] If the first mapped memory address is matched, the first mapped memory data is returned to the main station, including:
[0136] If a first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address can cover the register length, the first mapped memory data is returned to the master station.
[0137] Register length represents the number of consecutive registers starting from a given address. For example, if you request access to 10 consecutive registers starting at address 10, then the register length is 10.
[0138] To correctly respond to the master station's data access requests, after matching the first mapped memory address, the first mapped memory address and the register length can be compared. Specifically, first, the register address range represented by the register length is defined. For example, if the register length is 10 and the starting register address is 100, the address range is from 100 to 109. Then, based on the matched first mapped memory address, the memory address range corresponding to the mapped memory address is determined. For example, the starting mapped memory address of the first mapped memory address can be found, and the size or end address of the mapped memory block can be determined. Next, the register address range is compared with the mapped memory address range. For example, it can be checked whether the starting address of the mapped memory is earlier than or equal to the starting address of the register, and whether the ending address of the mapped memory is later than or equal to the ending address of the register. If the address range of the mapped memory covers the address range of the register, then the mapped memory can be considered large enough to accommodate the entire register length. The mapped memory can provide the data that the master station wants to access, and the first mapped memory address can be returned to the master station so that the master station can access the required data based on the first mapped memory address.
[0139] In the above technical solution, by determining whether the mapped memory has sufficient capacity to cover the requested register length, if the mapped memory is large enough to contain the requested data range, it means that the main station can provide complete data, which can effectively avoid missing data errors during data reading.
[0140] In some embodiments, the method further includes:
[0141] If the first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address cannot cover the register length, the first mapped memory is expanded according to the register length to obtain the third mapped memory.
[0142] A third data request is sent to the slave station corresponding to the slave station identifier based on the third mapped memory address, so that the slave station can return the third slave station data corresponding to the third data request;
[0143] After storing the data from the third slave station in the third mapped memory, the data from the third mapped memory is returned to the master station.
[0144] In this embodiment, if a first mapped memory address is matched, but the associated first mapped memory cannot cover the register length, it indicates that data in the mapped memory is missing and insufficient to meet the access requirements of the main station. In this case, the first mapped memory can be expanded according to the register length.
[0145] Specifically, the first mapped memory can be expanded based on the portion missing between the first mapped memory and the register length, adding a new memory space. This expanded portion is then initialized, and the first mapped memory and the expanded portion are used as the third mapped memory. A unique third mapped memory address is then generated; this address can be a physical address or a virtual address. Next, based on the slave data to be mapped at the third mapped memory address, a third data request is constructed according to the communication protocol used between the gateway and the slave. This third data request can include information such as slave identifier, function code, register address, register length, and register type. Upon receiving the third data request, the slave returns third slave data based on the information in the request. After receiving the third slave data, the gateway stores the third register data in the mapped memory associated with the third mapped memory address, and then returns the third mapped memory data to the master station.
[0146] Furthermore, after creating the third mapped memory address, the mapping table can be updated to associate the newly created third mapped memory address with the slave's register information, so that when the master station issues the same or similar data access requests, it can find the corresponding mapped memory address based on the updated mapping table.
[0147] In the above technical solution, when the existing mapped memory is insufficient to cover the requested register length, the mapped memory is expanded to create a larger mapped memory. This allows the expanded mapped memory to have enough space to store the data returned by the slave station, reducing communication failures caused by missing mapped memory data. This enables the master station to successfully access the required slave station data and improves communication efficiency.
[0148] To further illustrate the implementation process of the data access method provided in the embodiments of this application, a scenario example is provided below, such as... Figure 3 As shown.
[0149] In this example scenario, communication between the master station, slave station, and gateway based on the Modbus protocol is used. The gateway section mainly includes two communication threads: one between the gateway and the master station, and another between the gateway and the slave station.
[0150] The communication thread between the gateway and the master station includes: the master station sends a Modbus Rtu request message; the gateway receives the Modbus Rtu request message from the master station and parses the slave ID, register type, required register address, and register length from the request message; then, based on the parsed slave ID, register type, required register address, and register length, it queries the mapping table for the corresponding mapped memory address. If no corresponding mapped memory address is found, it creates a mapped memory for the register of the slave corresponding to the slave ID in local memory, initializes the created memory, and after interaction through the communication thread between the gateway and the slave, writes the register data of the slave corresponding to the slave ID into the created mapped memory, and then returns the created mapped memory address to the master station; if a corresponding mapped memory is found, but the mapped memory is insufficient to cover the register length, then the mapped memory is... The master station expands its memory by initializing the mapped memory for the expanded portion. After interaction between the gateway and the slave station via the communication thread, the register data of the slave station corresponding to the slave ID is written into the expanded mapped memory, and then the address of the expanded mapped memory is returned to the master station. If the corresponding mapped memory is found and can cover the register length, it can be determined whether the mapped memory has been updated. If the current time since the last update is less than a preset threshold, the mapped memory is considered to have been updated, and in this case, the address of the mapped memory can be returned to the master station. If the current time since the last update is greater than or equal to the preset threshold, the mapped memory is considered not to have been updated, and in this case, it is necessary to wait for the mapped memory to be updated before returning the address of the mapped memory to the master station. It should be noted that the mapped memory can be updated based on the register data returned by the slave station after interaction between the gateway and the slave station via the communication thread.
[0151] The communication thread between the gateway and the slave station includes: the gateway, based on the mapped memory address information, including the mapped slave station ID, register type, register address, and register length, and in accordance with the Modbus Rtu message rules, frames and initiates a data request to the slave station corresponding to the slave station ID; after receiving the data request from the gateway, the slave station returns the register data in the form of a message based on the content of the data request; after receiving the register data, the gateway stores the register in the corresponding mapped memory.
[0152] The following describes a serial communication parameter configuration method provided in an embodiment of this application. This serial communication parameter configuration method can be applied to a terminal, and can be executed by the hardware or software within the terminal.
[0153] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads). It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads).
[0154] The following embodiments describe a terminal including a display and a touch-sensitive surface. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and joystick.
[0155] The serial communication parameter configuration method provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the data access method. The electronic device has the function of a gateway device. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The serial communication parameter configuration method provided in this application embodiment is described below using an electronic device as the execution subject as an example.
[0156] like Figure 4 As shown, the serial communication parameter configuration method includes steps 410, 420 and 430.
[0157] Step 410: Receive the query message sent by the master station based on the target communication protocol via the uplink serial port;
[0158] Step 420: Adjust the serial communication parameters to parse the query message and obtain the parsed message;
[0159] Step 430: If the parsed message conforms to the format specified by the target communication protocol, configure the downlink serial port according to the target serial port communication parameters used in the parsed message.
[0160] Communication protocols define the rules and standards for data exchange between electronic devices. In automation, industrial control, computer networks, and many other fields, communication protocols are fundamental to achieving device interconnection. In the embodiments of this application, the target communication protocol may be Modbus, Profibus, CANopen, HART, etc. Of course, the target communication protocol can also be other communication protocols, and this application does not limit this.
[0161] The master station can connect to the gateway's uplink serial port. Through the uplink serial port, the gateway can receive query messages from the master station based on rule-based framing of the target communication protocol. These query messages can be requests for specific data from the master station to the slave station, such as reading sensor values or obtaining machine status; they can also be requests for configuration information from the master station, such as querying the slave station's network address, hardware parameters, or software version; or they can inquire about the slave station's current operating status, such as whether it is operating normally or whether any errors have occurred. Of course, query messages can also contain other information requested from the slave station, and this embodiment does not limit this.
[0162] Serial communication parameters refer to a series of settings used to define the characteristics and behavior of data transmission in serial communication. Serial communication parameters may include baud rate, stop bits, data bits, parity bits, flow control, etc.
[0163] After receiving an inquiry message, the gateway, perhaps due to its initial connection to a communication system including both master and slave stations, may not be familiar with the communication parameters used on the bus. Therefore, it may be unsure which serial communication parameters to use to parse the inquiry message. To correctly parse the message, the gateway can adjust the serial communication parameters, using different parameters to parse the message into binary parsed messages. After each parsed message, it checks if the parsed message conforms to the format defined by the target communication protocol. For example, if the master station sends an inquiry message via the Modbus Rtu protocol, it checks if the parsed message conforms to the Modbus Rtu protocol's format. If not, the serial communication parameters are adjusted again to parse the message, and the parsed message is checked again to ensure it conforms to the target communication protocol's format. If it does, it indicates that the current serial port is using the same communication parameters as the existing system's communication bus, and the downlink serial port can be configured according to these parameters.
[0164] Specifically, the gateway's downlink serial port connects to the slave station. To enable communication between the master station, gateway, and slave station, the downlink serial port can be configured by obtaining the target serial port communication parameters used in the parsed message, provided the parsed message conforms to the format specified by the target communication protocol. For example, if the target serial port communication parameters used in the parsed message are: baud rate 9600, data bits 8, stop bits 1, even parity, then the downlink serial port communication parameters should be adjusted to: baud rate 9600, data bits 8, stop bits 1, even parity.
[0165] In the above technical solution, by using the uplink serial port to receive and adjust the serial communication parameters to parse the query messages sent by the master station, the communication protocol used by the master station can be automatically identified and adapted. When the query message is successfully parsed and the format meets the requirements of the target communication protocol, the corresponding serial communication parameters will be automatically used to configure the downlink serial port, without the need for tedious manual parameter configuration, thereby improving the configuration efficiency of serial communication parameters.
[0166] The data access method provided in this application can be executed by a data access device. This application uses an example of a data access device executing the data access method to illustrate the data access device provided in this application.
[0167] This application also provides a data access device.
[0168] like Figure 5 As shown, the data access device includes:
[0169] The parsing module 510 is used to parse the data access request message sent by the master station and obtain the parsing information; the parsing information includes at least the identifier of the slave station requested by the master station.
[0170] The matching module 520 is used to match the first mapped memory address corresponding to the slave identifier from a preset mapping table according to the slave identifier; the first mapped memory address is a memory area mapped with slave data, and the mapping table includes at least the association relationship between the slave identifier and the mapped memory address;
[0171] The return module 530 is used to return the first mapped memory data to the main station if the first mapped memory address is matched.
[0172] In the above technical solution, a mapped memory is created to cache slave data. Upon receiving a data request from the master station, the mapping table can quickly determine whether the slave data to be accessed by the master station exists in the mapped memory. If the slave data to be accessed by the master station exists in the mapped memory, the mapped memory data is returned to the master station. In this way, the process of master station query and slave station response is decoupled, reducing the waiting time of the master station after initiating a data access request. Even when multiple master stations query slave data simultaneously, the master station's data requests can be responded to efficiently, thereby improving communication efficiency.
[0173] In some embodiments, the data access device further includes:
[0174] The update module is used to send a first data request to the slave station mapped by the first mapped memory at preset intervals, so that the slave station can return the first slave station data corresponding to the first data request; and update the data of the first mapped memory according to the first slave station data.
[0175] In some embodiments, the return module 530 is further configured to:
[0176] Determine the last update time of the first mapped memory;
[0177] If the time since the last update is less than a preset threshold, the first mapped memory data is returned to the main station.
[0178] In some embodiments, the return module 530 is further configured to:
[0179] If the first mapped memory address is not matched, a second mapped memory address is created based on the parsed information;
[0180] A second data request is sent to the slave station corresponding to the slave station identifier based on the second mapped memory address, so that the slave station can return the second slave station data corresponding to the second data request;
[0181] After storing the second slave station data in the second mapped memory associated with the second mapped memory address, the second mapped memory data is returned to the master station.
[0182] In some embodiments, the parsed information further includes register information; the matching module 520 is also used for:
[0183] The first mapped memory address is matched from the mapping table based on the slave identifier and register information; the mapping table also includes the association between register information and mapped memory addresses.
[0184] In some embodiments, the register information includes the register length; the return module 530 is further configured to:
[0185] If a first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address can cover the register length, the first mapped memory data is returned to the master station.
[0186] In some embodiments, the return module 530 is further configured to:
[0187] If the first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address cannot cover the register length, the first mapped memory is expanded according to the register length to obtain the third mapped memory.
[0188] A third data request is sent to the slave station corresponding to the slave station identifier based on the third mapped memory address, so that the slave station can return the third slave station data corresponding to the third data request;
[0189] After storing the data from the third slave station in the third mapped memory, the data from the third mapped memory is returned to the master station.
[0190] The serial communication parameter configuration method provided in this application can be executed by a serial communication parameter configuration device. This application uses the execution of the serial communication parameter configuration method by a serial communication parameter configuration device as an example to illustrate the serial communication parameter configuration device provided in this application.
[0191] This application also provides a serial communication parameter configuration device.
[0192] like Figure 6 As shown, the serial communication parameter configuration device includes:
[0193] The receiving module 610 is used to receive query messages sent by the master station based on the target communication protocol via the uplink serial port;
[0194] The adjustment module 620 is used to adjust the serial communication parameters to parse the query message and obtain the parsed message.
[0195] The configuration module 630 is used to configure the downlink serial port according to the target serial port communication parameters used in the parsed message, provided that the parsed message conforms to the format specified by the target communication protocol.
[0196] In the above technical solution, by using the uplink serial port to receive and adjust the serial communication parameters to parse the query messages sent by the master station, the communication protocol used by the master station can be automatically identified and adapted. When the query message is successfully parsed and the format meets the requirements of the target communication protocol, the corresponding serial communication parameters will be automatically used to configure the downlink serial port, without the need for tedious manual parameter configuration, thereby improving the configuration efficiency of serial communication parameters.
[0197] The data access device and serial communication parameter configuration device in the embodiments of this application can be electronic devices or components within electronic devices, such as integrated circuits or chips. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. The embodiments of this application do not impose specific limitations.
[0198] The data access device and serial communication parameter configuration device in the embodiments of this application can be devices with an operating system. This operating system can be a Microsoft (Windows) operating system, an Android operating system, an iOS operating system, or other possible operating systems; this application does not specifically limit the specific operating system used.
[0199] In some embodiments, such as Figure 7 As shown, this application embodiment also provides an electronic device 700, including a processor 701, a memory 702, and a computer program stored in the memory 702 and executable on the processor 701. When the program is executed by the processor 701, it implements the various processes of the above-described data access method or serial communication parameter configuration method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0200] It should be noted that the electronic devices in the embodiments of this application include the aforementioned mobile electronic devices and non-mobile electronic devices.
[0201] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described data access method or serial communication parameter configuration method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0202] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0203] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described data access method or serial communication parameter configuration method.
[0204] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0205] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface and the processor are coupled. The processor is used to run programs or instructions to implement the various processes of the above-described embodiments based on the data access method or serial communication parameter configuration method, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0206] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0207] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0208] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0209] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0210] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0211] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. A data access method, characterized in that, include: Parse the data access request message sent by the main station to obtain the parsing information; The parsed information includes at least the slave station identifier requested by the master station; The slave identifier is matched with the first mapped memory address corresponding to the slave identifier from a preset mapping table; the first mapped memory address is a memory area mapped with slave data, and the mapping table includes at least the association between the slave identifier and the mapped memory address; If the first mapped memory address is matched, the first mapped memory data is returned to the main station.
2. The method according to claim 1, characterized in that, The method further includes: A first data request is sent to the slave station mapped by the first mapped memory at preset intervals, so that the slave station can return the first slave station data corresponding to the first data request; The first mapped memory data is updated based on the first slave station data.
3. The method according to claim 1, characterized in that, Returning the first mapped memory data to the main station includes: Determine the last update time of the first mapped memory; If the time since the last update is less than a preset threshold, the first mapped memory data is returned to the main station.
4. The method according to claim 1, characterized in that, The method further includes: If the first mapped memory address is not matched, a second mapped memory address is created based on the parsed information; Based on the second mapped memory address, a second data request is sent to the slave station corresponding to the slave station identifier, so that the slave station can return the second slave station data corresponding to the second data request; After storing the second slave station data in the second mapped memory associated with the second mapped memory address, the second mapped memory data is returned to the master station.
5. The method according to claim 1, characterized in that, The parsed information also includes register information; Matching the slave identifier with the first mapped memory address corresponding to the slave identifier from a preset mapping table, including: The first mapped memory address is matched from the mapping table according to the slave identifier and the register information; wherein, the mapping table also includes the association between register information and mapped memory address.
6. The method according to claim 5, characterized in that, The register information includes the register length; The step of returning the first mapped memory data to the main station when the first mapped memory address is matched includes: If the first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address can cover the register length, the first mapped memory data is returned to the master station.
7. The method according to claim 6, characterized in that, The method further includes: If the first mapped memory address is matched, and the first mapped memory associated with the first mapped memory address cannot cover the register length, the first mapped memory is expanded according to the register length to obtain the third mapped memory. Based on the third mapped memory address corresponding to the third mapped memory, a third data request is sent to the slave station corresponding to the slave station identifier, so that the slave station can return the third slave station data corresponding to the third data request; After storing the third slave station data in the third mapped memory, the third mapped memory data is returned to the master station.
8. A method for configuring serial communication parameters, characterized in that, include: Receive query messages sent by the master station based on the target communication protocol via the uplink serial port; Adjust the serial communication parameters to parse the query message and obtain the parsed message; If the parsed message conforms to the format specified by the target communication protocol, the downlink serial port is configured according to the target serial port communication parameters used in the parsed message.
9. A data access device, characterized in that, include: The parsing module is used to parse the data access request messages sent by the main station and obtain the parsing information; The parsed information includes at least the slave station identifier requested by the master station; The matching module is used to match the first mapped memory address corresponding to the slave identifier from a preset mapping table based on the slave identifier; The first mapped memory address is a memory region mapped with slave data, and the mapping table includes at least the association between slave identifiers and mapped memory addresses; The return module is used to return the first mapped memory data to the main station if the first mapped memory address is matched.
10. A serial communication parameter configuration device, characterized in that, include: The receiving module is used to receive query messages sent by the master station based on the target communication protocol via the uplink serial port; An adjustment module is used to adjust serial communication parameters to parse the query message and obtain the parsed message. The configuration module is used to configure the downlink serial port according to the target serial port communication parameters used in the parsed message when the parsed message conforms to the format agreed upon by the target communication protocol.
11. A data access system, characterized in that, include: Master station, slave station, and gateway; The gateway is connected to the master station via an uplink serial port and to the slave station via a downlink serial port; The gateway is configured to implement the method as described in any one of claims 1-8.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-8.