Javascript » History » Version 17
Torbjorn Carlqvist Admin, 09/05/2021 08:11 PM
1 | 2 | Torbjorn Carlqvist Admin | h1. Javascript guide for DTXr code IDE |
---|---|---|---|
2 | 1 | Torbjorn Carlqvist Admin | |
3 | 9 | Torbjorn Carlqvist Admin | Shows the various commands and events that can be used to build automation scripts. |
4 | 1 | Torbjorn Carlqvist Admin | |
5 | 12 | Torbjorn Carlqvist Admin | [[#Commands|Commands]] |
6 | [[#Events|Events]] |
||
7 | 10 | Torbjorn Carlqvist Admin | |
8 | 11 | Torbjorn Carlqvist Admin | --- |
9 | |||
10 | 6 | Torbjorn Carlqvist Admin | h2. Commands |
11 | |||
12 | |||
13 | h3. *print* - Prints a message to footer log window as well as the automation.log file |
||
14 | |||
15 | 1 | Torbjorn Carlqvist Admin | <pre><code class="javascript">print("hello");</code></pre> |
16 | |||
17 | 6 | Torbjorn Carlqvist Admin | h3. *readProperty* - Reads an object property value |
18 | 3 | Torbjorn Carlqvist Admin | |
19 | 4 | Torbjorn Carlqvist Admin | <pre><code class="javascript"> |
20 | 8 | Torbjorn Carlqvist Admin | /*********************************************************************************************** |
21 | * @param {Number} device - The device id |
||
22 | * @param {Number} objectType - The object type. Both id and enumerated names can be used. |
||
23 | * @param {Number} objectInstance - The object instance. Must be a positive number. |
||
24 | * @param {Number} propertyId - The property id. Both id and enumerated names can be used. |
||
25 | 13 | Torbjorn Carlqvist Admin | * @return {*} The result can be of any type. It is dependent of the object type and property. Primitive values such as numbers and string but also JSON formatted text. |
26 | 8 | Torbjorn Carlqvist Admin | ***********************************************************************************************/ |
27 | |||
28 | 4 | Torbjorn Carlqvist Admin | //Reads a present value from analog input object 0. |
29 | Controller.readProperty(85343,analogInput,0,presentValue); |
||
30 | 5 | Torbjorn Carlqvist Admin | |
31 | //Use the result to print and in logic |
||
32 | res = Controller.readProperty(85343,analogInput,0,presentValue); |
||
33 | print(res); |
||
34 | 1 | Torbjorn Carlqvist Admin | if ( res > 0 ){ |
35 | print("value larger than 0!"); |
||
36 | 6 | Torbjorn Carlqvist Admin | } |
37 | 1 | Torbjorn Carlqvist Admin | </code></pre> |
38 | 15 | Torbjorn Carlqvist Admin | |
39 | 16 | Torbjorn Carlqvist Admin | h3. *eventSubscribe* - Send request for intrinsic reporting notification to a remote node. |
40 | 15 | Torbjorn Carlqvist Admin | |
41 | <pre><code class="javascript"> |
||
42 | /*********************************************************************************************** |
||
43 | * @param {Number} device - The device id |
||
44 | * @param {Number} notificationClass - This is the instance of the remote notification class where the request will be handled. |
||
45 | * @return N/A |
||
46 | ***********************************************************************************************/ |
||
47 | |||
48 | //Request for notification from device 84757 and notification class 0 |
||
49 | Controller.eventSubscribe(84757,0); |
||
50 | |||
51 | </code></pre> |
||
52 | 6 | Torbjorn Carlqvist Admin | |
53 | h2. Events |
||
54 | 7 | Torbjorn Carlqvist Admin | |
55 | 6 | Torbjorn Carlqvist Admin | h3. *eventNotificationReceived* - Called when an intrinsic report notification is received. |
56 | |||
57 | <pre><code class="javascript"> |
||
58 | /*********************************************************************************************** |
||
59 | 14 | Torbjorn Carlqvist Admin | * @param {Number} processIdentifier - Event process on the caller side |
60 | * @param {Number} initiatingDevice - The device that send the event |
||
61 | * @param {Number} object - The source object in readable format |
||
62 | 6 | Torbjorn Carlqvist Admin | * @param {Number} objectType - The source object of the event |
63 | 1 | Torbjorn Carlqvist Admin | * @param {Number} objectInstance - The instance of source object |
64 | 14 | Torbjorn Carlqvist Admin | * @param {String} timeStampUTC - Event timestamp in UTC format |
65 | * @param {Number} notificationClass - The NC handling this event on remote node |
||
66 | * @param {Number} priority - Event priority |
||
67 | 1 | Torbjorn Carlqvist Admin | * @param {Number} eventType - The type of event received |
68 | 14 | Torbjorn Carlqvist Admin | * @param {String} messageText - Readable notification message |
69 | * @param {Number} notifyType - Type of notification [0:Event,1:Alamr,2:AckNotif] |
||
70 | * @param {Boolean} ackRequired - true if ack is required to clear this event on the remote node |
||
71 | 1 | Torbjorn Carlqvist Admin | * @param {String} fromState - The previous state |
72 | 6 | Torbjorn Carlqvist Admin | * @param {String} toState - The current state after the change |
73 | 14 | Torbjorn Carlqvist Admin | * @param {Object} eventValues - A map of specific map of values for the particular eventType |
74 | 6 | Torbjorn Carlqvist Admin | ***********************************************************************************************/ |
75 | 1 | Torbjorn Carlqvist Admin | function eventNotificationReceived(processIdentifier,initiatingDevice,object,objectType,objectInstance,timeStampUTC,notificationClass,priority,eventType,messageText,notifyType,ackRequired,fromState,toState,eventValues){ |
76 | 7 | Torbjorn Carlqvist Admin | //Use this event to act on notifications that is set to be subscribed by this device. |
77 | 5 | Torbjorn Carlqvist Admin | } |
78 | 4 | Torbjorn Carlqvist Admin | </code></pre> |