As of Ignition 7.7, it is possible to import 3-rd party Python libraries / modules for use in scripting inside Ignition.
Verifying Compatibility
As Ignition uses Jython (an implementation of the Python programming language designed to run on the Java platform), when looking for libraries to use with Ignition it is important to verify that the library is Jython-compatible. This typically comes down to checking that:
-
The library or module is not written in C and is not dependent on C / C-Python features
-
The library is Python 2.5 compatible (*as of Ignition 7.8, Ignition uses Jython 2.5)
This information can obtained from the library author / maintainer, and will typically be available on the Web site where library was downloaded from.
Importing the Library
To import the library into Ignition:
-
On the computer where the Ignition Gateway is installed, navigate to the Inductive Automation\Ignition\user-lib\lib\pylib\ folder located inside the installation directory.
On a standard Windows installation, this will be C:\Program Files\Inductive Automation\Ignition\user-lib\pylib
On a standard Linux installation, this will be /var/lib/ignition/user-lib/pylib
On a standard Mac OS X installation, this will be /usr/local/ignition/user-lib/pylib
-
Copy the folder containing the library or the individual module file ( .py) into the pylib folder
Now you are ready to use the functionality of your newly imported library!
Using the 3-rd party library you have imported
To use the functions and methods your newly imported library offers in an Ignition script, you need to first import them:
#import
from mylib import myclass
#use
myclass.mymethod()
Example 1:
If you have imported a single Python module called fibo.py that contains a function called fibonacci, to call that function, your code will be as follows:
import fibo
print fibo.fibonacci(5)
Example 2:
If you have imported a Python library containing multiple modules, for example a folder called fibo_lib containting modules fibo.py and fibo2.py, and want to call the fibonacci function from the fibo.py module, your code will be as follows:
from fibo_lib import fibo
print fibo.fibonacci(5)
Comments
0 comments
Please sign in to leave a comment.