Javascript » History » Version 9
Torbjorn Carlqvist Admin, 09/01/2021 03:33 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 | 6 | Torbjorn Carlqvist Admin | h2. Commands |
6 | |||
7 | |||
8 | h3. *print* - Prints a message to footer log window as well as the automation.log file |
||
9 | |||
10 | 1 | Torbjorn Carlqvist Admin | <pre><code class="javascript">print("hello");</code></pre> |
11 | |||
12 | 6 | Torbjorn Carlqvist Admin | h3. *readProperty* - Reads an object property value |
13 | 3 | Torbjorn Carlqvist Admin | |
14 | 4 | Torbjorn Carlqvist Admin | <pre><code class="javascript"> |
15 | 8 | Torbjorn Carlqvist Admin | |
16 | /*********************************************************************************************** |
||
17 | * @param {Number} device - The device id |
||
18 | * @param {Number} objectType - The object type. Both id and enumerated names can be used. |
||
19 | * @param {Number} objectInstance - The object instance. Must be a positive number. |
||
20 | * @param {Number} propertyId - The property id. Both id and enumerated names can be used. |
||
21 | ***********************************************************************************************/ |
||
22 | |||
23 | 4 | Torbjorn Carlqvist Admin | //Reads a present value from analog input object 0. |
24 | Controller.readProperty(85343,analogInput,0,presentValue); |
||
25 | 5 | Torbjorn Carlqvist Admin | |
26 | //Use the result to print and in logic |
||
27 | res = Controller.readProperty(85343,analogInput,0,presentValue); |
||
28 | print(res); |
||
29 | 1 | Torbjorn Carlqvist Admin | if ( res > 0 ){ |
30 | print("value larger than 0!"); |
||
31 | 6 | Torbjorn Carlqvist Admin | } |
32 | </code></pre> |
||
33 | |||
34 | h2. Events |
||
35 | 7 | Torbjorn Carlqvist Admin | |
36 | 6 | Torbjorn Carlqvist Admin | h3. *eventNotificationReceived* - Called when an intrinsic report notification is received. |
37 | |||
38 | <pre><code class="javascript"> |
||
39 | /*********************************************************************************************** |
||
40 | * @param {Number} device - The device that send the event |
||
41 | * @param {Number} objectType - The source object of the event |
||
42 | * @param {Number} objectInstance - The instance of source object |
||
43 | * @param {Number} eventType - The type of event received |
||
44 | * @param {String} fromState - The previous state |
||
45 | * @param {String} toState - The current state after the change |
||
46 | * @param {Object} eventValues - A map of specific values for this particular eventType |
||
47 | ***********************************************************************************************/ |
||
48 | 1 | Torbjorn Carlqvist Admin | function eventNotificationReceived(processIdentifier,initiatingDevice,object,objectType,objectInstance,timeStampUTC,notificationClass,priority,eventType,messageText,notifyType,ackRequired,fromState,toState,eventValues){ |
49 | 7 | Torbjorn Carlqvist Admin | //Use this event to act on notifications that is set to be subscribed by this device. |
50 | 5 | Torbjorn Carlqvist Admin | } |
51 | 4 | Torbjorn Carlqvist Admin | </code></pre> |