Acceso a POU

Descripción general

En los siguientes ejemplos se muestra cómo imprimir y manipular el código de una POU. Solo están disponibles para lenguajes de programación textual.

Ejemplo de Script Engine

if not projects.primary:
    print('No primary project set')
 
proj = projects.primary
pou = proj.find('SR_Main', True)[0]
 
# read and print the declaration of the program
decl = pou.textual_declaration
print(decl.text)
 
# read and print the implementation of the program
code = pou.textual_implementation
print(code.text)
 
decl_text = "PROGRAM SR_Main\n" + \
            "VAR\n" + \
            "  iTest: INT;\n" + \
            "END_VAR";
 
code_text = "iTest := iTest + 1;"
 
# write new code to the declaration and implementation
decl.replace(decl_text)
code.replace(code_text)

Ejemplo de Script Engine de una API de set_interface_text() obsoleta

if not projects.primary:
    print("No primary project set")
 
proj = projects.primary
pou = proj.find('SR_Main', True)[0]
 
# read and print the declaration of the program
decl = pou.get_interface_text()
print(decl)
 
# read and print the implementation of the program
code = pou.get_implementation_text()
print(code)
 
decl = "PROGRAM SR_Main\n" + \
       "VAR\n" + \
       "  iTest: INT;\n" + \
       "END_VAR";
code = "iTest := iTest + 1;"
 
# write new code to the declaration and implementation
pou.set_interface_text(decl)
pou.set_implementation_text(code)