Difference between revisions of "GSD Ruby Interface"

From LinuxMCE
Jump to: navigation, search
(Usage samples)
m (None)
Line 8: Line 8:
 
Short description of available classes and methods. the list is not complete, but covers most of functionality.
 
Short description of available classes and methods. the list is not complete, but covers most of functionality.
 
== RubySerialIOConnectionWrapper ==
 
== RubySerialIOConnectionWrapper ==
The connection object, is the exported (already opened) connection to the device. It can be either Serial (or USB Serial) connection or a network connection (in this situation you need to specify host IP and port to connect).
+
The connection object, is the exported (already <span class="plainlinks">[http://www.thepiggybackrider.com/ <span style="color:black;font-weight:normal; text-decoration:none!important; background:none!important; text-decoration:none;/*CITATION*/">child carrier</span>]</span> opened) connection to the device. It can be either Serial (or USB Serial) connection or a network connection (in this situation you need to specify host IP and port to connect).
  
 
It's usually accessed via '''conn_''' variable.
 
It's usually accessed via '''conn_''' variable.
 
=== Methods ===
 
=== Methods ===
* '''Send (<string>)''' : will send the ''string'' to the device
+
* '''Send (&lt;string>)''' : will send the ''string'' to the device
* '''Recv (<count>, <timeout>)''' : will put return received data (either the count was reached, or the timeout)
+
* '''Recv (&lt;count>, &lt;timeout>)''' : will put return received data (either the count was reached, or the timeout)
* '''RecvDelimited(<delimiter>, <timeout>)''' : will return received data until the delimiter was found
+
* '''RecvDelimited(&lt;delimiter>, &lt;timeout>)''' : will return received data until the delimiter was found
 
* '''Reconnect()''' : will close and then reopen the connection to the device
 
* '''Reconnect()''' : will close and then reopen the connection to the device
 
* '''Close()''' : will close the connection
 
* '''Close()''' : will close the connection
Line 21: Line 21:
 
This class is the equivalent of DCECommandImpl, is the one which implements commands and most of the time your code will run in this context
 
This class is the equivalent of DCECommandImpl, is the one which implements commands and most of the time your code will run in this context
 
=== Methods ===
 
=== Methods ===
* '''SendCommand (<command>)''' : send a command (kind of DCEmessage, may be command or event)
+
* '''SendCommand (&lt;command>)''' : send a command (kind of DCEmessage, may be command or event)
* '''SendReceiveCommand (<command>)''' : send a command, like SendCommand, but also receives the response, that is any parameter that returns a value
+
* '''SendReceiveCommand (&lt;command>)''' : send a command, like SendCommand, but also receives the response, that is any parameter that returns a value
  
 
=== Members ===
 
=== Members ===
Line 34: Line 34:
 
* '''devid_''' : Device ID
 
* '''devid_''' : Device ID
 
* '''devtemplid_''' : Device Template ID
 
* '''devtemplid_''' : Device Template ID
* '''devdata_''' : a map <int, string> with device data
+
* '''devdata_''' : a map &lt;int, string> with device data
 
* '''parent_''' : parent device
 
* '''parent_''' : parent device
* '''childdevices_''' : a map <int, RubyDeviceWrapper> of child devices.
+
* '''childdevices_''' : a map &lt;int, RubyDeviceWrapper> of child devices.
  
 
== RubyCommandWrapper ==
 
== RubyCommandWrapper ==
Line 47: Line 47:
 
* '''type_''' : message type (1 = command, 2 = event)
 
* '''type_''' : message type (1 = command, 2 = event)
 
* '''id_''' : message ID (commandID or eventID)
 
* '''id_''' : message ID (commandID or eventID)
* '''params_''' : map <int, string> whith parameters
+
* '''params_''' : map &lt;int, string> whith parameters
  
 
== Usage samples ==
 
== Usage samples ==

Revision as of 09:09, 27 September 2011

Short description of available classes and methods. the list is not complete, but covers most of functionality.

RubySerialIOConnectionWrapper

The connection object, is the exported (already child carrier opened) connection to the device. It can be either Serial (or USB Serial) connection or a network connection (in this situation you need to specify host IP and port to connect).

It's usually accessed via conn_ variable.

Methods

  • Send (<string>) : will send the string to the device
  • Recv (<count>, <timeout>) : will put return received data (either the count was reached, or the timeout)
  • RecvDelimited(<delimiter>, <timeout>) : will return received data until the delimiter was found
  • Reconnect() : will close and then reopen the connection to the device
  • Close() : will close the connection

RubySerialWrapper

This class is the equivalent of DCECommandImpl, is the one which implements commands and most of the time your code will run in this context

Methods

  • SendCommand (<command>) : send a command (kind of DCEmessage, may be command or event)
  • SendReceiveCommand (<command>) : send a command, like SendCommand, but also receives the response, that is any parameter that returns a value

Members

  • parent_ : parent device
  • device_ : access to the device itself
  • children_ : list of children

RubyDeviceWrapper

The wrapper for DCEDevice, will have all devicedata and other stuff

Members

  • devid_ : Device ID
  • devtemplid_ : Device Template ID
  • devdata_ : a map <int, string> with device data
  • parent_ : parent device
  • childdevices_ : a map <int, RubyDeviceWrapper> of child devices.

RubyCommandWrapper

A wrapper over DCEMessage, not quite right called Command, because we can use it for both commands and events.

Members

  • devidfrom_ : device id of sender
  • devidto_ : device id of receiver
  • priority_ : message priority
  • type_ : message type (1 = command, 2 = event)
  • id_ : message ID (commandID or eventID)
  • params_ : map <int, string> whith parameters

Usage samples

To send a command

cmd = Command.new(devidfrom, devidto, priority, type, id);
cmd.params_[x] = y;
SendCommand(cmd);

To send a command which returns parameters

cmd = Command.new(devidfrom, devidto, priority, type, id);
cmd.params_[x] = y;
SendReceiveCommand(cmd);
myVar = cmd.params_[z]

To receive some data of unknown length

recv=""
while(true)
    buff=conn_.Recv(128,100)
    if(buff.length() == 0)
        break
    end
    recv = recv + buff
end

To process command for child device

dev_slot = device_.childdevices_[cmd.devidto_].devdata_[12]
case cmd.id_
    #power on
    when 192 then
        conn_.Send("ON "+dev_slot+"\r");
    #power off
    when 193 then
        conn_.Send("OFF "+dev_slot+"\r");
end