Project

General

Profile

Javascript » History » Version 8

Torbjorn Carlqvist Admin, 09/01/2021 02:32 PM

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