EC Master - V3.2 Python
EC Master - V3.2 Python
EC Master - V3.2 Python
SOFTWARE
EC-Master
Python Programming Interface
Version 3.2
EtherCAT® is registered trademark and patented technology, licensed by Beckhoff Automation GmbH, Germany.
© Copyright acontis technologies GmbH
Neither this document nor excerpts therefrom may be reproduced, transmitted, or conveyed to third parties by any
means whatever without the express permission of the publisher. At the time of publication, the functions described
in this document and those implemented in the corresponding hardware and/or software were carefully verified;
nonetheless, for technical reasons, it cannot be guaranteed that no discrepancies exist. This document will be reg-
ularly examined so that corrections can be made in subsequent editions. Note: Although a product may include
undocumented features, such features are not considered to be part of the product, and their functionality is therefore
not subject to any form of support or guarantee.
Python Programming Interface
Contents
1 Introduction 4
1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Programmers Guide 6
2.1 Sample Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Sample Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.1 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3.2 Return code vs. exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3.3 API with “out” or “ref” parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Supported IDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4.1 Python Shell IDLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4.2 Visual Studio 2019 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4.3 Visual Studio Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 FAQ 17
1 Introduction
The Python Wrapper provides a Python interface to use EC-Master, EC-Simulator and RAS Client/Server.
1.1 Requirements
• Python Pause. Required for ticked timing with pause.until(…) to lower JobTask’s drift, e.g. for Dis-
tributed Clocks
$ pip install pause
1.2 Architecture
• Native wrapper library, which provides API for object oriented access
Native Libraries
2 Programmers Guide
# Write variable
demo.processImage.variables.Slave_1005__EL2008_.Channel_1.Output.set(1)
# Read variable
demo.processImage.variables.Slave_1005__EL2008_.Channel_1.Output.get()
2.3 Wrapper
2.3.1 Modules
class CEcWrapperPython
EC-Wrapper base class
class CEcMasterPython
EC-Master
class CEcMasterMbxGatewayClientPython
Mailbox Gateway Client for EC-Master
class CEcMasterMbxGatewayServerPython
Mailbox Gateway Server for EC-Master
class CEcSimulatorPython
EC-Simulator
class CEcSimulatorRasServerPython
RAS Server for EC-Simulator
class CEcRasClientPython
RAS Client for EC-Master / EC-Simulator
EcMotionPython.py
class CEcMotionPython
EC-Motion interface
EcWrapperPythonTypes.py
Python types
EcWrapper.py
CPython interface (internal)
EcWrapperTypes.py
CPython types (internal)
The most of all API functions returns a return code for error handling. This behaviour can be changed to throw an
exception in error case by simply setting:
The Python Wrapper API is based on C# code. C# supports out and ref keywords for parameters. This is not
supported in Python and is solved by simply submitting CEcWrapperPythonOutParam or CEcWrapper-
PythonRefParam to those functions:
In this shell, the user can simply copy&paste the sample code from: Exam-
ples/EcMasterDemoPython/EcDemoAppInteractive.py
exec("""
import os
import sys
INSTALLDIR = "C:/Program
Files/acontis_technologies/EC-Master-Windows-x86_64Bit/"
os.environ["PATH"] += os.pathsep + INSTALLDIR + "Bin/Windows/x64"
sys.path.append(INSTALLDIR + "Sources/EcWrapperPython")
sys.path.append(INSTALLDIR + "Examples/EcMasterDemoPython")
from EcDemoApp import \*
demo = EcMasterDemoPython()
demo.pAppParms.tRunMode = RunMode.Master
demo.pAppParms.dwBusCycleTimeUsec = 4000
demo.pAppParms.szENIFilename = "ENI.xml"
demo.pAppParms.szLinkLayer = "winpcap 127.0.0.0 1"
demo.pAppParms.nVerbose = 3
demo.startDemo()
print("EcMasterDemoPython is running.")
print("Type demo.help() for interactive help.")
""")
• Search Paths:
../../Sources/EcWrapperPython;../EcMasterDemoPython
• Script Arguments:
• Environment Variables:
PATH=../../Bin/Windows/x64;%PATH%
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "",
"args" : [
"--mode", "1",
"-f", "ENI.xml",
"--link", "winpcap 127.0.0.1 1",
"-b", "4000",
"-t", "1000",
"-v", "3",
],
"env": {"PYTHONPATH": "${workspaceRoot}"}
}
]
}
{
"git.ignoreLimitWarning": true,
"python.linting.pylintArgs": [
"--init-hook='import sys; sys.path.append(\"C:/Temp/EC-Master-
,→Windows-x86_64Bit/Sources/EcWrapperPython\")'"
]
}
import os
import sys
INSTALLDIR = "C:/Temp/EC-Master-Windows-x86_64Bit/"
os.environ["PATH"] += os.pathsep + INSTALLDIR + "Bin/Windows/x64"
sys.path.append(INSTALLDIR + "Sources/EcWrapperPython")
sys.path.append(INSTALLDIR + "Examples/EcMasterDemoPython")
Start debugging and the demo output will be written into the terminal:
3 FAQ
PyQt5 cannot be installed on Ubuntu 14.04 x64, because it requires Python 3.5. How can I install it?
It can be installed by calling
$ sudo apt-get install python3-pyqt5
I installed Python and the demo crashes with strange errors. What can I do?
This might be a problem of mixing x86 with x64 binaries. Verify that if you have installed the Python
runtime for x64 bit, please install also EC-Master for x64 bit.