Эта страница является
переводом страницы
Routines. Перевод выполнен на 100%.
API iRidium.
Routines
Methods and ways to control server scenes that allow to work directly with equipment of via TimeTable item.
A routine is launched automatically when a certain event happens: when data come from equipment or an event happens according to a schedule.
More about server routines in iRidium Studio here.
You'll find a description how to work with TimeTable item if you follow this link.
Methods
IR.AddProRoutine()
Creating a server routine,
Syntax:
IR.AddProRoutine( name, routine_type, schedule_type);
| On input |
Value |
Description
|
| name |
"Routine 1" |
type: String A unique name of a server routine.
|
| routine_type |
IR.ROUTINE_TYPE_AUTONOMIC |
type: Object An ordinary server routine.
|
| IR.ROUTINE_TYPE_TIMETABLE |
A routine that allows to wirth with the Timetable item.
|
| schedule_type |
IR.ROUTINE_SERVICE_SCHEDULE _TYPE_WEEKLY_CYCLE |
type: Object Weekly schedule.
|
| IR.ROUTINE_SERVICE_ SCHEDULE_TYPE_CALENDAR |
Calendar schedule.
|
| On output |
|
|
| Object |
[Object ProRoutinePrototype] |
type: Object object template of a server routine.
|
Example
var routine = IR.AddProRoutine("Routine 1", IR.ROUTINE_TYPE_TIMETABLE, IR.ROUTINE_SERVICE_SCHEDULE_TYPE_WEEKLY_CYCLE); // weekly schedule
var routine2 = IR.AddProRoutine("Routine 2", IR.ROUTINE_TYPE_TIMETABLE, IR.ROUTINE_SERVICE_SCHEDULE_TYPE_CALENDAR); // calendar schedule
IR.GetProRoutine()
It allows to get access to a created routine.
Syntax:
IR.GetProRoutine( name / ID);
| On input |
Value |
Description
|
| name |
"Routine 1" |
type: String Name of a server routine.
|
| ID |
1 |
type: Number ID of a server routine
|
| On output |
|
|
| Object |
[Object ProRoutinePrototype] |
type: Object object template of a server routine.
|
Example
IR.Log("GET ROUTINE: " + IR.GetProRoutine("Routine 1")); // [Object proRoutinePrototype]
IR.GetProRoutines()
It allows to get access to all server routines in a project.
Syntax:
IR.GetProRoutines()
| On output |
Value |
Description
|
| Array |
[[object ProRoutinePrototype], [object ProRoutinePrototype]] |
type: Array An array of objects of server routines.
|
Example
IR.Log("GET ROUTINE: " + IR.GetProRoutines()); // [[Object proRoutinePrototype], [Object proRoutinePrototype]]
IR.GetScheduler()
It allows to get access to a created schedule.
Syntax:
IR.GetScheduler(#IR.GetScheduler() | name);
| On input |
Value |
Description
|
| name |
"Schedule 1" |
type: String Schedule name.
|
| On output |
|
|
| Object |
- |
type: Object copy of object schedule.
|
Example
var schedule = IR.GetScheduler("Schedule 1");
IR.EditRoutineSettings()
Сhange settings routines.
Syntax:
IR.EditRoutineSettings(name);
| On input |
Value |
Description
|
| name |
"Routine 1" |
type: String Schedule name.
|
| On output |
|
|
| Object |
- |
type: Object copy of object schedule.
|
Example
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 1"), function () {
IR.EditRoutineSettings("Routine 1");
IR.Log("EditRoutines");
});
IR.ShowListOfAllRoutines()
Сhange settings routines.
Syntax:
IR.ShowListOfAllRoutines();
| On output |
Value |
Description
|
| Object |
- |
type: Object copy of object schedule.
|
Example
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 6"), function () {
IR.ShowListOfAllRoutines();
IR.Log("ShowList");
});
Properties of Server Routines
IR.GetProRoutine(name / ID). property
| .Name |
"Routine 1" |
type: String It allows to give a name to a routine.
|
| .ID |
1 |
type: Number It allows to get the ID of a routine.
|
| .Type |
1 |
type: Number It allows to get the type of a routine: 0 - an ordinary server routine, 1 - a routine to work with Timetable.
|
| .Enabled |
true |
type: Boolean It allows to activate and deactivate a scene.
|
| .EventsCount |
2 |
type: Number It allows to get the number of events used in a routine.
|
| .ConditionsCount |
2 |
type: Number It allows to get the number of conditions used in a routine.
|
| .ActionsCount |
2 |
type: Number It allows to get the number of actions used in a routine.
|
| .ParametersCount |
3 |
type: Number It allows to get the number of parameters of a scene.
|
Parameters of Server Routines
It allows to send required values to a routine.
.AddParameter()
Creating a parameter.
Syntax:
IR.GetProRoutine(routine).AddParameter({Type,Name...});
| On input |
Value |
Description
|
| routine |
"Routine 1" |
type: String A name of a server routine.
|
| Type |
IR.ROUTINE_PARAMETER_TYPE_STRING, IR.ROUTINE_PARAMETER_TYPE_NUMBER, IR.ROUTINE_PARAMETER_TYPE_COLOR, IR.ROUTINE_PARAMETER_TYPE_SELECT. |
type: String, Number, RGBA, select. A type of a routine parameter.
|
| Name |
"numberParam" |
type: String A unique name of a parameter.
|
| ROUTINE_PARAMETER_TYPE_NUMBER |
|
|
| MinValue |
0 |
type: Number Minimum value.
|
| MaxValue |
100 |
type: Number Maximum value.
|
| ROUTINE_PARAMETER_TYPE_SELECT |
|
|
| SubType |
IR.PT_TEXT, IR.PT_INTEGER, IR.PT_FLOAT |
type: String, Number It transforms Values to a required type.
|
| SubParameterArray |
Key: ON/OFF, Value: 1/0. |
type: String Selection of set values.
|
| On output |
|
|
| Object |
[object ProRoutineParameterPrototype] |
type: Object Object of a parameter.
|
Example
var routine = IR.GetProRoutine(“Routine 1”); // access to script
// creating parameters:
if (routine) {
// string parameter
var stringParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_STRING,
Name: "String"
});
<!--T:30-->
// numeric parameter
var numberParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_NUMBER,
Name: "Number",
MinValue: 0,
MaxValue: 100
});
<!--T:31-->
// color parameter
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color"
});
<!--T:32-->
// selection parameter
var selectParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_SELECT,
Name: "Select",
SubType: IR.PT_INTEGER,
SubParameterArray: [{
Key: "ON",
Value: "1"
}, {
Key: "OFF",
Value: "2"
}]
});
.GetParameter()
It allows to get access to a created parameter.
Syntax:
routine.GetParameter( name / ID)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object A routined where a parameter is used.
|
| ID |
1 |
type: Number A unique ID of a parameter
|
| name |
"Color" |
type: String Name of a parameter.
|
| On output |
|
|
| Object |
[object ProRoutineParameterPrototype] |
type: Object Object of a parameter.
|
Example
// creating a parameter
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color",
});
// getting a parameter
IR.Log("GET PARAMETER: " + routine.GetParameter("Color"));
//GET PARAMETER: [object ProRoutineParameterPrototype]
.GetParameters()
It allows to get access to all parameters used in a routine.
Syntax:
routine.GetParameters()
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object A routine where a parameter is used.
|
| On output |
|
|
| Array |
[[object ProRoutineParameterPrototype], [object ProRoutineParameterPrototype]]. |
type: Array
An array of parameters.
|
Example
// getting parameter
IR.Log("GET PARAMETERS: " + routine.GetParameters());
//[[object ProRoutineParameterPrototype], [object ProRoutineParameterPrototype]]
.DeleteParameter()
Deleting a selected parameter
Syntax:
routine.DeleteParameter(Param)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object A routine where a parameter is used.
|
| Param |
routine.AddParameter({ Type: IR.ROUTINE_PARAMETER_TYPE_COLOR, Name: "Color" }); |
type: Object A selected parameter.
|
Example
//creating a parameter
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color"
});
IR.Log("DELETE_PARAMETER RESULT: " + routine.DeleteParameter(colorParam));
Properties of Parameters
routine.GetParameter(name / ID).property
| .ID |
1 |
type: Number It allows to get the ID of a parameter.
|
| .Name |
“String” |
type: String It allows to get the name of a parameter.
|
| .Type |
1 |
type: Object type: Number It allows to get the type of a parameter.
|
Events of Server Routines
It's the main condition of activation of a server routine.
.AddEvent()
Syntax:
routine.AddEvent({Type, ParametersValues...})
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| Type |
IR.ROUTINE_SERVICE_TYPE_TOKEN |
type: Object Actiation of a token.
|
| IR.ROUTINE_SERVICE_TYPE_SCHEDULE |
Activation of a schedule.
|
| IR.ROUTINE_SERVICE_TYPE_TOKEN |
|
|
| Token |
"Server.Tags.Virtual 1" |
type: String A link to a token.
|
| Operation |
IR.ROUTINE_COMPARE_EQUAL (==), IR.ROUTINE_COMPARE_NOT_EQUAL (!=), IR.ROUTINE_COMPARE_LESS (<), IR.ROUTINE_COMPARE_MORE (>), IR.ROUTINE_COMPARE_EQUAL_LESS (<=), IR.ROUTINE_COMPARE_EQUAL_MORE (>=). |
type: Object Conditional operators to compare values.
|
| Value |
"50" |
type: String Values to check conditions.
|
| IR.ROUTINE_SERVICE_TYPE_SCHEDULE |
|
|
| ScheduleID |
1 |
type: Number ID of a schedule.
|
| ScheduleEventID |
1 |
type: Number ID of an event.
|
| Value |
IR.SCHEDULE_EVENT_STATE_START |
type: Object Events on start.
|
| IR.SCHEDULE_EVENT_STATE_FINISH |
Events on finish.
|
| ParametersValues |
[{ParameterID: 1, Value: "1"}, {ParameterID: 2, Value: "0"}] |
type: {Number, String} It contains a list of objects with values.
|
Example
var event = routine.AddEvent({ // Creating an event
Type: IR.ROUTINE_SERVICE_TYPE_SCHEDULE, // Selecting a type of event
ScheduleID: 0, // ID of a schedule
ScheduleEventID: 0, // ID of a schedule event
Value: IR.SCHEDULE_EVENT_STATE_START, // Actiation by the start of an event
ParametersValues: [{
ParameterID: stringParam.ID, // ID of a string parameter
Value: "Hello, world!" // Value of a parameter
}, {
ParameterID: numberParam.ID, // ID of a numerical parameter
Value: "50" // Value of a parameter
}, {
ParameterID: colorParam.ID, // ID of RGBA parameter
Value: 0xFF00FFFF.toString() // Value of a parameter (in a string form)
}, {
ParameterID: selectParam.ID, // ID of the selection parameter
Value: "ON" // Value of a parameter
}]
});
If the type of an event and the type of a scene are different, an event won't be created!
If the type of a routine is ROUTINE_TYPE_TIMETABLE and no parameters are created - an event won't be created!
If the token is not correct - an event won't be created !
If the type of a routine is ROUTINE_TYPE_TIMETABLE, all ParametersValues must be entered, depending on the number of parameterd otherwise an event won't be created!
.GetEvent()
It allows to get access to a created event.
Syntax:
routine.GetEvent( ID)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| ID |
1 |
type: Number ID of an event.
|
| On output |
|
|
| Object |
[object ProRoutineServicePrototype] |
type: Object Object of an event.
|
Example
IR.Log("GET EVENT: " + routine.GetEvent(1)); //[object ProRoutineServicePrototype]
.GetEvents()
It allows to get access to an array of events.
Syntax:
routine.GetEvents()
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| On output |
|
|
| Array |
[[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]] |
type: Array An array of events.
|
Example
IR.Log("GET EVENTS: " + routine.GetEvents());
//[[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]]
.DeleteEvent()
Deleting an event.
Syntax:
routine.DeleteEvent(еvent)
| On output |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| event |
routine.GetEvent(0) |
type: Object Object of an event.
|
Example
// Deleting an event
IR.Log("DELETE_EVENT RESULT: " + routine.DeleteEvent(event)); //true/false
Properties of Events
routine.GetEvent(ID).property
| .Operation |
3 |
type: Number It allows to set a comparison type.
|
| .ID |
1 |
type: Number It allows to get the ID of an event.
|
| .Type |
4 |
type: Number It allows to get the type of an event.
|
| .Value |
1 |
type: Number It allows to set a value to send.
type:String
(ROUTINE_SERVICE_TYPE_TOKEN).
|
| .Token |
Server.Channels.Modbus TCP.Channel 1 |
type: String It allows to get the name of a token.
|
Conditions of Server Routines
They are additional conditions to activate server routines. A routine is activated only if an event happens and all conditions are fulfilled.
.AddCondition()
Creating an event.
Syntax:
routine.AddCondition({Type,...})
| On inout |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| Type |
IR.ROUTINE_SERVICE_TYPE_TOKEN |
type: Object Activation of a token.
|
| IR.ROUTINE_SERVICE_TYPE_SCHEDULE |
Activation of a schedule.
|
| ROUTINE_SERVICE_TYPE_SCHEDULE |
|
|
| ScheduleID |
1 |
type: Number ID of a schedule.
|
| ScheduleEventID |
1 |
type: Number ID of an event.
|
| Value |
IR.SCHEDULE_EVENT_STATE_UNKNOWN |
type: Object A schedule is not active.
|
| IR.SCHEDULE_EVENT_STATE_START |
A schedule is active.
|
| ROUTINE_SERVICE_TYPE_TOKEN |
|
|
| Token |
"Server.Tags.Virtual 1" |
type: String Token.
|
| Operation |
IR.ROUTINE_COMPARE_EQUAL(==), IR.ROUTINE_COMPARE_NOT_EQUAL(!=), IR.ROUTINE_COMPARE_LESS(<), IR.ROUTINE_COMPARE_MORE(>), IR.ROUTINE_COMPARE_EQUAL_LESS(<=), IR.ROUTINE_COMPARE_EQUAL_MORE(>=). |
type: Object Conditional operators of comparison.
|
| Value |
“50” |
type: String Token value.
|
Example
var condition = routine.AddCondition({ //Creating a condition
Type: IR.ROUTINE_SERVICE_TYPE_TOKEN, //Selection a type
Value: "1", //Token value
Token: "Modbus TCP.Channel", //The name of a token
Operation: IR.ROUTINE_COMPARE_EQUAL //Conditional operator
});
.GetCondition()
It allows to get access to a created condition.
Syntax:
routine.GetCondition(ID)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| ID |
1 |
type: Number ID of a condition.
|
| On output |
|
|
| Object |
[object ProRoutineServicePrototype] |
type: Object Object of a condition.
|
Example
IR.Log("GET CONDITION: " + routine.GetCondition(1)); //[object ProRoutineServicePrototype]
.GetConditions()
It allows to get access to an array of conditions.
Syntax:
routine.GetConditions()
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| On output |
|
|
| Array |
[[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]] |
type: Array An array of conditions.
|
Example
IR.Log("GET CONDITIONS: " + routine.GetConditions());
// [[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]]
.DeleteCondition()
Deleting a condition.
Syntax:
routine.DeleteCondition(condition)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| condition |
routine.GetCondition(1) |
type: Object Object of a condition.
|
Example
IR.Log("DELETE CONDITION RESULT: " + routine.DeleteCondition(condition)); // true/false
Properties of Conditions
routine.GetCondition(ID).property
| .Operation |
1 |
type: Number It allows to set the type of comparison.
|
| .ID |
1 |
type: Number It allows to get the ID of a condition.
|
| .Type |
6 |
type: Number It allows to get the type of a condition.
|
| .Value |
1 |
type: Number It allow to set a value to send.
type:String (ROUTINE_SERVICE_TYPE_TOKEN)
|
| .Token |
Server.Channels.Modbus TCP.Channel 1 |
type: String It allows to get the name of a token.
|
Actions of Server Routines
Actions that will be done when routines are activated.
.AddAction()
Creating an action.
Syntax:
routine.AddAction({Type, Value...})
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| Type |
IR.ACTION_TYPE_SEND_NUMBER, IR.ACTION_TYPE_SEND_TEXT, IR.ACTION_TYPE_SEND_TAG, IR.ACTION_TYPE_SEND_DATA, IR.ACTION_TYPE_DELAY, IR.ACTION_TYPE_NUMBER_TO_TAG, IR.ACTION_TYPE_TEXT_TO_TAG, IR.ACTION_TYPE_TAG_TO_TAG. |
type: Object Type of action.
|
| Value |
ACTION_TYPE_SEND_NUMBER, ACTION_TYPE_SEND_TEXT, ACTION_TYPE_NUMBER_TO_TAG, ACTION_TYPE_TEXT_TO_TAG, ACTION_TYPE_DELAY(мс) Example: “50”; ACTION_TYPE_SEND_TAG, ACTION_TYPE_TAG_TO_TAG Example: "Server.Tags.Virtual 1"; ACTION_TYPE_SEND_DATA Example: "01, 02, 03, 04, AA, BB". |
type: String Values to send.
|
| Channel |
"AV & Custom Systems (HTTP).AV Control Command" |
type: String The name of a channel where a value is sent
It is used only in:
IR.ACTION_TYPE_SEND_NUMBER, IR.ACTION_TYPE_SEND_TEXT, IR.ACTION_TYPE_SEND_TAG, IR.ACTION_TYPE_SEND_DATA.
|
| Tag |
"Server.Tags.Virtual 1" |
Type: String The name of a token where values are sent.
It is used only in:
IR.ACTION_TYPE_NUMBER_TO_TAG, IR.ACTION_TYPE_TEXT_TO_TAG, IR.ACTION_TYPE_TAG_TO_TAG.
|
Example
var numberAction = routine.AddAction({ //Creating an action
Type: IR.ACTION_TYPE_NUMBER_TO_NUMBER, //Type of data
Channel: "Modbus TCP.Channel 1", //The name of a channel
Value: "1" //A value to send
});
var colorAction = routine.AddAction({ //Creating an action
Type: IR.ACTION_TYPE_NUMBER_TO_TAG, //Type of data
Tag: "Server.Tags.Virtual 1", //The name of a tag
Value: "1" //A value to send
});
Creating an action for Timetable item using parameters:
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| Type |
IR.ACTION_TYPE_SEND_TAG |
type: Object Type of action.
|
| Value |
"Routines." + routine.Name + "." + parameter.Name |
type: String routine - object of a routine, parameter - object of a selected parameter.
|
| Channel |
"AV & Custom Systems (HTTP).AV Control Command" |
type: String The name of a channel where a value is sent.
|
| Tag |
"Server.Tags.Virtual 1" |
Type: String The name of a token where values are sent.
|
Example
var colorAction = routine.AddAction({ //Creating an action
Type: IR.ACTION_TYPE_SEND_TAG, //Type of data
Channel: "AV & Custom Systems (TCP).Command 1", //The name of a channel
Value: "Routines." + routine.Name + "." + colorParam.Name //A value to send
});
.GetAction()
It allows to get access to a created action.
Syntax:
routine.GetAction(ID)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| ID |
0 |
type: Number ID of an action.
|
| On output |
|
|
| Object |
[object ProRoutineActionPrototype] |
type: Object Object of an action.
|
Example
IR.Log("GET ACTION: " + routine.GetAction(0)); //[object ProRoutineActionPrototype]
.GetActions()
It allows to get access to an array of actions.
Syntax:
routine.GetActions()
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| On output |
|
|
| Array |
[[object ProRoutineActionPrototype], [object ProRoutineActionPrototype]] |
type: Array An array of actions.
|
'Example
IR.Log("GET ACTIONS: " + routine.GetActions());
//[[object ProRoutineActionPrototype], [object ProRoutineActionPrototype]]
.DeleteAction()
Deleting an action
Syntax:
routine.DeleteAction(action)
| On input |
Value |
Description
|
| routine |
IR.GetProRoutine(“Routine 1”) |
type: Object Object of a server routine.
|
| action |
routine.GetAction(0) |
type: Object Object of an action.
|
Example
IR.Log("DELETE ACTION RESULT: " + routine.DeleteAction(colorAction)); // true/false
Properties of Actions
routine.GetAction(ID). property
| .Channel |
"AV & Custom Systems (TCP).AV Control Command" |
type: String It allows to set the name of a channel.
|
| .ID |
1 |
type: Number It allows ti get the ID of an action.
|
| .Type |
11 |
type: Number It allows to get the type of an action.
|
| .Value |
1 |
type: Number It allows to set a value.
|
| .Tag |
“Server.Tags.Virtual 1” |
type: String It allows to set a tag name.
|