- Reference
- Routines
iRidium API. Routines
Methods and properties for controlling server routines, allowing interaction directly with equipment or through a TimeTable item.
A routine starts automatically when a specified event occurs: equipment data is received or a scheduled event is triggered.
Methods
IR.AddProRoutine()
Create a server routine.
Syntax:
IR.AddProRoutine( name, routine_type, schedule_type);
| Parameter | Value | Description |
|---|---|---|
| name | "Routine 1" | type: String Unique server routine name |
| rowspan="2" routine_type | IR.ROUTINE_TYPE_AUTONOMIC | type: Object Standard server routine |
| IR.ROUTINE_TYPE_TIMETABLE | Routine for working with a Timetable item | |
| rowspan="2" schedule_type | IR.ROUTINE_SERVICE_SCHEDULE_TYPE_WEEKLY_CYCLE | type: Object Weekly schedule |
| IR.ROUTINE_SERVICE_SCHEDULE_TYPE_CALENDAR | Calendar schedule |
| Output | ||
|---|---|---|
| Object | [Object ProRoutinePrototype] | type: Object Server routine object instance |
Example
var routine = IR.AddProRoutine("Routine 1", IR.ROUTINE_TYPE_TIMETABLE, IR.ROUTINE_SERVICE_SCHEDULE_TYPE_WEEKLY_CYCLE); // недельное расписание
var routine2 = IR.AddProRoutine("Routine 2", IR.ROUTINE_TYPE_TIMETABLE, IR.ROUTINE_SERVICE_SCHEDULE_TYPE_CALENDAR); // календарное расписание
IR.GetProRoutine()
Access an existing routine.
Syntax:
IR.GetProRoutine( name / ID);
| Parameter | Value | Description |
|---|---|---|
| name | "Routine 1" | type: String Server routine name |
| ID | 1 | type: Number Server routine identifier |
| Output | ||
| Object | [Object ProRoutinePrototype] | type: Object Server routine object instance |
Example
IR.Log("GET ROUTINE: " + IR.GetProRoutine("Routine 1")); // [Object proRoutinePrototype]
IR.GetProRoutines()
Access all server routines in the project.
Syntax:
IR.GetProRoutines()
| Parameter | Value | Description |
|---|---|---|
| Array | [[object ProRoutinePrototype], [object ProRoutinePrototype]] | type: Array Array of server routine objects |
Example
IR.Log("GET ROUTINE: " + IR.GetProRoutines()); // [[Object proRoutinePrototype], [Object proRoutinePrototype]]
IR.GetScheduler()
Access an existing schedule.
Syntax:
IR.GetScheduler(#IR.GetScheduler() | name);
| Input | Value | Description |
|---|---|---|
| name | "Schedule 1" | type: String Schedule name |
| Output | ||
| Object | - | type: Object schedule object instance |
Example
var schedule = IR.GetScheduler("Schedule 1");
IR.EditRoutineSettings()
Change the routine settings.
Syntax:
IR.EditRoutineSettings(name);
| Input | Value | Description |
|---|---|---|
| name | "Routine 1" | type: String Routine name |
| Output | ||
| Object | - | type: Object routine settings window |
Example
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 1"), function () {
IR.EditRoutineSettings("Routine 1");
IR.Log("EditRoutines");
});
IR.ShowListOfAllRoutines()
Show all routine settings.
Syntax:
IR.ShowListOfAllRoutines();
| Input | Value | Description |
|---|---|---|
| Object | - | type: Object settings window for all routines |
Example
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 6"), function () {
IR.ShowListOfAllRoutines();
IR.Log("ShowList");
});
Server routine properties
IR.GetProRoutine(name / ID). property
| parameter | Value | Description |
|---|---|---|
| .Name | "Routine 1" | type: String Set the routine name |
| .ID | 1 | type: Number Get the routine ID |
| .Type | 1 | type: Number Get the routine type 0 - standard server routine 1 - routine for working with Timetable |
| .Enabled | true | type: Boolean Enable or disable the routine |
| .EventsCount | 2 | type: Number Get the number of events used in the routine |
| .ConditionsCount | 2 | type: Number Get the number of conditions used in the routine |
| .ActionsCount | 2 | type: Number Get the number of actions used in the routine |
| .ParametersCount | 3 | type: Number Get the number of routine parameters |
Server routine parameters
Pass the required values to a routine.
.AddParameter()
Create a parameter.
Syntax:
IR.GetProRoutine(routine).AddParameter({Type,Name...});
| Input | Value | Description |
|---|---|---|
| routine | "Routine 1" | type: String Server routine name |
| 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 Routine parameter type |
| Name | "numberParam" | type: String Unique parameter name |
| 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 Convert values (Value) to the required type |
| SubParameterArray | Key: ON/OFF, Value: 1/0 | type: String Selection from preset values |
| Output | ||
| Object | [object ProRoutineParameterPrototype] | type: Object Parameter object |
Example
var routine = IR.GetProRoutine(“Routine 1”); // получение доступа к сценарию
// создание параметров:
if (routine) {
// строковый параметр
var stringParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_STRING,
Name: "String"
});
<!--T:30-->
// числовой параметр
var numberParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_NUMBER,
Name: "Number",
MinValue: 0,
MaxValue: 100
});
<!--T:31-->
// параметр цвета
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color"
});
<!--T:32-->
// параметр выбора
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()
Access an existing parameter.
Syntax:
routine.GetParameter( name / ID)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine("Routine 1") | type: Object Routine using the parameter |
| ID | 1 | type: Number Unique parameter identifier |
| name | "Color" | type: String Parameter name |
| Output | ||
| Object | [object ProRoutineParameterPrototype] | type: Object Parameter object |
Example
// создание параметра
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color",
});
<!--T:37-->
// получение параметра
IR.Log("GET PARAMETER: " + routine.GetParameter("Color"));
//GET PARAMETER: [object ProRoutineParameterPrototype]
.GetParameters()
Access all parameters used in the routine.
Syntax:
routine.GetParameters()
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine("Routine 1") | type: Object Routine using the parameter |
| Output | ||
| Array | [[object ProRoutineParameterPrototype], [object ProRoutineParameterPrototype]] | type: Array Parameter array |
Example
// получение параметра
IR.Log("GET PARAMETERS: " + routine.GetParameters());
//[[object ProRoutineParameterPrototype], [object ProRoutineParameterPrototype]]
.DeleteParameter()
Delete the selected parameter.
Syntax:
routine.DeleteParameter(Param)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine("Routine 1") | type: Object Routine using the parameter |
| Param | routine.AddParameter({Type: IR.ROUTINE_PARAMETER_TYPE_COLOR, Name: "Color"}); | type: Object Selected parameter |
Example
//создание параметра
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color"
});
IR.Log("DELETE_PARAMETER RESULT: " + routine.DeleteParameter(colorParam));
Parameter properties
routine.GetParameter(name / ID).property
| parameter | Value | Description |
|---|---|---|
| .ID | 1 | type: Number Get the parameter ID |
| .Name | "String" | type: String Get the parameter name |
| .Type | 1 | type: Object / Number Get the parameter type |
Server routine events
The main condition for activating a server routine.
.AddEvent()
Syntax:
routine.AddEvent({Type, ParametersValues...})
| Parameter | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine("Routine 1") | type: Object Server routine object |
| Type | IR.ROUTINE_SERVICE_TYPE_TOKEN | type: Object Token activation |
| IR.ROUTINE_SERVICE_TYPE_SCHEDULE | type: Object Schedule activation | |
| IR.ROUTINE_SERVICE_TYPE_TOKEN | ||
| Token | "Server.Tags.Virtual 1" | type: String Token reference |
| 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 Comparison operators for values |
| Value | "50" | type: String Value for checking the condition |
| IR.ROUTINE_SERVICE_TYPE_SCHEDULE | ||
| ScheduleID | 1 | type: Number Schedule identifier |
| ScheduleEventID | 1 | type: Number Event identifier |
| Value | IR.SCHEDULE_EVENT_STATE_START | type: Object Start event |
| IR.SCHEDULE_EVENT_STATE_FINISH | type: Object Finish event | |
| ParametersValues | [{ParameterID: 1, Value: "1"}, {ParameterID: 2, Value: "0"}] | type: {Number, String} Contains a list of objects with values |
Example
var event = routine.AddEvent({ // Создание события
Type: IR.ROUTINE_SERVICE_TYPE_SCHEDULE, // Указание типа события
ScheduleID: 0, // Идентификатор расписания
ScheduleEventID: 0, // Идентификатор события расписания
Value: IR.SCHEDULE_EVENT_STATE_START, // Активация по старту события
ParametersValues: [{
ParameterID: stringParam.ID, // Идентификатор строкового параметра
Value: "Hello, world!" // Значение параметра
}, {
ParameterID: numberParam.ID, // Идентификатор числового параметра
Value: "50" // Значение параметра
}, {
ParameterID: colorParam.ID, // Идентификатор RGBA параметра
Value: 0xFF00FFFF.toString() // Значение параметра (в строковом виде)
}, {
ParameterID: selectParam.ID, // Идентификатор параметра выбора
Value: "ON" // Значение параметра
}]
});
- If the event type and routine type differ, the event will not be created!
- If the routine type is ROUTINE_TYPE_TIMETABLE and no parameters have been created, the event will not be created!
- If the token is specified incorrectly, the event will not be created!
- If the routine type is ROUTINE_TYPE_TIMETABLE, all ParametersValues must be specified according to the number of parameters; otherwise, the event will not be created!
.GetEvent()
Access an existing event.
Syntax:
routine.GetEvent( ID)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| ID | 1 | type: Number Event identifier. |
| Output | ||
| Object | [object ProRoutineServicePrototype] | type: Object Event object. |
Example
IR.Log("GET EVENT: " + routine.GetEvent(1)); //[object ProRoutineServicePrototype]
.GetEvents()
Access the event array.
Syntax:
routine.GetEvents()
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| Output | ||
| Array | [[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]] | type: Array Event array. |
Example
IR.Log("GET EVENTS: " + routine.GetEvents());
//[[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]]
.DeleteEvent()
Delete an event.
Syntax:
routine.DeleteEvent(еvent)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| event | routine.GetEvent(0) | type: Object Event object. |
Example
// Удаление события
IR.Log("DELETE_EVENT RESULT: " + routine.DeleteEvent(event)); //true/false
Event properties
routine.GetEvent(ID).property
| parameter | Value | Description |
|---|---|---|
| .Operation | 3 | type: Number Set the comparison type. |
| .ID | 1 | type: Number Get the event ID. |
| .Type | 4 | type: Number Get the event type. |
| .Value | 1 | type: Number Set the value to send. type: String (ROUTINE_SERVICE_TYPE_TOKEN). |
| .Token | Server.Channels.Modbus TCP.Channel 1 | type: String Get the token name. |
Server routine conditions
Additional conditions for activating server routines. A routine activates only when an event occurs and all listed conditions are met.
.AddCondition()
Create a condition.
Syntax:
routine.AddCondition({Type,...})
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| Type | IR.ROUTINE_SERVICE_TYPE_TOKEN | type: Object Token activation. |
| Type | IR.ROUTINE_SERVICE_TYPE_SCHEDULE | Schedule activation. |
| ROUTINE_SERVICE_TYPE_SCHEDULE | ||
| ScheduleID | 1 | type: Number Schedule identifier. |
| ScheduleEventID | 1 | type: Number Event identifier. |
| Value | IR.SCHEDULE_EVENT_STATE_UNKNOWN | type: Object Schedule inactive. |
| Value | IR.SCHEDULE_EVENT_STATE_START | Schedule 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 Comparison operators. |
| Value | "50" | type: String Token value. |
Example
var condition = routine.AddCondition({ //Создание условия
Type: IR.ROUTINE_SERVICE_TYPE_TOKEN, //Выбор типа
Value: "1", //Значение токена
Token: "Modbus TCP.Channel", //Имя токена
Operation: IR.ROUTINE_COMPARE_EQUAL //Условный оператор
});
.GetCondition()
Access an existing condition.
Syntax:
routine.GetCondition(ID)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| ID | 1 | type: Number Condition identifier. |
| Output | ||
| Object | [object ProRoutineServicePrototype] | type: Object Condition object. |
Example
IR.Log("GET CONDITION: " + routine.GetCondition(1)); //[object ProRoutineServicePrototype]
.GetConditions()
Access the array of existing conditions.
Syntax:
routine.GetConditions()
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| Output | ||
| Array | [[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]] | type: Array Condition array. |
Example
IR.Log("GET CONDITIONS: " + routine.GetConditions());
// [[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]]
.DeleteCondition()
Delete a condition.
Syntax:
routine.DeleteCondition(condition)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| condition | routine.GetCondition(1) | type: Object Condition object. |
Example
IR.Log("DELETE CONDITION RESULT: " + routine.DeleteCondition(condition)); // true/false
Condition properties
routine.GetCondition(ID).property
| parameter | Value | Description |
|---|---|---|
| .Operation | 1 | type: Number Set the comparison type. |
| .ID | 1 | type: Number Get the condition ID. |
| .Type | 6 | type: Number Get the condition type. |
| .Value | 1 | type: Number Set the value to send. type: String (ROUTINE_SERVICE_TYPE_TOKEN) |
| .Token | Server.Channels.Modbus TCP.Channel 1 | type: String Get the token name. |
Server routine actions
Actions performed when the routine activates.
.AddAction()
Create an action.
Syntax:
routine.AddAction({Type, Value...})
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| 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 Action type. |
| Value | ACTION_TYPE_SEND_NUMBER, ACTION_TYPE_SEND_TEXT, ACTION_TYPE_NUMBER_TO_TAG, ACTION_TYPE_TEXT_TO_TAG, ACTION_TYPE_DELAY(ms) 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 Name of the channel to receive the value. 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 Name of the token to receive the values. 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({ //Создание действия
Type: IR.ACTION_TYPE_NUMBER_TO_NUMBER, //Тип данных
Channel: "Modbus TCP.Channel 1", //Имя канала
Value: "1" //Отправляемое значение
});
var colorAction = routine.AddAction({ //Создание действия
Type: IR.ACTION_TYPE_NUMBER_TO_TAG, //Тип данных
Tag: "Server.Tags.Virtual 1", //Имя тэга
Value: "1" //Отправляемое значение
});
- Create an action for a Timetable item using parameters:
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| Type | IR.ACTION_TYPE_SEND_TAG | type: Object Action type. |
| Value | "Routines." + routine.Name + "." + parameter.Name | type: String routine - routine object, parameter - selected parameter object. |
| Channel | "AV & Custom Systems (HTTP).AV Control Command" | type: String Name of the channel to receive the value. |
| Tag | "Server.Tags.Virtual 1" | Type: String Name of the token to receive the values. |
Example
var colorAction = routine.AddAction({ //Создание действия
Type: IR.ACTION_TYPE_SEND_TAG, //Тип данных
Channel: "AV & Custom Systems (TCP).Command 1", //Имя канала
Value: "Routines." + routine.Name + "." + colorParam.Name //Отправляемое значение
});
.GetAction()
Access an existing action.
Syntax:
routine.GetAction(ID)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| ID | 0 | type: Number Action identifier. |
| Output | ||
| Object | [object ProRoutineActionPrototype] | type: Object Action object. |
Example
IR.Log("GET ACTION: " + routine.GetAction(0)); //[object ProRoutineActionPrototype]
.GetActions()
Access the action array.
Syntax:
routine.GetActions()
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| Output | ||
| Array | [[object ProRoutineActionPrototype], [object ProRoutineActionPrototype]] | type: Array Array of action objects. |
Example
IR.Log("GET ACTIONS: " + routine.GetActions());
//[[object ProRoutineActionPrototype], [object ProRoutineActionPrototype]]
.DeleteAction()
Delete an action
Syntax:
routine.DeleteAction(action)
| Input | Value | Description |
|---|---|---|
| routine | IR.GetProRoutine(“Routine 1”) | type: Object Server routine object. |
| action | routine.GetAction(0) | type: Object Action object. |
Example
IR.Log("DELETE ACTION RESULT: " + routine.DeleteAction(colorAction)); // true/false
Action properties
routine.GetAction(ID). property
| parameter | Value | Description |
|---|---|---|
| .Channel | "AV & Custom Systems (TCP).AV Control Command" | type: String Set the channel name. |
| .ID | 1 | type: Number Get the action ID. |
| .Type | 11 | type: Number Get the action type. |
| .Value | 1 | type: Number Set the value. |
| .Tag | "Server.Tags.Virtual 1" | type: String Set the tag name. |