User Tools

Site Tools


transsecsscripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
transsecsscripts [2020/07/21 00:43] – wikiadmintranssecsscripts [2020/09/22 10:15] (current) – wikiadmin
Line 11: Line 11:
 For this example we have added a String VID called "ProcessStatus" to the ModbusPLCTool. We have added a Modbus 4X register to read an integer value from the PLC. We will convert the value read from the Modbus 4X register to a String and write this value to the ProcessStatus VID. This code is entered in the Modbus 4X register's script. For this example we have added a String VID called "ProcessStatus" to the ModbusPLCTool. We have added a Modbus 4X register to read an integer value from the PLC. We will convert the value read from the Modbus 4X register to a String and write this value to the ProcessStatus VID. This code is entered in the Modbus 4X register's script.
  
-<code>+<code javascript>
 var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController"); var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController");
 var SecsFormat20 = Java.type("com.ergotech.secs.SecsFormat20"); var SecsFormat20 = Java.type("com.ergotech.secs.SecsFormat20");
 var SecsFormat54 = Java.type("com.ergotech.secs.SecsFormat54"); var SecsFormat54 = Java.type("com.ergotech.secs.SecsFormat54");
  
- +status=incomingValue.getIntValue(); //the PLC register value 
-//convert integer value to String and update the VID on a value change+//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 //values are 0=Uninitialized 1=Ready To Start 2=Running 3=Completed
-//if value is out of range, set status to "Undefined"+//if value is out of range, set it to "Undefined"
 try { try {
- status=incomingValue.getIntValue(); //the PLC register value 
- stringValue="Undefined"; 
  switch (status) {  switch (status) {
    case 0:    case 0:
Line 35: Line 33:
    case 3:      case 3:  
      stringValue="Completed";      stringValue="Completed";
-     break; +      default: 
- }+         stringValue="Undefined"; 
 +  }
   tool=TransSecsController.findController("ModbusPLCTool");   tool=TransSecsController.findController("ModbusPLCTool");
   gh = tool.getGemHandler();   gh = tool.getGemHandler();
-  gh.setValue("ProcessStatus",new SecsFormat20(stringValue));  +   
- +  //get the current VID value and set this new value if this is a change 
 +  currentValue = gh.getValue("ProcessStatus").getStringValue(); 
 +  
 +  //check that the value has changed before writing to the VID 
 +  if (!(currentValue.equals(stringValue))){ 
 +    gh.setValue("ProcessStatus",new SecsFormat20(stringValue));  
 +  } 
 } catch (e)  { } catch (e)  {
      print("Error converting register value to String");      print("Error converting register value to String");
-     print(e.stack));  +     print(e.stack);  
 } }
  
 </code> </code>
  
 +=== Additional Examples ===
  
 +[[scriptingexamples|TansSECS and MIStudio JavaScript Examples]]
  
-more examples coming soon!+[[devices|TransSECS Devices JavaScript Examples]]
transsecsscripts.1595306603.txt.gz · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki