**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. **Controller Reference** For all scripts where you need a reference to the tool interface (or host definition) you will need to get this interface using TransSECSController.getSingleController() or TransSECSController.findController("XXXXX") where XXXXX is a specific tool interface. If you only have one interface in your project the preferred way to access the interface is using the getSingleController() method without using a specific tool interface name. var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController"); 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: var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController"); secsInterface=TransSecsController.getSingleController(); **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 to import the TransSECSController class: var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController"); **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); }