hi to bveklm,
here you see the code in c# express 2008 when you use a server.
i’m using VMB8PB ( address 1 to 12) ,VMB4PD( address 32), VMB4RY (address 48 to 51) , VMB1RY(address 52), VMB1DM(address 64 to 65), VMB1LED(address 80),VMB1TC(address 96) and VMB1TS(address 97 to 98)
private void velbusConnector1_PacketReceived(Velbusserver.VelbusConnector.ReceivedPacketArgs ar)
{
// look if relay is on or off
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 1 && ar.packet[3] == 1)// channel 1 is on
{
if (Bureel.InvokeRequired)
Bureel.BeginInvoke(new MethodInvoker(delegate() { Bureel.BackColor = Color.Green; }));
else
Bureel.BackColor = Color.Green;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 1 && ar.packet[3] == 0)// channel 1 is off
{
if (Bureel.InvokeRequired)
Bureel.BeginInvoke(new MethodInvoker(delegate() { Bureel.BackColor = Color.Red; }));
else
Bureel.BackColor = Color.Red;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 2 && ar.packet[3] == 2)// channel 2 is on
{
if (Master.InvokeRequired)
Master.BeginInvoke(new MethodInvoker(delegate() { Master.BackColor = Color.Green; }));
else
Master.BackColor = Color.Green;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 2 && ar.packet[3] == 0)// channel 2 is off
{
if (Master.InvokeRequired)
Master.BeginInvoke(new MethodInvoker(delegate() { Master.BackColor = Color.Red; }));
else
Master.BackColor = Color.Red;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 4 && ar.packet[3] == 4)// channel 3 is on
{
if (Guest.InvokeRequired)
Guest.BeginInvoke(new MethodInvoker(delegate() { Guest.BackColor = Color.Green; }));
else
Guest.BackColor = Color.Green;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 4 && ar.packet[3] == 0)// channel3 is off
{
if (Guest.InvokeRequired)
Guest.BeginInvoke(new MethodInvoker(delegate() { Guest.BackColor = Color.Red; }));
else
Guest.BackColor = Color.Red;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 8 && ar.packet[3] == 8)// channel4 is on
{
if (Kleerkast.InvokeRequired)
Kleerkast.BeginInvoke(new MethodInvoker(delegate() { Kleerkast.BackColor = Color.Green; }));
else
Kleerkast.BackColor = Color.Green;
}
if (ar.packet.Address == 48 && ar.packet.Command == 251 && ar.packet[1] == 8 && ar.packet[3] == 0)// channel 4 is off
{
if (Kleerkast.InvokeRequired)
Kleerkast.BeginInvoke(new MethodInvoker(delegate() { Kleerkast.BackColor = Color.Red; }));
else
Kleerkast.BackColor = Color.Red;
}
if (ar.packet.Address == 52 && ar.packet.Command == 251 && ar.packet[1] == 1 && ar.packet[3] == 1)
{
if (label11.InvokeRequired)
label11.BeginInvoke(new MethodInvoker(delegate() { label11.BackColor = Color.Green; }));
}
if (ar.packet.Address == 52 && ar.packet.Command == 251 && ar.packet[1] == 1 && ar.packet[3] == 0)
{
if (label11.InvokeRequired)
label11.BeginInvoke(new MethodInvoker(delegate() { label11.BackColor = Color.Red; }));
}
// Get value of the dimmer and put it into variables waarde1,2 & 3
if (ar.packet.Address == 64 && ar.packet.Command == 238)
{
if (numericUpDown1.InvokeRequired)
numericUpDown1.BeginInvoke(new MethodInvoker(delegate() { label15.Text = Convert.ToString(ar.packet[2]); }));
}
if (ar.packet.Address == 65 && ar.packet.Command == 238)
{
if (numericUpDown2.InvokeRequired)
numericUpDown2.BeginInvoke(new MethodInvoker(delegate() { label14.Text = Convert.ToString(ar.packet[2]); }));
}
if (ar.packet.Address == 80 && ar.packet.Command == 238)
{
if (numericUpDown3.InvokeRequired)
numericUpDown3.BeginInvoke(new MethodInvoker(delegate() { label16.Text = Convert.ToString(ar.packet[2]); }));
}
// Get temperatures and put it into numericUpDownTemp's
if (ar.packet.Address == 97 && ar.packet.Command == 234)
{
waarde13 = Convert.ToDecimal(ar.packet[5]);
if (numericUpDownTemp_leefruimte.InvokeRequired)
numericUpDownTemp_leefruimte .BeginInvoke(new MethodInvoker(delegate() { numericUpDownTemp_leefruimte.Value = waarde13 / 2; }));
}
if (ar.packet.Address == 98 && ar.packet.Command == 234)
{
waarde14 = Convert.ToDecimal(ar.packet[5]);
if (numericUpDown_bureel.InvokeRequired)
numericUpDown_bureel.BeginInvoke(new MethodInvoker(delegate() { numericUpDown_bureel.Value = waarde14 / 2; }));
}
if (ar.packet.Address == 99 && ar.packet.Command == 234)
{
waarde15 = Convert.ToDecimal(ar.packet[5]);
if (numericUpDown_temp_badkamer.InvokeRequired)
numericUpDown_temp_badkamer.BeginInvoke(new MethodInvoker(delegate() { numericUpDown_temp_badkamer.Value = waarde15 / 2; }));
}
// Get value from VMBTS and put it in waarde(4,5,6)
if (ar.packet.Address == 97 && ar.packet.Command == 230)
{
waarde4 = (((ar.packet[5] * 256) + ar.packet[6]) / 32) * 0.0625;
}
if (ar.packet.Address == 98 && ar.packet.Command == 230)
{
waarde5 = (((ar.packet[5] * 256) + ar.packet[6]) / 32) * 0.0625;
}
if (ar.packet.Address == 99 && ar.packet.Command == 230)
{
waarde6 = (((ar.packet[5] * 256) + ar.packet[6]) / 32) * 0.0625;
}
//Looking for input on VMB8pd at address 12
if (ar.packet.Address == 12 && ar.packet.Command == 0)
{
inputpir = ar.packet[2];
}
}
and to put a relay on and off
private void Bureel_Click(object sender, EventArgs e)
{
if (Bureel.BackColor == Color.Red)
{
packet_out.Address = 48;
packet_out.Priority = PacketPriority.High;
packet_out.Rtr = false;
packet_out.DataSize = 2;
packet_out.Command = 2;
packet_out[1] = 1;
packet_out[2] = 0;
packet_out[3] = 0;
packet_out[4] = 0;
velbusConnector1.SendPacket(packet_out);
}
else
{
packet_out.Address = 48;
packet_out.Priority = PacketPriority.High;
packet_out.Rtr = false;
packet_out.DataSize = 2;
packet_out.Command = 1;
packet_out[1] = 1;
packet_out[2] = 0;
packet_out[3] = 0;
packet_out[4] = 0;
velbusConnector1.SendPacket(packet_out);
}
}
how to switch all modules off
private void AllesUit_Click(object sender, EventArgs e)
{
//Switch all relaymodules off
for (int i = 48; i <= 0x63; i++)
{
packet_out.Address = i;
packet_out.Priority = PacketPriority.High;
packet_out.Rtr = false;
packet_out.DataSize = 2;
packet_out.Command = 1;
packet_out[1] = 15;
packet_out[2] = 0;
packet_out[3] = 0;
packet_out[4] = 0;
velbusConnector1.SendPacket(packet_out);
}
// Switch all dimmers off
for (int i = 64; i <= 95; i++)
{
packet_out.Address = i;
packet_out.Priority = PacketPriority.High;
packet_out.Rtr = false;
packet_out.DataSize = 5;
packet_out.Command = 7;
packet_out[1] = 1;
packet_out[2] = 0;
packet_out[3] = 0;
packet_out[4] = 0;
packet_out[5] = 0;
velbusConnector1.SendPacket(packet_out);
}
}
how to command a dimmer
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
packet_out.Address = 0x40;
packet_out.Priority = PacketPriority.High;
packet_out.Rtr = false;
packet_out.DataSize = 0x05;
packet_out.Command = 0x07;
packet_out[1] = 0x01;
packet_out[2] = Convert.ToByte(numericUpDown1.Value);
packet_out[3] = 0xff;
packet_out[4] = 0xff;
packet_out[5] = 0x00;
velbusConnector1.SendPacket(packet_out);
label15.Text = Convert.ToString(numericUpDown1.Value);
}
to use it without a server
// Loop over all relaymodules
// and send out my scan packet
for (int i = 0x30; i <= 0x3F; i++)
{
packet.Address = i;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0xFA;
packet[1] = 0x0F;
bus.Send(packet);
}
// Loop over all dimmermodules
// and send out my scan packet
for (int i = 0x40; i <= 0x5F; i++)
{
packet.Address = i;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0xFA;
packet[1] = 1;
bus.Send(packet);
}
// Send out my scan packet to all the VMBTS modules
for (int i = 0x61; i <= 0x6F; i++)
{
packet.Address = i;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0xFA;
packet[1] = 1;
bus.Send(packet);
packet.Address = i;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0xE5;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
public void PacketReceived(object source, BusPacketIoEventArgs args)
{
// look if relay is on or off
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 1)
{
if (Bureel.InvokeRequired)
Bureel.BeginInvoke(new MethodInvoker(delegate() { Bureel.BackColor = Color.Green; }));
else
Bureel.BackColor = Color.Green;
}
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 0)
{
if (Bureel.InvokeRequired)
Bureel.BeginInvoke(new MethodInvoker(delegate() { Bureel.BackColor = Color.Red; }));
else
Bureel.BackColor = Color.Red;
}
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 2)
{
if (Master.InvokeRequired)
Master.BeginInvoke(new MethodInvoker(delegate() { Master.BackColor = Color.Green; }));
else
Master.BackColor = Color.Green;
}
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 0)
{
if (Master.InvokeRequired)
Master.BeginInvoke(new MethodInvoker(delegate() { Master.BackColor = Color.Red; }));
else
Master.BackColor = Color.Red;
}
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 4)
{
if (Guest.InvokeRequired)
Guest.BeginInvoke(new MethodInvoker(delegate() { Guest.BackColor = Color.Green; }));
else
Guest.BackColor = Color.Green;
}
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 0)
{
if (Guest.InvokeRequired)
Guest.BeginInvoke(new MethodInvoker(delegate() { Guest.BackColor = Color.Red; }));
else
Guest.BackColor = Color.Red;
}
if (args.Packet.Address == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 8)
{
if (Kleerkast.InvokeRequired)
Kleerkast.BeginInvoke(new MethodInvoker(delegate() { Kleerkast.BackColor = Color.Green; }));
else
Kleerkast.BackColor = Color.Green;
}
if (args.Packet.Address == 0x34 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 1)
{
if (label10.InvokeRequired)
label10.BeginInvoke(new MethodInvoker(delegate() { label10.BackColor = Color.Green; }));
}
if (args.Packet.Address == 0x34 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 0)
{
if (label10.InvokeRequired)
label10.BeginInvoke(new MethodInvoker(delegate() { label10.BackColor = Color.Red; }));
}
// Get value of the dimmer and put it into variables waarde1,2 & 3
if (args.Packet.Address == 0x40 && args.Packet.Command == 0xEE)
{
if (numericUpDown1.InvokeRequired)
numericUpDown1.BeginInvoke(new MethodInvoker(delegate() { label15.Text = Convert.ToString(args.Packet[2]); }));
}
if (args.Packet.Address == 0x41 && args.Packet.Command == 0xEE)
{
if (numericUpDown2.InvokeRequired)
numericUpDown2.BeginInvoke(new MethodInvoker(delegate() { label14.Text = Convert.ToString(args.Packet[2]); }));
}
if (args.Packet.Address == 0x50 && args.Packet.Command == 0xEE)
{
if (numericUpDown3.InvokeRequired)
numericUpDown3.BeginInvoke(new MethodInvoker(delegate() { label16.Text = Convert.ToString(args.Packet[2]); }));
}
if (args.Packet.Address == 0x61 && args.Packet.Command == 0xEA)
{
waarde13 = Convert.ToDecimal(args.Packet[5]);
if (numericUpDownTemp_leefruimte.InvokeRequired)
numericUpDownTemp_leefruimte.BeginInvoke(new MethodInvoker(delegate() {numericUpDownTemp_leefruimte.Value = waarde13/2;}));
}
if (args.Packet.Address == 0x62 && args.Packet.Command == 0xEA)
{
waarde14 = Convert.ToDecimal(args.Packet[5]);
if (numericUpDown_bureel.InvokeRequired)
numericUpDown_bureel.BeginInvoke(new MethodInvoker(delegate() {numericUpDown_bureel.Value = waarde14/2;}));
}
if (args.Packet.Address == 0x63 && args.Packet.Command == 0xEA)
{
waarde15 = Convert.ToDecimal(args.Packet[5]);
if (numericUpDown_temp_badkamer.InvokeRequired)
numericUpDown_temp_badkamer.BeginInvoke(new MethodInvoker(delegate() {numericUpDown_temp_badkamer.Value = waarde15/2;}));
}
// Get value from VMBTS and put it in waarde(4,5,6)
if (args.Packet.Address == 0x61 && args.Packet.Command == 0xE6)
{
waarde4 = (((args.Packet[1] * 256) + args.Packet[2]) / 32) * 0.0625;
}
if (args.Packet.Address == 0x62 && args.Packet.Command == 0xE6)
{
waarde5 = (((args.Packet[1] * 256) + args.Packet[2]) / 32) * 0.0625;
}
if (args.Packet.Address == 0x63 && args.Packet.Command == 0xE6)
{
waarde6 = (((args.Packet[1] * 256) + args.Packet[2]) / 32) * 0.0625;
}
//Looking for input on VMB8pd
if (args.Packet.Address == 0x0C && args.Packet.Command == 0x00)
{
inputpir = args.Packet[1];
}
}
private void Bureel_Click(object sender, EventArgs e)
{
if (Bureel.BackColor == Color.Red)
{
packet.Address = 0x30;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x01;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x30;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x01;
packet[2] = 0x00;
bus.Send(packet);
}
}