If the command is already created in the device tree (built-in drivers):
http://wiki2.iridiummobile.net/Drivers_API#Set
If you want to form the command string inside the script:
http://wiki2.iridiummobile.net/Drivers_API#Send
Take part in webinars of iRidium Academy to receive more information about working with equipment using iRidium Script.
Let’s say you have GC-100-12, and some RS232-Device is connected to the output Serial 2. RS232-Device has a set of commands described in the driver (in output Commands).
So in order to activate the command what should you write?
One GC-100-12 module consists of 3 transports (as it works with 3 different devices at a time):
Thus, to refer to different ports, you will need to describe the device differently from the standard AV driver.
.Send command to GC:
IR.GetDevice("Global Cache").Send(['DATA'], <TRANSPORT ID>)
is 0, 1 or 2 - it is the number of TCP transport created by GC driver
0 = TCP transport on port 4998 (IR commands, system data, relays)
1 = TCP transport on port 4999 (Serial 1)
2 = TCP transport on port 5000 (Serial 2)
.Set command to GC:
IR.GetDevice("Global Cache").Set("COMMAND", "")
"COMMAND" have to be created on the GC output
Example 1 (.Send and .Set command to Serial output):
var device = IR.GetDevice("Global Cache"); IR.AddListener(IR.EVENT_ONLINE , device, function() { device.Send(['POWER_ON', '\r\n'], 1); // to Serial 1 device.Send([0x00, 0x00, 0x00, 0x0D], 2); // to Serial 2 device.Set("POWER_ON", ""); // Command from the tree });
var device = IR.GetDevice("Global Cache"); IR.AddListener(IR.EVENT_ONLINE , device, function() { var command1 = 'sendir,1:1,1,36127,1,1,96,31,17,16,16,16,16,32,16,32,49,32,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,32,17,16,16,16,16,16,32,16,16,16,16,16,16,16,16,32,32,16,16,16,16,16,16,16,16,32,17,16,16,16,16,16,32,16,4624'; device.Send([command1,0x0D]); }IR command has a following syntax:
'sendir,<connectoraddress>,<ID>,<frequency>,<repeat>,<offset>,<command sequence>'see the iTach API for details
To receive the feedback from Global Cache with COM port and process it with JS, please use the construction:
IR.AddListener(IR.EVENT_RECEIVE_TEXT, IR.GetDevice("Global Cache"), function(text, id) { if (id == 0) IR.Log("system data: "+ text); else if (id == 1) IR.Log("COM1 data: "+ text); else if (id == 2) IR.Log("COM2 data: "+ text); });
function (text, id)
text - the data received from equipment
id - is 0, 1 or 2, it is the number of TCP transport created by GC driver
0 = TCP transport on port 4998 (IR commands, system data, relays)
1 = TCP transport on port 4999 (Serial 1)
2 = TCP transport on port 5000 (Serial 2)
function Level_ASCII() { var Packet = "VOLUME " + IR.GetItem("Page 1").GetItem("Item 6").Value + '\r\n'; IR.GetDevice("AV & Custom Systems (TCP)").Send([Packet]); };
// -------- to send a Volume Value from the Level var Msg = "SET LEVEL "; //This is the string with our command without volume value var Packet; IR.AddListener(IR.EVENT_ITEM_RELEASE,IR.GetItem("Page 1").GetItem("Item 1"),function() //This event will be active when you release the level-button { Packet = Msg+IR.GetVariable("Drivers.GC-100-12:Serial 1.Volume").toString()+'\n'; //Here we add the volume value to our command //IR.Log("Sended message = "+Packet) IR.GetDevice("GC-100-12:Serial 1").Send([Packet]); //here we send the result string to device });
IR.AddListener(IR.EVENT_ONLINE , IR.GetDevice("GC-100-12:Serial 1"), function() { IR.GetDevice("GC-100-12:Serial 1").Set("CONNECT", ""); //IR.Log('online and sent'); });if this command is NOT in the list of GC-100 Commands:
IR.AddListener(IR.EVENT_ONLINE , IR.GetDevice("GC-100-12:Serial 1"), function() { IR.GetDevice("DEVICE").Send(['SYSTEM CONNECT', '\r\n']); //IR.Log('online and sent'); });SendCommandIfDriverOnline.irpz
[00:00:02.418] CCustomDevice(2): StartConnect() [00:00:07.426] CCustomDevice(2): Time of waiting for connection is over! [00:00:07.441] CCustomDevice(2): StartConnect() [00:00:12.464] CCustomDevice(2): Time of waiting for connection is over!It occurs only if 2 devices communicate with the same local port.
IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("HDL-BUS Pro Network (UDP)"), function(name,value) { if (name == "Relay 1:Channel 3") { IR.Log("Channel 3"+value); } });