Author
Topic: Generic Serial Device - (New user) (Read 3499 times)

I have managed to install a Core/Hybrid for testing purposes to see if I can integrate into my current lighting automation system.The lighting controls accepts serial commands in either ASCII text or Hex.

The part I am having trouble understanding is how to setup the Generic serial Device as an interface in Linux MCE to send and receive the commands to and from the lighting system.

I have looked through the documentation, but I do not really see a clear step by step procedure for doing this (or I could be looking in the wrong place).

If anyone could point me in the right direction for this it would be really appreciated.

dpkg -l 'pluto-generic-serial-device' (it should be there).2. Created a device template for your system and specify that it should use GSD. Add it under category lighting interfaces if you want to control lighting devices only. To control all kind of devices (security, climate etc) it's better to use Interface::Specialize. Also, you should specify a communication type - RS232, Ethernet etc.3. After you save a new template a new interface will be added automatically. You can see it under Wizard --> Devices --> Interfaces. Also, there is a GSD page - Wizard --> Devices --> Generic Serial Devices. On that page you'll able to add/modify Ruby commands. To do that you should specify a group and tick box 'internal Ruby Command'. After you quick reload router you should see GSD process in console:

Have a look into GSD log: /var/log/pluto/<GSD LinuxMCE ID>_Generic_Serial_Device.log. You can find here all Ruby errors, connection status and other useful information.

4. There are 6 base functions which you need: - Private Method Listing - you may place here all common functionality and use it from the others functions. - Process IDLE - method executed each one - two seconds, maybe useful to check a connection between your device and LinuxMCE. - Process Incoming Data - called when some data come from your device:

cmd = Command.new(plutoID, -1001, 1, 2, 48)cmd.params_[10] = 0SendCommand(cmd) - Process Receive Command For Child - called when the child device (in your case it's a dimmer of switch) gets some command: ON, OFF or SET LEVEL. Actually, those commands are routed to the parent device (your GSD interface) and it send the commands in desired format to the physical device:

case cmdId when 192 #192 is ON command = '<your ON command format>' when 193 #193 is OFF command = '<your OFF command format>' when 184 #184 is Level of dimmer command = '<your SET LEVEL command format>' end

conn_.Send(command)

In my case the command includes following parameters: LinuxMCE ID - to update the status in LinuxMCE, Port Number - to know where send actual command, command type - ON, OFF, SET LEVEL, level value for SET LEVEL. Plus, I generate an unique ID for each command to check its status. It might be good idea to push unsuccessful commands into array in the GSD device to run them one again.

- Process Initialize - called when GSD device is starting. It's good point to initialize common variables and start logging for example:

time = Time.now$logFile = File.new("/var/log/pluto/ICPDAS-" + time.strftime("%Y%m%d%H%M") + ".log", "w")$bFlush = true # flash output buffer$waitTime = 4000 # wait time in comunicationI use that log approach just for test purpose. When you go live it's better do not use time stamp.

Also, I use that method to get actual status real child devices and update their statuses in the LinuxMCE. Because some switch can be OFF manually during GSD device was down.

- Process Release - called when GSD device is closing. I don't use at all.

Note that you should quick reload router each time when you modify your Ruby code! Because LinuxMCE caches it.