python

This GEM Python host example uses the code generated from TransSECS using the Java/Javascript deployment option.

Most of the complexity is removed by the definitions you created in TransSECS.

The python wrapper uses the JPype library to directly interface with the Java code.

For the host,copy the GEMHostRuntime.jar from the TransSECS GEMHost project into the build folder

The sample, demonstrates all the features required to collect data from a host. It can be extended to include any features available in the Java host or tool.

Here's the code sample from the python wrapper archive:

#!/usr/bin/python3
import jpype
from jpype import JProxy
import jpype.imports
from jpype.types import *
 
jpype.startJVM(classpath=['.', './GEMHostRuntime.jar'])
 
from com.ergotech.util import SimulationManager
from deploy.GEMHost import EquipmentController
 
import time
 
hostname =  "localhost"
port = 5010
deviceid = 1
 
SimulationManager.getSimulationManager().setSimulating(False)
 
host = EquipmentController()
host.setEquipmentHostName(hostname)
host.setActivePort(port)
host.setDeviceId(deviceid)
host.init()
host.start()
 
def event_received(ceid, event_report_values):
	print("Event received: " + str(ceid) + " with values:\n" + str(event_report_values))
 
d = {'eventReceived': event_received }
listener_proxy = JProxy("com.ergotech.transsecs.secs.host.EventListener", dict=d)
 
# Add a listener for all events
host.setGlobalEventListener(listener_proxy)
 
while True:
    print('GEMHost running...')
    time.sleep(10)
  • python.txt
  • Last modified: 2021/08/11 10:57
  • by wikiadmin