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/14 21:02] wikiadmin |
host_connection_status [2025/03/14 16:30] (current) wikiadmin |
||
---|---|---|---|
Line 23: | Line 23: | ||
====JavaScript Example for MIStudio/ | ====JavaScript Example for MIStudio/ | ||
- | 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: | ||
} | } | ||
- | | + | |
| | ||
Line 58: | Line 58: | ||
function waitForHost() { | function waitForHost() { | ||
print(" | print(" | ||
- | host=TransSecsController.findController(" | + | host=TransSecsController.getSingleController(); //get the host controller |
while (host==null) { | while (host==null) { | ||
// | // | ||
Thread.sleep(50); | Thread.sleep(50); | ||
- | host=TransSecsController.findController(" | + | host=TransSecsController.getSingleController(); |
} | } | ||
- | host=TransSecsController.findController(" | + | host=TransSecsController.getSingleController(); |
// print(" | // print(" | ||
var connectionStatusListener = new ConnectionStatusListener() { | var connectionStatusListener = new ConnectionStatusListener() { | ||
connectionStatusChanged : function (connectionStatus, | connectionStatusChanged : function (connectionStatus, | ||
- | | + | //updateToolStatus(connectionStatus, |
- | // | + | // |
StatusListenerComment-> | StatusListenerComment-> | ||
StatusListenerValue-> | StatusListenerValue-> | ||
Line 90: | Line 90: | ||
new Thread(r).start(); | 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(" | ||
</ | </ | ||