Hardware data sending method and device, storage medium and electronic device
By using shared memory and socket communication to synchronize data between processes in PLCs, the method addresses delays caused by separate core operations, enhancing PLC efficiency.
Patent Information
- Application Number
- CN202411363411.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2024-12-31
AI Technical Summary
The synchronization of logic compilation and operation between C/C++ and IEC language parts on different cores of a multi-core CPU in programmable logic controllers (PLCs) causes delays in input and output operations.
A method involving shared memory and socket communication is employed to synchronize data between different processes, allowing the C/C++ process to write and process hardware data in a shared memory, reducing delays by using local call interfaces and notification messages.
This approach reduces input and output delays by enabling efficient data synchronization and processing between different processes, optimizing PLC operations.
Smart Images

Figure CN119226007A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a method and device for sending hardware data, a storage medium, and an electronic device. Background Art
[0002] A programmable logic controller (PLC) is a device used to monitor and control industrial processes and can be used by operators such as electrical technicians. In order to adapt to the traditional habits and mastery of operators, PLCs usually use graphical programming languages and text-based programming languages. Currently, PLC logic configurations are generally written in a PLC configuration language, such as Ladder Diagram (LD), Function Block Diagram (FBD), Structured Text (ST), and Sequential Function Chart (SFC).
[0003] At present, with the development of intelligent manufacturing and industrial automation, the complexity of PLC programming increases with the complexity of the control system. When the control algorithm tends to be complex, C / C++ is often used to write the algorithm logic, which requires the PLC logic configuration to support the C / C++ language and access the configuration hardware data in the C / C++ language. C / C++ has the advantages of flexible language, powerful functions, strong portability, low resource consumption, and is widely used in embedded system development. In addition, the C / C++ language has a concise and efficient syntax structure and rich library functions, which can reduce the workload of programming and improve development efficiency. Using C language for PLC programming can improve programming efficiency and realize more complex control logic and algorithms.
[0004] The prior art usually compiles the C / C++ part of the logic into an independent module, which occupies one core of a multi-core central processing unit (CPU), and the logic of the programming language part of the PLC logic configuration formulated by the International Electrotechnical Commission (IEC) (i.e., the IEC language part) runs on another core of the multi-core CPU. Multiple cores need to synchronize data regularly, which will cause delays in the input and output operations of the PLC.
[0005] In the prior art, the logic compilation of the C / C++ part and the logic operation of the IEC language part are located on different cores of the multi-core CPU respectively. The multiple cores need to synchronize data regularly, which causes the input and output operations of the PLC to be delayed. No effective solution has been proposed so far.
[0006] Therefore, it is necessary to improve the related technology to overcome the above-mentioned defects in the related technology. Summary of the invention
[0007] The embodiments of the present application provide a method and device for sending hardware data, a storage medium and an electronic device, so as to at least solve the problem in the prior art that the logic compilation of the C / C++ part and the logic operation of the IEC language part are respectively located on different cores of a multi-core CPU, and data synchronization needs to be performed regularly between the multiple cores, resulting in delays in the input and output operations of the PLC.
[0008] According to one aspect of an embodiment of the present application, a method for sending hardware data is provided, comprising: receiving first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of target hardware; controlling a first process to write second hardware data of the target hardware into a shared memory; controlling a second process to obtain the second hardware data in the shared memory, and processing the second hardware data to obtain the first hardware data, wherein the first process and the second process are processes of different types; controlling the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
[0009] In an exemplary embodiment, controlling the second process to obtain the first hardware data in the shared memory includes: creating a first socket, and determining a local call interface and a socket address to which the second socket is bound, wherein the second socket is created for the second process; establishing a connection relationship between the first socket and the local call interface based on the socket address; when the first process successfully writes the second hardware data of the target hardware into the shared memory, sending a first notification message to the second process through the connection relationship, wherein the first notification message is used to indicate that the first process has successfully written the second hardware data into the shared memory; when the second process receives the first notification message, controlling the second process to obtain the first hardware data in the shared memory.
[0010] In an exemplary embodiment, after controlling the second process to write the first hardware data into the shared memory, the method further includes: in a case where the second process successfully writes the first hardware data into the shared memory, sending a second notification message to the first process through the connection relationship, wherein the second notification message is used to indicate that the first process has successfully written the second hardware data into the shared memory; in a case where the first process obtains the second notification message, controlling the second process to obtain the second hardware data in the shared memory.
[0011] In an exemplary embodiment, processing the second hardware data includes: when the second process receives the second request information sent by the first process, determining the message type of the second request information, wherein the second request information is used to indicate how the second process processes the second hardware data; determining a callback processing function corresponding to the message type, and sending the second request information to the callback processing function so that the callback processing function processes the second hardware data.
[0012] In an exemplary embodiment, before receiving the first request information sent by the requesting device, the method also includes: establishing a hardware tree relationship of the target hardware through the host computer software, wherein the hardware tree relationship is used to indicate the measurement point variable information of the target hardware; determining the first dynamic library corresponding to the second process according to the hardware tree relationship, so that when the second process is running, the second hardware data is obtained in the shared memory based on the first dynamic library.
[0013] In an exemplary embodiment, after determining the first dynamic library corresponding to the second process according to the hardware tree relationship, the method further includes: periodically detecting whether the hardware tree relationship is updated; if the hardware tree relationship is updated, generating a second dynamic library according to the updated hardware tree relationship; closing the second process and updating the first dynamic library to the second dynamic library, so that when the second process is running, the second hardware data can be obtained in the shared memory based on the second dynamic library.
[0014] In an exemplary embodiment, determining a first dynamic library corresponding to a second process according to the hardware tree relationship includes: determining source code of a target function to be implemented according to the hardware tree relationship, and determining compilation options according to the hardware tree relationship, wherein the compilation options include: compiler options, link options, and the source code is a code written in a programming language corresponding to the second process; compiling the source code into a target file based on the compilation options, and linking the target file into the first dynamic library.
[0015] According to another aspect of an embodiment of the present application, a hardware data sending device is also provided, including: a receiving module, used to receive a first request information sent by a requesting device, wherein the first request information is used to request to obtain the first hardware data of the target hardware; a first control module, used to control the first process to write the second hardware data of the target hardware into a shared memory; a second control module, used to control the second process to obtain the second hardware data in the shared memory, and process the second hardware data to obtain the first hardware data, wherein the first process and the second process are different types of processes; a third control module, used to control the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
[0016] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned method for sending hardware data when running.
[0017] According to another aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the method for sending hardware data through the computer program.
[0018] Through this application, due to the first request information sent by the receiving device for requesting the first hardware data of the target hardware; controlling the first process to write the second hardware data of the target hardware into the shared memory, controlling the second process of a different type from the first process to obtain and process the second hardware data in the shared memory to obtain the first hardware data; controlling the second process to write the first hardware data into the above-mentioned shared memory, so that the first process sends the first hardware data to the requesting device. That is to say, in the embodiment of the present application, when the first request information is received, the first process is controlled to write the obtained second hardware data into the shared memory, and after the second process obtains the second hardware data in the shared memory, it processes it and writes the processed data into the shared memory, so that the first process sends the processed data to the requesting device. Therefore, the input and output delay can be reduced. The above technical solution solves the problem that the input and output operations of the PLC are delayed in the prior art, where the logic compilation of the C / C++ part and the logic operation of the IEC language part are respectively located on different cores of the multi-core CPU, and multiple cores need to synchronize data regularly. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The exemplary embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 It is a hardware structure block diagram of a computer terminal of the method for sending hardware data of an embodiment of the present application;
[0021] Figure 2 is a flowchart of a method for sending hardware data according to an embodiment of the present application;
[0022] Figure 3 It is an overall framework diagram of a method for performing PLC logic configuration using C / C++ according to an optional embodiment of the present application;
[0023] Figure 4 is an overall operation block diagram of a local procedure call module according to an optional embodiment of the present application;
[0024] Figure 5 It is a structural block diagram of a hardware data sending device according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0026] It should be noted that the terms and "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 11 is a hardware structure block diagram of a computer terminal of the method for sending hardware data in an embodiment of the present application. Figure 1 As shown, the computer terminal may include one or more ( Figure 1 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a microprocessor (Microprocessor Unit, referred to as MPU) or a programmable logic device (Programmable logic device, referred to as PLD)) and a memory 104 for storing data. In an exemplary embodiment, the computer terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. Figure 1 More or fewer components as shown, or with Figure 1 Equivalent functions or comparisons shown Figure 1 A different configuration with more features is shown.
[0028] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for sending hardware data in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, which is equivalent to implementing the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0029] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0030] In this embodiment, a method for sending hardware data is provided. Figure 2: is a flowchart of a method for sending hardware data according to an embodiment of the present application, and the process includes the following steps:
[0031] Step S202, receiving first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of target hardware;
[0032] Step S204, controlling the first process to write the second hardware data of the target hardware into the shared memory;
[0033] It can be understood that the first process mentioned above can be a real-time operating system process (Rea lTime System Process, referred to as RTS process), and the second hardware data mentioned above can be real-time hardware data.
[0034] Step S206, controlling the second process to obtain the second hardware data in the shared memory, and processing the second hardware data to obtain the first hardware data, wherein the first process and the second process are different types of processes;
[0035] It can be understood that the second process mentioned above can be a C++ process.
[0036] Step S208: Control the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
[0037] Through the above steps, the first request information sent by the receiving device for requesting the first hardware data of the target hardware is received; the first process is controlled to write the second hardware data of the target hardware into the shared memory, and the second process of a different type from the first process is controlled to obtain and process the second hardware data in the shared memory to obtain the first hardware data; the second process is controlled to write the first hardware data into the above-mentioned shared memory, so that the first process sends the first hardware data to the requesting device. That is to say, when the present application receives the first request information, it controls the first process to write the obtained second hardware data into the shared memory, and after the second process obtains the second hardware data in the shared memory, it processes it and writes the processed data into the shared memory, so that the first process sends the processed data to the requesting device. Therefore, the input and output delay can be reduced. The above technical solution is adopted to solve the problem that the input and output operations of the PLC are delayed in the prior art, in which the logic compilation of the C / C++ part and the logic operation of the IEC language part are respectively located on different cores of the multi-core CPU, and the multiple cores need to synchronize data regularly.
[0038] Optionally, the above-mentioned step S206 of controlling the second process to obtain the first hardware data in the shared memory includes: creating a first socket, and determining a local call interface and a socket address to which the second socket is bound, wherein the second socket is created for the second process; establishing a connection relationship between the first socket and the local call interface based on the socket address; when the first process successfully writes the second hardware data of the target hardware into the shared memory, sending a first notification message to the second process through the connection relationship, wherein the first notification message is used to indicate that the first process has successfully written the second hardware data into the shared memory; when the second process receives the first notification message, controlling the second process to obtain the first hardware data in the shared memory.
[0039] It can be known from the above technical solution that a first socket can be created, and a second socket can be created for the second process. Furthermore, a local call interface bound to the second socket can be determined, wherein the local call interface can be a set of low-latency local process communication interfaces, and the time taken by the local call interface to complete an inter-process call (i.e., obtaining the first hardware data in the present application) can be controlled within a certain time length, for example: the time taken by the local call interface to complete an inter-process call is controlled within 150 microseconds to improve the efficiency of the inter-process call. And the socket address of the second socket is determined. A connection relationship between the local call interface and the first socket can be established according to the socket address of the second socket, so that the same socket can be used between the first process and the second process, and then the first process and the second process can communicate through the above connection relationship.
[0040] That is to say, after a connection relationship is established between the first socket and the local call address through the socket address of the second socket, when the first process successfully writes the second hardware data of the target hardware into the shared memory, the first process can act as a requester and send a first notification message to the second process through the connection relationship, and then the second process can act as a responder and obtain the first hardware data in the shared memory when receiving the first notification message.
[0041] After controlling the second process to write the first hardware data into the shared memory, the method further includes: when the second process successfully writes the first hardware data into the shared memory, sending a second notification message to the first process through the connection relationship, wherein the second notification message is used to indicate that the first process has successfully written the second hardware data into the shared memory; when the first process obtains the second notification message, controlling the second process to obtain the second hardware data in the shared memory.
[0042] The above connection relationship can not only be used for the first process to send the first notification message to the second process, but also, when the second process has successfully written the first hardware data, the second process can send the second notification message to the first process through the above connection relationship, so that the second process can obtain the second hardware data. (The above acquisition of the first hardware data is a one-process call, and the acquisition of the second hardware data is a second-process call) Specifically: the second process sends the second notification message to the first process through the connection relationship to notify the first process that the second hardware data has been successfully written. When the first process obtains the second notification message, the second process can be controlled to obtain the second hardware data in the shared memory.
[0043] Optionally, processing the second hardware data includes: when the second process receives the second request information sent by the first process, determining the message type of the second request information, wherein the second request information is used to indicate how the second process processes the second hardware data; determining a callback processing function corresponding to the message type, and sending the second request information to the callback processing function so that the callback processing function processes the second hardware data.
[0044] Through the above embodiment, when the second process receives the second request message sent by the first process, the second request message can be parsed to determine the message type of the second request message, and the callback processing function corresponding to the message type can be determined to process the second hardware data through the callback processing function.
[0045] Optionally, before receiving the first request information sent by the requesting device, the method also includes: establishing a hardware tree relationship of the target hardware through upper computer software, wherein the hardware tree relationship is used to indicate the measurement point variable information of the target hardware; determining a first dynamic library corresponding to the second process according to the hardware tree relationship, so that when the second process is running, the second hardware data is obtained in the shared memory based on the first dynamic library.
[0046] Among them, after determining the first dynamic library corresponding to the second process according to the hardware tree relationship, the method also includes: periodically detecting whether the hardware tree relationship is updated; if the hardware tree relationship is updated, generating a second dynamic library according to the updated hardware tree relationship; closing the second process, and updating the first dynamic library to the second dynamic library, so that when the second process is running, the second hardware data is obtained in the shared memory based on the second dynamic library.
[0047] Wherein, determining the first dynamic library corresponding to the second process according to the hardware tree relationship includes: determining the source code of the target function to be implemented according to the hardware tree relationship, and determining the compilation options according to the hardware tree relationship, wherein the compilation options include: compiler options, link options, and the source code is a code written in the programming language corresponding to the second process; compiling the source code into a target file based on the compilation options, and linking the target file into the first dynamic library.
[0048] Before receiving the first request information sent by the requesting device, the second hardware data needs to be obtained. Specifically, the hardware tree relationship can be set by the host computer software, and the measurement point variable information of the target hardware is added to the hardware tree relationship to establish the hardware tree relationship of the target hardware.
[0049] Furthermore, the source code and compile options of the target function to be implemented can be determined according to the hardware tree relationship of the target hardware, the source code is compiled based on the compile options, and the first dynamic library corresponding to the second process is determined. The first dynamic library can be a C / C++ configuration logic dynamic library.
[0050] In the process of periodically detecting the hardware tree relationship, if it is detected that the hardware tree relationship is updated, the second process can be closed, and the first dynamic library can be updated to a new C / C++ configuration logic dynamic library according to the updated hardware tree relationship, that is, the first dynamic library is updated to the second dynamic library. Then, when the second process is running, the second hardware data can be obtained based on the updated second dynamic library.
[0051] Obviously, the above-described embodiments are only a part of the embodiments of the present application, not all of the embodiments. In order to better understand the above-mentioned method for sending hardware data, the above-mentioned process is described below in conjunction with the embodiments, but it is not intended to limit the technical solutions of the embodiments of the present application, specifically:
[0052] In an optional embodiment, a method for performing PLC logic configuration using C / C++ is proposed, specifically:
[0053] In PLC system programming, in order to use C / C++ language configuration, the configuration software needs to send the user configuration program and data to the controller. The address of the configuration variable (i.e., the socket address of this application) has been determined in the program compilation stage, and the size of each configuration variable (including hardware measurement points) and the offset in the memory have also been determined. The corresponding variables can be read and written through the size and offset. The host computer software sets the hardware tree relationship and adds each measurement point variable. The host computer uses C / C++ language to write the logic code. The type, size, offset, and structural relationship of the hardware measurement point variables are collected during compilation, and a C++ header file is generated; a CMake project will also be generated during compilation. The project has preset the dynamic library interface required by the C++ process, and contains the hardware configuration data header file above. The user writes logic in the CMake project, reads and writes the hardware measurement point variables, and compiles to generate a dynamic library that meets the requirements.
[0054] Figure 3 is an overall framework diagram of a method for performing PLC logic configuration using C / C++ according to an optional embodiment of the present application, such as Figure 3 As shown:
[0055] The PLC system mainly includes the host computer, controller and field input / output system (Input / Output at the scene, i.e. field I / O), among which:
[0056] 1) The host computer (i.e., the host computer software in the embodiment of the present application) is mainly used for:
[0057] (1) Setting a hardware tree relationship, adding variables of each measuring point (i.e., the measuring point variable information of the target hardware of this application), generating hardware configuration data, and reflecting the hardware configuration data in a private format;
[0058] (2) Use C / C++ language to write logic code. During compilation, the type, size, offset, structural relationship, etc. of the hardware measurement point variables can be collected to generate a C++ header file (i.e., C / C++ logic configuration data), and the C++ header file is expressed in the Linux dynamic library format.
[0059] 2) The controller is mainly used for:
[0060] (1) The logic operation part of the system is separated into a C / C++ process (i.e., the second process of this application), so as to meet the requirements of rapid system expansion and fault isolation. The RTS process (i.e., the first process of this application) communicates with the host computer and the field I / O, and the C / C++ process performs logic operations. The RTS process and the C / C++ process are synchronized and controlled through local process communication and shared memory. Specifically:
[0061] The RTS process is mainly used for:
[0062] 1. When the host computer sends the hardware configuration data to the controller, after the RTS process processes the received hardware configuration data, the C / C++ process is closed, and the new C / C++ configuration logic dynamic library (ie, the second dynamic library of the present application) is updated to the specified location.
[0063] 2. When the task starts running, start the C / C++ process, initialize the local procedure call interface (i.e., the local call interface of this application) as the client, and notify the C / C++ process to start the operation through the local procedure call interface;
[0064] 3. During periodic operations, the hardware I / O real-time data is written to the shared memory at the beginning of each cycle, and the C / C++ process is notified through the local procedure call interface that the hardware I / O real-time data has been written. The process starts waiting for the C / C++ process to notify it that the operation is complete. When the operation is completed, the operation result is read from the shared memory and assigned to the hardware I / O.
[0065] 4. When the task stops, the C / C++ process is notified to stop the operation through the local process communication interface.
[0066] C / C++ processes are mainly used for:
[0067] 1. After the RTS process is started, the local procedure call interface is initialized as a server and waits for instructions from the client;
[0068] 2. Respond to instructions and start and stop periodic operations.
[0069] 3. During periodic calculations, wait for the notification that the shared memory data of the RTS process is ready (i.e., wait for the first notification message of this application). After receiving the notification, read data from the shared memory and perform calculations. After the calculations are completed, store the calculation results in the shared memory, and notify the RTS process that the memory read data has been calculated (i.e., the second notification message of this application).
[0070] Wherein, the PLC system also includes: a local process call module. Figure 4 is an overall operation block diagram of a local procedure call module according to an optional embodiment of the present application, such as Figure 4 As shown:
[0071] The current system is a Linux real-time operating system. There are two processes, the RTS process and the C / C++ process. There is a synchronization thread in each of the Linux real-time operating system. The two processes are connected through the local procedure call interface (i.e. Figure 4Each of them has an endpoint and supports a two-way request-response mode, that is, both parties can initiate a request to trigger the other party's response, and both parties exchange data through the same shared memory.
[0072] (1) Control the order of multi-process calculations. The operating efficiency of the local procedure call module itself will directly affect the duration of the entire cycle and the delay of hardware I / O data.
[0073] (2) Based on UNIX inter-domain sockets and POSIX (Portable Operating System Interface) shared memory, a low-latency local procedure communication interface was developed. The local procedure communication interface takes less than 150 microseconds to complete an inter-process call. One cycle requires two inter-process local procedure calls, and the total time overhead can be maintained within 300 microseconds.
[0074] (3) Call implementation process: When both ends of the local process communication interface are initialized, different processing callback functions are registered for different messages. When the requester sends a request message, the request thread enters the receiving state; after receiving the request message, the responder verifies and parses the message content, triggers the corresponding callback processing function according to the message type, and passes the parsed request data to the callback processing function. After the responder completes the processing, it uses the same inter-domain socket to reply the result message. The requester parses the result, so that the request function returns according to the result, completing an inter-process local process call. Among them, when the requester is a C / C++ process, the responder can be an RTS process; when the requester is an RTS process, the requester can be a C / C++ process.
[0075] Through an optional embodiment of the present application, local procedure calls can solve the coordination problem between multi-process calculations, so that the system strictly executes the cycle sequence of input, operation, and output, and the cycle time is accurate and the error is small. The modules of the system maintain a one-to-one relationship, which will not cause the operation to be ignored because there is no time to process the input, or the output to be ignored because there is no time to process the operation result.
[0076] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0077] In the present embodiment, a sending device for hardware data is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the description has been made no further. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the equipment described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0078] Figure 5 : is a structural block diagram of a device for sending hardware data according to an embodiment of the present application, the device comprising:
[0079] A receiving module 52, configured to receive first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of a target hardware;
[0080] A first control module 54, used for controlling the first process to write the second hardware data of the target hardware into the shared memory;
[0081] A second control module 56, used for controlling the second process to obtain the second hardware data in the shared memory, and processing the second hardware data to obtain the first hardware data, wherein the first process and the second process are different types of processes;
[0082] The third control module 58 is used to control the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
[0083] Through this device, a first request message for requesting to obtain the first hardware data of the target hardware sent by the receiving device is controlled; the first process is controlled to write the second hardware data of the target hardware into the shared memory, and the second process of a different type from the first process is controlled to obtain and process the second hardware data in the shared memory to obtain the first hardware data; the second process is controlled to write the first hardware data into the above-mentioned shared memory, so that the first process sends the first hardware data to the requesting device. That is to say, when the present application receives the first request message, it controls the first process to write the obtained second hardware data into the shared memory, and after the second process obtains the second hardware data in the shared memory, it processes it and writes the processed data into the shared memory, so that the first process sends the processed data to the requesting device. Therefore, the input and output delay can be reduced. The above technical solution is adopted to solve the problem that the input and output operation of the PLC in the prior art is delayed because the logic compilation of the C / C++ part and the logic operation of the IEC language part are respectively located on different cores of the multi-core CPU, and the multiple cores need to synchronize data regularly.
[0084] In an exemplary embodiment, the second control module 56 is also used to create a first socket and determine the local call interface and socket address bound to the second socket, wherein the second socket is created for the second process; establish a connection relationship between the first socket and the local call interface based on the socket address; when the first process successfully writes the second hardware data of the target hardware into the shared memory, send a first notification message to the second process through the connection relationship, wherein the first notification message is used to indicate that the first process has successfully written the second hardware data into the shared memory; when the second process receives the first notification message, control the second process to obtain the first hardware data in the shared memory.
[0085] In an exemplary embodiment, the second control module 56 is also used to send a second notification message to the first process through the connection relationship when the second process successfully writes the first hardware data into the shared memory, wherein the second notification message is used to indicate that the first process has successfully written the second hardware data into the shared memory; and when the first process obtains the second notification message, control the second process to obtain the second hardware data in the shared memory.
[0086] In an exemplary embodiment, the second control module 56 is also used to determine the message type of the second request information when the second process receives the second request information sent by the first process, wherein the second request information is used to indicate how the second process processes the second hardware data; determine the callback processing function corresponding to the message type, and send the second request information to the callback processing function so that the callback processing function processes the second hardware data.
[0087] In an exemplary embodiment, the receiving module 52 is also used to establish a hardware tree relationship of the target hardware through the host computer software, wherein the hardware tree relationship is used to indicate the measurement point variable information of the target hardware; determine the first dynamic library corresponding to the second process according to the hardware tree relationship, so that when the second process is running, the second hardware data is obtained in the shared memory based on the first dynamic library.
[0088] In an exemplary embodiment, the receiving module 52 is also used to periodically detect whether the hardware tree relationship is updated; when the hardware tree relationship is updated, generate a second dynamic library based on the updated hardware tree relationship; close the second process, and update the first dynamic library to the second dynamic library, so that when the second process is running, the second hardware data is obtained in the shared memory based on the second dynamic library.
[0089] In an exemplary embodiment, the receiving module 52 is also used to determine the source code of the target function to be implemented based on the hardware tree relationship, and to determine the compilation options based on the hardware tree relationship, wherein the compilation options include: compiler options, link options, and the source code is a code written in the programming language corresponding to the second process; based on the compilation options, the source code is compiled into a target file, and the target file is linked to the first dynamic library.
[0090] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0091] S1, receiving first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of a target hardware;
[0092] S2, controlling the first process to write the second hardware data of the target hardware into the shared memory;
[0093] S3, controlling the second process to obtain the second hardware data in the shared memory, and processing the second hardware data to obtain the first hardware data, wherein the first process and the second process are processes of different types;
[0094] S4, controlling the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
[0095] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0096] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0097] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0098] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0099] S1, receiving first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of a target hardware;
[0100] S2, controlling the first process to write the second hardware data of the target hardware into the shared memory;
[0101] S3, controlling the second process to obtain the second hardware data in the shared memory, and processing the second hardware data to obtain the first hardware data, wherein the first process and the second process are processes of different types;
[0102] S4, controlling the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
[0103] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0104] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0105] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0106] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for sending hardware data, characterized in that: include: Receiving first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of target hardware; Controlling the first process to write the second hardware data of the target hardware into the shared memory; Controlling the second process to obtain the second hardware data in the shared memory, and processing the second hardware data to obtain the first hardware data, wherein the first process and the second process are different types of processes; The second process is controlled to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
2. The method for sending hardware data according to claim 1, characterized in that: Controlling the second process to obtain the first hardware data in the shared memory includes: Creating a first socket, and determining a local call interface and a socket address bound to a second socket, wherein the second socket is created for the second process; Establishing a connection relationship between the first socket and the local call interface based on the socket address; When the first process successfully writes the second hardware data of the target hardware into the shared memory, sending first notification information to the second process through the connection relationship, wherein the first notification information is used to indicate that the first process has successfully written the second hardware data into the shared memory; When the second process receives the first notification information, the second process is controlled to obtain the first hardware data in the shared memory.
3. The method for sending hardware data according to claim 2, characterized in that: After controlling the second process to write the first hardware data into the shared memory, the method further includes: When the second process successfully writes the first hardware data into the shared memory, sending second notification information to the first process through the connection relationship, wherein the second notification information is used to indicate that the first process has successfully written the second hardware data into the shared memory; When the first process obtains the second notification information, the second process is controlled to obtain the second hardware data in the shared memory.
4. The method for sending hardware data according to claim 1, characterized in that: Processing the second hardware data includes: In the case where the second process receives the second request information sent by the first process, determining a message type of the second request information, wherein the second request information is used to indicate a processing method of the second process on the second hardware data; Determine a callback processing function corresponding to the message type, and send the second request information to the callback processing function, so that the callback processing function processes the second hardware data.
5. The method for sending hardware data according to claim 1, characterized in that: Before receiving the first request information sent by the requesting device, the method further includes: Establishing a hardware tree relationship of the target hardware through the host computer software, wherein the hardware tree relationship is used to indicate the measurement point variable information of the target hardware; The first dynamic library corresponding to the second process is determined according to the hardware tree relationship, so that when the second process is running, the second hardware data is obtained in the shared memory based on the first dynamic library.
6. The method for sending hardware data according to claim 5, characterized in that: After determining the first dynamic library corresponding to the second process according to the hardware tree relationship, the method further includes: periodically detecting whether the hardware tree relationship is updated; In the case where the hardware tree relationship is updated, generating a second dynamic library according to the updated hardware tree relationship; The second process is closed, and the first dynamic library is updated to the second dynamic library, so that when the second process is running, the second hardware data is obtained in the shared memory based on the second dynamic library.
7. The method for sending hardware data according to claim 5, characterized in that: Determining a first dynamic library corresponding to the second process according to the hardware tree relationship includes: Determine the source code of the target function to be implemented according to the hardware tree relationship, and determine the compilation options according to the hardware tree relationship, wherein the compilation options include: compiler options and link options, and the source code is a code written in the programming language corresponding to the second process; The source code is compiled into a target file based on the compilation options, and the target file is linked into the first dynamic library.
8. A hardware data sending device, characterized in that: include: A receiving module, configured to receive first request information sent by a requesting device, wherein the first request information is used to request to obtain first hardware data of a target hardware; A first control module, used for controlling the first process to write the second hardware data of the target hardware into the shared memory; A second control module is used to control the second process to obtain the second hardware data in the shared memory, and process the second hardware data to obtain the first hardware data, wherein the first process and the second process are different types of processes; The third control module is used to control the second process to write the first hardware data into the shared memory, so that the first process sends the first hardware data to the requesting device.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.