host_connection_status

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
host_connection_status [2021/05/25 23:51]
wikiadmin [Set Up Alarm Listeners]
host_connection_status [2025/03/14 16:30] (current)
wikiadmin
Line 23: Line 23:
 ====JavaScript Example for MIStudio/TransSECS==== ====JavaScript Example for MIStudio/TransSECS====
  
-This code example is run from a StartupTrigger script in TransSECS (or a script triggered by the StartupTrigger in MIStudio) to set up the ConnetionStatusListener. For MIStudio, this script pushes data to two BroadcastServers (StatusListenerCommand and StatusListenerValue) whenever there is a connection status change.+This code example is run from a StartupTrigger script in TransSECS (or a script triggered by the StartupTrigger in MIStudio) to set up the ConnectionStatusListener. For MIStudio, this script pushes data to two BroadcastServers (StatusListenerCommand and StatusListenerValue) whenever there is a connection status change.
  
 <code javascript> <code javascript>
Line 40: Line 40:
   }   }
  
- host=TransSecsController.findController("GEMHost");     //use  your GEM Host name + host=TransSecsController.getSingleController(); //get the host controller for this tool connection
  host.addConnectionStatusListener(statusListener);  host.addConnectionStatusListener(statusListener);
  
Line 58: Line 58:
 function waitForHost() {   function waitForHost() {  
     print("wait for host THREAD started");      print("wait for host THREAD started"); 
-    host=TransSecsController.findController("GEMHost"); //use your host name here+    host=TransSecsController.getSingleController(); //get the host controller
     while (host==null) {      while (host==null) { 
         //print("host is still null");           //print("host is still null");  
         Thread.sleep(50); //wait 50 ms         Thread.sleep(50); //wait 50 ms
-        host=TransSecsController.findController("GEMHost");+        host=TransSecsController.getSingleController();
     }      } 
-    host=TransSecsController.findController("GEMHost");+    host=TransSecsController.getSingleController();
    // print("host is not null, setting up connection status listener");      // print("host is not null, setting up connection status listener");  
     var connectionStatusListener = new ConnectionStatusListener() {     var connectionStatusListener = new ConnectionStatusListener() {
Line 70: Line 70:
     connectionStatusChanged : function (connectionStatus, comment) {     connectionStatusChanged : function (connectionStatus, comment) {
        //updateToolStatus(connectionStatus,comment);//optional, if you want to store this information somewhere        //updateToolStatus(connectionStatus,comment);//optional, if you want to store this information somewhere
-       //below is for MIStudio projects, two BroadcastServers are written to with the connection status values+       //below is for MIStudio UI projects, two BroadcastServers are written to with the connection status values to be displayed to the operator
       StatusListenerComment->setStringValue(comment);       StatusListenerComment->setStringValue(comment);
       StatusListenerValue->setIntValue(connectionStatus);           StatusListenerValue->setIntValue(connectionStatus);    
Line 163: Line 163:
  
 </code> </code>
 +
 +Alternate Alarm Listener using a SQL Statement rather than a Historical
 +
 +<code javascript>
 +//additional class imports needed by this script
 + var DataSource = Java.type("com.ergotech.vib.servers.DataSource");
 + var AlarmListener = Java.type("com.ergotech.transsecs.secs.host.AlarmListener");
 + var ArrayValueObject = Java.type("com.ergotech.vib.valueobjects.ArrayValueObject");
 + var StringValueObject = Java.type("com.ergotech.vib.valueobjects.StringValueObject");
 + var LongValueObject = Java.type("com.ergotech.vib.valueobjects.LongValueObject"); 
 +
 +
 +//make sure that the "host" variable is not null by using the threaded script above to wait for the initialization to be complete
 +
 +  //set up alarm listener 
 + 
 + var alarmHandler  = new AlarmListener() {
 +    alarmReceived : function(alarmValues) {
 +        
 +        //prepare to log alarm data to the database
 +       id = alarmValues.getAlid();
 +       alcd = alarmValues.getAlcd();//alcd  plus set/cleared bit
 +       altx = alarmValues.getAltx();
 +       isSet = alarmValues.isSet(); // boolean, whether this alarm is set (true) or cleared (false)
 +       
 +       print ("alarm received -- id="+id+" altx="+altx+" alcd="+alcd+" set? "+isSet);
 +       DataSource.logMessage("alarm received -- id="+id+" altx="+altx+" alcd="+alcd+" set? "+isSet); 
 +       
 +       
 +       //make a ArrayValueObject of the alarm data so it can be saved in the database
 +       
 +       alarmData = new ArrayValueObject();
 +       alarmData.add(new StringValueObject(id));
 +       alarmData.add(new StringValueObject(altx));
 +       alarmData.add(new LongValueObject(alcd & 0x7F));  // remove the set/clear bit
 +       alarmData.add(new LongValueObject(isSet)); 
 +           
 +       //write to database
 +       //This assumes you have a database connection manager for your database set up in Devices called "AlarmDatabase"
 +       //"AlarmStore" is the name of the Database Write server added to "AlarmDatabase"
 +       // the SQL statement must include ?'s for each of the parmeters in the long value object (alix, altx, alcd and isSet 
 +       // for example:
 +       // insert into SECSAlarms (alid, altx, alcd, isset) values (?,?,?,?)
 +       
 +       /Devices/AlarmDatabase_Servers/AlarmStore->setValueObject(alarmData);
 +
 +  }
 +
 +};
 + 
 +  host.addAlarmListener(alarmHandler);
 +   
 +  print("Alarm Listener set up and registered");   
 +
 +</code>
 +
  • host_connection_status.1622004699.txt.gz
  • Last modified: 2021/05/25 23:51
  • by wikiadmin