Project

General

Profile

Javascript » History » Revision 16

Revision 15 (Torbjorn Carlqvist Admin, 09/01/2021 03:54 PM) → Revision 16/28 (Torbjorn Carlqvist Admin, 09/01/2021 03:55 PM)

h1. Javascript guide for DTXr code IDE 

 Shows the various commands and events that can be used to build automation scripts. 

 [[#Commands|Commands]] 
 [[#Events|Events]] 

 --- 

 h2. Commands 


 h3. *print*    - Prints a message to footer log window as well as the automation.log file 

 <pre><code class="javascript">print("hello");</code></pre> 

 h3. *readProperty*    - Reads an object property value 

 <pre><code class="javascript"> 
 /*********************************************************************************************** 
  * @param {Number} device - The device id 
  * @param {Number} objectType - The object type. Both id and enumerated names can be used. 
  * @param {Number} objectInstance - The object instance. Must be a positive number. 
  * @param {Number} propertyId - The property id. Both id and enumerated names can be used. 
  * @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. 
  ***********************************************************************************************/ 

 //Reads a present value from analog input object 0. 
 Controller.readProperty(85343,analogInput,0,presentValue); 

 //Use the result to print and in logic 
 res = Controller.readProperty(85343,analogInput,0,presentValue); 
 print(res); 
 if ( res > 0 ){ 
   print("value larger than 0!"); 
 } 
 </code></pre> 

 

 h3. *eventSubscribe* *EventSubscribe*    - Send request for intrinsic reporting notification to a remote node. 

 <pre><code class="javascript"> 
 /*********************************************************************************************** 
  * @param {Number} device - The device id 
  * @param {Number} notificationClass - This is the instance of the remote notification class where the request will be handled. 
  * @return N/A 
  ***********************************************************************************************/ 

 //Request for notification from device 84757 and notification class 0 
 Controller.eventSubscribe(84757,0); 

 </code></pre> 

 


 h2. Events 

 h3. *eventNotificationReceived* - Called when an intrinsic report notification is received. 

 <pre><code class="javascript"> 
 /*********************************************************************************************** 
  * @param {Number} processIdentifier - Event process on the caller side 
  * @param {Number} initiatingDevice - The device that send the event 
  * @param {Number} object - The source object in readable format  
  * @param {Number} objectType - The source object of the event 
  * @param {Number} objectInstance - The instance of source object 
  * @param {String} timeStampUTC - Event timestamp in UTC format 
  * @param {Number} notificationClass - The NC handling this event on remote node 
  * @param {Number} priority - Event priority 
  * @param {Number} eventType - The type of event received 
  * @param {String} messageText - Readable notification message 
  * @param {Number} notifyType - Type of notification [0:Event,1:Alamr,2:AckNotif] 
  * @param {Boolean} ackRequired - true if ack is required to clear this event on the remote node 
  * @param {String} fromState - The previous state 
  * @param {String} toState - The current state after the change 
  * @param {Object} eventValues - A map of specific map of values for the particular eventType 
  ***********************************************************************************************/ 
 function eventNotificationReceived(processIdentifier,initiatingDevice,object,objectType,objectInstance,timeStampUTC,notificationClass,priority,eventType,messageText,notifyType,ackRequired,fromState,toState,eventValues){ 
 //Use this event to act on notifications that is set to be subscribed by this device. 
 } 
 </code></pre>