lifeemotions / knx.net

KNX.net provides a KNX API for .NET
MIT License
102 stars 47 forks source link

Receive Status from Group Address #9

Closed denneboomyo closed 9 years ago

denneboomyo commented 9 years ago

How do you get the status(e.g. false or true on a switch) from a group address?

CumpsD commented 9 years ago

There is this which can let you know:

static void Main(string[] args)
{
  var connection = new KnxConnectionRouting();
  connection.Connect();
  connection.KnxEventDelegate += new KnxConnection.KnxEvent(Event);
}

static void Event(string address, string state)
{
  Console.WriteLine("New Event: device " + address + " has status " + state);
}

However, that only catches the live incoming status.

I'm not sure if it is already implemented to actively query for status, maybe @abelsilva can tune in?

abelsilva commented 9 years ago

Hi

You can do the same thing to request status (just change the function and delegate):

static void Main(string[] args)
{
  var address = "3/4/5";
  var connection = new KnxConnectionRouting();

  connection.Connect();
  connection.KnxStatusDelegate += Status;

  // ...

  connection.RequestStatus(address);

  // ....
}

static void Status(string address, string state)
{
  Console.WriteLine("Status: device " + address + " has status " + state);
}
RisaI commented 9 years ago

Hello. I am having issues with my implementation of your library. I can successfully connect to the KNXnet/IP and I recieve CONNECT_RESPONSE datagram. However, when I try to retrieve the status of a group address, nothing comes in. I wasn't able to receive events, until I changed a line of code on the line number 117 in KnxReceiverTunneling.cs from

if (sequenceNumber <= _rxSequenceNumber)

to

if (sequenceNumber < _rxSequenceNumber)

now I receive random events, but I still don't receive any statuses.

denneboomyo commented 9 years ago

I can't really get KnxStatus and KnxEvent to work. Changing the state of a KNX Switch through PC works, but i dont get any Event or Status printed at console.

abelsilva commented 9 years ago

@RisaI can you please open a new issue? thanks!

@denneboomyo There are two things in KNX programming that might influence the events and status: 1) the KNX device itself, when programming it, make sure you configure it to send events and respond the status requests 2) configuration of the IP router/interface: make sure you configure it to forward everything between TP and IP

let me know if this works for you

AnaKatarina commented 9 years ago

Hello everybody :)

First of all, I'm sorry if my english is bad. I'm Ana Katarina from Croatia and I really, really need solution for my problem. I would be very thankful if you could help me :)

My task is to make a desktop application that will be able to connect with the KNX / IP router and receive telegram from weather station and save that parameters to database. I'm using Schneider knx router and ETS 3 software. What should I do? I have no one to ask, KNX is in Croatia still unknown, and I promise that I'm just a student who is stuck with this problem.

I'm using Visual Studio 2013 pro and these classes of Mr. David. I'm sending you guys how I wrote code for that solution, but it doesn't work.

using KNXLib; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

namespace zavrsni { public partial class Form1 : Form { string IPadresa; string Port;

    private static KnxConnection _connection;

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

    }

    private void btnPotvrda_Click(object sender, EventArgs e)
    {
        IPadresa = txtIPadresa.Text;
        Port = txtPort.Text;

        int port = Convert.ToInt32(Port);

        try
        {
            _connection = new KnxConnectionRouting(IPadresa, port);
            _connection.Connect();

            _connection.KnxEventDelegate += new KnxConnection.KnxEvent(Event);
            _connection.KnxStatusDelegate += new KnxConnection.KnxStatus(Event);

            _connection.Action("4/1/1", _connection.ToDataPoint("9.001", 24.0f));
        }
        catch (Exception es)
        {
            txtStatus.Text = es.Message;
        }
    }

    private void Event(string address, string state)
    {
        float temp = (float)_connection.FromDataPoint("9.001", state);
        txtStatus.Text = "Temperature: " + temp;          
    }      
}

}

abelsilva commented 9 years ago

@AnaKatarina please open a different ticket with your issue, thanks!

@denneboomyo I'm closing this issue for now, feel free to comment if you still can't get it to work