EcoStruxure Machine Expert version 1.1 does not support the M258, LMC058 and LMC078 controllers.

Accessing the Python Interpreter in EcoStruxure Machine Expert

Overview

EcoStruxure Machine Expert can be automated with the Python script language.

The Python scripting capabilities in EcoStruxure Machine Expert are exposed in various ways. The table lists different entry points:

Where

Input type

Description / Use case

How to open

Logic Builder user interface

Interactive (REPL)

Interactive Python shell with a command-line interface, embedded in the user interface of EcoStruxure Machine Expert.

Menu command View > Scripting Immediate in the Logic Builder (also refer to the chapter Using the Logic Builder Scripting Immediate View).

Python file (*.py)

Select a script file to be executed from within the user interface of EcoStruxure Machine Expert.

Menu command Tools > Scripting > Execute Script File... command in the Logic Builder (also refer to the chapter Using the Logic Builder Scripting Immediate View.

Stand-alone shell

REPL

Interactive Python shell with a command-line interface, running stand-alone (without the graphical user interface of EcoStruxure Machine Expert).

Open LogicBuilderShell.exe without command-line arguments (refer to the chapter Using the Logic Builder Shell).

Python file (*.py)

Executes a Python script from the Windows command-line, from a batch file, or similar ways.

Open LogicBuilderShell.exe with a script file as a command-line argument (refer to the chapter Using the Logic Builder Shell).

Microsoft Visual Studio + PTVS (Python Tools for Visual Studio)

REPL

You can use the interactive REPL view in Microsoft Visual Studio to execute Python commands on the Logic Builder Shell.

Configure the LogicBuilderShell.exe as Python interpreter inside Microsoft Visual Studio (refer to the chapter Using Logic Builder Shell with Microsoft Visual Studio and PTVS).

Python file (*.py)

Python files in a Visual Studio project can be executed and debugged on the Logic Builder Shell.

Also refer to the considerations concerning debugging in the feature comparison table.

JetBrains PyCharm

REPL

You can use the Python Console in JetBrains PyCharm to execute Python commands on the Logic Builder Shell.

Configure the LogicBuilderShell.exe as Python interpreter inside PyCharm (refer to the chapter Using Logic Builder Shell with JetBrains PyCharm).

Python file (*.py)

Python files can be executed and debugged on the Logic Builder Shell.

Microsoft Visual Studio Code + Python extension

Python file (*.py)

Python files can be executed and debugged on the Logic Builder Shell.

Also refer to the considerations concerning the autocomplete and the syntax error check functions in the feature comparison table.

Configure the LogicBuilderShell.exe as Python interpreter inside Microsoft Visual Studio Code (refer to the chapter Using Logic Builder Shell with Microsoft Visual Studio Code and Python extension).

The following sections provide an overview of how Python scripting integrates in EcoStruxure Machine Expert for different use cases.

Feature Comparison of Integrated Development Environment (IDE) from Third-Party Vendors

Each IDE from third-party vendors mentioned in this chapter supports different functions. The table lists the three IDE with the functions they support.

NOTE: The Autocomplete (IntelliSense) function does not recognize any fields, properties, and methods of the EcoStruxure Machine Expert-specific API.

Function

Microsoft Visual Studio + PTVS

PyCharm

Microsoft Visual Studio Code + Python extension

REPL

X

X

Execute

X

X

X

Debug

X

X

X

Breakpoints

X

X

X

Step Into / Over

X

X

X

Watch Variables / Evaluate Expressions

X

X

Syntax Highlighting

X

X

X

Syntax Error Check

X

X

Autocomplete (IntelliSense)

X

X

Partial (local elements and code snippets only)

Considerations

Modifications have to be performed on the EcoStruxure Machine Expert installation for PyCharm.

Debugging can be performed with IronPython but error messages are displayed in the console.

Debugging stops execution at a Python module function but can be continued.

The Autocomplete function starts several processes of the LogicBuilderShell.exe. It will be available again after they have been completed. By further using the Autocomplete function, error messages are provoked by the extension and will be displayed in the Microsoft Visual Studio Code development console (for further information, refer to Help > Toggle Developer Tools).

X Function is supported

 Function is not supported

Logic Builder User Interface

The Logic Builder user interface allows you to execute script files via the Tools > Scripting > Execute Script File... command or executes scripting statements via the Scripting Immediate view

The Scripting Immediate view is a (Python) interpreter integrated in EcoStruxure Machine Expert allowing you, for example, to start functions.

The Scripting Immediate view hosts an interpreter and is based on REPL principles.

The block diagram shows how the EcoStruxure Machine Expert user interface is using the script engine to execute Python commands:

G-SE-0068842.1.gif-high.gif

 

 

Execute Statements Via Interactive Shell

The block diagram shows how the interactive interpreter in a REPL-based shell is using the script engine to execute Python statements:

G-SE-0073209.1.gif-high.gif

 

 

Script Execution Via Non-Interactive Shell

The block diagram shows how the (non-interactive) shell is using the script engine to execute scripts:

G-SE-0073210.1.gif-high.gif

 

 

Script Debugging Using Integrated Development Environment (IDE) from Third-Party Vendors

The block diagram shows how an Integrated Development Environment (IDE) from third-party vendors (for example, Visual Studio and PTVS) can be used for debugging Python scripts:

G-SE-0073211.1.gif-high.gif