Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
scripting [2020/05/12 18:25] wikiadmin created |
scripting [2024/11/17 13:17] (current) wikiadmin |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | **Scripting** | + | **TransSECS |
+ | |||
+ | See also: [[TransSECScriptingMethodList | Common TransSECS JavaScript Methods List]] | ||
The Devices version of TransSECS (TransSECS Devices) enables java scripting on the data sources, messages, and message data. | 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. | 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(" | ||
+ | |||
+ | |||
+ | <code javascript> | ||
+ | var TransSecsController = Java.type(" | ||
+ | |||
+ | secsInterface=TransSecsController.findController(" | ||
+ | </ | ||
+ | |||
+ | where " | ||
+ | |||
+ | <code javascript> | ||
+ | var TransSecsController = Java.type(" | ||
+ | |||
+ | secsInterface=TransSecsController.getSingleController(); | ||
+ | </ | ||
+ | |||
**Common Problems** | **Common Problems** | ||
Line 10: | Line 32: | ||
TypeError: null has no such function " | TypeError: null has no such function " | ||
For example: | For example: | ||
- | TypeError: null has no such function " | + | TypeError: null has no such function " |
+ | <code javascript> | ||
var TransSecsController = Java.type(" | var TransSecsController = Java.type(" | ||
- | before you do this: | + | </ |
- | secsInterface=TransSecsController.findController("PLCTool" | + | |
+ | **Register to Receive All Events in a TransSECS host application** | ||
+ | |||
+ | This snippet registers a notification of any event received. | ||
+ | |||
+ | <code javascript> | ||
+ | // register to be notified of any event received. | ||
+ | var evntHandler | ||
+ | eventReceived | ||
+ | time=java.lang.System.currentTimeMillis(); | ||
+ | id=ceid.getId(); | ||
+ | print (" | ||
+ | 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 | ||
+ | |||
+ | <code javascript> | ||
+ | var TransSecsController | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | try { | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | //if state=0, cassette has been lifted,if state=1 then it has been placed | ||
+ | if (state==0) { | ||
+ | // | ||
+ | | ||
+ | |||
+ | } else { | ||
+ | // | ||
+ | placedEvent.setIntValue(1); | ||
+ | } | ||
+ | } catch(e) { | ||
+ | print(" | ||
+ | print(e); | ||
+ | |||
+ | } | ||
+ | </ | ||
- | where " |