Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
host_connection_status [2021/04/13 19:20] wikiadmin |
host_connection_status [2025/03/14 16:30] (current) wikiadmin |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | **Host Connection Status** | + | =====Host Connection Status |
After building a GEM Host in TransSECS you can register to receive the current status of the connection: | After building a GEM Host in TransSECS you can register to receive the current status of the connection: | ||
Line 12: | Line 12: | ||
}); | }); | ||
</ | </ | ||
- | <!-- include the wiki page " | ||
- | {{page> | + | For this code snippet to work correctly, host must not be null. This can happen if this code is run in an initialization process, such as in a StartupTrigger script, because the StartupTrigger code could be (and probably will be) run before the normal TransSECS/ |
- | **JavaScript Example for MIStudio/ | ||
- | Trigger this script | + | |
+ | /** include the wiki page " | ||
+ | |||
+ | {{page> | ||
+ | |||
+ | ====JavaScript Example for MIStudio/ | ||
+ | |||
+ | This code example is run from a StartupTrigger | ||
<code javascript> | <code javascript> | ||
Line 35: | Line 40: | ||
} | } | ||
- | | + | |
| | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====Threaded Example To Wait for Host Initialization==== | ||
+ | |||
+ | In the code below, which is run from a StartupTrigger script in TransSECS (or a script triggered by the StartupTrigger in MIStudio), a Thread is started which waits for the host not to be null and then sets up the ConnectionStatusListener. | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | // | ||
+ | var TransSecsController = Java.type(" | ||
+ | var ConnectionStatusListener = Java.type(" | ||
+ | var Thread = Java.type(" | ||
+ | |||
+ | function waitForHost() { | ||
+ | print(" | ||
+ | host=TransSecsController.getSingleController(); | ||
+ | while (host==null) { | ||
+ | // | ||
+ | Thread.sleep(50); | ||
+ | host=TransSecsController.getSingleController(); | ||
+ | } | ||
+ | host=TransSecsController.getSingleController(); | ||
+ | // print(" | ||
+ | var connectionStatusListener = new ConnectionStatusListener() { | ||
+ | |||
+ | connectionStatusChanged : function (connectionStatus, | ||
+ | // | ||
+ | // | ||
+ | StatusListenerComment-> | ||
+ | StatusListenerValue-> | ||
+ | print (" | ||
+ | } | ||
+ | }; | ||
+ | // add this listener to the host | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | /// START OF MAIN JAVASCRIPT CODE /// | ||
+ | print(" | ||
+ | |||
+ | var r = new java.lang.Runnable() { | ||
+ | run: function() { waitForHost(); | ||
+ | } | ||
+ | |||
+ | new Thread(r).start(); | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Set Up Alarm Listeners ==== | ||
+ | |||
+ | This is an example of setting up an "alarm listener" | ||
+ | |||
+ | It also stores the alarm data to a table in a database. | ||
+ | |||
+ | A simple Devices setup may be something such as: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | where Historical might be configured as such (as used in this example): | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Use this code in the same script (e.g. StartupTrigger) where you have waited for the " | ||
+ | |||
+ | <code javascript> | ||
+ | // | ||
+ | var DataSource = Java.type(" | ||
+ | var ValueChangedEvent = Java.type(" | ||
+ | var AlarmListener = Java.type(" | ||
+ | var StringValueObject = Java.type(" | ||
+ | var LongValueObject = Java.type(" | ||
+ | var LinkedHashMap = Java.type(" | ||
+ | |||
+ | |||
+ | //make sure that the " | ||
+ | |||
+ | //set up alarm listener | ||
+ | |||
+ | var alarmHandler | ||
+ | alarmReceived : function(alarmValues) { | ||
+ | | ||
+ | //prepare to log alarm data to the database | ||
+ | id = alarmValues.getAlid(); | ||
+ | alcd = alarmValues.getAlcd();// | ||
+ | altx = alarmValues.getAltx(); | ||
+ | isSet = alarmValues.isSet(); | ||
+ | |||
+ | print (" | ||
+ | | ||
+ | |||
+ | |||
+ | // | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | //add this alarm data to a valueobject | ||
+ | | ||
+ | | ||
+ | | ||
+ | // | ||
+ | // | ||
+ | //" | ||
+ | |||
+ | / | ||
+ | |||
+ | } | ||
+ | |||
+ | }; | ||
+ | |||
+ | host.addAlarmListener(alarmHandler); | ||
+ | |||
+ | print(" | ||
+ | |||
+ | </ | ||
+ | |||
+ | Alternate Alarm Listener using a SQL Statement rather than a Historical | ||
+ | |||
+ | <code javascript> | ||
+ | // | ||
+ | var DataSource = Java.type(" | ||
+ | var AlarmListener = Java.type(" | ||
+ | var ArrayValueObject = Java.type(" | ||
+ | var StringValueObject = Java.type(" | ||
+ | var LongValueObject = Java.type(" | ||
+ | |||
+ | |||
+ | //make sure that the " | ||
+ | |||
+ | //set up alarm listener | ||
+ | |||
+ | var alarmHandler | ||
+ | alarmReceived : function(alarmValues) { | ||
+ | | ||
+ | //prepare to log alarm data to the database | ||
+ | id = alarmValues.getAlid(); | ||
+ | alcd = alarmValues.getAlcd();// | ||
+ | altx = alarmValues.getAltx(); | ||
+ | isSet = alarmValues.isSet(); | ||
+ | |||
+ | print (" | ||
+ | | ||
+ | |||
+ | |||
+ | // | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | // | ||
+ | // | ||
+ | //" | ||
+ | // 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 (?,?,?,?) | ||
+ | |||
+ | / | ||
+ | |||
+ | } | ||
+ | |||
+ | }; | ||
+ | |||
+ | host.addAlarmListener(alarmHandler); | ||
+ | |||
+ | print(" | ||
</ | </ | ||