Data sharing method, device and system
By setting the cache area and shared memory of the upper system on the PLC side, combined with intermediate programs and semaphore control, efficient data sharing between the PLC and the upper system is achieved, solving the problem of low data transmission efficiency and ensuring data continuity and integrity.
Patent Information
- Application Number
- CN202111321530.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-09
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2041-11-09
AI Technical Summary
In the prior art, the data transmission efficiency of PLC and the upper system is low, which easily leads to data accumulation, discarding and covering, especially when data changes rapidly, the complete chronological transmission of data points cannot be met.
A first-level cache area is set on the PLC side to preprocess the fast data and store it in the first cache area on the PLC side. The data is sent to the shared memory of the upper system through an intermediate program. The pre-configured application in the upper system reads data from the shared memory, reducing dependence on industrial communication protocols, and using semaphores and application data status tables to control read and write operations.
The data transmission efficiency on the PLC side and the upper system side is improved, communication overhead is reduced, data throughput is enhanced, and data discontinuity is avoided due to short-term communication interruption.
Smart Images

Figure CN114020493B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and more specifically, to a method, device and system for sharing data between a PLC side and a host system side. Background Art
[0002] In certain specialized automation scenarios, PLCs need to transmit external data collected by them and data generated by them to a higher-level system for use by applications within that system, such as analysis, storage, display, and forwarding. Currently, PLCs are typically connected to host computers via communication protocols such as OPC UA and Modbus, with data transmission and sharing based on these protocols. This data transmission and sharing method, which requires data packaging and unpacking, is inefficient. Furthermore, the external real-time data collected by PLCs and the data they generate themselves change rapidly, leading to data accumulation and eventual data loss and overwriting. Summary of the Invention
[0003] In view of this, the present invention proposes a data sharing method to solve the above problems.
[0004] According to a first aspect of the present invention, the present invention provides a data sharing method, comprising:
[0005] Preprocessing the fast data on the PLC side and storing the preprocessed fast data in a first buffer area on the PLC side;
[0006] sending the fast data stored in the first buffer area to a host system;
[0007] Writing the received fast data into the shared memory of the host system;
[0008] One or more programs preconfigured in the host system read the fast data from the shared memory.
[0009] Based on the data sharing method of the above embodiment, a first-level cache is set on the PLC side and a second-level cache is set in the upper system to realize protocol-free shared storage area between the PLC side and the upper system, thereby reducing communication overhead, improving communication efficiency, improving throughput, and avoiding data discontinuity caused by short-term communication interruptions.
[0010] Furthermore, the fast data stored in the first buffer area is sent to a host system based on an intermediate program, and the received fast data is written into a shared memory of the host system based on the intermediate program.
[0011] By setting up intermediate programs on the PLC side and the host system side respectively, and realizing data sharing between the PLC side and the host system side based on the intermediate programs, the efficiency of data transmission and data reception is improved without going through the industrial communication protocol.
[0012] Furthermore, the step of writing the received fast data into the shared memory of the upper system includes:
[0013] Get the write semaphore;
[0014] Determine whether the fast data at the last written location has been read by all the pre-configured applications,
[0015] If the data has been read by all the pre-configured applications, writing the data starts from the start position of the shared memory;
[0016] If the data has not been read by all the pre-configured applications, writing the data starts from a location next to the last written location.
[0017] Based on the above steps, when performing a write operation, only the data packet currently received from the PLC side is written to the shared memory. When performing a read operation, all unread data in the shared memory is read at once. Therefore, each time a write operation is performed, it is only necessary to judge from the position of the last write operation, and decide whether to start writing from the starting position of the shared memory or from the next position based on the judgment result, which can improve the efficiency of the write operation.
[0018] Furthermore, the step of one or more applications preconfigured in the upper system reading the fast data from the shared memory area further includes:
[0019] Get the read semaphore;
[0020] detecting whether the fast data in the last written position and all positions before it have been read by the preconfigured application,
[0021] If it has been read by the preconfigured application, releasing the read semaphore;
[0022] If it has not been read by the preconfigured application, the preconfigured application reads the fast data in the current unread position and all previous positions, and releases the read semaphore after the stored data in the last written position and all previous positions have been read by the preconfigured application.
[0023] Based on the above steps, it is only necessary to determine whether all the previous data has been read by the application starting from the last write position. If the reading has been completed before the current read operation, the read semaphore is directly released. If the reading has not been completed before, the data at all previous positions needs to be read, thereby improving the efficiency of the read operation.
[0024] Furthermore, by querying the application data status table maintained in the shared memory, it is determined whether the fast data in the shared memory is read by the preconfigured application, wherein the rows of the application data status table correspond to different blocks into which the shared memory is divided starting from the starting position, and the columns correspond to the preconfigured applications in the upper system. Each cell of the application data status table is set with a status value, and the status value represents whether the preconfigured application corresponding to the cell has read the fast data in the block of the shared memory corresponding to the cell, and the status value includes "read" and "not read".
[0025] By setting up an application data status table and recording the application's reading status of data in a shared memory block through the status values of the cells in the table, it is convenient to make judgments before reading and writing, thereby improving the efficiency of data reading and writing.
[0026] Furthermore, an offset m is set, where the offset m indicates pointing to the m+1th row of the application data status table.
[0027] By using the offset m to correspond to the row in the application data status table, and then to the location of the shared memory block, it is convenient to record the location of the operation.
[0028] Furthermore, the step of the upper system writing the received fast data into the shared memory further includes:
[0029] Get the offset m of the last write;
[0030] Determine the status values of all cells in the m+1th row of the application data status table. When the status values of all cells in the m+1th row are "read",
[0031] The received fast data is stored in the block at the starting position of the shared memory, and the offset position m is modified to 0, the status values of all cells in the application data status table are modified to "unread", and the write semaphore is released.
[0032] Furthermore, the step of the upper system writing the received fast data into the shared memory further includes:
[0033] Get the offset m of the last write;
[0034] Determine the status values of all cells in the m+1th row of the application data status table. When the status values of all cells in the m+1th row are "unread",
[0035] Determine whether the offset m is greater than the number of rows in the application data status table - 1,
[0036] If it is not greater than, modify m=m+1, store the received fast data into the block of the shared memory corresponding to the row pointed to by the modified offset m, and set the status values of all cells in the row pointed to by the current offset m to "unread", and release the write semaphore.
[0037] Based on the above steps, when writing is required, first determine whether the data in the shared memory has been read by all applications. If it has not been read by all pre-configured applications, the stored data cannot be overwritten, and writing needs to continue after the last write position. Only when the data in the shared memory has been read by all applications can new data be rewritten to avoid overwriting unread data, thereby affecting the data continuity of applications that have not read the data. When judging, the position is recorded based on the offset m, which is convenient and efficient.
[0038] Furthermore, the step of one or more preconfigured programs in the upper system reading the fast data from the shared memory further includes:
[0039] Get the offset m of the last write;
[0040] Get the column number n where the preconfigured application is located;
[0041] Check and determine whether the status value of the cell in the m+1th row and nth column in the application data status table is "read", and if it is "read", modify the offset m=m-1;
[0042] Repeat the above steps until it is confirmed that the status values of the nth column of the application data status table from the row corresponding to the last write to the first row are all "read", and then release the read semaphore.
[0043] Furthermore, the step of one or more preconfigured programs in the upper system reading the fast data from the shared memory further includes:
[0044] Get the offset m of the last write position;
[0045] Get the column number n where the preconfigured application is located;
[0046] Check and determine whether the status value of the m+1th row and nth column in the application data status table is "read",
[0047] If it is "not read", read the fast data of the shared memory block corresponding to the current m+1th row, and modify the status value of the cell in the m+1th column n to "read", and modify the offset m=m-1;
[0048] Repeat the above steps until it is confirmed that the status values of the nth column of the application data status table from the row corresponding to the last write to the first row are all "read", and then release the read semaphore.
[0049] Based on the method of the above steps, when the application needs to read the shared memory, it determines whether all the data before the last write position has been read. If all of them have been read, the read semaphore is released to perform the next round of write operations. If not all of them have been read, they are read in sequence, and all the data from the last write position and the position before it are read. When making the judgment, the position is recorded based on the offset m, which is convenient and efficient.
[0050] According to a second aspect of the present invention, the present invention further provides a data sharing device, comprising:
[0051] A preprocessing module, the preprocessing module being used to preprocess the fast data on the PLC side and store the preprocessed fast data in a first buffer area on the PLC side;
[0052] a data sending module, configured to upload the fast data stored in the first buffer area to a host system;
[0053] A data writing module, wherein the data writing module writes the received fast data into the shared memory of the upper system;
[0054] A data reading module is used to enable one or more preconfigured applications in the host system to read the fast data from the shared memory.
[0055] Based on this data sharing device, data is shared between the PLC side and the upper system, which reduces the communication overhead caused by using industrial communication protocols to share data between the two, improves communication efficiency, increases throughput, and avoids data discontinuity caused by short-term communication interruptions.
[0056] According to a third aspect of the present invention, the present invention further provides a data sharing system, comprising:
[0057] a soft PLC, the soft PLC being deployed in a hardware platform and having a first buffer allocated thereto;
[0058] a Windows host system, wherein the Windows host system and the soft PLC are deployed on the same hardware platform, a shared memory is allocated to the Windows host system, and one or more application programs that can access the shared memory are pre-configured on the Windows host system;
[0059] a data sharing device, deployed on the hardware platform, for implementing data sharing between the soft PLC and the Windows host system;
[0060] An external data source device is connected to the hardware platform to provide fast data for the soft PLC.
[0061] Based on the shared data system of the above embodiment, a soft PLC and a host Windows system are integrated into one machine, and data sharing between the soft PLC and the host Windows system is realized on the same hardware platform, avoiding the inefficiency caused by using industrial communication protocols to exchange data between the two. At the same time, caches are set on both sides, so that multiple applications can read fast data more securely and are less likely to have problems such as missing data and wrong data.
[0062] Furthermore, the data sharing device further includes a preprocessing module, a data sending module, a data writing module and a data reading module, wherein the preprocessing module is used to preprocess the fast data on the PLC side and store the preprocessed fast data in the first cache area on the PLC side; the data sending module uploads the fast data stored in the first cache area to the upper system; the data writing module writes the received fast data into the shared memory of the upper system; and the data reading module is used to enable one or more preconfigured applications in the upper system to read the fast data from the shared memory.
[0063] Based on this data sharing device, the soft PLC and the upper Windows system can share the storage area without protocol, which reduces the communication overhead, improves the communication efficiency, increases the throughput, and avoids data discontinuity caused by short-term communication interruptions.
[0064] According to the data sharing method, device and system described above, based on the first-level cache set on the PLC side, the second-level cache of the upper system, and the non-protocol shared storage area between the first-level PLC side and the upper system, fast data sharing is achieved between the two, data throughput is improved, and the application program's reading of PLC data is maximized. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] The preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings so that those skilled in the art will be more aware of the above and other features and advantages of the present invention.
[0066] Figure 1 This is a connection diagram for sharing data between a PLC and a host computer in the prior art;
[0067] Figure 2 is a schematic diagram of sub-steps of a data sharing method according to one embodiment;
[0068] Figure 3 A schematic diagram of sub-steps of step S300 of writing the received fast data into the shared memory of the host system according to one embodiment;
[0069] Figure 4 A schematic diagram of sub-steps of step S400 of reading the fast data from the shared memory by one or more application programs pre-configured in the host system according to one embodiment;
[0070] Figure 5 A schematic diagram of a shared memory divided into blocks and a schematic diagram of an application data status table according to an embodiment;
[0071] Figure 6 is a schematic diagram of a data sharing device according to an embodiment;
[0072] Figure 7 FIG. 4 is a connection diagram of a data sharing system according to an embodiment.
[0073] In the attached figure:
[0074] 1PLC 2 Host system 3 Host computer
[0075] 5 Applications in the Industrial Bus 10 and 20 host systems
[0076] 30 Upper system shared memory 40 Application data status table 50 External data source device
[0077] 100 Pre-processing module 200 Data sending module 300 Data writing module
[0078] 400 Data reading module 500 Data sharing device 600 Hardware platform
[0079] S100: Preprocessing the fast data on the PLC side, and storing the preprocessed fast data in a first buffer area on the PLC side;
[0080] S200: Sending the fast data stored in the first buffer area to a host system;
[0081] S300: Writing the received fast data into the shared memory of the upper system;
[0082] S400: One or more applications preconfigured in the upper system read the fast data from the shared memory;
[0083] S310: Get write semaphore;
[0084] S320: Determine whether the fast data at the last written location has been read by all the pre-configured applications;
[0085] S321: Writing data from the starting position of the shared memory;
[0086] S322: Writing the data from a position next to the last written position;
[0087] S410: Get the read semaphore;
[0088] S420: Detect whether the fast data in the last written position and all previous positions thereof have been read by the preconfigured application.
[0089] S421: Release the semaphore of the pre-configured application;
[0090] S422: The preconfigured application reads the stored data in the current unread position and all preceding positions, and releases the read semaphore after the stored data in the last written position and all preceding positions have been read by the preconfigured application. DETAILED DESCRIPTION
[0091] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by those skilled in the art based on the embodiments in the embodiments of the present invention should fall within the scope of protection of the embodiments of the present invention.
[0092] Figure 1 This is a connection diagram for sharing data between a PLC and a host computer in the prior art;
[0093] like Figure 1As shown, in the prior art, one end of a PLC 1 is connected to an external data source device 50 for collecting real-time data. This device 50 can be a field data acquisition device or a data transfer device that provides field data. The other end of the PLC is connected to a host computer 3 via an industrial communication bus 5 such as Profibus or CAN, and communicates with the host computer 3 based on an industrial communication protocol such as OPC UA or Modbus. The PLC uploads the fast data from the field data source device 50 and its own generated data to the host computer 3 via the industrial communication bus. One or more application programs (10, 20) in the host computer 3 (such as LABVIEW) analyze, store, display, and forward the data.
[0094] This existing solution transmits and receives data between the PLC and the host computer based on the industrial communication protocol. When the data points change rapidly with the CPU scan cycle or bus cycle (Khz level, microsecond interval), it is easy to cause data accumulation, and the data points cannot be transmitted to the host computer in full and in chronological order.
[0095] In order to solve the above problems, the present invention provides a data sharing method.
[0096] Figure 2 FIG. 1 is a schematic diagram of sub-steps of a data sharing method according to an embodiment. Figure 2 As shown, a data sharing method according to an embodiment of the present invention includes:
[0097] S100: Preprocessing the fast data on the PLC side and storing the preprocessed fast data in a first buffer area on the PLC side;
[0098] Specifically, a first buffer area is opened on the PLC side, for example, by specifying a DB block on the PLC side as a buffer area, and a large amount of fast data collected by the PLC side or generated by itself is stored in the first buffer area after preprocessing.
[0099] The data preprocessing methods include extracting valid data segments, adding timestamps to the data, etc. Since the data preprocessing methods are already relatively mature technologies for those skilled in the art, those skilled in the art can define the preprocessing methods according to their needs, and the details will not be described here one by one.
[0100] Setting the first cache area on the PLC side as the first-level cache when the PLC side shares data with the host system is conducive to improving the efficiency of data sharing.
[0101] S200: Sending the fast data stored in the first buffer area to the host system;
[0102] S300: writing the received fast data into the shared memory of the upper system;
[0103] A certain size of shared memory is set in the upper system as a secondary cache. When the fast data on the PLC side is transmitted to the upper system, it can be temporarily stored in the shared memory, waiting to be read and used by the application in the upper system; the setting of this secondary cache further improves the data throughput and can coordinate the data discontinuity caused by short-term program communication interruptions.
[0104] In the above, the fast data stored in the first cache area is popped out in sequence according to the time tag and sent to the upper system. The size of the data sent at one time is equal to the block size of multiple blocks of the same size divided in the shared memory. The frequency of one transmission is not fixed and depends on the feedback on the completion of the processing result of the previous packet of data in the upper system.
[0105] The size of the shared memory in the upper system is set to, for example, an integer multiple of a data packet sent by the PLC side at one time, and the multiple can be adjusted to a suitable size according to the actual communication load.
[0106] S400: One or more applications preconfigured in the host system read fast data from the shared memory.
[0107] One or more applications that can read the shared memory are preconfigured in the host system. These applications include, for example, third-party applications that can call dynamic link library interface functions, as well as custom applications, including but not limited to LabVIEW. These applications read the shared memory data through the application interface in the host system. Multiple preconfigured applications can simultaneously perform read operations.
[0108] Based on the data sharing method of the above embodiment, a first-level cache is set on the PLC side and a second-level cache is set in the upper system to realize protocol-free shared storage area between the PLC side and the upper system, thereby reducing communication overhead, improving communication efficiency, improving throughput, and avoiding data discontinuity caused by short-term communication interruptions.
[0109] It should be noted that there is no strict order requirement for the above steps. In actual applications, the order may be reversed, for example, S400 is executed first, and then S200 and S300 are executed synchronously. Various combinations of situations are not described here one by one.
[0110] Further, the fast data stored in the first buffer area is sent to the upper system based on an intermediate program, and the received fast data is written into the shared memory of the upper system based on the intermediate program;
[0111] The intermediate program is, for example, SIMATIC ODK.
[0112] SIMATIC ODK is a development kit. When the intermediate program is SIMATIC ODK, SIMATIC ODK establishes corresponding data transmission and reception services between the PLC and the host system, enabling data communication between the two. Specifically, the three SIMATIC ODK function blocks LoadFB, UnloadFB, and Funs are activated on the PLC side. LoadFB is called once in the PLC startup block to prepare the data transmission prerequisites. Triggering this block generates an executable program in the host system that calls the corresponding dynamic link library. UnloadFB triggers the destruction of the data transmission conditions, terminating the executable program of the corresponding dynamic link library. Funs is a data interface program that completes a data transfer to the host system by triggering this program. After LoadFB is successfully executed, the Funs program is periodically triggered. The Funs program includes three pins: Funs.REQ, Funs.Status, and Funs.Done, which respectively trigger data transfer requests, check data transfer status, and complete data transfers. Correspondingly, the host system sets up corresponding ODK application function interfaces, such as ODK Load / Unload / Funs. In addition, there is an ODK Onrun / Stop function interface for calling when the PLC is running or stopping. The ODK Fun in the host system corresponds to the Funs on the PLC side to receive data from the PLC side. ODK interfaces can have multiple groups. For example, one group of interfaces (Load / Unload / Funs) is used to share data content with some applications, and another group of interfaces (Load / Unload / Funs) is used to share data content with other applications and open up a new shared memory area. Of course, the data can also be pre-processed on the PLC side to organize different contents together.
[0113] By setting up intermediate programs on the PLC side and the host system side respectively, and realizing data sharing between the PLC side and the host system side based on the intermediate programs, the efficiency of data transmission and data reception is improved without going through the industrial communication protocol.
[0114] Furthermore, sending the fast data stored in the first buffer area to the upper system includes: sending a data transmission request, and transmitting the fast data in the first buffer area to the upper system.
[0115] After the fast data in the first buffer area is transmitted to the upper system, whether the data transmission is successful is monitored. For example, if the transmission is successful, a success signal Funs.Done is returned, and if it fails, an error signal is reported.
[0116] If the return result is successful, determine whether the remaining data in the first buffer area on the PLC side is sufficient. If so, pop the data in the PLC data buffer area, offset the address of the PLC data buffer area, and wait for a new round of data sending request to be triggered; if the remaining data in the PLC data buffer area is not sufficient, return to the timeout status.
[0117] Further, Figure 3 The sub-step diagram of step S300 of writing the received fast data into the shared memory of the host system according to one embodiment is as follows: Figure 3 As shown, step S300 of writing the received fast data into the shared memory of the host system further includes the following sub-steps:
[0118] S310: Get write semaphore;
[0119] Specifically, semaphore is a technology for realizing mutually exclusive execution of threads. In the present invention, control of mutual exclusion of reading and writing is realized by semaphore. When a pre-configured application needs to read the shared memory data of the upper system, the reading application attempts to obtain the semaphore. After obtaining the semaphore, if a write operation is to be performed at this time, that is, the fast data transmitted from the PLC side needs to be stored in the shared memory, it will fail due to the inability to obtain the semaphore; when a write operation is to be performed, the write operation program attempts to obtain the semaphore. After obtaining the semaphore, if the pre-configured application wants to read the data in the shared memory, it will fail due to the inability to obtain the semaphore.
[0120] S320: Determine whether the fast data at the last written location has been read by all pre-configured applications.
[0121] If it has been read by all pre-configured applications, then step S321 is executed: writing data from the start position of the shared memory;
[0122] If the data has not been read by all pre-configured applications, step S322 is executed: writing data starts from the position next to the last written position.
[0123] Based on the above steps, when performing a write operation, only the data packet currently received from the PLC side is written to the shared memory. When performing a read operation, all unread data in the shared memory is read at once. Therefore, each time a write operation is performed, it is only necessary to judge from the position of the last write operation, and decide whether to start writing from the starting position of the shared memory or from the next position based on the judgment result, which can improve the efficiency of the write operation.
[0124] It should be noted that it is necessary to determine whether all pre-configured applications have read the location of the last write operation. If only one or some applications have read it, a new write operation cannot be performed directly, because this will overwrite the data, causing the application that has not read the data to be unable to read the data, resulting in data loss.
[0125] Furthermore, step S310 includes: determining whether the memory is occupied by a reading program,
[0126] If it has been occupied by the reading program, determine whether it has timed out.
[0127] If the judgment result is timeout, the program will alarm timeout;
[0128] If the result is that the timeout has not occurred, the program will return to the "Busy" state;
[0129] If it is not occupied by the reading program, execute step S320;
[0130] Furthermore, according to another embodiment of the present invention, before executing subsequent S320, a shared memory mapping needs to be created. By creating a shared memory mapping to the writer's private address space, the shared memory can be operated. For a host system, such as a Windows system, the shared memory is physically overlapped for different applications and logically isolated between processes. That is, each application needs to create its own private space to operate the physical shared memory space.
[0131] Further, Figure 4 This is a schematic diagram of sub-steps of step S400 of reading fast data from a shared memory in one or more pre-configured applications in a host system according to an embodiment, as shown in FIG. Figure 4 As shown, the sub-steps of S400 include:
[0132] Step S410: obtaining a read semaphore;
[0133] Specifically, the preconfigured application attempts to obtain the semaphore. If no write operation is currently being performed, that is, the semaphore is not occupied by a write program, the preconfigured application obtains the read semaphore.
[0134] It should be noted that multiple pre-configured applications can perform read operations at the same time.
[0135] Step S420: Detect whether the fast data in the last written position and all previous positions have been read by the pre-configured application.
[0136] If it has been read by the pre-configured application, then step S421 is executed: releasing the read semaphore;
[0137] If it has not been read by the preconfigured application, step S422 is executed: the preconfigured application reads the fast data in the current unread position and all the positions before it, and releases the read semaphore after the stored data in the last written position and all the positions before it have been read by the preconfigured application.
[0138] Based on the above steps, it is only necessary to determine whether all the previous data has been read by the application starting from the last write position. If the reading has been completed before the current read operation, the read semaphore is directly released. If the reading has not been completed before, the data at all previous positions needs to be read, thereby improving the efficiency of the read operation.
[0139] Furthermore, step S410 further includes: determining whether a semaphore exists,
[0140] If the semaphore does not exist, create it;
[0141] If there is a semaphore, determine whether it is occupied by the program being written.
[0142] If it has been occupied by the writing program, then determine whether it has timed out.
[0143] If the judgment result is timeout, the application program will alarm timeout;
[0144] If the judgment result is not timed out, then randomly back off;
[0145] If it is not occupied by other programs, proceed to the subsequent step S420;
[0146] It can be seen that the semaphore is created when the application is preconfigured. When writing, all semaphores need to be acquired at the same time and released after writing. When performing a read operation, only the application that needs to perform the read operation needs to acquire the semaphore, and the semaphore will be released after the read operation is completed.
[0147] Furthermore, before executing the subsequent step S420 , a shared memory mapping needs to be created, and the shared memory is mapped to the private address space of the application program so as to operate on the shared memory.
[0148] Furthermore, by querying the application data status table maintained in the shared memory, it is determined whether the fast data in the shared memory is read by the preconfigured application, wherein the rows of the application data status table correspond to different blocks into which the shared memory is divided starting from the starting position, and the columns correspond to the preconfigured applications in the upper system. Each cell of the application data status table is set with a status value, and the status value represents whether the preconfigured application corresponding to the cell has read the fast data in the block of the shared memory corresponding to the cell, and the status values include "read" and "not read".
[0149] Specifically, Figure 5 Schematic diagram of a shared memory 30 divided into blocks and a schematic diagram of an application data status table 40 according to an embodiment; Figure 5 As shown, the shared memory 30 in the upper system for storing data from the PLC side is divided into M blocks, for example, M=6, and the size of each block is adapted to the size of the data received from the PLC side at one time. For example, each block is set to 1000 bytes, and the size of the data received from the PLC side at one time is also 1000 bytes; at the same time, N applications are pre-set in the upper system, for example, N=3, and these applications can read the PLC data by accessing the blocks of the shared memory 30. Correspondingly, an M*N, i.e., 6*3, two-dimensional application data status table 40 is maintained in the shared memory 30. The first row in the application data status table 40 corresponds to the first segment block at the starting position of the shared memory 30, the second row corresponds to the second segment block with the address shifted backward, and the address of the shared memory block corresponding to the second row is the starting address of the shared memory 30 + 1000 bytes. And so on, the address of the shared memory block corresponding to the mth row is the starting address of the shared memory 30 + (m-1)*1000 bytes... The first column in the application data status table 40 corresponds to the preconfigured first application, the second column corresponds to the preconfigured second application, and the third column corresponds to the preconfigured third application; each cell is set with a status value, and the status value variable is used to indicate whether the preconfigured application corresponding to the column of the cell has read the fast data in the block of the shared memory 30 corresponding to the row of the cell, and the status values include "read" and "not read".
[0150] When data is transmitted from the PLC side to the upper system and stored in a block of shared memory, since the data in the shared memory is shared by all pre-configured applications, the status values of all cells in the row corresponding to the block in the two-dimensional table are set to "unread". When an application reads the block of shared memory, the status value of the cell in the corresponding column of the application in the table that intersects with the corresponding row of the shared memory block is set to "read". The status value of the cell in the corresponding column of other applications in the same row remains "unread" until other applications also read the data of the block.
[0151] By setting up an application data status table and recording the application's reading status of data in a shared memory block through the status values of the cells in the table, it is convenient to make judgments before reading and writing, thereby improving the efficiency of data reading and writing.
[0152] Furthermore, an offset m is set, where the offset m indicates that the current pointer points to the m+1th row of the application data status table.
[0153] Specifically, by default, m=0. When it is necessary to query in sequence whether the data in the shared memory block has been read, starting from the first row, each row of the application data status table is judged in sequence. After each row is judged, m is automatically increased by 1; based on the current offset value m, the corresponding block in the shared memory is found, and then the data in the block is read or written.
[0154] By using the offset m to correspond to the row in the application data status table, and then to the location of the shared memory block, it is convenient to record the location of the operation.
[0155] Furthermore, the step of writing the received fast data into the shared memory by the upper system further includes, after obtaining the write semaphore:
[0156] Get the offset m of the last write;
[0157] Determine the status values of all cells in the m+1th row of the application data status table. When the status values of all cells in the m+1th row are "read",
[0158] The received fast data is stored in the block at the start position of the shared memory, and the offset position m is modified to 0, the status values of all cells in the application data status table are modified to "unread", and the write semaphore is released.
[0159] Furthermore, the step of writing the received fast data into the shared memory by the upper system further includes, after obtaining the write semaphore:
[0160] Get the offset m of the last write;
[0161] Determine the status values of all cells in the m+1th row of the application data status table. When the status values of all cells in the m+1th row are "unread",
[0162] Determine whether the offset m is greater than the number of rows in the application data status table - 1,
[0163] If it is not greater, modify m=m+1, store the received fast data into the block of shared memory corresponding to the row pointed to by the modified offset m, and set the status values of all cells in the row pointed to by the current offset m to "unread", and release the write semaphore.
[0164] Based on the above steps, when writing is required, first determine whether the data in the shared memory has been read by all applications. If it has not been read by all pre-configured applications, the stored data cannot be overwritten, and writing needs to continue after the last write position. Only when the data in the shared memory has been read by all applications can new data be rewritten to avoid overwriting unread data, thereby affecting the data continuity of applications that have not read the data. When judging, the position is recorded based on the offset m, which is convenient and efficient.
[0165] Furthermore, the step of one or more preconfigured programs in the upper system reading fast data from the shared memory, after obtaining the read semaphore, further includes:
[0166] Get the offset m of the last write;
[0167] Get the column number n where the preconfigured application is located;
[0168] Check and determine whether the status value of the cell in the m+1th row and nth column in the application data status table is "read". If it is "read", modify the offset m=m-1;
[0169] Repeat the above steps until it is confirmed that the status values of the nth column of the application data status table from the row corresponding to the last write to the first row are all "read", and then release the read semaphore.
[0170] Furthermore, the step of one or more preconfigured programs in the upper system reading fast data from the shared memory, after obtaining the read semaphore, further includes:
[0171] Get the offset m of the last write position;
[0172] Get the column number n where the preconfigured application is located;
[0173] Check and determine whether the status value of the m+1th row and nth column in the application data status table is "read".
[0174] If it is "not read", read the fast data of the shared memory block corresponding to the current m+1th row, and modify the status value of the cell in the m+1th column n to "read", and modify the offset m=m-1;
[0175] Repeat the above steps until it is confirmed that the status values of the nth column of the application data status table from the row corresponding to the last write to the first row are all "read", and then release the read semaphore.
[0176] Based on the method of the above steps, when the application needs to read the shared memory, it determines whether all the data before the last write position has been read. If all of them have been read, the read semaphore is released to perform the next round of write operations. If not all of them have been read, they are read in sequence, and all the data from the last write position and the position before it are read. When making the judgment, the position is recorded based on the offset m, which is convenient and efficient.
[0177] According to the second aspect of the present invention, the present invention also provides a data sharing device, including: a preprocessing module, a data sending module, a data writing module and a data reading module, wherein the preprocessing module is used to preprocess the fast data on the PLC side, and store the preprocessed fast data in the first cache area on the PLC side; the data sending module uploads the fast data stored in the first cache area of the PLC module to the upper system; the data writing module writes the received fast data into the shared memory of the upper system; the data reading module is used to enable one or more preconfigured programs in the upper system to read the fast data from the shared memory.
[0178] Figure 6 FIG. 1 is a schematic diagram of a data sharing device according to an embodiment; FIG. Figure 6 As shown, the data sharing device 500 includes a pre-processing module 100, a data sending module 200, a data writing module 300, and a data reading module 40. Based on the data sharing device 500, the PLC side and the host system share a storage area without a protocol, which reduces communication overhead, improves communication efficiency, increases throughput, and avoids data discontinuity caused by short-term communication interruptions.
[0179] According to the third aspect of the present invention, the present invention also provides a data sharing system including: a soft PLC, a host Windows system, a data sharing device and an external data source device, the soft PLC is deployed in a hardware platform 6, and a first cache area is allocated to the soft PLC; an upper Windows system, the upper Windows system and the soft PLC are deployed in the same hardware platform, shared memory is allocated to the upper Windows system, and the upper Windows system is pre-configured with one or more applications that can access the shared memory; a data sharing device, the data sharing device is deployed on the hardware platform, and is used to realize data sharing between the soft PLC and the upper Windows system; the external data source device, the external data source device is connected to the hardware platform to provide fast data for the soft PLC.
[0180] Figure 7 FIG. 1 is a connection diagram of a data sharing system according to an embodiment, as shown in FIG. Figure 7The shared data system shown includes a hardware platform 600 and an external data source device 50, and the external data source device 50 and the hardware platform 600 are connected and communicated via an industrial bus 5 such as PROFINET; the external data source device 50 is, for example, a field device, or a transit device that provides field data; the hardware platform 600 is built with an IPC of an underlying software platform, and the underlying software platform is, for example, a Siemens hypervisor, and the soft PLC1 and the upper Windows system 2 are integrated and set on the underlying software platform of the hardware platform 600; a first cache area is set for the soft PLC, and a shared memory is set for the upper Windows system, wherein the soft PLC1 is, for example, a SIMATIC 1500 soft controller, and the upper Windows system is pre-configured with one or more applications that can access the shared memory, and the application is, for example, Labview.
[0181] A data sharing device 500 is installed on the hardware platform 600 , and the device is connected to the soft PLC and the upper Windows system respectively. Data sharing between the soft PLC 1 and the upper Windows system 2 is realized based on the data sharing device.
[0182] Based on the shared data system of the above embodiment, a soft PLC system and a host Windows system are integrated into one machine, and fast data sharing between the two systems is achieved through a data sharing device, avoiding the inefficiency caused by using industrial communication protocols to exchange data between the two. At the same time, caches are set on both sides, so that multiple applications can read fast data more securely and are less likely to have problems such as missing data and wrong data.
[0183] Furthermore, the data sharing device 500 further includes a preprocessing module 100, a data sending module 200, a data writing module 300 and a data reading module 400, wherein the preprocessing module 100 is used to preprocess the fast data on the PLC side and store the preprocessed fast data in the first buffer area on the PLC side; the data sending module 200 uploads the fast data stored in the first buffer area to the upper system; the data writing module 300 writes the received fast data into the shared memory of the upper system; the data reading module 400 is used to enable one or more preconfigured applications in the upper system to read the fast data from the shared memory.
[0184] Based on the data sharing device 500, the soft PLC and the upper Windows system can share storage areas without protocol, which reduces communication overhead, improves communication efficiency, increases throughput, and avoids data discontinuity caused by short-term communication interruptions.
[0185] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A data sharing method, characterized in that: include: S100: Preprocessing the fast data on the PLC side, and storing the preprocessed fast data in a first buffer area on the PLC side; S200: sending the fast data stored in the first buffer area to a host system based on an intermediate program; S300: writing the received fast data into the shared memory of the upper system based on the intermediate program; S400: One or more pre-configured programs in the host system read the fast data from the shared memory; The step S300 of writing the received fast data into the shared memory of the host system further includes: S310: Get write semaphore; S320: Determine whether the fast data at the last written location has been read by all pre-configured applications. If the data has been read by all the pre-configured applications, writing the data starts from the start position of the shared memory (S321); If the data has not been read by all the pre-configured applications, writing the data starts from a position next to the last written position (S322).
2. The data sharing method according to claim 1, wherein: The step S400 of one or more pre-configured applications in the upper system reading the fast data from the shared memory area further includes: S410: Get read semaphore; S420: Detect whether the fast data in the last written position and all previous positions have been read by the pre-configured application. If it has been read by the pre-configured application, releasing the read semaphore (S421); If it has not been read by the preconfigured application, the preconfigured application reads the fast data in the current unread position and all previous positions, and releases the read semaphore after the storage data in the last written position and all previous positions have been read by the preconfigured application (S422).
3. A data sharing method according to claim 2, characterized in that: Whether the fast data in the shared memory has been read by the preconfigured application is determined by querying the application data status table maintained in the shared memory, wherein the rows of the application data status table correspond in sequence to different blocks into which the shared memory is divided starting from the starting position, and the columns correspond to the preconfigured applications in the upper system. Each cell of the application data status table is provided with a status value, and the status value indicates whether the preconfigured application corresponding to the cell has read the fast data in the block of the shared memory corresponding to the cell, and the status value includes "read" and "not read".
4. A data sharing method according to claim 3, characterized in that: An offset m is set, where the offset m indicates pointing to the m+1th row of the application data status table.
5. A data sharing method according to claim 4, characterized in that: The step S300 in which the host system writes the received fast data into the shared memory further includes: Get the offset m of the last write; Determine the status values of all cells in the m+1th row of the application data status table. When the status values of all cells in the m+1th row are "read", The received fast data is stored in the block at the starting position of the shared memory, and the offset position m is modified to 0, the status values of all cells in the application data status table are modified to "unread", and the write semaphore is released.
6. A data sharing method according to claim 4, characterized in that: The step S300 in which the host system writes the received fast data into the shared memory further includes: Get the offset m of the last write; Determine the status values of all cells in the m+1th row of the application data status table. When the status values of all cells in the m+1th row are "unread", Determine whether the offset m is greater than the number of rows in the application data status table - 1, If it is not greater than, modify m=m+1, store the received fast data into the block of the shared memory corresponding to the row pointed to by the modified offset m, and set the status values of all cells in the row pointed to by the current offset m to "unread", and release the write semaphore.
7. A data sharing method according to claim 6, characterized in that: The step S400 of one or more pre-configured programs in the upper system reading the fast data from the shared memory further includes: Get the offset m of the last write; Get the column number n where the preconfigured application is located; Check and determine whether the status value of the cell in the m+1th row and nth column in the application data status table is "read", and if it is "read", modify the offset m=m-1; Repeat the above steps until it is confirmed that the status values of the nth column of the application data status table from the row corresponding to the last write to the first row are all "read", and then release the read semaphore.
8. A data sharing method according to claim 4, characterized in that: The step S400 of one or more pre-configured programs in the upper system reading the fast data from the shared memory further includes: Get the offset m of the last write position; Get the column number n where the preconfigured application is located; Check and determine whether the status value of the m+1th row and nth column in the application data status table is "read", If it is "not read", read the fast data of the shared memory block corresponding to the current m+1th row, and modify the status value of the cell in the m+1th column n to "read", and modify the offset m=m-1; Repeat the above steps until it is confirmed that the status values of the nth column of the application data status table from the row corresponding to the last write to the first row are all "read", and then release the read semaphore.
9. A data sharing device (500), characterized in that: include: A preprocessing module (100), the preprocessing module (100) being used to preprocess the fast data on the PLC side and store the preprocessed fast data in a first buffer area on the PLC side; A data sending module (200), wherein the data sending module (200) uploads the fast data stored in the first buffer area to a host system based on an intermediate program; A data writing module (300), wherein the data writing module (300) writes the received fast data into the shared memory of the upper system based on the intermediate program; A data reading module (400), the data reading module (400) is used to enable one or more pre-configured applications in the host system to read the fast data from the shared memory; The data writing module (300) further performs the following operations: S310: Get write semaphore; S320: Determine whether the fast data at the last written location has been read by all pre-configured applications. If the data has been read by all the pre-configured applications, writing the data starts from the start position of the shared memory (S321); If the data has not been read by all the pre-configured applications, writing the data starts from a position next to the last written position (S322).
10. A data sharing system, characterized in that: include: A soft PLC (1), the soft PLC (1) being deployed in a hardware platform (600), and a first buffer area being allocated to the soft PLC (1); a Windows host system (2), wherein the Windows host system (2) and the soft PLC (1) are deployed on the same hardware platform (600), a shared memory is allocated to the Windows host system (2), and one or more application programs (10, 20) that can access the shared memory are pre-configured on the Windows host system (2); a data sharing device (500), the data sharing device (500) being deployed on the hardware platform (600) and being used to realize data sharing between the soft PLC (1) and the Windows host system (2); An external data source device (50), the external data source device (50) being connected to the hardware platform (600) and providing fast data to the soft PLC (1); The data sharing device (500) further comprises a pre-processing module (100), a data sending module (200), a data writing module (300) and a data reading module (400), wherein the pre-processing module (100) is used to pre-process the fast data on the PLC side and store the pre-processed fast data in a first buffer area on the PLC side; the data sending module (200) uploads the fast data stored in the first buffer area to the upper system based on an intermediate program; the data writing module (300) writes the received fast data into the shared memory of the upper system based on the intermediate program; the data reading module (400) is used to enable one or more pre-configured programs in the upper system to read the fast data from the shared memory; wherein the data writing module (300) further performs the following operations: S310: Get write semaphore; S320: Determine whether the fast data at the last written location has been read by all pre-configured applications. If the data has been read by all the pre-configured applications, writing the data starts from the start position of the shared memory (S321); If the data has not been read by all the pre-configured applications, writing the data starts from a position next to the last written position (S322).
Citation Information
Patent Citations
Open type numerical control system based on PC
CN101196738A
Method for realizing rapid data acquisition
CN102413035A