Материал из for iRidium developers
Перейти к: навигация, поиск
Эта страница является переводом страницы Systems API. Перевод выполнен на 100%.

Other languages:
English • ‎русский

IR object - it is a global object containing all functions and constants of iRidium API. Methods of IR objects for controlling system events of the iRidium application.

Methods

IR.ShowSystemMenu

to open the system menu with the engineer password. After executing the command you will see the window for inputting the password, the system menu will open after you input 2007.

Syntax

IR.ShowSystemMenu();

input value description

-

output

-


Sample

function ShowMenu () {
    IR.ShowSystemMenu();
};

you cannot get access to the system menu via scripts without inputting the engineer password.


IR.ShowSettingsMenu

Open the projects menu of i3 pro on the specified tab: Cloud or Local

Syntax

IR.ShowSettingsMenu(tab_id);

input value description
tab_id 1 type: number
identifier of menu tab:
  • 0 - Local projects
  • 1 - Cloud projects
output

-


Sample

function ShowMenu () {
    IR.ShowSettingsMenu(1);
};





IR.HWID

the property of IR objects, it stores HWID of the control panel where the i3 pro is running.

Syntax

IR.HWID

input value description

-

output
hwid ff2c...1958 type: string
conrol panel HWID


Sample

IR.AddListener(IR.EVENT_START,0,function()
{
    IR.Log("Panel HWID: "+IR.HWID); // Panel HWID: ff2c589a2879c0fe1158697d5d4c1958
});

to get a symbol from HWID use the function charAt(symbol). The numeration of symbols starts with zero:

IR.Log(IR.HWID.charAt(0));




IR.Exit

to close the application. It is available for Android and Windows only

Syntax

IR.Exit();

input value description

-

output

-


Sample

function CloseApp () {
    IR.Exit();
};

it is available for Android and Windows only


IR.ShowKeyboard

to show the system keyboard of iOS or Android devices

Syntax

IR.ShowKeyboard(type, ok_text, color, capitalization)

input value description
type 1 type: Number
keyboard type that can also hide the keyboard (with 0 value):
  • works with iOS and Android:
    • 0 - Hide
    • 1 - Regular
    • 2 - URL address
    • 3 - Numeric
    • 4 - Phone number
    • 5 - E-mail address
    • 6 - Decimal
    • 7 - Text
    • 8 - Twitter
    • 9 - Web search
    • 10 - Numeric
    • 11 - Password
  • works only with Android:
    • 12 - Date and Time
    • 13 - Date
    • 14 - Time
    • 15 - Numeric signed
    • 16 - Numeric password
    • 17 - Text characters
    • 18 - Text sentences
    • 19 - Text words
    • 20 - Text ime multi line
    • 21 - Text multi line
    • 22 - Text suggestions
    • 23 - Text email subject
    • 24 - Text filter
    • 25 - Text long message
    • 26 - Text password
    • 27 - Text phonetic
    • 28 - Text postal address
    • 29 - Text short message
    • 30 - Text visible password
    • 31 - Text web email address
    • 32 - Text web password
    • 33 - Smart
    • 34 - Voice
ok_text 0 type: Number
text on "return" button:
  • 1 - default
  • 2 - go
  • 3 - google
  • 4 - join
  • 5 - next
  • 6 - route
  • 7 - search
  • 8 - send
  • 9 - yahoo
  • 10 - done
  • 11 - call
  • 12 - continue
color 0 type: Number
keyboard color
  • 1 - auto
  • 2 - dark
  • 3 - lite
capitalization 0 type: Number
auto-capitalization of text
  • 1 - none
  • 2 - words
  • 3 - sentences
  • 4 - all symbols
output

-


Sample

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 1"), function()
{
  IR.ShowKeyboard(1); // regular
  IR.ShowKeyboard(1, 1, 1, 1); // regular, default, default, no capitalization
});

For iOS - use the command IR.ShowKeyboard(0) to hide the keyboard. It will not work on Android.
To open the keyboard, all other keyboards have to be closed. If a keyboard (for example, a numeric one) is already opened, the command for opening the alphabet keyboard will not work.
To open a keyboard on Windows, use the command IR.Execute("osk").


IR.Execute

to execute a random URL scheme (a command to the OS) supported by the device. Such commands include: opening hyperlinks in the browser, sending SMS, making calls by the phone number, writing e-mails, launching applications by their names, запустить Launching applications by the indicated path, etc.

Syntax

IR.Execute(scheme)

input value description
scheme http://iridiummobile.net type: string
the command to be executed
output

-


Sample

IR.AddListener(IR.EVENT_START, 0, function() {
    IR.Execute('http://iridiummobile.net');
});

examples of URL schemes

 // All
	IR.Execute("http://iridiummobile.net"); // open link
	IR.Execute("mailto:support@iridiummobile.ru"); // send email
// Windows	
	IR.Execute("cmd"); // command string
	IR.Execute("calc"); // calculator
	IR.Execute("c:\\Program Files\\iRidium\\iRidium.exe"); // launch app
// iOS, Android
	IR.Execute("music:"); // open Music
	IR.Execute("videos:"); // open Videos
	IR.Execute("ibooks://"); // open iBooks
	IR.Execute("fb://feed"); //open Facebook
	IR.Execute("twitter://"); // open Twitter
// iPhone, Android smartphone
	IR.Execute("tel:+1234567890"); // call to
	IR.Execute("sms:+1234567890"); // send SMS


Windows: to launch an application on Windows - each slash in the path to the file must be substituted by the double back slash mark


IR.GetSystemInfo

to get information about the application memory and cache

Syntax

IR.GetSystemInfo("GC_MEMORY_INFO").property

input value description
property UsedMemory type: object
the property to return:
  • .UsedMemory
  • .TotalMemory
  • .ChunkHeaps
  • .ChunkCache
  • .MemoryHeaps
  • .MemoryBusyBlocks
  • .MemoryFreeBlocks
output
property type: string
the value in the property


Sample

IR.AddListener(IR.EVENT_START,0,function() {
    IR.Log(IR.GetSystemInfo("GC_MEMORY_INFO").UsedMemory);
});





IR.GetCurrentWlanInfo

to get information about the wireless network to which the control panel is connected. The list of networks in united in an array. Each network is an array element with fixed list of properties.

Syntax

IR.GetCurrentWlanInfo()[element].property

input value description
element 0...n type: number
the number of the array element corresponding to the sequence number of the network connection
property Name type: object
the property to return:
  • .Name - the type of the network connection
  • .SSID - the network name
output
property type: string
the value in the property


Sample

IR.Log(IR.GetCurrentWlanInfo()[0].SSID)
IR.AddListener(IR.EVENT_START,0,function()
{
   var l_aWlanInfo = IR.GetCurrentWlanInfo();
   if (l_aWlanInfo.length) {
	   IR.Log("Name = " + l_aWlanInfo[0].Name);
	   IR.Log("SSID = " + l_aWlanInfo[0]['SSID']);
   } else {
      IR.Log("There is no network connections found");
   }
});

Check the length of the array to make sure there is at least one network


IR.GetCurrentLocalIPInfo

to get network settings of the control panel with running i3 pro

Syntax

IR.GetCurrentLocalIPInfo()[element].property

input value description
element 0...n type: number
the number of the array element corresponding to the sequence number of the network connection
property Name type: object
the property to return:
  • .Name - the name of the network connection
  • .IP - the control panel IP-address
  • .Mask - the subnet mask
  • .MAC - the MAC address
output
property type: string
the value in the property


Sample

IR.AddListener(IR.EVENT_START,0,function()
{      
   var l_aIPInfo = IR.GetCurrentLocalIPInfo();
   IR.Log("Name = " + l_aIPInfo[0].Name);
   IR.Log("IP = " + l_aIPInfo[0].IP);
   IR.Log("Mask = " + l_aIPInfo[0].Mask);
   IR.Log("MAC = " + l_aIPInfo[0].MAC);
});





IR.Log

t output data in the debug console of the i3 pro application (the console is opened in Windows through F4)

Syntax

IR.Log(data);

input value description
data type: object, string, number, array
the data for output in the log
output
data type: string
the string data in the application log


Sample

IR.AddListener(IR.EVENT_START,0,function() {
    IR.Log("Hello World!");
});

the data sent to the console are converted into a string


IR.SetInterval

to repeat action in a cycle with the preset interval (ms)

Syntax

IR.SetInterval(time, action)

input value description
time 500 type: number
(ms) the interval of executing the function
action function() { } type: number
the unnamed function or the name of the function which contains the list of actions for executing them in a cycle
output

-


Sample

function actions() 
{
  IR.Log("do action");
}
IR.SetInterval (2000, actions);
IR.SetInterval (2000, function() 
{
  IR.Log("do action");
});
var Inv = IR.SetInterval (2000, function() 
{
  IR.Log("do action");
}); 
IR.ClearInterval(Inv);

IR.SetInterval will work until the project is closed, if you do not stop it with the help of IR.ClearInterval
The interval can be stopped only by referring to it by the variable name. Make sure you assign the name to the variable when you create the interval
In the interval you cannot start functions with parameters
JavaScript works in one stream in iRidium. It means all functions in it are executed sequentially. For the IR.SetInterval function it means that each cycle of script execution can take different time. It leads to errors of interval execution which depend on the number and type of executed operations. The system compensates the errors automatically for accuracy in big time periods (to avoid accumulation of temporary errors). That is why the intervals can differ by dozens or hundreds milliseconds upward or downward. Keep this in mind when creating commands for which the minimal interval is critical - set up the bigger interval value or use the function IR.SetTimeout which does not use the compensation mechanism.


IR.SetTimeout

to perform the function after the preset timeout (ms)

Syntax

IR.SetTimeout(time, action)

input value description
time 500 type: number
(ms) the delay of function execution
action function() { } type: number
the unnamed function or the name of the function which stores the list of actions for execution with the delay
output

-


Sample

function actions() 
{
  IR.Log("do action");
}
IR.SetTimeout(2000, actions);
IR.SetTimeout(2000, function() 
{
  IR.Log("do action");
});
var Tmr = IR.SetTimeout(2000, function() 
{
  IR.Log("do action");
}); 
IR.ClearInterval(Tmr);

IR.SetTimeout can be stopped with the help of IR.ClearInterval (there is no separate function IR.ClearTimeout).
The timer can be stopped only when you refer to it by the variable name. That is why do not forget to assign the name to the variable when creating the timeout
You cannot send functions with parameters to the timer


IR.ClearInterval

to delete the timers IR.SetInterval and IR.SetTimeout by their identifiers. To get the identifier, save it in the variable. It is possible only when you create the timer.

Syntax

IR.ClearInterval(timer_id)

input value description
timer_id var timer type: object
the identifier of the timer you want to delete
output

-


Sample

var id = IR.SetTimeout (10000, function ()
{
        IR.Log("do something");
}); 
IR.SetTimeout(5000, function ()  // stop after 5000 ms
{
        IR.ClearInterval(id);
});

it is used to delete IR.SetInterval and IR.SetTimeout
you can get the identifier used at deletion only when you create the timer


IR.AddListener

to create a listener - a function which is executed in case of activation of the indicated event. The event - a process forwarded in scripts with the identifier for monitoring. The list of event is available in the handbook.

Syntax

IR.AddListener(event, input, function, [pointer]);

input value description
event type: object
the identifier of the event monitored by the listener
input type: object
the input parameter required to create the listener. If there is no such parameter, indicate 0
function function() {} type: function
the unnamed function or reference to the function where action are executed
pointer type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_START,0,function()
{
    IR.Log("app started");
});
IR.AddListener(IR.EVENT_ITEM_PRESS,IR.GetItem("Page 1").GetItem("Item 61"),function()
{
   IR.Log("button 61 pressed");  
});


Example 2:

for(var i = 0; i < IR.GetItem("Page 1").ItemsCount; i++){
   // call the listener and add the pointer
   IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem(i),  press,  IR.GetPage("Page 1").GetItem(i) );
} 
function press(){
   //output the name of the activated button in the log using 'this' as a reference to the object
 
   IR.Log(this.Name);
}

You can read about execution of scripts with the help of listeners in the guide


IR.RemoveListener

to remove the listener created with the help of IR.AddListener. The function has to receive the same parameters which were indicated at creation of the listener.

Syntax

IR.RemoveListener(event, input, function, [pointer]);

input value description
event type: object
the identifier of the event monitored by the listener
input type: object
the input parameter required to create the listener. If there is no such parameter, indicate 0
function function() {} type: function
the unnamed function or reference to the function where action are executed
pointer type: object
the pointer to the object which serves the function (optional)
output

-


Sample

function pressed () 
{
    IR.Log("action");
}
// add listener
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), pressed); 
// remove listener
IR.RemoveListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), pressed);
var l_pressed;
// add listener
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), l_pressed =  function () 
{
    IR.Log("action");
});
// remove listener
IR.RemoveListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), l_pressed);





IR.SetGlobalListener

to create the global listener - the function which is executed in case of activation of the indicated event. It can operate only with two events: IR.EVENT_GLOBAL_TAG_CHANGE (it is activated when changing any tag in iRidium) and IR.EVENT_GLOBAL_GUI_CHANGE (it is activated at any interface event).

Unlike IR.AddListener, the global listener can be called only once. When calling the listener again, only the last listener created by the interpreter at script launch will work.

For the listener to work at tag changes in the iRidium project, you need to subscribe to the changes with the help of the method IR.SubscribeTagChange

Syntax

IR.SetGlobalListener(event, function, [pointer]);

input value description
event IR.EVENT_GLOBAL_TAG_CHANGE type: object
the identifier of the event which is monitored by the global listener:
function function(name, value) {} type: function
the unnamed function or reference to the called function inside which actions are executed. The function received the name of the tag for which there is a subscription and the changed value
pointer type: object
the pointer to the object which serves the function (optional)
output

-


Sample

// Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
     IR.Log("Active Global Listener: " + name + "\tValue: " + value);
});
// Subscribe 
IR.SubscribeTagChange("Drivers.KNX.Online");       // driver token
IR.SubscribeTagChange("Drivers.KNX.Address 1");       // driver feedback
IR.SubscribeTagChange("Global.Token 1");           // project token
IR.SubscribeTagChange("UI.Page 1.Item 1.Text");    // item property
IR.SubscribeTagChange("System.Time.Hour");         // system time, hours
IR.SubscribeTagChange("System.Time.Minutes");      // system time, minutes
// resend the data from KNX Address 1 to Address 2 on change (for iRidium Server)
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
   if (name == "Server.Channels.KNX.Address 1")
      IR.SetVariable("Server.Channels.KNX.Address 2", value);
});
IR.SubscribeTagChange("Server.Channels.KNX.Address 1");

the listener will get the full name of the tag to which you subscribed (name)
The global listener can be created only once - only the listener created last will work
The listener reacts on tag changes only when it is subscribed to this tag with the method IR.SubscribeTagChange
The listener reacts only on tag changes (it will not work if the received value equals to the current one)
The maximum number of subscriptions to the global listener is almost not limited (it is about a million)
Unsubscribe from the tag: IR.UnsubscribeTagChange


IR.SubscribeTagChange

to subscribe to the tag changes in iRidium via the global listener to the event IR.EVENT_GLOBAL_TAG_CHANGE. The tags the listener is subscribed to return their value at each change.

Syntax

IR.SubscribeTagChange(name);

input value description
name "Drivers.AV (TCP).Feedback 1" type: string
the full name of the tag on which you need to subscribe with the help of the global listener IR.EVENT_GLOBAL_TAG_CHANGE
output

-


Sample

//Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
     IR.Log("Global Listener Activated: " + name + "\tValue: " + value);
});
// Subscribe 
IR.SubscribeTagChange("Drivers.KNX IP Router.Address 1"); 
IR.SubscribeTagChange("Drivers.AV & Custom Systems (TCP).Online"); 
IR.SubscribeTagChange("UI.Page 1.Item 1.Text"); 
IR.SubscribeTagChange("System.Time.24");
// resend the data from KNX Address 1 to Address 2 on change (for iRidium Server)
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
   if (name == "Server.Channels.KNX.Address 1")
      IR.SetVariable("Server.Channels.KNX.Address 2", value);
});
IR.SubscribeTagChange("Server.Channels.KNX.Address 1");

You can unsubscribe from the tag with the help of the method IR.UnsubscribeTagChange


IR.UnsubscribeTagChange

to unsubscribe from the iRidium tag which changes are monitored by the global listener on the event IR.EVENT_GLOBAL_TAG_CHANGE. The subscription to the tag is performed with the help of the method IR.SubscribeTagChange

Syntax

IR.UnsubscribeTagChange(name);

input value description
name "Drivers.AV (TCP).Feedback 1" type: string
the full name of the tag from which you need to unsubscribe
output

-


Sample

//Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value) 
{
     IR.Log("Global Listener Activated: " + name + "\tValue: " + value);
});
// Subscribe
IR.SubscribeTagChange("UI.Page 1.Item 1.Text"); 
// Unsubscribe
IR.UnsubscribeTagChange("UI.Page 1.Item 1.Text");

You can subscribe to the tag with the help of the method IR.SubscribeTagChange


IR.CopyToClipboard

to copy the string in the exchange buffer of the iOS, Android, Windows device

Syntax

IR.CopyToClipboard(text)

input value description
text 'data' type: string
the string which have to be placed in the exchange buffer
output

-


Sample

IR.AddListener(IR.EVENT_START, 0, function()
{    
   IR.CopyToClipboard(IR.GetVariable("System.Device.Name") + " HWID: " + IR.HWID);
});





IR.PasteFromClipboard

Paste the text from clipboard to an active EditBox Item. Only the Text will be pasted (not an images or other data). Cursor will be positioned after the text

Синтаксис

IR.PasteFromClipboard()

на входе значение описание

-

на выходе

-


Пример

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Paste Button"),function()
{
   IR.PasteFromClipboard();  
});

how to use: create the item "Paste text" beside of EditBox Item


IR.GetClipboard

Receive the text from clipboard

Syntax

IR.GetClipboard()

input value description

-

output

-


Sample

var clipboard = IR.GetClipboard();

how to use: send the text from clipboard to JS


IR.ShowPasteHelper

This method shows the native Paste dialog above the EditBox item. This dialog includes the text "Paste" and performs the action IR.PasteFromClipboard();. when you press on it. If you press on any other item it will close this dialog

Syntax

IR.ShowPasteHelper()

input value description

-

output

-


Sample

IR.AddListener(IR.EVENT_ITEM_HOLD, IR.GetItem("Page 1").GetItem("EditBox"),function()
{
   IR.ShowPasteHelper();  
});

How it works on Editbox Item:

  • Windows:
    • When you press CTRL+V, the metod IR.PasteFromClipboard(); occures if the clipboard is not empty and it is the Text there
    • If you press on EditBox with rhe right mouse button, you'll see the standard Paste dialog
    • cursor will be positioned in the end of pasted string
  • iOS, Android:
    • When you hold the EditBox 1 second, IR.ShowPasteHelper(); occures
    • cursor will be positioned in the end of pasted string




IR.GetDesignsCount

to count the number of visualization projects in the application memory.

Syntax

IR.GetDesignsCount();

input value description

-

output
number 1 type: number
the number of projects uploaded in the memory of the control panel


Sample

IR.AddListener(IR.EVENT_START, 0, function() {
   var l_iCount = IR.GetDesignsCount();
   IR.Log("Designs Count = " + l_iCount);
   IR.Log("Current Project: " + IR.ProjectName);
 
   for(var i = 0; i < l_iCount; i++) {
      var l_sName = IR.GetDesignByIndex(i);
      IR.Log("Design(" + i + "): " + l_sName.Name);
   }
});

An additional functions:

  • IR.ProjectName - the property of IR object that stores the name of project opened in i3 pro
  • IR.GetDesignByIndex(i) - get the link to the project as an object by calling it by the index of project position in the list of downloaded projects




IR.DesignSwitch

count the number of projects uploaded to the i3 pro app

Syntax

IR.DesignSwitch(name);

input value description
name "Welcome" type: string
the name of project you want to switch to
output

-


Sample

IR.AddListener(IR.EVENT_START, 0, function() {
   var l_iCount = IR.GetDesignsCount();
   IR.Log("Designs Count = " + l_iCount);
   IR.Log("Current Project: " + IR.ProjectName);
 
   for(var i = 0; i < l_iCount; i++) {
      var l_sName = IR.GetDesignByIndex(i);
      IR.Log("Design(" + i + "): " + l_sName.Name);
   }
}); 
 
function switch_to () {
   IR.DesignSwitch("Welcome"); // name of Project you want to switch to
}

in a sample we switch to the start page of i3 pro (Welcome project) by the button click. An additional functions:

  • IR.GetDesignsCount() - to count the number of visualization projects in the i3 pro memory
  • IR.ProjectName - the property of IR object that stores the name of project opened in i3 pro
  • IR.GetDesignByIndex(i) - get the link to the project as an object by calling it by the index of project position in the list of downloaded projects




IR.AndroidSendIR

to send IR command through built-in IR emitter of Android device (IRDA)

Syntax

IR.AndroidSendIR(frequency, command);

input value description
frequency 38000 type: number
(Hz) the frequency of the IR command send
command [67,67,44,...,55,53,13] type: array
IR command as an array that includes pulses and a pause of IR signal
output

-


Sample

IR.AndroidSendIR(38000, [67,67,67,67,67,66,67,67,67,67,67,67,66,67,66,66,66,66,66,66,44,50,49,44,55,53,54,13]);

if you have a command in HEX format, you can transform it into a format for sending via the program iConvert from Global Cache


IR.OpenBrowser

Open link in browser of iOS, Android, Windows, Mac device without leaving the i3 pro app

Syntax

IR.OpenBrowser(link);

input value description
link "http://google.com" type: string
HTTP(s) link
output

-


Sample

function openbrowser () 
{
    IR.OpenBrowser("http://google.com");
}

while you work with a browser, iRidium for iOS is "frozen"
the included browser correctly supported by i3 pro on iOS and Android devices


Popen

Popen - a process enabling iRidium Server to execute a command in the Windows and Linux command string. Popen does not work in the i3 pro client application. Executing of Popen opens the file directory of the process and allows you to sent information about command work in the indicated instance of the listener function. In order to execute several commands and distinguish information about their work, create Popen instances.

Syntax

var cmd_process = new Popen (command, function);

input value description
command 'ping 192.168.0.1' type: string
the command for execution in the command string (cmd.exe)
function cmd_result type: function
the instance of the listener function where the results of command execution will be sent
output
line .onRecieve type: string
the data generated by the command during execution. The .OnReceive event is activated in the context of Popen and receives the line string as an input parameter. The string can be output in the log or written in the iRidium Server variable
result .onEnd type: number
the code generated by the command at its finishing. The .onEnd event is activated in the context of Popen and result is received as an input parameter. You can output the code in the log or write in the iRidium Server variable:
  • 0 - the command is successfully finished
  • 259 and other numbers - errors. Error codes will be generated at execution of the .Stop() method - premature command finishing and in case of a negative result (for example, when the IP-address is unavailable for the ping command)
.Stop() .Stop() type: method
the command of forced finish of the Popen process. You do not need to finish the process if the .onEnd event is activated. But you are required to finish it when the command does not finish (for example, as continuous ping)


Sample

function Listener (cmd)
{
   this.onRecieve = function(line)
   {
      IR.Log(line); 
   }
 
   this.onEnd = function(result)
   {
      IR.Log('Command: '+ cmd + " Result: " + result);
   }   
}
 
function stop()
{
  cmd_process.Stop();
}
 
var cmd_result    =  new Listener ('ping 192.168.0.1');
var cmd_process   =  new Popen ('ping 192.168.0.1', cmd_result);

To finish the process use the Stop() method. Command which do not finish by themselves must be stopped as each of them uses OS resources and affects speed of operation

Popen works only in iRidium Server on Windows and Linux. It does not work in i3 pro


iDate (object)

iDate - it is a representation of a date as 64 bit number with floating point. It can operate dates and time in the range from January 1, 100 to December 31, 9999.

Details and samples: iDate Object


IR.CalculateCRC

Calculate Cyclic Redundancy Check (CRC) with CRC8, CRC16 or CRC32 algorithm

Syntax

IR.CalculateCRC(algorithm, string);

input value description
algorithm IR.CRC_16 type: object
CRC algorithm:
  • IR.CRC_8
  • IR.CRC_16
  • IR.CRC_32
string "Test" type: string
string for which you want to calculate CRC
output
CRC 7205 type: number
CRC calculating result


Sample

var crc8 = IR.CalculateCRC(IR.CRC_8,  "Test");
var crc16 = IR.CalculateCRC(IR.CRC_16, "Test");
var crc32 = IR.CalculateCRC(IR.CRC_32, "Test");
 
IR.Log(crc8) // 207
IR.Log(crc16) // 7205
IR.Log(crc32) // 2018365746





IR.CalculateHash

Calculate the hash-sum with MD5, SHA1, SHA256, SHA384 or SHA512 algorithm

Syntax

IR.CalculateCRC(algorithm, string);

input value description
algorithm IR.HASH_MD5 type: object
the algorithm for calculating the hash-sum:
  • IR.HASH_MD5
  • IR.HASH_SHA1
  • IR.HASH_SHA256
  • IR.HASH_SHA384
  • IR.HASH_SHA512
string "Test" type: string
string for which you want to calculate hash-sum
output
hash 0cbc66...5a615b type: number
hash-sum calculating result


Sample

var hashMD5 = IR.CalculateHash(IR.HASH_MD5, "Test");
var hashSHA1 = IR.CalculateHash(IR.HASH_SHA1, "Test");
var hashSHA256 = IR.CalculateHash(IR.HASH_SHA256, "Test");
var hashSHA384 = IR.CalculateHash(IR.HASH_SHA384, "Test");
var hashSHA512 = IR.CalculateHash(IR.HASH_SHA512, "Test");
 
IR.Log(hashMD5);     // 0cbc6611f5540bd0809a388dc95a615b
IR.Log(hashSHA1);    // 640ab2bae07bedc4c163f679a746f7ab7fb5d1fa
IR.Log(hashSHA256);  // 532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25
IR.Log(hashSHA384);  // 7b8f4654076b80eb963911f19cfad1aaf4285ed48e826f6cde1b01a79aa73fadb5446e667fc4f90417782c91270540f3
IR.Log(hashSHA512);  // c6ee9e33cf5c6715a1d148fd73f7318884b41adcb916021e2bc0e800a5c5dd97f5142178f6ae88c8fdd98e1afb0ce4c8d2c54b5f37b30b7da1997bb33b0b8a31





IR.UrlDecode

change the UTF-8 sequences to the related symbols (decode UTF-8 sequence)

Syntax

IR.UrlDecode(url);

input value description
url 'http://www.google.com/search?&q=%D0%BE%D0%BA' type: string
UTF-8 string, usually the link that should be decoded
output
url http://www.google.com/search?&q=ок type: string
result


Sample

IR.AddListener(IR.EVENT_START,0,function()
{
   var utf8_encode = encodeURI('http://www.google.com/search?&q=ок');
   IR.Log(utf8_encode); // http://www.google.com/search?&q=%D0%BE%D0%BA
 
   var decode = IR.UrlDecode(utf8_encode);
   IR.Log(decode);	// http://www.google.com/search?&q=ок
});





IR.HtmlDecode

decode symbols (mnemonic references) in HTML structure

Syntax

IR.HtmlDecode(text)

input value description
text
"&gt;"
type: string
source text
output
text > type: string
decoded text


Sample

IR.AddListener(IR.EVENT_START, 0, function() 
{  
    var data = IR.HtmlDecode("&gt;");
    IR.Log(data) // >
});





JSON

JSON.Stringify

convert JSON object into the string

Syntax

JSON.Stringify(object)

input value description
object type: object
JSON object
output
text type: string
JSON object converted into the string


Sample

IR.AddListener(IR.EVENT_START,0,function()
{
   var object = {"Room" : [{"Floor" : "Ground", "Name" : "Kitchen"}]}
   var string = JSON.Stringify(object);
   IR.Log(string) // {"Room":[{"Floor":"Ground", "Name":"Kitchen"}]}
});





JSON.Parse

преобразовать строку в JSON объект

Синтаксис

JSON.Parse(text)

на входе значение описание
text type: string
строка
на выходе
object type: object
JSON объект


Пример

IR.AddListener(IR.EVENT_START,0,function()
{
   var string = '{"Room":[{"Floor":"Ground", "Name":"Kitchen"}]}'
   var object = JSON.Parse(string);
   IR.Log(object) // [object Object]
});





XML

new XML

create XML object

Syntax

new XML(text)

input value description
text type: string
string with XML message
output
object type: object
XML object


Sample

IR.AddListener(IR.EVENT_START,0,function()
{
   var xml_string = '<file><name>project 1</name><version>v 1.0</version></file><Panel>"panel #1"</Panel><Panel>"panel #2"</Panel>'
   var xml_object = new XML(xml_string); // create XML object
 
   var name = xml_object.file["name"];	
   var version = xml_object.file.version;	
   var panel1 = xml_object.Panel[0];
   var panel2 = xml_object.Panel[1];	
 
   IR.Log(name+" "+version+" "+panel1+" "+panel2); // project 1 v 1.0 "panel #1" "panel #2"
});





.toXMLString

convert XML object into the string

Syntax

string.toXMLString()

input value description
object type: object
XML object
output
string type: string
string


Sample

IR.AddListener(IR.EVENT_START,0,function()
{
   var xml_string = '<file><name>project 1</name><version>v 1.0</version></file><Panel>panel #1</Panel><Panel>"panel #2"</Panel>'   
 
   var xml_object = new XML(xml_string);
   var xml_string_from_object = xml_object.toXMLString()  // XML object to XML string
 
   IR.Log(xml_string_from_object);
});





IR.IsModuleLicensed

the method applicable for commercialization of unique scripts. It allows you to find out if an iRidium license has some particular "product". The products that this method allows you to check are included in iRidium mobile commercial licenses after agreement with the developer. The principle of use:

  1. Create a script that you want to encrypt and distribute on a commercial basis
  2. Contact iRidium mobile team to get the unique ID for your product (script)
  3. Add ID checking with the method IR.IsModuleLicensed(id)in the script so the script would not work until the project receives the license
  4. Protect the script file with a password to distribute the file to other users
  5. Contact the iRidium mobile team to arrange the inclusion of your product ID in commercial licenses

Syntax

IR.IsModuleLicensed(id)

input value description
id 57599 type: number
the unique product ID provided to the developer by iRidium mobile is stored in the license
output
success true type: boolean
the result of the checking:
  • true - if the product is included in the license
  • false - if it is not


Sample

function RunProtectedModule  () {
    // protected content
}
 
// unique module ID  = 65537;
if (IR.IsModuleLicensed(65537)) RunProtectedModule ();

Trial licenses and the test mode always return "true" on ID checking. It is due to the principle of free use of iRidium products in the testing mode.


IR.ValidatePassword

This method allows to use the standard "4-layer passwords system" of project. The method can be used to create your own Password request window or request password by any event. The method compares any string with the system password preset in the project. It allows to use the same list of passwords in standard functions and JS and also makes you able to change passwords when project works.

Syntax

IR.ValidatePassword(pwd_number, check_string)

input value description
pwd_number 1 type: number
1...4 - the number of password that you want to compare with some string (the password strings configured in project properties)
check_string "password" type: string
the password strings that will be compared with some system password from project properties
output
result true type: boolean
the result of the validation, true if the password is correct, false if it is not correct


Sample

var editbox = IR.GetItem("Page 1").GetItem("Item 1"); // editbox item on page
 
IR.AddListener(IR.EVENT_ITEM_CHANGE, editbox, function (action, key) // listen to changes in Editbox
{    
    if (action == 2) { // when press Enter in Editbox item
        var confirm = IR.ValidatePassword(1, editbox.Text) // check the password from Editbox
            if (confirm) {
                IR.Log("Access confirmed!");
                // any action have to be activated by correct password
            } else {
                IR.Log("Access denied!");
            }
        }
});

if in the project settings the password is not specified, the method will always return true


Events

IR.EVENT_START

the identifier of the event which is activated at the i3 pro application launch

Syntax

IR.AddListener(IR.EVENT_START, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_START, 0, function ()
{
    IR.Log("app started"); // action
});





IR.EVENT_WORK

the identifier of the event which is activated at each clock cycle of processor when the app works

Syntax

IR.AddListener(IR.EVENT_WORK, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

// IS NOT RECOMMENDED FOR REAL TASKS! 
IR.AddListener(IR.EVENT_WORK, 0, function ()
{
    IR.Log("app works"); // action
});

This event IS NOT recommended for using in real JS tasks, because of not the optimal use of resources. Please use IR.SetInterval() or the listeners of tag changes.


IR.EVENT_EXIT

the identifier of the event which is activated at closing of the i3 pro application. It is activated when receiving the command to close the application.

Syntax

IR.AddListener(IR.EVENT_EXIT, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_EXIT, 0, function ()
{
    IR.Log("app closed"); // action
});

the event will not be activated at emergency closing of the application


IR.EVENT_GLOBAL_TAG_CHANGE

the identifier of the event which is activated at change of any tag in iRidium. Tags are any properties of interface items or drivers which can be requested. For the system to register tag changes, you need to subscribe to it with the help of the method IR.SubscribeTagChange

Syntax

IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function() {}, [pointer]); IR.SubscribeTagChange(tag);

input value description
function function() {} type: function
the unnamed function or reference to the function
tag "Drivers.AV (TCP).Online" type: string
the full name of the tag to which you want to subscribe with the help of the method IR.SubscribeTagChange. Without the subscription tag changes will not be displayed in the system
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

//Set global listener
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
     IR.Log("Global Listener Activated: " + name + "\tValue: " + value);
});
// Subscribe 
IR.SubscribeTagChange("Drivers.KNX IP Router.Address 1"); 
IR.SubscribeTagChange("Drivers.AV & Custom Systems (TCP).Online"); 
IR.SubscribeTagChange("UI.Page 1.Item 1.Text"); 
IR.SubscribeTagChange("System.Time.24");
// Unsubscribe
IR.UnsubscribeTagChange("UI.Page 1.Item 1.Text");
// resend the data from KNX Address 1 to Address 2 on change (for iRidium Server)
IR.SetGlobalListener(IR.EVENT_GLOBAL_TAG_CHANGE, function(name, value)
{
   if (name == "Server.Channels.KNX.Address 1")
      IR.SetVariable("Server.Channels.KNX.Address 2", value);
});
IR.SubscribeTagChange("Server.Channels.KNX.Address 1");

The global listener can be created only once - only the listener created last will work
To activate the listener: IR.SetGlobalListener
The listener reacts on tag changes only when it is subscribed to this tag with the method IR.SubscribeTagChange
The listener reacts only on tag changes (it will not work if the received value equals to the current one)
Unsubscribe from the tag: IR.UnsubscribeTagChange


IR.EVENT_ORIENTATION

the identifier of the event which will be activated at turn of the control panel with an accelerometer. The work of the event can be emulated on Windows by clicking F5

Syntax

IR.AddListener(IR.EVENT_ORIENTATION, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output
orientation_id 1 type: number
the number of the new device:
  • 1 - vertical, the Home button is down, the constant: IR.ORIENTATION_PORTRAIT
  • 2 - vertical, the Home button is up, the constant: IR.ORIENTATION_PORTRAIT_UPSIDE_DOWN
  • 3 - horizontal, the Home button is to the right, the constant: IR.ORIENTATION_LANDSCAPE_LEFT
  • 4 - horizontal, the Home button is to the left, the constant: IR.ORIENTATION_LANDSCAPE_RIGHT


Sample

IR.AddListener(IR.EVENT_ORIENTATION, 0, Message);
function Message(orientation)
{
IR.Log("new orientation id: " + orientation);
switch (orientation) {
      case IR.ORIENTATION_PORTRAIT:
      IR.Log("Vertical")
      break;
      case IR.ORIENTATION_PORTRAIT_UPSIDE_DOWN:
      IR.Log("Upside down")
      break;
      case IR.ORIENTATION_LANDSCAPE_LEFT:
      IR.Log("Turned to the left");
      break;
      case IR.ORIENTATION_LANDSCAPE_RIGHT:
      IR.Log("Turned to the right");
      break;
   }
}

the initial orientation value will be received at the application launch
you can emulate the turn on Windows by clicking F5


IR.EVENT_KEYBOARD_SHOW

the identifier of the event which is activated at opening a keyboard on the iOS or Android device

Syntax

IR.AddListener(IR.EVENT_KEYBOARD_SHOW, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_KEYBOARD_SHOW, 0, function()
{
   IR.Log("keyboard showed"); 
});





IR.EVENT_RECIEVE_SCHEME

the identifier of the event which is activated when the i3 pro application on the iOS or Android device is started with the help of the URL scheme from the browser, mail agent or another application. The URL scheme for starting i3 pro looks as follows:
iridium://script?data1&data2
data1&data2 - the string with data which will be sent to the script , to the query parameter

Syntax

IR.AddListener(IR.EVENT_RECIEVE_SCHEME, 0, function, [pointer]);

input value description
function function{} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output
query - type: string
the data string sent in URL
source - type: string
the application which called URL схему


Sample

// called URL scheme: iridium://script?Page1
IR.AddListener(IR.EVENT_RECIEVE_SCHEME,0,function(query, source) 
{
   if (query == "Page1")
      IR.ShowPage("Page 1");
});





IR.ANDROID_BACK_PRESS

the identifier of the event which is activated by press on Back button of android device (it could be hardware or software Back button).If you are subscribed for the event, the Back button perform only an actions, programmed in on the entrance function of the listener. If you are not subscribed, click on the Back button will minimize the app

Syntax

IR.AddListener(IR.ANDROID_BACK_PRESS, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
output

-


Sample

var back_subscribe = function () 
{
   IR.Log("Back button pressed!");
}
IR.AddListener(IR.ANDROID_BACK_PRESS, 0, back_subscribe);
 
// to unsunscribe you can call the function back_unsubscribe (); in any moment
function back_unsubscribe () 
{
   IR.RemoveListener(IR.ANDROID_BACK_PRESS, 0, back_subscribe);
}

If you are subscribed for the event, the Back button perform only an actions, programmed in on the entrance function of the listener. If you are not subscribed, click on the Back button will minimize the app


Not supported

The list of methods and events below is not supported in iRidium v3

IR.DownLoadProject

to download the project available by the HTTP link to the control panel. When downloading the project, it can be given a unique name for working in the Multi-design mode.

Syntax

IR.DownLoadProject({type: protocol, host: host, path: path, multiproject: mode, name: name});

input value description
protocol 'https' type: string
the protocol type: http or https
host 'drive.google.com' type: string
the IP-address or domain name of the resource
path '/folder/file.irpz' type: string
the path to the project file
mode 0 type: number
the Multi-design mode, 0 - off, 1 - on
name 'Main' type: string
the project name, Main - the default interface
output
object [Object DevicePrototype] type: object
the reference to the iRidium HTTP Updater driver which starts project update


Sample

IR.AddListener(IR.EVENT_START, 0, function()
{    
   IR.DownLoadProject({
				type: 'https', 
				host: 'drive.google.com', 
				path: '/uc?export=view&id=0B2nsHBulOZWTR2tUaW85Vlo1Yzg', 
				multiproject: 0, 
				name: 'Main' 
   });
});
// regular expression returns the parsed link to Project
function parse_url(url) 
{
    var pattern = RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");
    var matches =  url.match(pattern);
    return {
        scheme: matches[2],
        authority: matches[4],
        path: matches[5],
        query: matches[7],
        fragment: matches[9]
    };
}
// start the uroject uploading
function HTTPUpdate(url)
{
   var parsed_url = parse_url(url);
   var downloader = IR.DownLoadProject({
                type:parsed_url.scheme,
                host:parsed_url.authority,
                path:parsed_url.path + '?' + parsed_url.query,
                multiproject: 1,
                name: "TestNew"
                    });
}
// call the uploading function and send the URL for parsing
function Update_new()
{
         HTTPUpdate('https://drive.google.com/uc?export=view&id=0B2nsHBulOZWTR2tUaW85Vlo1Yzg');
}

the project name is set up in the name property: the file system received the new name at project upload, creates a file with the new name and writes data in this file. If the Multi-design mode is on, the project with the new name will be added to the current one and not substitute it.


IR.SendNotification

to send the local notification to the iOS device with running i3 pro (it does not work on other OS)

Syntax

IR.SendNotification(text, delay, sound_id, badge_increment_num, id)

input value description
text "event N" type: string
текст уведомления
delay 0 type: number
(s) the delay of notification sending
sound_id 1 type: number
the identifier of the sound which will be used for the notification:
  • 0 - without any sound
  • 1 - the standard sound of iOS notifications
  • 2 - the standard iOS ringtone
badge_increment_num 1 type: number
by what number the number of received notifications has to be increased on the application icon
id "None" type: string
the unique notification identifier
output

-


Sample

IR.AddListener(IR.EVENT_APP_ENTER_BACKGROUND, 0, function()
{  
      IR.SendNotification("iRidium minimized", 0, 1, 1, "None");
});

it works only on iOS, it is not a push-notification


IR.ClearNotification

to clear the list of local notifications generated by i3 pro on the iOS device

Syntax

IR.ClearNotification()

input value description

-

output

-


Sample

IR.AddListener(IR.EVENT_APP_ENTER_FOREGROUND, 0, function()
{  
      IR.ClearNotification();
});

it works only on iOS


IR.EVENT_RECIEVE_NOTIFY

the identifier of the event which is activated when the application receives a local notification

Syntax

IR.AddListener(IR.EVENT_RECIEVE_NOTIFY, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output
text - type: string
the notification text
id - type: string
the text identifier of the notification


Sample

IR.AddListener(IR.EVENT_RECIEVE_NOTIFY, 0, notify)
function notify (text, id) 
{
   switch (id) 
   {
      case "Notify 1": // notification ID
      IR.ShowPopup("Popup 1");
      IR.GetItem("Popup 1").GetItem("Item 1").Text = text; // notification text
      break;
      case "Notify 2":
      IR.ShowPopup("Popup 2");
      IR.GetItem("Popup 2").GetItem("Item 1").Text = text;
      break;
   }
}





IR.EVENT_APP_ENTER_BACKGROUND

the identifier of the event which is activated at minimizing and closing of the application on the iOS or Android device

Syntax

IR.AddListener(IR.EVENT_APP_ENTER_BACKGROUND, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_APP_ENTER_BACKGROUND, 0, function()
{
   IR.Log("app minimized"); 
});

the event will not be activated at emergency closing (crash) of the application


IR.EVENT_APP_ENTER_FOREGROUND

the identifier of the event which is activated at maximizing of the application on the iOS or Android device

Syntax

IR.AddListener(IR.EVENT_APP_ENTER_FOREGROUND, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_APP_ENTER_FOREGROUND, 0, function()
{
   IR.Log("app maximized"); 
});

the event will not be activated at the application launch


IR.EVENT_APP_WILL_TERMINATE

the identifier of the event which is activated right before the application on the iOS or Android device will be closed.

Syntax

IR.AddListener(IR.EVENT_APP_WILL_TERMINATE, 0, function, [pointer]);

input value description
function function() {} type: function
the unnamed function or reference to the function
pointer - type: object
the pointer to the object which serves the function (optional)
output

-


Sample

IR.AddListener(IR.EVENT_APP_WILL_TERMINATE, 0, function()
{
   IR.Log("app will be closed right now"); 
});

the event will not be activated at the emergency closing of the application