Executing Scripts

You can control e!COCKPIT using Python scripts.

Note

Information and references to the Python scripting language

Literature/Internet
For general information and references to the Python scripting language, please refer to the relevant literature and the Internet.

CODESYS Online help
You can also find a quick guide for using scripts in the CODESYS online help (keyword “Python”).

API Reference of Python Commands
Additional information on the API reference of Python commands:
The “ScriptEngine.chm” help file for the scripting commands is not implemented in the online help, but is available in the CODESYS installation directory (“\WAGO Software\e!COCKPIT\3S CODESYS\CODESYS\Online Help\de\”). The help file contains the Python reference from CODESYS which has been expanded by an e!COCKPIT -specific reference. If you work with Python, use the e!COCKPIT -specific commands. If there is no e!COCKPIT -specific command for a required function, use the default CODESYS commands. Both commands are described in the API reference.

Sample Projects
The Backstage view, page “Help” > [Links] > [Sample Projects] has sample scripts for different use cases in e!COCKPIT.
You can find a short description of the example scripts after the following steps.

Execute Python scripts from a command line or the user interface.

Command line

  1. Open the Windows command line:
    Click the Start Menu ([Start]) or the [Windows button] + [R].
  2. Enter “cmd” in the input field.
  3. The command line opens.
  4. Python scripts are called up as follows::
    e!COCKPIT.exe --runscript=“<scriptfile>.py” --scriptargs:‘<arg1> <arg2> ... <argn>’ –enablescripttracing
    The two parameters below are optional:
    -- scriptargs:‘argument1 argument2’: Arguments are passed to the script.
    -- enablescripttracing: Script-tracing is turned on.
  5. Execute the Python script, e.g.:
    “e!COCKPIT.exe’ --runscript=“C:\CTemp\test.py” –enablescripttracing

e!COCKPIT user interface

  1. Open the “FILE” tab in the e!COCKPIT user interface.
  2. Open the “Scripting” page.
  3. To select and execute a Python script file (*.py) on your PC, click [Execute script file].
  4. To output all commands within a Python script to the message window and to save them in the Python script log file, click [Enable script-tracing]. The button label changes to “Disable script-tracing”. Click the button again to end the trace function.
  5. To open the Python script log file, click [Open SCRIPT log file].

Using Example Scripts

e!COCKPIT provides example scripts via the backstage view. You can access the scripts either through the “Help” page > [Links] > [Example Projects] > Python Scripting or through the “Open” page > [Example Applications] > Python Scripting.

Overview of example scripts

Overview of Python Example Scripts

Folder/File

Description

Device Related

 

 

 

 

 

 

 

access_device_catalog.py

Open device from catalog and read properties

add_delete_device.py

Add/remove devices

create_delete_logical_connection.py

Establish/delete logical connection

export_import_element.py

Import/export program elements

import_application.py

Import application

set_ip_address.py

Assign IP Address

update_device.py

Perform device update

Module Related

 

 

 

 

 

 

 

add_delete_device.py

Add/remove modules

export_io_mapping.py

Export I/O mapping

get_module.py

Call module

import_io_mapping.py

Import I/O mapping

read_write_module_parameter.py

Read/write module parameters

set_io_mapping.py

Map inputs/outputs

Online Operation

 

 

 

 

 

 

 

 

connect_disconnect_device.py

Establish/terminate connection to device

create_boot_application_offline.py

Create boot application offline

create_boot_application_online.py

Create boot application online

print_paramter_list.py

Output parameter list

read_variable_online.py

Read variables online

read_write_parameter.py

Read/write variables

simulate_application.py

Simulate application

Project Related

 

 

 

 

 

 

 

 

 

create_project_from_template.py

Create project from template

create_save_project.py

Create and save project

get_device_in_project.py

Query/retrieve device in project

get_set_compiler_version.py

Query/retrieve compiler version

get_set_visualization_profile.py

Query/retrieve visualization profile

open_and_update_project.py

Open project and perform update

open_archive.py

Open archive

save_archive.py

Save archive

update_project.py

Perform project update

System Related

 

 

close_ecockpit.py

Close e!COCKPIT

For additional information see: