Sending packet to serial port to operate relay

Up till now i have been concentrating on using recieving commands from the two VMB6IN units i have, and using them to operate in an alarm form, using NC motion sensors, all works well but now I have a VMB4RYLD module and need to now how to send a packet to it to operate, say the 3rd relay in the module using VB.NET.

There appears to be a lot on info on C+ programming but very little on VB.NET.
Using the USB connection.

Can some give me a sample of some code to get me going in the right direction.

Thanks in advance for the help

Andrew

But you’re already receiving packets, so you know what a packet looks like? Sending is quite the same…

What do you have problems with exactly?

Maybe itis just me but serial ports comms is not my strong point.
This is what i have below, understand there must be a “&H” before the address in VB.NET
How about the checksum requirement ?

Am i heading in the right direction ?

VBpacket = New Packet()
VBpacket.Address = &HF1
VBpacket.Priority = PacketPriority.High
VBpacket.DataSize = 2
VBpacket.Command = &H2
VelbusSerialBus.SendBlocking(VBpacket)

It’s always a good idea to learn the basics of the programming language first

  • &H1A is the hexadecimal notation in VB.NET for 1A, which is 26 in decimal. Since the rotary switch for the address on the module is in hexadecimal (0…9 A…F) it makes sense that we use hexadecimal notation as well
  • You don’t have to worry about how serial communications work since that is already handled behind your back by the SerialBus class. The only thing you need to know is the name of the serial port you will be using (COM1, …)
  • The Packet class handles a lot of things automatically, like calculating the checksum

That’s the beauty of VelbusLib for .NET, you can write

VBpacket.Priority = PacketPriority.High

Without having to worry which byte needs to be modified for the packet to have high priority.

Use VelbusLink 8 to examine packets as they pass over the bus. Try to understand what each byte in that packet means by using the protocol manual of each module as a reference. Then all will be a lot clearer for you to start sending your own packets.

So the script should be like this to operate the 2nd relay on the relay module with address F1 ?

VBpacket = New Packet()
VBpacket.Address = F1
VBpacket.Priority = PacketPriority.High
VBpacket.DataSize = 2
VBpacket.Command = 2
VelbusSerialBus.SendBlocking(VBpacket)

As i said serial ports comms are not my strong point !

Thank you for your help.

Andrew

You forgot to set your second data byte to indicate which channel(s) to switch on

In C#:

Packet packet = new Packet();
packet.Address = 0xF1;                  // change this address to reflect your setup
packet.Priority = PacketPriority.High;  // high priority command
packet.DataSize = 2;                    // 2 data bytes
packet.Command = 0x02;                  // Command "Switch relay ON"
packet[1] = 0x03;                       // Switch on relay 1 and 2

Thanks

packet[1] = 0x03; // Switch on relay 1 and 2

This is the bit that confuses me.
What is the [1] part for

Andrew

Those are the extra bytes attached to the packet, they are usually parameters for the command that you use.

packet.DataSize = 5;                    // 5 data bytes, indexed from 0..4
packet.Command = 0xFF;                  // Command (this is data byte 0)
packet[1] = 0x00;                       // Data byte 1
packet[2] = 0x00;                       // Data byte 2
packet[3] = 0x00;                       // Data byte 3
packet[4] = 0x00;                       // Data byte 4

Thanks, think i am making progress

The script below throws up a fault saying the syntax is not valid.

packet[1] = 0x00

After some serching, this appears to be accepted, but will need to wait till i get home to try it out, does it look right

I am trying to turn on relay 1 and 3 on the moudle with address F0

VBpacket = New Packet()
VBpacket.Address = &HF0
VBpacket.Priority = PacketPriority.High
VBpacket.DataSize = 2
VBpacket.Command = &H2
VBpacket.Item(1) = &H3
VelbusSerialBus.SendBlocking(VBpacket)

Thanks

Andrew

If you want relay 1 and 3, then you need to put in &H5 instead of &H3.

Each bit represents a relay, here’s how you calculate it:

---------------------------------------
      |       1 Byte = 8 Bits         |
---------------------------------------
Relay | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
---------------------------------------
      | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
---------------------------------------

00000101 in binary = 5 in decimal = 5 in hexadecimal

Thanks, got that bit now. Understand it now.

Dim VBpacket As Packet
VBpacket = New Packet()
VBpacket.Address = &HF0
VBpacket.Priority = PacketPriority.High
VBpacket.DataSize = 2
VBpacket.Command = &H2
VBpacket.Item(1) = &H1
VelbusSerialBus.SendBlocking(VBpacket)

The above code produces no responce, not even a flicker on the Rx light on the relay
Can switch the realys on and off ok with Velbuslink.

Andrew

Sorry if this is a stupid question, but did you connect?

Not stupid at all, one of the first things i checked !

Yes, it can accept incomming packets

Does the code look right ?

Andrew

[quote=“rockhoppers1964”]Up till now i have been concentrating on using recieving commands from the two VMB6IN units i have, and using them to operate in an alarm form, using NC motion sensors, all works well but now I have a VMB4RYLD module and need to now how to send a packet to it to operate, say the 3rd relay in the module using VB.NET.

There appears to be a lot on info on C+ programming but very little on VB.NET.
Using the USB connection.

Can some give me a sample of some code to get me going in the right direction.

Thanks in advance for the help

Andrew[/quote]

hello Andrew,

I tried to send you many email to the following adresse but unfortunatly no response:
andrew (AT)rockhoppers.co.uk

Can you contact me at velbus@ciceron-solutions.com.

thank you in advance

object:test your software

my dear andrew it would be nice of you, if you could reply from time to time to the question asked.

thank you