Page 1 of 2

Controlling the Velleman K8056 relay card?

Posted: Fri May 19, 2006 5:02 pm
by wetwired
Would it be possible to control this relay card using Housebot?

http://www.velleman.be/ot/en/product/view/?id=351282

It is controllable using the RS232 port on a PC...

Posted: Fri May 19, 2006 6:03 pm
by Richard Naninck
Yes, very easy!
If you figure or find out the protocol to control this board, you can use the generic serial device and vbscript to control this. Velleman is also known for offering SDK's for their boards. This dll can possibly be used to control it using vbscript or C++. VBScript is already implemented in HB, using C++ would create the option to use it together with the HB SDK to create a HB plugin.
In other words.... yes, but you need some programming skills.

Posted: Sat May 20, 2006 3:45 am
by wetwired
Sounds good. I think I´ll have go with this card...

Posted: Sun May 28, 2006 3:30 pm
by wetwired
Ok, I bought the card and assembled it. It works great with the testing software that Velleman has made. But when I take a look at the the generic serial control from Housebot I am at a loss. Could someone please help me step by step along the way to get this card controlled through Housebot?

This is the part from the cards manual about controlling it through RS232
Image

I have tried setting up the serial hardware interface in Housebot but I need help with the "Interface command configuration" and what exactly I should put in the "write data" input field.

Any help is really appreciated, thanks.

Posted: Sun May 28, 2006 3:36 pm
by Richard Naninck
Before going into depth, did you read both help files on this subject?

HouseBot/help/D_genericSerialDevice.CHM and H_GenericSerial.CHM
They explain pretty clear on what you should do to get this to work. If not, come again...

Posted: Sun May 28, 2006 3:51 pm
by wetwired
Yes, I have read the help files and I understand most of it but when I get to "Interface command configuration" I get stuck.
I need help figuring out what I should put in the "write data" input field. I think the info is in the manual I posted but I can´t decipher it.

Posted: Sun May 28, 2006 4:28 pm
by Richard Naninck
Wow, an example would have been nice here.
According to me if you want a two's complement checksum, the previous bytes should be hex like bytes. Since there can be instructions with S and T, you cannot set the Write Data to Hex. It needs to be Ascii. You also need to write a small program to calculate your checksums. Maybe using the wildcard "*" option and a vbscript which calculates your checksums on the fly is a good option.
Try this:
0D01S9A0
0D = Chr(13)
01 = Card Address
S9 = Set all relays
9F = Checksum

Checksum program should be something like this:

'-------------------------------
Data = "0D01S9"
Checksum = 0
For n = 1 to Len(Data)
Checksum = Checksum + Asc(Mid(Data, n, 1))
Next
MsgBox Right(Hex((Checksum Xor 255) + 1), 2)
'-------------------------------

You can use an InputBox to set your data without having to edit the script all the time.

Another example could be:
0DFFT27A

Toggle Relay 2 at address 255

I am really not sure if this helps any because I don't have the board. If this doesn't do anything, at least I am out of options and cannot help you anymore.

Good luck

Posted: Sun May 28, 2006 5:48 pm
by wetwired
Thanks so much for your reply, Richard. I understand much better now how the command sequence is built. I have run the small checksum program you wrote and it works great. But...

I can´t understand how the serial plugin is supposed to be setup in Housebot. How do I create a device whose property changes to a serial command sequence I send to it from a task?

I have the hardware interface and the hardware definition file, but what about the device definition file? I´m confused.

Posted: Sun May 28, 2006 5:54 pm
by Richard Naninck
Well, that should have been the easy part. I really can't explain it better than it is said in the help fileS. Capital S here since there are two help files on the subject. One for the hardware device and one for the Serial device that contains the properties or wildcard linked to the hardware device. That device is used in tasks etc.
maybe Scott can elaborate on that OR your questions need oto be somewhat more specific on where you hang.
Bed time, so this is my last one for the day.

Posted: Sun May 28, 2006 6:23 pm
by Richard Naninck
I edited my previous mail to make up for the incorrect Chr(13) as 0C.
0C Hex = 12 Dec, so it should be 0D.
Sorry for that!

Posted: Mon May 29, 2006 6:52 am
by wetwired
Something is wrong with the command sequence, Richard. The card doesn´t respond when I try it with girder.
I found this in the vb example program from Velleman:

Private Sub Command5_Click()
checksum = (255 - ((((13 + address + Asc("S") + Asc("9")) / 256) - Int((13 + address + Asc("E") + Asc("1")) / 256)) * 256)) + 1

messagestring = Chr$(13) & Chr$(address) & "E1" & Chr$(checksum)
messagestring = messagestring & messagestring
messagestring = messagestring & messagestring
comm.Output = messagestring
End Sub

This code snippet seems to create the correct command sequence. But I can´t replicate it using VBscript :(

Posted: Mon May 29, 2006 10:46 am
by Richard Naninck
In your example the message gets sent about 4 times as advertised in the manual.
Can you tell me what the example vbscript outputs and what checksum is outputted. Just create some examples and post them here.
I am not sure how this can work at all. The checksum consists of S9 AND E1 which seems to me that these are two different command strings. SHouldn't it be:

checksum = (255 - ((((13 + address + Asc("S") + Asc("9")) / 256) - Int((13 + address + Asc("S") + Asc("9")) / 256)) * 256)) + 1

messagestring = Chr$(13) & Chr$(address) & "S9" & Chr$(checksum)

OR

checksum = (255 - ((((13 + address + Asc("E") + Asc("1")) / 256) - Int((13 + address + Asc("E") + Asc("1")) / 256)) * 256)) + 1

messagestring = Chr$(13) & Chr$(address) & "E1" & Chr$(checksum)

Posted: Mon May 29, 2006 4:11 pm
by wetwired
Yes, the example is wrong. I mistyped it, sorry.
But I think I have found the solution! If you use this formula to calculate the checksum:

checksum = 255-(13+1+83+57)+1

where
13 is the char$(13)
1 is the card address
83 is the "S" in dec
57 is the relay number in dec ie "9"

and then hex everything above except the address (!?) You get this command sequence:

0D01533966

If I send this to the card using a software called "RS232 Hex Com Tool"
http://tucows.com/start_dl/344067_128270_573
The card responds and sets all the relays. Success!

If only I could work out how to send this command through Housebot. The serial plugin is a bit confusing to say the least...

Posted: Mon May 29, 2006 4:35 pm
by Richard Naninck
Glad you figured it out. It seems strange that the address is a plain number and the instruction (but also) the relay should be in ascii code.
What do you mean with 'except the address (!?)'. 01 Dec is also Hex 01.
Some example code always does the trick. The manual really falls short here I would say.

I am sure that if you dig a while, you will find the serial device easy to work with. Did you read BOTH help files on the subject, or just ONE?

Posted: Mon May 29, 2006 5:46 pm
by wetwired
Yes I have read both help files. When I use the "Configure generic serial port devices" tool from the settings menu and I create a "new device definition", what property should I choose? There is no property for sending hex codes, or can´t I see it?

What confuses me is that I have three things to configure,
The "hardware interface"
The "device definition"
The "device" which is somehow connected to the "device definition".

And how do I go about using this in a task?

All I want to do is send a hexcode through the com-port. Why isn´t there a device called "comport" which a dynamic property called "command"? Then it would be easy :)