Author Topic: Any good example of GSD&Ruby created device to look at ?  (Read 4644 times)

archived

  • Hello, I'm new here
  • Posts: 0
    • View Profile
Any good example of GSD&Ruby created device to look at ?
« on: September 28, 2005, 04:31:43 pm »
Hi,

I'm learning how to connect with my custom home automation system over rs232 connection (I can programme things on both side - home automation rs232 gateway and Pluto side)....

Since how to is not finished yet, I'd like to take a look at some good examples of doing it....

I guess I need to add device for main rs 232 gateway and then create templates and instances for other devices that will be controlled over this rs232 interface...

Any pointers, advice how to do it ?

P.S.: I've looked at Denon templates, but clicking on Edit IR/GSD Commands gets me back to pluto home page .....

Thanks in advance,

regards,

Rob.

archived

  • Hello, I'm new here
  • Posts: 0
    • View Profile
Any good example of GSD&Ruby created device to look at ?
« Reply #1 on: September 28, 2005, 05:25:54 pm »
I also need some hints on this. I'm trying to use a Weeder board, that is a serial device that can drive 14 digital I/O channel.

According to what Aaron was saying in a post of some weeks ago it should be a simple task, but I wasn't able to find any doc/example.

The 2 main points that are not clear to me are:

1. how to write/read strings to/from serial device, i.e how to implement the "protocol" in order to properly talk to device

2. how to implement some logic, like "when I push this button on orbiter then write this string to serial device" or " when you read this string from serial device do that action/command", et similia.

TIA
MarcoZan

archived

  • Hello, I'm new here
  • Posts: 0
    • View Profile
Any good example of GSD&Ruby created device to look at ?
« Reply #2 on: September 29, 2005, 08:25:54 am »
Generic_Serial_Device can handle devices attached to serial port (/dev/ttyS[0-9]) and network attached devices.
 
Practically GSD makes an interface between DCERouter and your device.
Your device usually implements some set of commands (like ON and OFF or some other commands) for full list go to Advanced->DCE->Commands.

So you can create a scenario and when you are pressing a button on orbiter, a command will be sent to your device. You should take care to implement in Ruby the code you want to be executed to actually perform requested action (turn the device ON/OFF or whatever else)

GSD exports into Ruby some variables like device configuration data, connection opened to device so you can communicate with it and so on.

In Ruby context you may call following methods:
conn_.Send(<string to send>) => returns number of characters sent
conn_.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 (the number is shown on web interface).

For example on ON command you probably want something like
Code: [Select]
conn_.Send("ON CODE");
resp=conn_.Recv(10,500);
if(resp=="OK")
    print "OK"
else
    print "NOT OK"
end

To receive something there is an internal function Process_Incoming_Data you can simply put:
Code: [Select]
buffer = conn_.Recv(100,500);
print buffer;

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)

If the buffer you read is very important and you want to trigger some other device you can write something like this
Code: [Select]
cmd = Command.new(device_.devid_ , <DEVICE TO TRIGGER>,<PRIORITY=1>, <MESSAGETYPE: 1=COMMAND/2=EVENT>, <COMMAND/EVENT ID>);
device_.SendCommand(cmd);


For more examples of Ruby code for GSD devices try to search the forum.

archived

  • Hello, I'm new here
  • Posts: 0
    • View Profile
Any good example of GSD&Ruby created device to look at ?
« Reply #3 on: September 29, 2005, 09:17:25 am »
Hi,

thanks for info.... I'm curious about other thing.... I have rs232 gateway that acts pretty similar to EIB or X-10 gateways. But on the other side of gateway I have a network of canbus devices (similar as x-10)...

Now gateway will translate between rs232 side and canbus side. The problem is I don't know where to parse rs232 strings. Do this in gateway device or each canbus (or x10) device separately ?

For instance:

I get "light1_ON" event from rs232 - that means that light number 1 has changed its state to on - now I'd like to pass this state change to Pluto device light 1....  

Or if I set light 1 to OFF on Pluto Orbiter, then it should proceed to sending "light1_OFF" on rs232 connection...

Thanks in advance,

regards,

Rob.

archived

  • Hello, I'm new here
  • Posts: 0
    • View Profile
Any good example of GSD&Ruby created device to look at ?
« Reply #4 on: September 29, 2005, 10:20:50 am »
First of all you need do add you gateway as Pluto GSD device, Then you add devices (let's say it's a lightning devices) having the gateway as parent.

Now you can have 2 ways:

Program the LightDevice directly with GSD, meaning your Light also will be a
GSD device. And on ON command it will do something like
Code: [Select]
parent_.conn_.Send("DEVICE ID + ON CODE");

The other way is to implement a special function Process_Receive_Command_For_Child, in your gateway.
It has a parameter called "cmd" of type Command (an equivalent on Message in DCE).
Code: [Select]
if cmd.id_ == 192 #192 is ON
    id=device_.childdevices[cmd_.devidto_].devdata_[12]; #12 is port/channel
    conn_.Send(id+"ON COMMAND")
end

You also have to check somewhere a checkbox "command will be handled in parent device" or something like this.
Now when DCERouter is sending ON command to Light_device, the message will be processed in it's parent (your gateway) by that function.

When receiving data in parent you can decode from which of his child the message is comming and send a coresponding command to the child or handle it internally.

For example you are receiving that light1 was switched off. You can send an event OFF to that device (i'm not sure that GSD devices listen to events but you can try) or you can send a command which will set status of the device to OFF.
Because all messagees will return to your gateway anyway you can simply modify your internal state (it makes sense when for example device is using toggle on/off, so you keep somewhere that device is off and when you need to turn it on you only have to send one toggle command)