Velleman K8055 support in Domotiga

Forum about Domotiga Open Source Home Automation for Linux.

Moderator: RDNZL

Post Reply
BreFra
Starting Member
Starting Member
Posts: 21
Joined: Wed Jan 06, 2010 10:44 pm

Velleman K8055 support in Domotiga

Post by BreFra »

Hello domoti(ca/ga) fans.

First of all, I've learned a lot about domotica/domotiga by reading all the posts at this forum. So thanks to everybody. Now its my time to contribute too with this very long post.

I've managed to add support for the Velleman K8055 board (velleman.eu/distributor/products/view/? ... ;id=351346 into DomotiGa)

To get the K8055 board working in DomotiGa just follow these steps:

1. Install libusb support (sudo apt-get install libusb-dev) as this is required for step 2
2. Install K8055 linux driver/control (follow the instructions @ http://libk8055.sourceforge.net/, make sure you can communicate with the K8055 board using the "k8055" command as this is also used in the DomotiGa code)
3. Add these CASE statements at the specified routines at the FDeviceEditor.class file
RefreshDeviceType()

Code: Select all

   CASE "K8055"
      cmbInterface.Text = "Velleman K8055"
SelectAddressFields()

Code: Select all

   CASE "K8055"
      lblOther.Text = ("Port")
4. Add this CASE statement to the SetDevice() routine of the Devices.module file

Code: Select all

   CASE 30 ' Velleman Interface
      IF Main.bDevicesDebug THEN Main.WriteDebugLog("[Devices] Velleman K8055 board : " & sAddress & " " & sValue)
      IF Main.hK8055 THEN
        Main.hK8055.SendCommand(sAddress, sValue)
        Devices.ValueUpdate(Find(sAddress, iInterface), sValue, "", "", "")
        sText = ("Switched ") & sDeviceName & " " & sValue
      ELSE
        Main.WriteDebugLog(("[Devices] Can't control device '") & sDeviceName & ("' because K8055 is disabled!"))
      END IF
5. Add this routine to the FMain.class file

Code: Select all

PUBLIC SUB MenuSettingsK8055_Click()
   FSettingsK8055.Show
END
6. Add following code to the main.module file
@Declarations section:

Code: Select all

' Velleman K8055
PUBLIC bK8055Enabled AS Boolean
PUBLIC sK8055SerialPort AS String
PUBLIC iK8055BoardAddress AS Integer
PUBLIC iK8055PollTime AS Integer
PUBLIC iK8055DebounceTime1 AS Integer
PUBLIC iK8055DebounceTime2 AS Integer
PUBLIC bK8055Debug AS Boolean
PUBLIC hK8055 AS CK8055
@ GetSettings() routine add

Code: Select all

' Velleman K8055
rResult = GetSettingTable("k8055")
bK8055Enabled = rResult!enabled
iK8055BoardAddress = rResult!boardaddress
iK8055PollTime = rResult!polltime
iK8055DebounceTime1 = rResult!debouncetime1
iK8055DebounceTime2 = rResult!debouncetime2
bK8055Debug = rResult!debug
@ setup() routine add:

Code: Select all

Setup_K8055() ' Velleman K8055 support
@ CloseAll() routine add:

Code: Select all

' k8055 close
TRY hK8055.Disconnect
And finally add the following routines too

Code: Select all

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' open Velleman K8055 board and initialize
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRIVATE SUB Setup_K8055()
   IF bK8055Enabled THEN
   WriteLog(("Velleman K8055 support enabled."))
   IF bServer THEN
      ' create a new K8055 class instance
      hK8055 = NEW CK8055
      ' set the properties
      WITH hK8055
          .PollTime = iK8055PollTime
          .K8055Debug = bK8055Debug
          .AddressBoard = iK8055BoardAddress
          .DebounceTime1 = iK8055DebounceTime1
          .DebounceTime2 = iK8055DebounceTime2
       END WITH
       ' connect to the serial port
       IF hK8055.Connect() THEN
          WriteLog(("K8055 interface connected to board address ") & iK8055BoardAddress)
          hK8055.Run()
       ELSE
          WriteLog(("ERROR: K8055 interface FAILED to connect to board address ") & iK8055BoardAddress)
          hK8055 = NULL
       END IF
     END IF
   ELSE
      WriteLog(("Velleman K8055 support disabled."))
   END IF
END

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' restart K8055 after settings change
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PUBLIC SUB Restart_K8055()
   IF hK8055 THEN
      hK8055.Disconnect
      hK8055 = NULL
   END IF
   Setup_K8055()
END
7. Add the K8055 to the interface menu of FMain form
use these settings:
Name = MenuSettingsK8055
Caption = Velleman K8055
Picture = icons/k8055.png

8. Extract the attached file and add the files to the domotiga folder

9. Add K8055 tables to the domotiga database : mysql -u root -p <k8055.sql
The k8055.sql file is in the attached file.

10. finally compile and run DomotiGa....


@Ron, I hope you have some time to add these changes into the next update of DomotiGa.
Attachments
K8055.zip
Velleman K8055 files for domotiga
(6.01 KiB) Downloaded 450 times
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Re: Velleman K8055 support in Domotiga

Post by RDNZL »

Hi what a nice suprise!

A few people asked for k8055 support, so this code is welcome.

Will add it, thanks!
Regards, Ron.
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Re: Velleman K8055 support in Domotiga

Post by RDNZL »

Ok added your code to my development version, will probably be released today as version 0.1.193.
I changed the WAIT to SLEEP (we must find a way to get rid of it)
Doesn't the k8055 command/lib do any queuing?

Maybe you can send k8055.png icon to me too.
And I have added a check at startup to see if the k8055 command is installed/found, if not a message is displayed.

Thanks again!
Regards, Ron.
BreFra
Starting Member
Starting Member
Posts: 21
Joined: Wed Jan 06, 2010 10:44 pm

Re: Velleman K8055 support in Domotiga

Post by BreFra »

Sorry forgot to add the icon file to the zip. So attached the icon file.

I've also notice a wrong record (The Analog input port was accidentally called Digital input port) in the sql file. I've attached the corrected sql file too.

The code can have some little improvements, after all it's my first time writing in Gambas :)
I'll have a look into the waiting/sleep part. When start writing the code I experienced some strange behaviours so that's why I've added the waiting loop. In the meantime the code have been changed a lot. I'll let you know if it's possible to get rid of...

regards,
Frank van Breugel
Attachments
k8055.sql.zip
(1016 Bytes) Downloaded 461 times
icon file
icon file
k8055.png (759 Bytes) Viewed 13547 times
Andy_Burn
Starting Member
Starting Member
Posts: 43
Joined: Sun Nov 28, 2010 10:47 pm

Re: Velleman K8055 support in Domotiga

Post by Andy_Burn »

Brilliant!
Good work! Now I can take my unit out of the box and play with it!

Thank you :)
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Re: Velleman K8055 support in Domotiga

Post by RDNZL »

I have fixed the names, but didn't upgraded the version, so if you run 0.1.193 already you have to fix it yourself in edit modules window.

In gambas you can also call library calls directly, so you can perhaps skip calling k8055 command altogether.
But this requires some C and more advanced Gambas knowlegde...

Look here for more info:
http://gambasdoc.org/help/cat/externfunc
Regards, Ron.
BreFra
Starting Member
Starting Member
Posts: 21
Joined: Wed Jan 06, 2010 10:44 pm

Re: Velleman K8055 support in Domotiga

Post by BreFra »

Thanks for the info, I didn't know this is possible so I'll have a look into this.

I've already noticed that the sleep part is needed as the command doesn't like to be running concurrently. Without the sleep I get now and then a "Could not open..." error. Not a big issue as at the next poll the command works so the new config is read/writen to the board. It just takes a little longer....

Just give me a couple of day's to get familiar with the direct library calls in gambas.
insomniux
Starting Member
Starting Member
Posts: 23
Joined: Fri Mar 11, 2011 3:34 pm

Re: Velleman K8055 support in Domotiga

Post by insomniux »

ehhh... maybe a bit off topic:
I have a K8000 card which used to be addressed through the parallel port. Can the k8055 drivers and Domotiga instructions be used for the K8000 through a parallel-usb adapter?
Server: Intel® D945GSEJT dual Atom
Linux: Ubuntu Server 10.04
RFXCom receiver/xmitter
Domotiga 0.1.197
BreFra
Starting Member
Starting Member
Posts: 21
Joined: Wed Jan 06, 2010 10:44 pm

Re: Velleman K8055 support in Domotiga

Post by BreFra »

No that is not going to work.
Mainly because the plugin is communicating directly to the k8055 over USB
The USB to parallel converter won't be seen as the right device when it searches the USB bus for any k8055.

On topic, i have rewriten the plugin to use the k8055 library directly. Everything works except the debounce configuration of the 2 digital input ports. Still investigating why this isnt working. Maybe I'll use the program as a workarround for this.
If the workarround works I'll share the result.
insomniux
Starting Member
Starting Member
Posts: 23
Joined: Fri Mar 11, 2011 3:34 pm

Re: Velleman K8055 support in Domotiga

Post by insomniux »

OK, thanks for your reply...
I'm afraid the K8000's desitiny is the museum... :-(
Server: Intel® D945GSEJT dual Atom
Linux: Ubuntu Server 10.04
RFXCom receiver/xmitter
Domotiga 0.1.197
BreFra
Starting Member
Starting Member
Posts: 21
Joined: Wed Jan 06, 2010 10:44 pm

Re: Velleman K8055 support in Domotiga

Post by BreFra »

Finally got some time to finish the job I started before.

Unfortunatly I still haven't solved the problem setting the debounce timers using the direct functions, so I've still the workarround for this in place :-(
As all other code works a lot smoother I would like to share the updated code.
The improvements:

- a lot smoother/faster by using direct library calls (except when initializing the debounce timers)
- better debug information.
- more comments in code for readability by other programmers.

as it's not allowed to attache *.class files at this forum I had to compress it.
I guess Ron is happy to update he class file into the source code...

frank
Attachments
CK8055.class.tar.gz
(3.67 KiB) Downloaded 481 times
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Re: Velleman K8055 support in Domotiga

Post by RDNZL »

That's funny, another user asked me yesterday if I could look at the delays in this module, and I ordered a board so I could test myself, and add command queueing etc....
What is the problem with the debounce timers and library calls? I can have a look at it.
Regards, Ron.
Post Reply

Return to “DomotiGa Forum”