Python™ is an accessible scripting language that gives you access to greater functionality in GainSeeker. It allows you to automate customized data entry and analytics in a readable syntax. People who are familiar working with other programming or scripting languages are encouraged to explore the use of Python with GainSeeker.
See the Python website for more information about this scripting language.
Contents [Hide] |
GainSeeker maintains five separate lists of Python scripts, which you can use for:
Customizing Inspections for data entry in PC Collect, or running as standalone scripts (without Inspections) in PC Collect or in GS Console, or running as blocks of re-usable code (below)
Creating custom statistics
Charting external SPC data, retrieving external SPC data in Dashboard controls such as dial and bar gages, and creating Scripted SPC Retrievals in Dynamic Reports 2
Charting external DMS data, retrieving external DMS data in Dashboard controls such as dial and bar gages, and creating Scripted DMS Retrievals in Dynamic Reports 2
Embedding Python controls in Dashboards
This means that a script you create for dashboard controls will not
be displayed when you are working with inspections, for example.
You can also insert Python code into a Device Profile for RS-232 input in an Inspection.
If you find yourself re-creating the same block of code in multiple scripts, you can probably save time and error by creating that code block as a re-usable script! Here's how:
Create a script containing only this block of code.
In another Python script, run this "code block" script by calling it with the misc.executescript command. (This command is not available for Custom Statistics or Device Profiles.)
The Python Script Editor is used to edit, debug, and manage your GainSeeker Python scripts. (The exceptions are custom statistics and Device Profiles, which use a different editor.)
The majority of your Python code will be standard Python 2.7x, but several specialized GainSeeker Python commands are also available.
Command |
Description |
Confirm whether an argument exists, get the value of a command line argument, or view the entire argument string. |
|
Perform various actions for corrective action values in the database. |
|
Open a dashboard or desktop, or refresh or close the current dashboard. |
|
Store DMS data records to the database. |
|
Store SPC data records in the database and optionally store them to the monitor table. |
|
Place controls on a form to show on the screen. |
|
Sends email. |
|
Access a listing of errors that can occur when running commands within GainSeeker's Python library. |
|
Manipulate Excel, CSV, TAB, and other text file types. |
|
Access and format date and time information. |
|
Modify a running inspection. This command only functions while a Formula test is running in a sub-inspection. |
|
Draw a simple line chart or bar chart in a custom dashboard or a Python script in PC Collect. |
|
Retrieve information specific to the current GainSeeker User. |
|
Start and stop other processes not listed in another command group. |
|
Interface with MTConnect agents. |
|
Interface with OPC servers. |
|
Manipulate the SPC and DMS retrieval as part of an executing Python script. Chart external data or create a scripted retrieval for dashboard controls. |
|
Pass in functions that gather the data for each cell. |
|
Interface with Solartron Orbit 3 networks. |
|
There are special Python variables that can be used in specific areas of GainSeeker. |
|
Access a variety of SQL functions. |
|
Read and write DMS standards and set various attributes of them. |
|
Read and write SPC standards and set various attributes of them. |
|
View calculated statistics for an SPC or DMS retrieval. |
|
Connect to another device using the TCP/IP protocol. |
|
Compare note text with standard responses to make sure that operators are entering legitimate notes. |
|
Retrieve, edit, update, delete, and insert traceability values in the database. |
Over 550 Python library files are installed with GainSeeker in the PyLib folder. These library files can be imported and used as part of any Python script. They may be updated in future GainSeeker releases; therefore, you should not edit any of these files.
If you want to add or change the functionality of these installed library files, you can create and edit new copies of these library files, which will not be changed in future GainSeeker releases. Remember to install these libraries on any other GainSeeker workstations that will run scripts based on these libraries.
Because GainSeeker uses the IronPython 2.7.5 implementation of Python, any third-party Python library must also be compatible with IronPython 2.7.5.
The python library must be compatible with Python 2.x.
Pure-python libraries are typically compatible with IronPython.
Libraries that use native C extensions are not
typically compatible with IronPython.
(However, a potential workaround may exist for the popular SciPy and
NumPy libraries. For details, contact technical
support.)
A web search of "ironpython" and the desired library name may indicate whether that library is compatible with IronPython.
If you cannot determine whether your library is compatible with IronPython 2.7.5, you can still try installing it to GainSeeker and use some Python code to test it.
After using the guidelines above to ensure that the new library is compatible with both Python 2.x and IronPython 2.7.5, you can install the library.
In broad terms, you will need to install Python 2.7 on one GainSeeker computer, use it to install the third-party library to your GainSeeker PyLib folder, and find which files have been installed. Then you can later copy those files to other GainSeeker workstations that need that library to run Python scripts.
Here are the detailed steps to perform at one GainSeeker workstation:
Download the Python 2.7 installer. Choose the Latest Python 2 Release, then select the Windows x86 MSI Installer.
Run the Python 2.7 installer with the default options.
Open the Windows command prompt (cmd.exe) as administrator, then change to the Python 2.7 folder (typically C:\Python27).
Use Python 2.7 pip to install the desired library to your %programfiles(x86)%\Hertzler Systems\GainSeeker\PyLib folder.
Using pip ensures that any dependencies required by your third-party package will be downloaded and installed. It also takes care of installing the correct version of the package for your version of Python.
You can typically use the syntax
python -m pip install --target="C:\Program Files (x86)\Hertzler Systems\GainSeeker\PyLib" your_package_name
For example, to install the pypdf2 package and its dependencies from the Python Package Index (pypi.org), use the command line
python -m pip install --target="C:\Program Files (x86)\Hertzler Systems\GainSeeker\PyLib" pypdf2
Review your %programfiles(x86)%\Hertzler
Systems\GainSeeker\PyLib folder for any new files or folders
that have been added.
Then copy these files and folders to the same location on other GainSeeker
workstations that need this library to run Python scripts.
To use the new library in your Python code, use a standard Python import statement.
For example, to use the pypdf2 package that you installed using the instructions above, your script might begin with import PyPDF2 or from PyPDF2 import PdfFileReader .
If you prefer to install the third-party library to a different folder (such as \GainSeeker\PyLib\site-packages), add these two lines to your script before you import the new library:
import site
site.addsitedir(file.getpath(11) + r"\PyLib\site-packages")
If you prefer not to use pip, you might be able to download
the library and put its contents in your \GainSeeker\PyLib
(or other) folder.
To see which dependencies are required, look for a requirements.txt
file in the downloaded library contents.
The installation process copies the file TemplatePythonGuide.txt to the PyLib folder in the GainSeeker Installation folder. This file contains a list of all the template commands and the corresponding Python command to achieve the same results. This file is useful as templates are converted to Inspections or stand-alone Python scripts. The file is updated with each new version of the GainSeeker Suite.