Python Scripting and Python Commands

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]

 

Using Python in GainSeeker

Different lists of Python scripts for different uses

GainSeeker maintains five separate lists of Python scripts, which you can use for:

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.

Creating Python scripts as blocks of re-usable code

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:

  1. Create a script containing only this block of code.

  2. 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.)

Using the Python Script Editor

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.

GainSeeker Python commands

Command

Description

Command Line arguments

Confirm whether an argument exists, get the value of a command line argument, or view the entire argument string.

Corrective Actions

Perform various actions for corrective action values in the database.

Dashboard

Open a dashboard or desktop, or refresh or close the current dashboard.

Data DMS

Store DMS data records to the database.

Data SPC

Store SPC data records in the database and optionally store them to the monitor table.

Display

Place controls on a form to show on the screen.

Email

Sends email.

Error

Access a listing of errors that can occur when running commands within GainSeeker's Python library.

File

Manipulate Excel, CSV, TAB, and other text file types.

HSI Date

Access and format date and time information.

Inspection

Modify a running inspection. This command only functions while a Formula test is running in a sub-inspection.

Line chart and Bar chart

Draw a simple line chart or bar chart in a custom dashboard or a Python script in PC Collect.

Login

Retrieve information specific to the current GainSeeker User.

Miscellaneous

Start and stop other processes not listed in another command group.

MTConnect

Interface with MTConnect agents.

OPC

Interface with OPC servers.

Retrieval

Manipulate the SPC and DMS retrieval as part of an executing Python script. Chart external data or create a scripted retrieval for dashboard controls.

Serial Port

Pass in functions that gather the data for each cell.

Solartron

Interface with Solartron Orbit 3 networks.

Special Variables

There are special Python variables that can be used in specific areas of GainSeeker.

SQL

Access a variety of SQL functions.

Standard DMS

Read and write DMS standards and set various attributes of them.

Standard SPC

Read and write SPC standards and set various attributes of them.

Statistics

View calculated statistics for an SPC or DMS retrieval.

TCP

Connect to another device using the TCP/IP protocol.

Text Evaluator

Compare note text with standard responses to make sure that operators are entering legitimate notes.

Traceability

Retrieve, edit, update, delete, and insert traceability values in the database.

Python library files

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.

Third-party Python libraries

Compatibility with IronPython 2.7.5

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.

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.

Installing and using a third-party library

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:

  1. Download the Python 2.7 installer. Choose the Latest Python 2 Release, then select the Windows x86 MSI Installer.

  2. Run the Python 2.7 installer with the default options.

  3. Open the Windows command prompt (cmd.exe) as administrator, then change to the Python 2.7 folder (typically C:\Python27).

  4. Use Python 2.7 pip to install the desired library to your %programfiles(x86)%\Hertzler Systems\GainSeeker\PyLib folder.

  5. 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.

  6. To use the new library in your Python code, use a standard Python import statement.

More information

Comparing Python commands with Template commands

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.