MTConnect.NET-AgentProcessor-Python implements using Python scripts for Agent Processing for use with the MTConnectAgentApplication class in the MTConnect.NET-Applications-Agent library. Supports MTConnect Versions up to 2.5. Supports .NET Framework 4.6.1 up to .NET 9
$ dotnet add package MTConnect.NET-AgentProcessor-Python
This Agent Processor uses individual Python script files to transform input data
processors:
- python:
directory: processors
directory - The directory to load and monitor for ".py" script files.Scripts are implemented using IronPython and supports Python v3. Both the MTConnect Entity to process and the MTConnect Agent are both accessible from the script.
Change the Result for a DataItem with a Type = "EMERGENCY_STOP"
def process(observation):
if observation.DataItem.Type == 'EMERGENCY_STOP':
result = observation.GetValue('Result')
if result.lower() == 'TRUE'.lower():
observation.AddValue('Result', 'ARMED')
else:
observation.AddValue('Result', 'TRIGGERED')
return observation
Change the Result for a DataItem with a Type = "PATH_FEEDRATE_OVERRIDE" from a Percentage to an Integer by multiplying by 100
def process(observation):
if observation.DataItem.Type == 'PATH_FEEDRATE_OVERRIDE':
result = float(observation.GetValue('Result'))
observation.AddValue('Result', result * 100)
return observation
Add a new TimeSeries observation for any time a DataItem with an ID = "L2p1Fact" changes
import clr
clr.AddReference("MTConnect.NET-Common")
import MTConnect.Input
def process(observation):
if observation.DataItem.Id == "L2p1Fact":
timeseries = MTConnect.Input.TimeSeriesObservationInput()
timeseries.DataItemKey = 'L2p1Sensor'
timeseries.SampleRate = 100
n = 15
samples = [0] * n
for x in range(n):
samples[x] = float(x)
timeseries.Samples = samples
observation.Agent.AddObservation(observation.DataItem.Device.Uuid, timeseries)
return observation
This application and it's source code is licensed under the MIT License and is free to use.