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

martinS

  • Newbie
  • *
  • Posts: 5
    • View Profile
Generic Serial Device - (New user)
« on: July 16, 2007, 09:52:50 am »
Hi

I hope someone can help me out with this.

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.

Thanks

Martin S

Zaerc

  • Alumni
  • LinuxMCE God
  • *
  • Posts: 2256
  • Department of Redundancy Department.
    • View Profile
Re: Generic Serial Device - (New user)
« Reply #1 on: July 16, 2007, 03:46:22 pm »
"Change is inevitable. Progress is optional."
-- Anonymous


martinS

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Generic Serial Device - (New user)
« Reply #2 on: July 16, 2007, 04:49:10 pm »
Yes - I had looked at this, but unless I am missing something I am not able to understand how to define the interface correctly and then how to send and receive the ascii text through the interface.

Thanks

Martin

Cj_MaN

  • Regular Poster
  • **
  • Posts: 39
    • View Profile
Re: Generic Serial Device - (New user)
« Reply #3 on: July 18, 2007, 04:12:09 pm »
Try to contact one of the support guy on yahoo or skype (linuxmce, linuxmce4, linuxmce5). They will help you!

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Generic Serial Device - (New user)
« Reply #4 on: July 19, 2007, 09:39:35 am »
Yes - I had looked at this, but unless I am missing something I am not able to understand how to define the interface correctly and then how to send and receive the ascii text through the interface.

The steps are following:
1. Be sure that you have installed GSD package -
Code: [Select]
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:
Code: [Select]
# ps -elf|grep Generic_Serial_Device
Code: [Select]
5 S root     10085     1  0  76   0 -   683 -      Jul17 ?        00:00:00 SCREEN -d -m -S LinCon_8000-30 /usr/pluto/bin/Spawn_Device.sh 30 localhost Generic_Serial_Device
4 S root     10086 10085  0  75   0 -   646 wait   Jul17 pts/8    00:00:00 /bin/bash /usr/pluto/bin/Spawn_Device.sh 30 localhost Generic_Serial_Device
0 S root     31800 10086  0  79   0 - 123146 295621 Jul17 pts/8   00:00:00 ./Generic_Serial_Device -d 30 -r localhost -l /var/log/pluto/30_Generic_Serial_Device.log

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:
Code: [Select]
recv = conn_.Recv(100,500);recv contains now the data received from the physical device (some switch is OFF). You can parse it to update a status of that switch in LinuxMCE:
Code: [Select]
cmd = Command.new(plutoID, -1001, 1, 2, 48)
cmd.params_[10] = 0
SendCommand(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:
Code: [Select]
cmdId           = cmd.id_                                                         # Command ID: ON, OFF, SET LEVEL
cmdTo           = cmd.devidto_                                                # Device ID in LinuxMCE
devPort         = device_.childdevices_[cmdTo].devdata_[12] # 12 contains a port/channel
childType       = device_.childdevices_[cmdTo].devtemplid_   # Template ID to know type of device: switch or dimmer

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:
Code: [Select]
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 comunication

I 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.

Hope it help you to bring up your GSD device.
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

martinS

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Generic Serial Device - (New user)
« Reply #5 on: July 23, 2007, 09:51:41 am »
Michael

Thanks for your description. 
Your instructions pointed me in the right direction and I have managed to have some success over the weekend and have got LMCE to send a string using the GSD successfully.

Once again thank you.

Martin

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Generic Serial Device - (New user)
« Reply #6 on: July 23, 2007, 11:57:50 am »
You're very welcome, Martin :)
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru