Embedded Soft PLC Virtual Machine Applied in Electrical Testing (2)

October 28, 2018


The runtime system runs on a variety of supported platforms. It separates the data area from the code area, enabling dynamic updates of programs and efficient dynamic downloading of code.

(1) Implementation of soft PLC virtual machine implementation steps on μClinux platform

    Translating instructions of the ladder diagram into macro assemblies and creating a macro library;

    Compiling a user-written ladder program into a PLM file in the form of an intermediate code;

    Convert a PLM file into an assembler;

    Assemble the successful assembler with the assembler, convert the execution internal instruction (PLM file) into a program, assemble it into machine code execution, realize the PLC instruction machine code execution scheme, greatly improve the execution speed, and greatly save the memory space. ;

    The machine code corresponding to the PLC instruction is transplanted to the embedded operating system for execution.

(2) Two modules of the operating system
The operating system is mainly composed of two major modules: 1) conversion of ladder diagram to machine code program; 2) execution of machine code file. The function of each module is as follows:

1) Conversion of ladder diagram to machine code program. First, the user-written ladder program is compiled into a PLM file in the form of intermediate code, then the PLM file is converted into an assembler, and finally the assembler is successfully assembled by the assembler, and the machine code is generated to generate an executable PLE file.

2) Execute the machine code file. The PLE file is embedded in the configured execution environment and executed, and the correctness of the program is monitored by the panel indicator of the industrial computer.

(3) Overall design of virtual machine
According to the principle and execution mechanism of the virtual machine, the overall design of the machine code execution scheme of the virtual machine is performed, as shown in FIG. The PLC file is a saved file of the ladder program. The PLM file is generated by lexical analysis, syntax analysis and semantic analysis of the PLC file, then the macro assembly library is called, and a series of conversions are generated to generate the machine code to generate the PLE file; The machine running environment executes the machine code, and the macro assembly library is a macro assembly segment corresponding to each ladder instruction.


Figure 3 Virtual operation overall design block diagram

(4) Research on cross-development and debugging algorithms
Non-embedded usually adopts the development mode of native development, native debugging, and native operation; while embedded development requires cross-development, most of them adopt host development, cross debugging between host and target, and target operation. Way to develop.

Cross development debugging algorithm:

    Writing program code on the host platform;

    Curing the monitor to the target machine;

    Connect the host machine and the target machine;

    Compile the link application to generate executable code;

    Download the executable code to the target machine;

    Use the cross debugger for debugging;

    If the program debugging does not find an exception, go to 11);

    An error occurred while debugging the program, using the cross debugger to locate the error;

    Modify the error code;

    Repeat 4)-10);

    The target program is solidified on the target machine.

    Previous page next page