Get Status off relay C#

Hello im programing an interface in C# to comand my velbus installation with a touch screen. To change the status of the relay there is no problem, i use for every comand a button so i have a button to set the relay and one to reset the relay, but now i want that the button’s also show the status of the relay.

Ex: If the relay is active, Only the OFF button can be used
If the relay is inactive, Only the ON button can be pressed

So i can control the state off the relay.

To disabel the button I use the command

 btnSend1off.Enabled = false;

Can sombody give me a code example to see the state of relay 1 of VMB4RY with adres A0


You will need to capture the relay status (command FBh)

Address: A0h
Priority: Low
Databytes: 8

Databyte 4 contains the relay status:
0000 0000b Relays off
0000 0001b Relay channel 1 on
0000 0010b Relay channel 2 on
0000 0100b Relay channel 3 on
0000 1000b Relay channel 4 on
0001 0001b Relay channel 1 blinks
0010 0010b Relay channel 2 blinks
0100 0100b Relay channel 3 blinks
1000 1000b Relay channel 4 blinks

The VMB1RY only uses the least significant bit while the VMB4RY uses all four bits to represent each channel.

Thanks for the reaction, my problem on this stage is that i c’ant find the methode to listen to the serial port :blush: , so i can get the information that is recive on the velbus.

this is wath i get


        // Prepare a packet that will switch on the relays
        // of a VMB4RY module (see: p.17 of the VMB4RY manual)
        Packet packet = new Packet();
        packet.Address = 0x0A;                  // 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] = 0x04;                       // We want to switch on relay3

        // Issue the command!

        packet.Address = 0x0A;                  // change this address to reflect your setup
        packet.Priority = PacketPriority.Low;  // LOW priority command
        packet.DataSize = 8;                    // 8 data bytes
        packet.Command = 0xFB ;                  // GET STATUS"
        packet[1] = 0x08;

        // Issue the command!

        // Be sure to close the bus so everything
        // can be cleaned up properly */

can anybody give me a code or a methode to get the data of the serial connection.

thanks best regards

    public partial class SerialBus
        public SerialBus(String portName, int baudRate)
            m_SerialPort = new SerialPort(portName, baudRate);
            m_SerialPort.Parity = Parity.None;
            m_SerialPort.StopBits = StopBits.One;
            m_SerialPort.DataBits = 8;
            m_SerialPort.DtrEnable = false;
            m_SerialPort.RtsEnable = true;
            m_SerialPort.DataReceived += new SerialDataReceivedEventHandler(SerialDataReceivedHandler);
            m_SerialPort.ReceivedBytesThreshold = 1;
            m_Dispatcher = new Dispatcher(this);

            m_Parser = new PacketParser();

        private void SerialDataReceivedHandler(object source, SerialDataReceivedEventArgs args)
            int BytesRead = m_SerialPort.Read(m_InBuffer, 0, m_SerialPort.BytesToRead);
            m_Parser.Feed(m_InBuffer, BytesRead);

            Packet packet = m_Parser.Next();
            while (packet != null)
                TreatePacket(packet); // Treat your packet here
                packet = m_Parser.Next();


But all this come from the SerialBus.cs file in the library.

Yes you can just use our SerialBus component for .NET (VelbusLib) and handle the PacketReceived event.