## 3 Results
### Description of Developed Software Tool: \"PetriNet editor + PetriNet engine\"
#### 3.1.2 Application Layer--PetriNet Engine  
The result of the first part of the implementation was the graphical interface providing the in Petri nets modelling functionality. The application layer of the program system (called PetriNet engine) provides conversion of the modelled Petri net to the program code realising control of the discrete event system. The PetriNet engine is the very core of the program enabling to generate a control algorithm. The editor generates a C++ code with regard to specifics of the Arduino platform. The code generation emulates creation of a regular project for the Arduino IDE consisting of two phases. In the first phase, all the necessary.h and.cpp files are collected, which are pre-prepared and are part of the project. These files contain, for example, definitions of the Place, Transition, Arc, and FiringScheduler classes. In the second phase, the main.ino file of the project is created on the basis of the currently modelled Petri net. Because the creation of an.ino file is dynamic, a general template is used in which the generator writes the necessary code lines in the specified places (Figure 7). Figure 6: GUI of developed extension of PNEditor named PetriNet editor. The _StrSubstitutor_ library from Apache is used to work with the template. All necessary information about the net status and settings for Arduino are stored in the Subnet and ArduinoManager objects. The resulting generation status, the code itself and all error messages are displayed in the log window in the PetriNet editor. After a successful preparation of the whole necessary source code, this code can be uploaded to Arduino directly from the editor. The generated files are a full-fledged project for the Arduino IDE and it is possible to open and edit them in an external program. The compilation and upload of the code is performed using the _AvrDude_ program. _AvrDude_ is a utility for working with the contents of ROM and EEPROM memories of AVR microcontrollers. _AvrDude_ is part of the Arduino IDE program by default. All statements and information messages created by _AvrDude_ are captured and displayed in the PetriNet editor log window. In addition, the total time of compilation and upload of the project to Arduino is calculated and displayed. The PetriNet editor stores Petri net information in an XML file. New elements were added to the existing XML structure of the original PNEdiror output. On the global level of the XML Petri net structure, the arduinoManager element was added to store information about the board type, serial port number, selected time policy and transition fire strategy, and some other information about the compilation and upload process. Each place and transition associated with an Arduino includes additional information in the arduinoNodeExtension element e.g.the pin number, the type of performed function and some other parameters. An example is shown in Figure 8.  
In the PetriNet editor, it is possible to create two types of places and transitions--places and transitions associated with an Arduino pin, and places and transitions without association. This latter option has been retained for the sake of a greater flexibility in net modeling. Transitions of both types support time information. The time assigned to a transition can be deterministic or stochastic. The PetriNet editor is used just for graphical modelling of the Petri net and does not implement any logic; the logic is implemented in the PetriNet engine--the second part of the presented solution. The design of the proposed prototype application able to implement the logic of Petri nets has faced several challenges in terms of functionality and possible scalability supported by new Petri nets aspects:  
* mapping of a formal Petri net model into an object language,
* definition of an appropriate transition firing mechanism to ensure consistency and parallelism throughout the start-up period of the net,
* conflict resolution in several possible executable transitions,  
Figure 7: Template of.ino file.