# Petri Net-Based Semi-Compiled Code Generation for Programmable Logic Controllers
## 5 Conclusions and Future Work  
A novel application-independent and platform-independent methodology for implementing PNs in PLCs has been shown, in which most of the code is validated according to PN model structural analysis prior to implementation. Only net interpretation is manually coded and error-prone in the proposed approach, making it possible to generate PN-based code for PLC in a simple way. In comparison with previous work in the area of interest of this paper, analyzed in Section 1, the implementation (Section 3) of the proposed algorithm (Section 2) reveals the following:  
* A PN is designed and formally analyzed, and the matrices representing its structure are obtained through a free license software tool, and these matrices are transferred to data memory of devices from different vendors. Thus, net structure is validated automatically before net implementation. * Fixed program blocks, independent of both PLC and PN, manage net marking evolution, using the above-mentioned data structure. This is why the approach can be considered semi-compiled. ST programming makes this part standard. * Consequently, the workload in terms of coding is reduced to associating conditions to transitions and actions to places, i.e., PN interpretation. It can be added in any language supported by the corresponding environment. These points are based on the results achieved and already shown in Section 4:
* The scan cycle time required by the algorithm does not differ from that of similar, fully interpreted approaches, i.e., with both net marking and net interpretation management integrated into the code itself. * The portability to the desired PLC is simple and not time-consuming. As far as the code is concerned, fixed program block contents are directly transferred. Regarding variables in data memory, it is necessary to declare and initialize those required for the algorithm to work. Arrays representing net structure are generated in a PN design and simulation software, and adapted by a proprietary parser software to PLC particular variables definition and initialization. It is considered that the contribution of the work presented in this paper may have these implications:
* PN-based automated industrial systems are implemented in a simple way, with a reduced programming workload and, consequently, fewer potential errors in the control device code. The inclusion or modification of a PN is simple, requiring editing, validation, and transfer of new data into the PLC. * The way to manage several nets (associated with respective subsystems) is to do it as a single one (as a single system), in which some arcs are considered to be zero weight. User-defined data types can be used if larger matrices are required than the limit set by the development tool. * For technicians used to working with GRAFCET, the paradigm shift to a PN-based approach is not a handicap. Similar modeling skills are needed. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Implementation** & **CPU: Siemens 1521C-1 PN** & **CPU: Omron NX102-1020** \\ \hline PN & 1.029 ms & 0.285 ms \\ ST & 1.035 ms & 0.276 ms \\ LD & 1.130 ms & 0.283 ms \\ SFC & 1.361 ms & - \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Measured scan cycle periods. Note that the system under study has made it possible to test the algorithm by applying it in a case present in literature as suitable for the application of PNs. Shared resources and multiple marking make it more demanding for a GRAFCET-based approach. The existence of tokens (\(\textbf{N}=\{0,1,2,...\}\)) in a place in a PN versus states (bool) of steps in a GRAFCET, gives the former the capability to integrate the system's characterization into the model's structure, against further coding work in the latter. The use of a DT of the process has allowed the testing of the algorithm without availability of the necessary equipment, reproducing scenes difficult to assemble or reproduce.