transsecsscripts
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| transsecsscripts [2020/05/13 23:59] – created wikiadmin | transsecsscripts [2020/09/22 10:15] (current) – wikiadmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== TransSECS Scripting Examples ===== | + | ====== TransSECS Scripting Examples |
| - | examples coming soon! | + | ==== Devices TransSECS ==== |
| + | |||
| + | === Converting Raw Data === | ||
| + | |||
| + | Normally you will read a value from a PLC, Database, OPCServer, etc. and use this value directly to set an ID value. For example, read a PLC register as an integer and set this value to a U4 (unsigned integer) type VID by selecting the Device Server and Tag for the VID. However, if you need to do a conversion on the raw data read from the data source, this can be done by scripting, calculating a new value, then setting this new value to the VID. Be sure that the VID type is defined for this calculated value. | ||
| + | |||
| + | Here is an example of using an integer value read from a PLC register and converting this to a String for a type 20 (String) VID (ProcessStatus). This assumes | ||
| + | |||
| + | For this example we have added a String VID called " | ||
| + | |||
| + | <code javascript> | ||
| + | var TransSecsController = Java.type(" | ||
| + | var SecsFormat20 = Java.type(" | ||
| + | var SecsFormat54 = Java.type(" | ||
| + | |||
| + | status=incomingValue.getIntValue(); | ||
| + | //convert integer value to a String and update the VID on a value change | ||
| + | //values are 0=Uninitialized 1=Ready To Start 2=Running 3=Completed | ||
| + | //if value is out of range, set it to " | ||
| + | try { | ||
| + | switch (status) { | ||
| + | case 0: | ||
| + | stringValue=" | ||
| + | break; | ||
| + | case 1: | ||
| + | stringValue=" | ||
| + | break; | ||
| + | case 2: | ||
| + | stringValue=" | ||
| + | break; | ||
| + | case 3: | ||
| + | stringValue=" | ||
| + | default: | ||
| + | | ||
| + | } | ||
| + | tool=TransSecsController.findController(" | ||
| + | gh = tool.getGemHandler(); | ||
| + | |||
| + | //get the current VID value and set this new value if this is a change | ||
| + | currentValue = gh.getValue(" | ||
| + | |||
| + | //check that the value has changed before writing to the VID | ||
| + | if (!(currentValue.equals(stringValue))){ | ||
| + | gh.setValue(" | ||
| + | } | ||
| + | |||
| + | } catch (e) { | ||
| + | print(" | ||
| + | print(e.stack); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | === Additional Examples === | ||
| + | |||
| + | [[scriptingexamples|TansSECS and MIStudio JavaScript Examples]] | ||
| + | |||
| + | [[devices|TransSECS Devices JavaScript Examples]] | ||
transsecsscripts.1589428793.txt.gz · Last modified: by wikiadmin
