GSD - Ruby codes

From LinuxMCE
Revision as of 14:24, 16 March 2007 by Juliet (Talk | contribs)

Jump to: navigation, search

GSD

Generic Serial Device is a module that offers basic functionality for accessing devices via the serial port (mostlly through the RS232 interface). The project sources are located in pluto/src/Generic_Serial_Devices.

Command implementation in Ruby

For Generic Serial Devices the architecture allows implementing the commands directly from the LinuxMCE Admin Web Page, using Advanced/Device Templates. After picking the device template, select ruby codes and add the command groups that you want to implement (should be supported by the devices for witch you want to create the template)

The framework offers an Ruby Command object that actually behaves as a container for data also found in the C++ class Command from DCE. In order to create an instance of the ruby command use:


    cmd = Command.new( <device from>, <device to>, <priority>, <type>, <id>)


There is a hash map associated with the command object that allows setting values for the command parameters:


    cmd.params_[<parameter id>] = <string value for command parameter>


And for sending the command you should use the SendCommand function:


    SendCommand(cmd)


Directly implementing each command this way may prove inconvenient. You can use the Private Method dummy command for writing helper functions. Besides from the params_ member, the ruby Command object has members for all the parameters from the constructor. Still, the wrapper offers only simple access to what a command really is in the DCE Framework, but, of course, it can be extended to allow more by adding members to the RubyCommandWrapper C++ class. All that's implemented here gets translated to Ruby.

The actual forwarding to the DCE framework is done in the Generic_Serial_Device project, in classes implementing RubyDCEConnector (ex: RubyIOManager). These are used at their turn from the RubySerialWrapper, witch offers the actual context where the Ruby code runs (Ruby twin classes are generated for each device at runtime). The SendCommand used above is a method of the RubySerialWrapper class.