C# code for relais, dimmer and display update of VMD4PD

I did some testing with C# examples provided by Velleman that are downloadable at the download section of the vellman.be site.

Note that you can download Microsoft Visual C# 2008 express edition for free at Microsofts site! This is all you need to create VelBus tools :slight_smile:

This is what I made:
http://stogo.net/varia/velbusTool.jpg

I started from Vellemans DemoBasic example and added this:

  • relay 1 on
  • relay 1 off
  • dim to 50%
  • dim to 0%
  • change the display of the VMB4PD by your own 16-char string.
  • log all sent messages.

You can download my proof of concept tool here: stogo.net/varia/VelbusTools.zip
The code is a little bit documented. If you want to run this tool on your own velbus setup: Do not forget to change the com port and channel values of the modules.

An annoyance about this tool: If Vellemans’ VelbusLink tool is still connected and I try to run mine, then I’m having an access error (“Access to the port ‘COM32’ is denied.”). This is a pitty because you can’t listen to net traffic using their tool which would come in handy for debugging reasons … any solutions for this?

My goal is to show extra info at the display.
For example: show what song is playing now on media player and use the buttons to scroll through the playlist.

The ultimate goals are:

  • a nice interaction with Vista Media Center. Have to learn that API first … all hints are welcome!

  • controlling the velbus over tcp/ip. Once having that we can access it from all devices having internet connections (mobiles, pda’s, all remote pc’s!). I thought Velleman is working on that but did not hear any concrete news about it? What’s the status there?

  • having a nice C# velbus api that can be used as middle tier for flash/flex applications. This opens the way to create attractive GUIs.

I will post my progress …
So where’s the velbus community to jump in on this? This forum is rather quite now, and that’s a pitty … :slight_smile:
VelBus is a super environment to create outstanding domotic/automation tools! The sky is the limit! :slight_smile:

Cheers,
Gert

Hi,

When usgin the PackedtReceived event, I’m able to get the address of the module but not the state:

private void PacketReceived(object source, BusPacketIoEventArgs args)
{
// Log read operation
WriteLog(String.Format(“Packet received from address {0}”, args.Packet.Address));
WriteLog(String.Format(“Packet type: {0}”, args.Packet.Command));

    }

The Command property seems blank.

Can anyone provide some help here?

Thanks

That’s correct. But in fact you don’t need the command to know the state. Fortunately you can get all the info (also the state) from the args.Packet.Pack().

eg: Check when button 3 is pressed on the VMB4PD with address 13:

  • Check the address nr 13: args.Packet.Address or args.Packet.Pack()[2] == 0x13
  • Check button nr 3: args.Packet.Pack()[5] == 0x04

Hello!

Where I can find the document that you refer in the code (VMB4RY module p.17)? I download VMB4RY module protocol edition 1 - velleman.be/downloads/0/velbus/manuals/protocol/protocol_vmb4ry.pdf - but it only have 11pages and in this document highest priority byte is 0x00 (lowest priority byte is 0x11).

Regards

Hi Neper,

Sorry, I made a mistake: it should be page 7, not page 17 :slight_smile:
Have a look at ‘switch relay on’:

  • byte 1 is the command = 0x02 for “switch on”
  • byte 2 (= packet[1]) is the relay nr.

Hope this helps,
Gert

Hi Gert!

Ok, now I understand :slight_smile:
I still don’t understand which are lowest and highest bytes! I see different sources with different specifications.

Have a nice day!

On a sidenote, you should not use the Pack() function to access databytes. This function prepares the packet for transfer over the Velbus network (by calculating the checksum, adding the ETX byte, etc). Instead, call Pack() once, and then use the indexer to access the databytes.

Example:

packet.Pack(); // finalize the packet (adds checksum etc)

if (packet[5] == packet[4]); // use the indexer to access data bytes