Topic:
- Is it possible to command the EPOS4 (or EPOS2) by Python?
Basics:
maxon does not provide documentation, specific libraries, sample code, or support to command the EPOS controllers by Python. Anyway it is possible to use the "Epos Command library" by Python script to command an EPOS4 (resp. EPOS2).
There are two main solutions present to command the EPOS4, EPOS2, or IDX by a Python application program based on maxon's "EPOS Command Library".
- Solution 1: ctypes <- Recommended library!
A solution which is favored by most users is the "ctypes" library for Python.
This library is quite often installed by Python programming environments (Linux and Windows) by default. ctypes is a function library which provides "C" compatible data types and allows calling DLL functions (like present by maxon's "EPOS Command library").
maxon clearly recommends to use the ctypes libraries (instead of pythonnet).
The usage of "ctypes" is explained by the following article:
EPOS2 / EPOS4: Commanding by Python -> ctypes - Solution 2: pythonnet <- Not recommended
Another possible solution is the usage of "pythonnet" (which has been developed for Windows based systems).
The following information describes the usage of "pythonnet" although the use of "pythonnet" is no longer recommended by maxon no further support can be offered for "pythonnet" than the notes in this following article. The attached sample code was shared by an EPOS4 and "pythonnet" user.
Solution: "pythonnet":
The only thing which needed is to command the EPOS4 (or EPOS2) by Python is the package "pythonnet" (clr) and the EPOS .NET libraries. The former should be located in your working directory.
1.) pythonnet
Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers. It allows Python code to interact with the CLR, and may also be used to embed Python into a .NET application.
The required "pythonnet" library package can be downloaded here:
Hints:
- The installation package (-> *.whl Wheel file type) should be copied into a local drive and directly installed afterwards using "pip install pythonnet" [hit tab to autocomplete] ...
- Additional information on installation, FAQ, troubleshooting, debugging, and projects using "pythonnet" can be found here:
2.) EPOS Command library for .NET
If you have "EPOS Studio" installed which is required for initial commissioning and tuning anyway, the required EposCmd.Net.dll and EposCmd64.dll is located in the following directory of your local drive by default:
- C:\Program Files (x86)\maxon motor ag\EPOS Positioning Controller\EPOS4\04 Programming\Windows DLL\Microsoft Visual C Sharp\Example C#
It is also possible to download the "EPOS .Net Library" package by the "Software/firmware" section of the "Downloads" tab of each maxon EPOS product site. It is always the same library and documentation independent what EPOS2 or EPOS4 product type is chosen, e.g. "EPOS4 50/5":
The EPOS Command library documentation holding the description of each function and its parameters can be found here:
- C:\Program Files (x86)\maxon motor ag\EPOS Positioning Controller\EPOS4\04 Programming\Windows DLL\Microsoft Visual C Sharp\Documentation
-> "EposCmd.Net.chm" - C:\Program Files (x86)\maxon motor ag\EPOS Positioning Controller\EPOS4\04 Programming\Windows DLL
-> "EPOS Command Library.pdf"
3.) Python sample script
Please find a sample script attached for commanding the EPOS4 by Python. This script has been tested in Spyder / Anaconda with Python 3.7.3.
Remark:
- Please note that maxon cannot provide support or training for Python, pythonnet, or any application specific adaptation of the program example.
- The sample program code can be shared, modified, and used for free without any restrictions.
- maxon disclaims any liability and warranty based on the usage of the sample code.
- We are pleased about your feedback if this information was helpful and you managed to command the EPOS4 by Python.
Cross Reference:
- Recommended library to use (instead of pythonnet):
-> EPOS2 / EPOS4 / IDX: Commanding by Python -> ctypes
Comments
0 comments
Article is closed for comments.