devices_scripting

This is an old revision of the document!


Scripting with TransSECS Devices

To write a value to a server in the devices the format is:

/Devices/[DeviceNodeName]_Servers/[ServerName]→[setValue]

For example, to set the integer value 2 to a server called ModbusWord under the ModbusTCP node use:

/Devices/ModbusTCP_Servers/ModbusWord->setIntValue(2);

TransSECS is thread safe and so you can create threads in a script. Here's an example that creates a thread before setting the value of a Modbus server.

var Thread = Java.type("java.lang.Thread");
var Runnable = Java.type("java.lang.Runnable");
 
// declare our thread
this.thread = new Thread(new Runnable(){
  run: function () {
      /Devices/ModbusTCP_Servers/ModbusWord->setIntValue(2);
      print("printed from a separate thread");
  }
});
 
// start our thread
this.thread.start();

Register for Connection Status Notification in TransSECS Host Application

In a GEMHost application the TransSECS controller publishes the status of the connection.

To register for this, add a “Startup Trigger” from the “Demo Servers”

Register for the notification in the “script” field. Here the notification is just printed to the display.

var TransSecsController = Java.type("com.ergotech.transsecs.secs.TransSecsController");
var ConnectionStatusListener = Java.type("com.ergotech.transsecs.secs.host.ConnectionStatusListener");
 
print("Startup Trigger");
 
host=TransSecsController.findController("GEMHost");
 
// create the connection status listener
var connectionStatusListener = new ConnectionStatusListener() {
 
   connectionStatusChanged : function (connectionStatus, comment) {
       print ("Current Connection Status " + connectionStatus + " Status String \"" + comment + "\"");        
   }
};
 
// add this to the host  
host.addConnectionStatusListener(connectionStatusListener);
print("Connection Status Trigger Registered");

The details of the connection status are described here

  • devices_scripting.1591733844.txt.gz
  • Last modified: 2020/06/09 15:17
  • by wikiadmin