system.mes.bc.executeChartSynchronous

Sepasoft MES Module Suite

system.mes.bc.executeChartSynchronous 

These script functions are used to execute (run) Business Connector charts. The third variant of this function requires a list of Chart Parameters be passed into the chart and will return a Python dictionary after chart execution. These three function variants are synchronous and therefore will wait for the chart to complete execution before returning control to the calling script.

Information

For asynchronous variants of the first two functions below, refer to: system.mes.bc.executeChart

Method Options

executeChartSynchronous(chartPath)

Description

Execute a Business Connector Chart. No Chart Parameter values are passed or returned. This function will wait for the chart to complete execution before returning control to the calling script.

Syntax

executeChartSynchronous(chartPath)


  • Parameters

String chartPath - The path of the Chart in the Business Connector section of the Ignition Project Browser.

  • Returns

Nothing

  • Scope

All

Code Examples

Simple Chart Execution (no parameters)

  • The chart location is set in the variable chartPath (its path in the hierarchy tree of the Business Connector section of the Ignition Project Browser).
  • The chart is not expecting to receive or return any Chart Parameters. The chart, in essence, is a self-contained sequence of actions triggered to run by the calling script.
  • This variation of the function will wait for the chart to complete execution.


Code Snippet

Code
#This script is in a Business Connector chart Script Block

def executeScript(chart):

	#Write the incoming chart parameter values (sent from the button press) to tags x1 and x2
	system.tag.writeSynchronous('[default]x1', chart.getParameterValue('@newMaterialClass'), 45)
	system.tag.writeSynchronous('[default]x2', chart.getParameterValue('@newMaterialDef'), 45)
	
	#Set values to be returned to the chart-execution function in the button
	chart.setParameterValue('@validClass', 'Bread')
	chart.setParameterValue('@validDef', 'Raisin')
	
	return

executeChartSynchronous(chartPath, chartParameters)

Description

Execute a Business Connector Chart. Passes a Python dictionary of Chart Parameter value(s) into the chart. This function will wait for the chart to complete execution before returning control to the calling script.

Syntax

executeChartSynchronous(chartPath, chartParameters)


  • Parameters

String chartPath - The path of the Chart in the Business Connector section of the Ignition Project Browser.

Object chartParameters - A Python dictionary of Chart Parameter name(s) and value(s) to pass into the chart (may be a subset of all available Chart Parameters for the chart). The Chart Parameters must be defined in the chart's Start Block or an exception will be thrown.

  • Returns

Nothing

  • Scope

All

Code Examples

Chart Execution With Parameters Passed In

  • This chart receives two Chart Parameter values from the calling script (newMaterialClass = 'Flour'  and newMaterialDef = 'Whole Wheat').
  • A Script Block in the chart writes those values to Tags x1 and x2.

Chart Parameters Defined in Start Block


Code Snippet -- from a chart Script Block

Code
#This script is in a Business Connector chart Script Block

def executeScript(chart):

	#Write the incoming chart parameter values (sent from the button press) to tags x1 and x2
	system.tag.writeSynchronous('[default]x1', chart.getParameterValue('@newMaterialClass'), 45)
	system.tag.writeSynchronous('[default]x2', chart.getParameterValue('@newMaterialDef'), 45)
	
	#Set values to be returned to the chart-execution function in the button
	chart.setParameterValue('@validClass', 'Bread')
	chart.setParameterValue('@validDef', 'Raisin')
	
	return

Code Snippet -- from a Button

Code
#This script is in an Ignition Button

#Business Connector chart path
chartPath = 'Working with Parameters'
#Python dictionary of chart parameters to pass values to
parameterValues = {'newMaterialClass':'Flour', 'newMaterialDef':'Whole Wheat'}
#Python list of chart parameters to retrieve values for
returnThese = ['validClass', 'validDef']

#Execute the chart (pass in two chart parameter values and return a Python dictionary with the requested Chart Parameters into 'r')
#Waits for the chart to complete before control returns to the script.
r = system.mes.bc.executeChartSynchronous(chartPath, parameterValues, returnThese)

#Write the returned values to tags
system.tag.write('[default]x3', r.get('validClass'))
system.tag.write('[default]x4', r.get('validDef'))

Output

Code
Tags x1 and x2 were written by a Business Connector chart's Script Block (chart parameter values passed into the chart)
Tags x3 and x4 were written from within an Ignition Button script (using chart parameter values returned by the chart)
(see tags below)

Ignition Tags

executeChartSynchronous(chartPath, chartParameters, returnChartParameters)

Description

Execute a Business Connector Chart. Passes a Python dictionary of Chart Parameter value(s) into the chart and waits for a Python dictionary of the final Chart Parameter value(s) to be returned upon completion of chart execution. This function will wait for the chart to complete execution before returning control to the calling script (and returns a Python dictionary).

Syntax

executeChartSynchronous(chartPath, chartParameters, returnChartParameters )


  • Parameters

String chartPath - The path of the Chart in the Business Connector section of the Ignition Project Browser.

Object chartParameters - A Python dictionary of Chart Parameter name(s) and value(s) to pass into the chart (may be a subset of all available Chart Parameters for the chart). The Chart Parameters must be defined in the chart's Start Block or an exception will be thrown.

String or Object returnChartParameters - Either a string (containing one Chart Parameter name) or a Python list of Chart Parameter names to have values returned by the chart upon the completion of execution of the chart (may be a subset of the available Chart Parameters for the chart). The Chart Parameters must be defined in the chart's Start Block or an exception will be thrown.

  • Returns

Object A Python dictionary of the requested Chart Parameter name(s) and value(s).

  • Scope

All

Code Examples

Chart Execution With Parameters Passed In and Returned

  • This chart receives two Chart Parameter values from the calling script (newMaterialClass = 'Flour'  and newMaterialDef = 'Whole Wheat').
  • A Script Block in the chart writes those values to Tags x1 and x2.
  • The Script Block then writes to two other Chart Parameters, which will be returned to the calling script in the button when chart execution concludes (validClass = 'Bread' and validDef = 'Raisin')
  • The button script writes the returned values to Tags x3 and x4 to demonstrate that the values were properly returned by the chart function.

Chart Parameters Defined in Start Block


Code Snippet -- from a chart Script Block

Code
#This script is in a Business Connector chart Script Block

def executeScript(chart):

	#Write the incoming chart parameter values (sent from the button press) to tags x1 and x2
	system.tag.writeSynchronous('[default]x1', chart.getParameterValue('@newMaterialClass'), 45)
	system.tag.writeSynchronous('[default]x2', chart.getParameterValue('@newMaterialDef'), 45)
	
	#Set values to be returned to the chart-execution function in the button
	chart.setParameterValue('@validClass', 'Bread')
	chart.setParameterValue('@validDef', 'Raisin')
	
	return

Code Snippet -- from a Button

Code
#This script is in an Ignition Button

#Business Connector chart path
chartPath = 'Working with Parameters'
#Python dictionary of chart parameters to pass values to
parameterValues = {'newMaterialClass':'Flour', 'newMaterialDef':'Whole Wheat'}
#Python list of chart parameters to retrieve values for
returnThese = ['validClass', 'validDef']

#Execute the chart (pass in two chart parameter values and return a Python dictionary with the requested Chart Parameters into 'r')
#Waits for the chart to complete before control returns to the script.
r = system.mes.bc.executeChartSynchronous(chartPath, parameterValues, returnThese)

#Write the returned values to tags
system.tag.write('[default]x3', r.get('validClass'))
system.tag.write('[default]x4', r.get('validDef'))

Output

Code
Tags x1 and x2 were written by a Business Connector chart's Script Block (chart parameter values passed into the chart)
Tags x3 and x4 were written from within an Ignition Button script (using chart parameter values returned by the chart)
(see tags below)

Ignition Tags

Other Examples

The Chart Parameter(s) to be returned by the script function can be either a Python list, or a single string with either the name of one Chart Parameter to be returned, or an asterisk (return all Chart Parameters). Returned Chart Parameter(s) is/are in the form of a Python Dictionary, such as: {"name":"John Smith", "id":12345} or {'Bob': 89.9, 'Joe': 188.72, 'Sally': 21.44}.

Python list (return just these Chart Parameters)

Code
r = system.mes.bc.executeChartSynchronous(chartPath, parameterValues, ['param1', 'param2'])
p1 = r['param1']
p2 = r['param2']

String with one Chart Parameter name

Code
r = system.mes.bc.executeChartSynchronous(chartPath, parameterValues, 'param2')
p2 = r['param2']

Asterisk (return all Chart Parameters --- in this example there are four)

Code
r = system.mes.bc.executeChartSynchronous(chartPath, parameterValues, '*')
p1 = r['param1']
p2 = r['param2']
p3 = r['param3']
p4 = r['param4']



Sepasoft MES Module Suite