For situations where a Python script is constantly running - such as polling a data source for new information every few minutes - you can use the GainSeeker Console Manager module to launch and/or monitor the progress of such scripts.
Contents [Hide] |
To run the GainSeeker Console Manager, launch GSConsoleMgr.exe from the GainSeeker application folder (typically C:\Program Files(x86)\Hertzler Systems\GainSeeker) on your computer. You must log in as a GainSeeker user with permission for Module Access to PC Collect.
When setting up a Windows shortcut or Scheduled Task to run GainSeeker Console Manager, you may wish to add command line parameters to automatically log in to GainSeeker and Start Console Manager Groups.
The GainSeeker Console Manager module lets you set up Groups of similar Machines.
For each Group, you can choose a Python script that collects data for a single machine and writes some of those values - such as Mode, Execution, Last Active (date/time), Part Count or other values you need to display - to the HSICT control table. The GainSeeker Console Manager then displays this information from HSICT.
You can use the GainSeeker Console Manager to perform several basic functions:
View the status of scripts that are (or are not) currently running for the machines in a Group - even if those scripts are running on a different workstation. This view is updated every 3 seconds.
Start running the scripts for all machines in a Group. This will launch a separate instance of GSConsole for each machine.
Stop running the scripts for all machines in a Group - even if those scripts are running on a different workstation.
Pause a machine to stop running the script for it but continue data collection on the other machines in the Group.
In the GainSeeker Inspections module, use the Manage Python function to create and debug a Python script that will read the data for any machine in the Group.
A basic script that provides an outline for your Group-specific script is shown below.
You will need to find and edit the two code sections marked #TODO .
The first #TODO section should be used to read and store data for one machine.
Please note that machine-specific information such as machine name, IP address, port, etc., as well as Group-specific values, will be passed in by the GainSeeker Console Manager as command-line parameters. See the #Get the command-line arguments section of the script for variables you can use for these values. To see how these values are entered when setting up the GainSeeker Console Manager, see Setting up Groups and Machines (below).
The second #TODO
section should be used to read the machine's current Mode, Execution,
and Part Count and set the value of the three variables provided.
The values you set here will be displayed on the Console Manager
main window, and that display is updated every 3 seconds.
Alternately, you can display different values (instead
of Mode, Execution, and Part Count) by setting any of these
three variables to those values.
Then, you can change the columns headers displayed on the Console
Manager main window by inserting a record in the HSICT
control table for the current configuration. In this record,
the LEVEL_1 field must be set to the string 'GSCOLUMNHEADERSCM',
and the GP_VALUE field must be set to a tab-delimited list
of columns headers to replace the default column headers Mode,
Execution, Last Active, and Part Count. If a column header
is set to a blank value, that column will not be displayed
in the Console Manager main window.
For example, to set the column headers to Part Number, Uptime,
Last Active, and Part Count, you could run a query like this
against your GainSeeker database:
INSERT INTO HSICT VALUES('GSCOLUMNHEADERSCM',
'', '', '', '', '', CONCAT('Part Number', CHAR(9), 'Uptime',
CHAR(9), 'Last Active', CHAR(9), 'Part Count'))
Here is the basic script:
import time
STOP_FILE_PATH = file.getpath(3) #Files telling us to stop
are stored in the DMS Data folder
UPDATE_FAILED_LAST_TIME = False
def main(group, machine_name,
ip_address, port, uuid, mt_connect_prefix, arg1, arg2, arg3, arg4, running_char):
global UPDATE_FAILED_LAST_TIME
#TODO
- Get a reading from the machine, IP address, and Port. Create a data
record with this information
#TODO
- Update the mode, execution, and part count of this machine so they can
be reported in GS Console Manager
mode = "mode"
execution = "execution"
part_count = "part
count"
#Update
the timestamp for this machine in the HSICT table
where_clause = "LEVEL_1
LIKE 'GSCM_{}%' AND LEVEL_2 LIKE '{} {} {}%'".format(group, machine_name,
ip_address, port)
full_sql = "UPDATE
{} SET GP_VALUE = '{} {} {}{} {}'
WHERE {}".format(sql.tables.hsict,
mode, execution, running_char, hsidate.dbdatetime(), part_count, where_clause)
lines_affected = sql.execute(full_sql)
#If
we failed to update the line in the database two times in the row, then
the machine was likely deleted in the database.
#If
this is the case, then we don't want to keep running this script.
if lines_affected ==
0:
if UPDATE_FAILED_LAST_TIME:
return False
UPDATE_FAILED_LAST_TIME
= True
else:
UPDATE_FAILED_LAST_TIME
= False
return True
#Get
the command-line arguments for this script
group = cmdargs.getargvalue("Group")
machine_name = cmdargs.getargvalue("Machine")
ip_address = cmdargs.getargvalue("Ipaddr")
port = cmdargs.getargvalue("Ipport")
uuid = cmdargs.getargvalue("Uuid")
mt_connect_prefix = cmdargs.getargvalue("Mtcprefix")
arg1 = cmdargs.getargvalue("Arg1") #additional args are set in
the group in the GS Console Manager Module
arg2 = cmdargs.getargvalue("Arg2")
arg3 = cmdargs.getargvalue("Arg3")
arg4 = cmdargs.getargvalue("Arg4")
#Build
the filepath we should check for a stop file.
stop_file_fullpath = "{}{}.gscstop".format(STOP_FILE_PATH,
group)
#Call
the main function to update the database so we know the machine is running.
Pause 5 seconds in between calls so we don't overload the db.
#Check
for the existence of a stop file during the loop to see if we should stop
this script.
while not file.exists(stop_file_fullpath):
if main(group, machine_name,
ip_address, port, uuid, mt_connect_prefix, arg1, arg2, arg3, arg4, ""):
time.sleep(5)
else:
break;
main(group, machine_name, ip_address, port, uuid, mt_connect_prefix, arg1,
arg2, arg3, arg4, "*") #"*"
signifies "Not running"
On the GainSeeker Console Manager main window, click the Set Up button to open the Console Setup window.
After making any changes on this window, your changes will not take effect until you Stop and Start the affected Group(s).
Each Group must contain at least one Machine.
You should specify the Python Script for the Group (above).
Optionally, you can create up to four Script Arguments for the Group. Enter a label on the left (such as "model") and a value on the right (such as "XT5000").
These fields were designed for MTConnect data collection. If you will be reading data from a different type of data source, you can use these fields to store other machine-specific information.
All fields are optional.
IP - The MTConnect agent IP address or computer name.
Port - The MTConnect agent Port.
Status -
OK - When GainSeeker Console starts this Group, it should launch the script for this Machine. The Last Active column for this Machine will show this machine as active.
Paused - When GainSeeker Console starts this Group, it should not launch the script for this Machine. The Last Active column for this Machine will show this machine as paused.
UUID - The device UUID for MTConnect.
MT Connect Prefix - The device prefix for MTConnect.
On the GainSeeker Console Manager main window, click the Group list and select the Group you want to start.
Before you start a Group, use the Active Status column to ensure that all machines in that Group are currently stopped ("Not Running") - like the following example:
If any machines in the group display activity, like Molders 2 and 3 in the example below, you must stop the Group before you start it again.
When you click Start Group, this module launches one instance of GSConsole for each machine in the Group that is configured with Status is set to OK. (No GSConsole window is launched for machines configured with Status set to Paused.) Clicking Start Group will also delete the "stop file" for the Group.
Each machine's GSConsole window is launched with command line parameters for:
automatically logging in to GSConsole as the current GainSeeker user
launching the Python script configured for the Group
Script Arguments configured for the Group
the Group name
the machine name
the IP, Port, UUID, and MT Connect Prefix configured for the machine
The Python script above captures these script arguments, Group and machine name, and machine connection parameters and sets them to variables you can use when collecting data for the machine.
On the GainSeeker Console Manager main window, click the Group list and select the Group you want to stop.
When you click Stop Group, this module creates a "stop file" for the Group and places this file in the DMS Data folder for the current configuration.
The Python script above looks for the current Group's stop file and terminates the script if the file is found.
This allows you to stop the scripts for a Group, even if they are running at a different workstation on the network.
GainSeeker Console Manager data is stored in the HSICT control table, with one row per machine, as follows:
Field... |
contains a tab-delimited string containing... |
whose values are set by |
LEVEL_1 |
|
|
LEVEL_2 |
|
the Console Setup window |
LEVEL_3 |
|
the Console Setup window |
LEVEL_4 |
|
the Console Setup window |
LEVEL_5 |
not used |
|
LEVEL_6 |
not used |
|
GP_VALUE |
|
the Python script for the machine |