General description

Principles of working with modules are identical to the principles of working with projects in i3 pro excluding methods and and properties described below. When a module is developed new notions appear "Module", "Subdevice", "Module properties ".
Parameters described in the methods in brackets are not obligatory.

Module

This section describes methods and properties for working with modules. By default a developer can get access to module methods and properties by refering to the module variable.

module.GetSubDevice

get a subdevice by the name or ID

Syntax

module.GetSubDevice(Name)

input

sample

description

Name

"SubDevice 1"

type: stringSubdevice name

output

Object

type: ObjectSubdevice object

Example:

var SubDevice = module.GetSubDevice("SubDevice 1");

Access to a subdevice can be received via ID. To do it, indicate the required ID of a subdevice as the input parameter.

the set of parameters is different for different drivers if the parameter is not given in the list, its value is set by default (i.e. when a driver is created only Host and Port can be given) if you create a driver not at the app launch but later, call Connect() method for this driver for it to connect to equipment. Drivers created at the app launch connect automatically. If required, they can be disconnected using the following method .Disconnect()

module.GetDevice

Get device

Syntax

module.GetDevice(Name)

input

sample

description

Name

"Device 1"

type: stringDevice name

output

Object

type: ObjectSubdevice object

Example:

var Device = module.GetDevice("Device 1");

module.GetSubDevices

Get subdevices list

Syntax

module.GetSubDevices()

input

sample

description

-

-

type: --

output

Array

type: ArrayArray of subdevices

Example:

var SubDevices = module.GetSubDevices();

module.GetPopup

Get a popup from module

Syntax

module.GetPopup(Name)

input

sample

description

Name

"Popup 1"

type: stringPopup name

output

Object

type: ObjectPopup object

Example:

var Popup = module.GetPopup("Popup 1");

module.ShowPopup

Get a popup from module

Syntax

module.ShowPopup(Name, [GroupEffectNumber])

input

sample

description

Name

"Popup 1"

type: stringPopup name

GroupEffectNumber

1000

type: numberNumber of effect group (optional)

output

Boolean

type: BooleanResult (true, false)

Example:

module.ShowPopup("Popup 1");

module.HidePopup

Hide a popup from module

Syntax

module.HidePopup(Name, [GroupEffectNumber])

input

sample

description

Name

"Popup 1"

type: stringPopup name

GroupEffectNumber

1000

type: numberNumber of effect group (optional)

output

Boolean

type: BooleanResult (true, false)

Example:

module.HidePopup("Popup 1");

module.ClonePopup

Clone a popup

Syntax

module.ClonePopup(Popup, ClonePopupName)

input

sample

description

Popup

Popup

type: ObjectObject of original popup

ClonePopupName

"ClonePopup"

type: stringThe name of cloned popup

output

Object

type: ObjectObject of the cloned popup on the basis of the original one

module.CreateEffect

type: stringVariable name to save a group of effects is requiered to assign a number and other parameters to the group

Type

IR.EFFECT_FADE

type: ObjectEffect type

output

Object

[Object EffectPrototype]

type: ObjectLink to a group of animation effects

Example:

var Fade = module.CreateEffect(IR.EFFECT_FADE);// create group and save it in variable
Fade.Group=1000;// asign a number to a group
Fade.Delay=0;// delay before doing an effect
Fade.Duration=400;// effect duration
Fade.Tween=0;// a formula to calculate an effer (tweener)
module.ShowPopup("Popup 1",1000)// show a popup with effects of group 1000

Effects:

IR.EFFECT_FADE - smoth appearing / disappearing

IR.EFFECT_ROTATE - rotation, the center of rotation is the middled of the popup

IR.EFFECT_SCALE - zooming in / zooming out

IR.EFFECT_SLIDE - moving from side to side

IR.EFFECT_TVSCAN - horizontal squeezing

Effects properties:

Group (число) - The number of effer group where the effect is located. It it recommended to use numbers of effect groups starting with 1000. It will prevent them from mixing up with effect groups created by the studio. If you want to add dynamically created effects to effect groups creted in the studio, use it deliberatelly.

//Name_1.js - first js filethis.Text="Hello, world!";//Pointer to a text variable//Name_2.js - second js filevar Text = module.Import("Name_1.js").Text;//Impor an object with a pointer to a text variable from the first js file
IR.Log(Text);//"Hello, world!" //log the text variable

module.GetDeviceSetup

Get data, set in the driver

Syntax

module.GetDeviceSetup(DeviceName)

input

sample

description

DeviceName

"Device 1"

type: stringDevice name

output

Object

type: ObjectObject with data set in the driver

Example:

var SetupData = module.GetDeviceSetup("Device 1");

module.GetDeviceSetups

Get all data set in all drivers

Syntax

module.GetDeviceSetups()

input

sample

description

-

output

Array

type: ArrayArray of data objects set in drivers

Example:

var SetupsData = module.GetDeviceSetups();

module.SaveCache

Save the module cache

Syntax

module.SaveCache(Value)

input

sample

description

SaveCache

"1"

type: stringValue

output

-

Example:

module.SaveCache("1");

module.LoadCache

Download module cache

Syntax

module.LoadCache()

input

sample

description

-

output

String

type: StringValue, saved in the cache

Example:

var CacheData = module.LoadCache();

module.CreateImage

Create a dynamic image with a given set of parameters. If not all parameters of an image are indicated, the missed parameters are taken by default or keep the previous value. The image is created without a connection to a graphic item, it can be used on different popups when called by the name. The name of a created image unlike other properties, can not be changed.

Syntax

module.CreateImage(Name, Param);

input

sample

description

Name

"Camera 1"

type: Stringname of a dynamic image (cameras)

Param

type: Object

set of properties of a dynamic image

URI: link to an image

Refresh: for pictures (snapshots), the frequency of image update. For video-stream it is 0.

Demuxer: automatic or manual selection of a stream type. FFMPEG is for cases when the stream is not defined. Empty field is automatic choice, mxg if for Mobotix camera

Probe Size: the size of data, required to start playing video (caching). By default (0) is 5 Mb. It can be decreased for the video to start faster.

Param: the line to set the type of RTSP transport. Indicate tcp, if the camera video is not broadcast via the Internet or gives video artefacts.

Audio: play audio stream. It works with Mobotix cameras (mxg)

ScaleWidth, ScaleHeight: image resolution. If it is not indicated, the image is displayed in the original resolution

HTTP: When a command is sent to HTTP driver, indicate at the beginning the sending method: GET, POST, PUT, indicate URI commands and Data separated by commas for POST and PUT. No commas inside URI and Data are possible. If your protocol uses commas in HTTP commands, send them via AV & Custom Systems (TCP), forming whole requests.
Global Cache: indicate the tranport ID where data must be sent

SubDevice.SendEx

The method can be used only with AV & Custom Systems (HTTP) drivers. It allows to send to equipment a data array with a pointer to a parent object (execution context). A number or events can be added inside SendEx that send data about their work to functions. Events allow to track getting data from HTTP server and process different stages of work with a server.

Parameter format coming to the function (Method):
1. If one object is used, the format is String (exception: If IR.ADVANCED_COLOR is used in AdvancedField the parameter has the Object format)
2. If an object array is used, the parameter is Object

SubDevice.AddSettingsFunction

Installing a a subdevice setting function. It is used for additional settings of a device. It is called by pressing the "wheel" icon in the app
i3 lite -> "Config" -> "Devices" -> Select a required device-> The setting button is in the top right corner (the "wheel" icon).

IR.ModuleSetupFinish

Completion of module installation. It is required for scanner development. When a scanner is developed, use this method to set the module to installation with all required data.

Syntax

IR.ModuleSetupFinish(StoreID, ModuleData, [Callback])

input

sample

description

StoreID

82

type: NumberModule ID in the store

ModuleData

type: ObjectData for module required for its work. See below the format to write data for module work

Callback

function(in_error){...}

type: FunctionFunction that is executed after a module is installed.

in_error - the incoming parameter, signaling successful installation

0 - no errors

1 - errors in installation

output

-

Example:

//Example of installing HDL Dimmer with a scannervar l_nStoreID =82;var l_oModuleData ={
Module:{//Data required for module work
Type:"Dimmer",
SubnetID:3,
DeviceID:6
Name:"HDL Dimmer"}
Drivers:{//Data for a driver"HDL-BUS Pro Network (UDP)":{
Host:"255.255.255.255",//installing a host for a driver
Port:"6000"//installing a port for a driver},}}
IR.ModuleSetupFinish(l_nStoreID, l_oModuleData,function(in_error){if(!in_error){
...
}else{
...
}});//Data are received in a module via module.GetProperty//Data received ina module after its installationvar l_sType = module.GetProperty("Type");//calling the popup name that was written in ModuleData in Module object
...

Setup object

When a module is added from the store, sometimes a user must enter information required for module work. Setup object has to be used for this purpose. Data can be sent to module and driver with the help of this object.

To realize it, create a new script file in iRidium studio and indicate it type - Type: Setup. The script itself if JSONObject.

The following writing format is required:

// format of coming Setup data (creted in the studio){// Data to connect derivers created in Project Device Panel
Drivers:[{
Name:"HDL-BUS Pro Network (UDP)",// driver name
Properties:// driver property[{
Type:"textfield",//It signals that a test field to enter data must be shown
Name:"SubnetID",//Property name where data are sent
Validation:function(in_value){//Function that checks values entered by a user //in_value - the coming parameter, containing a value, entered by a userif(in_value !="")return0;//If there are no erros, 0 is returned.elsereturn"Please input SubnetID";//If there are errors, error text is returned.}},
..
],},
..
],// General data for a module (and drivers created via script)
Module:[{
Type:"textfield",//It signals that a test field to enter data must be shown
Name:"Relay Count",//property name, that can be received in a module via module.GetProperty
Validation:function(in_value){//Function that checks values entered by a user//in_value - the coming parameter, containing a value, entered by a userif(in_value !="")return0;//If there are no erros, 0 is returned.elsereturn"Please input Count";//If there are errors, error text is returned.}}
..
]};

Module example

To understand better how modules are made, you can download Demo module for Netatmo and see the code example. It is fully functional, you can test its work of you have Netatmo equipment and an account Netatmo, Client_secret and Client_id. Enter Client_secret and Client_id JS editor (iRidium studio) in Driver.js. You can download this module at this link: Netatmo Demo