This is an old revision of the document!
Scripting
The Devices version of TransSECS (TransSECS Devices) enables java scripting on the data sources, messages, and message data.
Look at the sample scripts on the messages and data sources in the sample PLCTool.
Common Problems
if you see an error such as: TypeError: null has no such function “someFunctionName”, this usually means you forgot to add an import for a class which has method “someFunctionName”. For example: TypeError: null has no such function “findController” or TypeError: null has no such function “getSingleController” is commonly due to forgetting to do this:
var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController");
before you do this:
secsInterface=TransSecsController.findController("PLCTool");
where “PLCTool” is the name of your tool definition. The preferred way to get a single controller reference when you only have one interface defined in the project (which is most common) is:
secsInterface=TransSecsController.getSingleController();
Register to Receive All Events in a TransSECS host application
This snippet registers a notification of any event received.
// register to be notified of any event received. var evntHandler = new EventListener() { eventReceived : function(ceid,reports) { time=java.lang.System.currentTimeMillis(); id=ceid.getId(); print ("Event " + id + " received at" + time ); if (id==129) {//port1 loaded // handle the port loaded event } } }
Trigger Events in a Tool
In this example there is one data source which triggers two events, a cassette placed event and a cassette lifted event. If the value is 0, the cassette was lifted, if it is 1, the cassette was placed
var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController"); tool=TransSecsController.getSingleController(); gemHandler = tool.getGemHandler(); print(gemHandler); try { liftedEvent = gemHandler.getServerForName("CEID.Lifted"); placedEvent = gemHandler.getServerForName("CEID.Placed"); state=incomingValue.getIntValue();//this is the value of the data source //if state=0, cassette has been lifted,if state=1 then it has been placed if (state==0) { //trigger lifted event liftedEvent.setIntValue(1); } else { //trigger placed event placedEvent.setIntValue(1); } } catch(e) { print("Error in Cassette Lifted/Placed Event script: \n"+e.stack); print(e); }