@ danssaertd
here is my program code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Velleman.Velbus;
namespace Lindemeers
{
public partial class Form_lindemeers : Form
{
public bool pir_enabled;
public bool week_changed = false;
public int inputpir;
public int dag_in_jaar;
public int old_dag_in_jaar;
public int index_zon;
public int index_temp;
public int index_temp_bureel;
public int index_temp_badkamer;
public int index_jaar;
public int kolum1;
public int kolum2;
public int aantal_schakelmomenten;
public int aantal_schakelmomenten_bureel;
public int aantal_schakelmomenten_badkamer;
public int j = 0;
public int k = 0;
public int l = 0;
public int waarde1;
public int waarde2;
public int waarde3;
public decimal waarde13;
public decimal waarde14;
public decimal waarde15;
public double waarde4;
public double waarde5;
public double waarde6;
public string str_row_zon;
public string str_row_temp;
public string str_row_jaar;
public string opkomstuur;
public string onderganguur;
public string kolumnaam1;
public string kolumnaam2;
public string stis;
public string temp_regime_leefruimte;
public string temp_regime_bureel;
public string temp_regime_badkamer;
public string input_week = "1";
public string ] uur = {" "," "," "," "," "," "};
public string ] temp = {" "," "," "," "," "," "};
public string] uur_badkamer = { " ", " ", " ", " ", " ", " " };
public string] temp_badkamer = { " ", " ", " ", " ", " ", " " };
public string] uur_bureel = { " ", " "};
public string] temp_bureel = { " ", " "};
public Packet packet = new Packet();
public SerialBus bus = new SerialBus("Com5");
public Form_lindemeers()
{
InitializeComponent();
bus.Open();
bus.PacketReceived += new BusPacketIoEventHandler(PacketReceived);
label4.Text = " ";
label7.Text = input_week;
// 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);
}
// Reading data from database 'Lindemeers'
this.zonsopenondergangTableAdapter.Fill(this.lindemeersDataSet.zonsopenondergang);
this.TempTableAdapter.Fill(this.lindemeersDataSet.Temp);
this.temp_bureelTableAdapter.Fill(this.lindemeersDataSet.Temp_bureel);
this.temp_badkamerTableAdapter.Fill(this.lindemeersDataSet.Temp_badkamer);
this.schoolvakantieTableAdapter.Fill(this.lindemeersDataSet.Schoolvakantie);
this.feestdagenTableAdapter.Fill(this.lindemeersDataSet.Feestdagen);
}
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 == 0x30 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 0)
{
if (Kleerkast.InvokeRequired)
Kleerkast.BeginInvoke(new MethodInvoker(delegate() { Kleerkast.BackColor = Color.Red; }));
else
Kleerkast.BackColor = Color.Red;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 1)
{
if (Zolder.InvokeRequired)
Zolder.BeginInvoke(new MethodInvoker(delegate() { Zolder.BackColor = Color.Green; }));
else
Zolder.BackColor = Color.Green;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 0)
{
if (Zolder.InvokeRequired)
Zolder.BeginInvoke(new MethodInvoker(delegate() { Zolder.BackColor = Color.Red; }));
else
Zolder.BackColor = Color.Red;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 2)
{
if (Wc.InvokeRequired)
Wc.BeginInvoke(new MethodInvoker(delegate() { Wc.BackColor = Color.Green; }));
else
Wc.BackColor = Color.Green;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 0)
{
if (Wc.InvokeRequired)
Wc.BeginInvoke(new MethodInvoker(delegate() { Wc.BackColor = Color.Red; }));
else
Wc.BackColor = Color.Red;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 4)
{
if (Vestiare.InvokeRequired)
Vestiare.BeginInvoke(new MethodInvoker(delegate() { Vestiare.BackColor = Color.Green; }));
else
Vestiare.BackColor = Color.Green;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 0)
{
if (Vestiare.InvokeRequired)
Vestiare.BeginInvoke(new MethodInvoker(delegate() { Vestiare.BackColor = Color.Red; }));
else
Vestiare.BackColor = Color.Red;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 8)
{
if (Inkom.InvokeRequired)
Inkom.BeginInvoke(new MethodInvoker(delegate() { Inkom.BackColor = Color.Green; }));
else
Inkom.BackColor = Color.Green;
}
if (args.Packet.Address == 0x31 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 0)
{
if (Inkom.InvokeRequired)
Inkom.BeginInvoke(new MethodInvoker(delegate() { Inkom.BackColor = Color.Red; }));
else
Inkom.BackColor = Color.Red;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 1)
{
if (Keukenkasten.InvokeRequired)
Keukenkasten.BeginInvoke(new MethodInvoker(delegate() {Keukenkasten.BackColor = Color.Green;}));
else
Keukenkasten.BackColor = Color.Green;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 0)
{
if (Keukenkasten.InvokeRequired)
Keukenkasten.BeginInvoke(new MethodInvoker(delegate() { Keukenkasten.BackColor = Color.Red; }));
else
Keukenkasten.BackColor = Color.Red;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 2)
{
// WriteLog_rcv(String.Format(“Packet received from address {0,0}”, args.Packet.Address,args.Packet.Command));
if (Keukentafel.InvokeRequired)
Keukentafel.BeginInvoke(new MethodInvoker(delegate() { Keukentafel.BackColor = Color.Green; }));
else
Keukentafel.BackColor = Color.Green;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 0)
{
// WriteLog_rcv(String.Format(“Packet received from address {0,0}”, args.Packet.Address, args.Packet.Command));
if (Keukentafel.InvokeRequired)
Keukentafel.BeginInvoke(new MethodInvoker(delegate() { Keukentafel.BackColor = Color.Red; }));
else
Keukentafel.BackColor = Color.Red;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 4)
{
if (Keuken.InvokeRequired)
Keuken.BeginInvoke(new MethodInvoker(delegate() { Keuken.BackColor = Color.Green; }));
else
Keuken.BackColor = Color.Green;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 0)
{
if (Keuken.InvokeRequired)
Keuken.BeginInvoke(new MethodInvoker(delegate() { Keuken.BackColor = Color.Red; }));
else
Keuken.BackColor = Color.Red;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 8)
{
if (Amplix.InvokeRequired)
Amplix.BeginInvoke(new MethodInvoker(delegate() { Amplix.BackColor = Color.Green; }));
else
Amplix.BackColor = Color.Green;
}
if (args.Packet.Address == 0x32 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 0)
{
if (Amplix.InvokeRequired)
Amplix.BeginInvoke(new MethodInvoker(delegate() { Amplix.BackColor = Color.Red; }));
else
Amplix.BackColor = Color.Red;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 1)
{
if (Berging.InvokeRequired)
Berging.BeginInvoke(new MethodInvoker(delegate() { Berging.BackColor = Color.Green; }));
else
Berging.BackColor = Color.Green;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 1 && args.Packet[3] == 0)
{
if (Berging.InvokeRequired)
Berging.BeginInvoke(new MethodInvoker(delegate() { Berging.BackColor = Color.Red; }));
else
Berging.BackColor = Color.Red;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 2)
{
if (Garage.InvokeRequired)
Garage.BeginInvoke(new MethodInvoker(delegate() { Garage.BackColor = Color.Green; }));
else
Garage.BackColor = Color.Green;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 2 && args.Packet[3] == 0)
{
if (Garage.InvokeRequired)
Garage.BeginInvoke(new MethodInvoker(delegate() { Garage.BackColor = Color.Red; }));
else
Garage.BackColor = Color.Red;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 4)
{
if (Badkamer.InvokeRequired)
Badkamer.BeginInvoke(new MethodInvoker(delegate() {Badkamer.BackColor = Color.Green;}));
else
Badkamer.BackColor = Color.Green;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 4 && args.Packet[3] == 0)
{
if (Badkamer.InvokeRequired)
Badkamer.BeginInvoke(new MethodInvoker(delegate() { Badkamer.BackColor = Color.Red; }));
else
Badkamer.BackColor = Color.Red;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 8)
{
if (Buiten.InvokeRequired)
Buiten.BeginInvoke(new MethodInvoker(delegate() { Buiten.BackColor = Color.Green; }));
else
Buiten.BackColor = Color.Green;
}
if (args.Packet.Address == 0x33 && args.Packet.Command == 0xFB && args.Packet[1] == 8 && args.Packet[3] == 0)
{
if (Buiten.InvokeRequired)
Buiten.BeginInvoke(new MethodInvoker(delegate() { Buiten.BackColor = Color.Red; }));
else
Buiten.BackColor = Color.Red;
}
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; }));
else
Guest.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);
}
}
private void Master_Click(object sender, EventArgs e)
{
if (Master.BackColor == Color.Red)
{
packet.Address = 0x30;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x02;
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] = 0x02;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Guest_Click(object sender, EventArgs e)
{
if (Guest.BackColor == Color.Red)
{
packet.Address = 0x30;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x04;
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] = 0x04;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Kleerkast_Click(object sender, EventArgs e)
{
if (Kleerkast.BackColor == Color.Red)
{
packet.Address = 0x30;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x08;
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] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Zolder_Click(object sender, EventArgs e)
{
if (Zolder.BackColor == Color.Red)
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x03;
packet[1] = 0x01;
packet[2] = 0x0;
packet[3] = 0x0;
packet[4] = 0x0;
bus.Send(packet);
}
else
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x01;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Wc_Click(object sender, EventArgs e)
{
if (Wc.BackColor == Color.Red)
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x03;
packet[1] = 0x02;
packet[2] = 0x0;
packet[3] = 0x0;
packet[4] = 0x0;
bus.Send(packet);
}
else
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x02;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Vestiare_Click(object sender, EventArgs e)
{
if (Vestiare.BackColor == Color.Red)
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x04;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x04;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Inkom_Click(object sender, EventArgs e)
{
if (Inkom.BackColor == Color.Red)
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x31;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Keukenkasten_Click(object sender, EventArgs e)
{
if (Keukenkasten.BackColor == Color.Red)
{
packet.Address = 0x32;
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 = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x01;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Keukentafel_Click(object sender, EventArgs e)
{
if (Keukentafel.BackColor == Color.Red)
{
packet.Address = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x02;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x02;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Keuken_Click(object sender, EventArgs e)
{
if (Keuken.BackColor == Color.Red)
{
packet.Address = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x04;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x04;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Amplix_Click(object sender, EventArgs e)
{
if (Amplix.BackColor == Color.Red)
{
packet.Address = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x32;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Berging_Click(object sender, EventArgs e)
{
if (Berging.BackColor == Color.Red)
{
packet.Address = 0x33;
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 = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x01;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Garage_Click(object sender, EventArgs e)
{
if (Garage.BackColor == Color.Red)
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x02;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x02;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Badkamer_Click(object sender, EventArgs e)
{
if (Badkamer.BackColor == Color.Red)
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x03;
packet[1] = 0x04;
packet[2] = 0x0;
packet[3] = 0x0;
packet[4] = 0x0;
bus.Send(packet);
}
else
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x04;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Vitrine_Click(object sender, EventArgs e)
{
// if (Vitrine.BackColor == Color.Red)
// {
// packet.Address = 0x34;
// 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 = 0x34;
// packet.Priority = PacketPriority.High;
// packet.Rtr = false;
// packet.DataSize = 2;
// packet.Command = 0x01;
// packet[1] = 0x01;
// packet[2] = 0x00;
// bus.Send(packet);
// }
}
private void Buiten_Click(object sender, EventArgs e)
{
if (Buiten.BackColor == Color.Red)
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x02;
packet[1] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
else
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x08;
packet[2] = 0x00;
bus.Send(packet);
}
}
private void Pergola_Click(object sender, EventArgs e)
{
// if (Pergola.BackColor == Color.Red)
// {
// packet.Address = 0x34;
// packet.Priority = PacketPriority.High;
// packet.Rtr = false;
// packet.DataSize = 2;
// packet.Command = 0x02;
// packet[1] = 0x02;
// packet[2] = 0x00;
// bus.Send(packet);
// }
// else
// {
// packet.Address = 0x34;
// packet.Priority = PacketPriority.High;
// packet.Rtr = false;
// packet.DataSize = 2;
// packet.Command = 0x01;
// packet[1] = 0x02;
// packet[2] = 0x00;
// bus.Send(packet);
// }
}
private void AllesUit_Click(object sender, EventArgs e)
{
//Switch all relaymodules off
for (int i = 0x30; i <= 0x3f; i++)
{
packet.Address = i;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x0F;
packet[2] = 0x00;
packet[3] = 0;
packet[4] = 0;
bus.Send(packet);
}
// Switch all dimmers off
for (int i = 0x40; i <= 0x5F; i++)
{
packet.Address = i;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x07;
packet[1] = 0x01;
packet[2] = 0x00;
packet[3] = 0x00;
packet[4] = 0x00;
bus.Send(packet);
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
packet.Address = 0x40;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x07;
packet[1] = 0x01;
packet[2] = Convert.ToByte(numericUpDown1.Value);
packet[3] = 0xFF;
packet[4] = 0xFF;
bus.Send(packet);
label15.Text = Convert.ToString(numericUpDown1.Value);
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
packet.Address = 0x41;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x07;
packet[1] = 0x01;
packet[2] = Convert.ToByte(numericUpDown2.Value);
packet[3] = 0xFF;
packet[4] = 0xFF;
bus.Send(packet);
label14.Text = Convert.ToString(numericUpDown2.Value);
}
private void numericUpDown3_ValueChanged(object sender, EventArgs e)
{
packet.Address = 0x50;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x07;
packet[1] = 0x01;
packet[2] = Convert.ToByte(numericUpDown3.Value);
packet[3] = 0xFF;
packet[4] = 0xFF;
bus.Send(packet);
label16.Text = Convert.ToString(numericUpDown3.Value);
}
private void numericUpDownTemp_leefruimte_ValueChanged(object sender, EventArgs e)
{
packet.Address = 0x61;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xE4;
packet[1] = 0;
packet[2] = Convert.ToByte(numericUpDownTemp_leefruimte.Value * 2);
packet[3] = 0;
packet[4] = 0;
bus.Send(packet);
}
private void numericUpDown_bureel_ValueChanged(object sender, EventArgs e)
{
packet.Address = 0x62;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xE4;
packet[1] = 0;
packet[2] = Convert.ToByte(numericUpDown_bureel.Value * 2);
packet[3] = 0;
packet[4] = 0;
bus.Send(packet);
}
private void numericUpDown_temp_badkamer_ValueChanged(object sender, EventArgs e)
{
packet.Address = 0x63;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xE4;
packet[1] = 0;
packet[2] = Convert.ToByte(numericUpDown_temp_badkamer.Value * 2);
packet[3] = 0;
packet[4] = 0;
bus.Send(packet);
}
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString();
dag_in_jaar = DateTime.Now.DayOfYear;
//controleren op verandering van dag zodat de database mag gelezen worden
if (dag_in_jaar != old_dag_in_jaar)
{
old_dag_in_jaar = dag_in_jaar;
index_zon = this.lindemeersDataSet.zonsopenondergang.Count();
index_temp = this.lindemeersDataSet.Temp.Count();
index_temp_bureel = this.lindemeersDataSet.Temp_bureel.Count();
index_temp_badkamer = this.lindemeersDataSet.Temp_badkamer.Count();
index_jaar = this.lindemeersDataSet.Feestdagen.Count();
//uur van opkomst en ondergang uit datatabel zonsopenondergang lezen
for (int teller_zon = 1; teller_zon <= index_zon; teller_zon++)
{
foreach (DataRow row1 in lindemeersDataSet.zonsopenondergang)
{
str_row_zon = row1"Id"].ToString();
if (str_row_zon == dag_in_jaar.ToString())
{
opkomstuur = row1"Opkomst"].ToString().Substring(11);
onderganguur = row1"Ondergang"].ToString().Substring(11);
break;
}
}
}
label5.Text = opkomstuur;
label6.Text = onderganguur;
// lezen van schakelmomenten voor temperatuurregeling van leefruimte
for (int teller_temp = 1; teller_temp <= index_temp; teller_temp++)
{
foreach (DataRow row2 in lindemeersDataSet.Temp)
{
if (input_week == row2"week"].ToString())
{
if (DateTime.Now.DayOfWeek.ToString() == row2"dag"].ToString())
{
int teller1 = Convert.ToInt16(row2"aantal_schakelmomenten"]);
aantal_schakelmomenten = teller1;
for (int i = 0; i < teller1; i++)
{
kolum1 = 4 + (2 * i);
if (kolum1 == 4)
{
kolumnaam1 = "uur_1";
kolumnaam2 = "temperatur_1";
uur[0] = row2[kolumnaam1].ToString();
temp[0] = row2[kolumnaam2].ToString();
}
if (kolum1 == 6)
{
kolumnaam1 = "uur_2";
kolumnaam2 = "temperatuur_2";
uur[1] = row2[kolumnaam1].ToString();
temp[1] = row2[kolumnaam2].ToString();
}
if (kolum1 == 8)
{
kolumnaam1 = "uur_3";
kolumnaam2 = "temperatuur_3";
uur[2] = row2[kolumnaam1].ToString();
temp[2] = row2[kolumnaam2].ToString();
}
if (kolum1 == 10)
{
kolumnaam1 = "uur_4";
kolumnaam2 = "temperatuur_4";
uur[3] = row2[kolumnaam1].ToString();
temp[3] = row2[kolumnaam2].ToString();
}
if (kolum1 == 12)
{
kolumnaam1 = "uur_5";
kolumnaam2 = "temperatuur_5";
uur[4] = row2[kolumnaam1].ToString();
temp[4] = row2[kolumnaam2].ToString();
}
if (kolum1 == 14)
{
kolumnaam1 = "uur_6";
kolumnaam2 = "temperatuur_6";
uur[5] = row2[kolumnaam1].ToString();
temp[5] = row2[kolumnaam2].ToString();
}
if (i == Convert.ToInt16(row2"aantal_schakelmomenten"]))
{
break;
}
}
}
}
if (teller_temp > index_temp)
{
break;
}
}
}
// lezen van schakelmomenten voor temperatuurregeling van badkamer
for (int teller_temp_badkamer = 1; teller_temp_badkamer <= index_temp_badkamer; teller_temp_badkamer++)
{
foreach (DataRow row3 in lindemeersDataSet.Temp_badkamer)
{
if (input_week == row3"week_badkamer"].ToString())
{
if (DateTime.Now.DayOfWeek.ToString() == row3"dag_badkamer"].ToString())
{
int teller1 = Convert.ToInt16(row3"aantal_schakelmomenten_badkamer"]);
aantal_schakelmomenten_badkamer = teller1;
for (int i = 0; i < teller1; i++)
{
kolum1 = 4 + (2 * i);
if (kolum1 == 4)
{
kolumnaam1 = "uur_1_badkamer";
kolumnaam2 = "regime_1_badkamer";
uur_badkamer[0] = row3[kolumnaam1].ToString();
temp_badkamer[0] = row3[kolumnaam2].ToString();
}
if (kolum1 == 6)
{
kolumnaam1 = "uur_2_badkamer";
kolumnaam2 = "regime_2_badkamer";
uur_badkamer[1] = row3[kolumnaam1].ToString();
temp_badkamer[1] = row3[kolumnaam2].ToString();
}
if (kolum1 == 8)
{
kolumnaam1 = "uur_3_badkamer";
kolumnaam2 = "regime_3_badkamer";
uur_badkamer[2] = row3[kolumnaam1].ToString();
temp_badkamer[2] = row3[kolumnaam2].ToString();
}
if (kolum1 == 10)
{
kolumnaam1 = "uur_4_badkamer";
kolumnaam2 = "regime_4_badkamer";
uur_badkamer[3] = row3[kolumnaam1].ToString();
temp_badkamer[3] = row3[kolumnaam2].ToString();
}
if (i == Convert.ToInt16(row3"aantal_schakelmomenten_badkamer"]))
{
break;
}
}
}
}
if (teller_temp_badkamer > index_temp)
{
break;
}
}
}
// lezen van schakelmomenten voor temperatuurregeling van bureel
for (int teller_temp_bureel = 1; teller_temp_bureel <= index_temp_bureel; teller_temp_bureel++)
{
foreach (DataRow row4 in lindemeersDataSet.Temp_bureel)
{
if (DateTime.Now.DayOfWeek.ToString() == row4"dag_bureel"].ToString())
{
int teller1 = Convert.ToInt16(row4"aantal_schakelmomenten_bureel"]);
aantal_schakelmomenten_bureel = teller1;
for (int i = 0; i < teller1; i++)
{
kolum1 = 3 + (2 * i);
if (kolum1 == 3)
{
kolumnaam1 = "uur_1_bureel";
kolumnaam2 = "regime_1_bureel";
uur_bureel[0] = row4[kolumnaam1].ToString();
temp_bureel[0] = row4[kolumnaam2].ToString();
}
if (kolum1 == 5)
{
kolumnaam1 = "uur_2_bureel";
kolumnaam2 = "regime_2_bureel";
uur_bureel[1] = row4[kolumnaam1].ToString();
temp_bureel[1] = row4[kolumnaam2].ToString();
}
if (i == Convert.ToInt16(row4"aantal_schakelmomenten_bureel"]))
{
break;
}
}
}
}
if (teller_temp_bureel > index_temp_bureel)
{
break;
}
}
}
stis = DateTime.Now.ToLongTimeString();
label1.Text = stis;
//Disabelen van bewegingsmelder tussen zonsop- en zonsondergang
if (stis == opkomstuur)
{
pir_enabled = false;
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 2;
packet.Command = 0x01;
packet[1] = 0x08;
bus.Send(packet);
}
else if (stis == onderganguur)
{
pir_enabled = true;
}
if (pir_enabled == true)
{
label3.Text = "Enabled";
}
else
{
label3.Text = "Disabled";
}
if (pir_enabled == true && inputpir == 0x10)
{
packet.Address = 0x33;
packet.Priority = PacketPriority.High;
packet.Rtr = false;
packet.DataSize = 5;
packet.Command = 0x03;
packet[1] = 0x08;
packet[2] = 0x00;
packet[3] = 0x00;
packet[4] = 0x00;
bus.Send(packet);
}
label4.Text = Convert.ToString(waarde4);
label8.Text = Convert.ToString(waarde5);
label9.Text = Convert.ToString(waarde6);
// testen of er tussen dag- en nachttemperatuur moet geschakeld worden in leefruimte
if (uur[j]== DateTime.Now.ToLongTimeString())
{
if (temp[j] == "Day")
{
packet.Address = 0x61;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xDC;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
if (temp[j] == "Night")
{
packet.Address = 0x61;
packet.DataSize = 3;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.Command = 0xDD;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
j = j+1;
if (j > aantal_schakelmomenten-1)
{
j = 0;
}
}
// testen of er tussen dag- en nachttemperatuur moet geschakeld worden in bureel
if (uur_bureel[k] == DateTime.Now.ToLongTimeString())
{
if (temp_bureel[k] == "Day")
{
packet.Address = 0x62;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xDC;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
if (temp_bureel[k] == "Night")
{
packet.Address = 0x62;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xDD;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
k = k + 1;
if (k > aantal_schakelmomenten_bureel - 1)
{
k = 0;
}
}
// testen of er tussen dag- en nachttemperatuur moet geschakeld worden in badkamer
if (uur_badkamer[l] == DateTime.Now.ToLongTimeString())
{
if (temp_badkamer[l] == "Comfort")
{
packet.Address = 0x63;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xDB;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
if (temp_badkamer[l] == "Night")
{
packet.Address = 0x63;
packet.Priority = PacketPriority.Low;
packet.Rtr = false;
packet.DataSize = 3;
packet.Command = 0xDD;
packet[1] = 0x00;
packet[2] = 0x00;
bus.Send(packet);
}
l = l + 1;
}
if (l > aantal_schakelmomenten_badkamer - 1)
{
l = 0;
}
if (DateTime.Now.DayOfWeek.ToString() == "Sunday" && DateTime.Now.ToLongTimeString() == "23:59:59" && input_week == "1" && !week_changed)
{
input_week = "2";
label7.Text = "Week 2";
week_changed = true;
}
if (DateTime.Now.DayOfWeek.ToString() == "Sunday" &&DateTime.Now.ToLongTimeString() == "23:59:59" && input_week == "2" && week_changed)
{
input_week = "1";
label7.Text = "Week 1";
week_changed = false;
}
}
void MainForm_Formclosed(object sender, FormClosedEventArgs e)
{
// Be sure to clean up
bus.Close();
}
}
}
What i want to do is to send my packet to your velbus-server. can you adapt my code or show me the code to do that?
i have tried the code from Cantryn but i thing i did something wrong. it won’t work for me.
thx
stis