Practically Generic_Serial_Device makes an interface between DCERouter and your device. Right now only sending commands (usually from DCERouter to Device) is supported.
The nice catch is that you can write your own handler for each command you want to implement in Ruby. This way you don't need to go down to low level C++ programming.
GSD exports into Ruby some variables like device configuration data, connection opened to device so you can communicate with it and so on.
There are also some "default" methods that you can implement :
is called when your device is started maybe you need some global variables, or send something to device to notify it that you are online.
is called then device is trying to send you some data, here you usually read the data, acknowledge the transmission and do other things depending on what the device sent to you.
is called when you have child devices attached to your GSD device. This is the case of more sophisticated devices like for example Bang&Olufsen interface: you have one device attached to CORE, but there are more devices attached to that devise, so you can not send something directly to a child device, you need to say to parent device to send that and that to one of his children.
In Ruby context you may call following methods to communicate with your device:conn_.Send(<string to send>)
=> returns number of characters sentconn_.Recv(<numeric max buffer size>,<numeric timeout in ms>)
=> returns a string which was read
Some useful variables:
- device_.devdata[<a number>] => gives you acces to data you entered in "Device Data" section when you added the device
In web interface you can write Ruby code that will execute when the device is receiving a
command. The connection to device is exported into Ruby so for example on Process_Incoming_Data
you can simply put:
buffer = conn_.Recv(100,500);
it will receive a buffer of max 100 characters, waiting 0.5 seconds to receive it, and will print it, the result can be seen in log (/var/log/pluto/XXXX_Generic_Serial_Device.newlog)
Try to look for GSD devices and take a look at ruby code for some samples.