lifeemotions / knx.net

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

bus statusrequest #33

Closed ThomasLammens closed 7 years ago

ThomasLammens commented 7 years ago

Hey,

I am working on a vb.net project where one connected appliance, lets say a lightbulb for example can be turned on by my program, but also by a lightswitch. I was looking through the code to find out if there exists a statusrequest of my bus(adress). Of course, i found the "connection".statusrequest but this doesn't seem to return a value.

Is there a way in which I can read the status of an adress?

Kind regards, Thomas

abelsilva commented 7 years ago

Hi Thomas

The function doesn't return a value because the bus functions are async, you have to subscribe to events:

e.g.:

connection.KnxStatusDelegate += Status;
connection.RequestStatus("1/1/16");

static void Status(string address, string state)
{
  if (address == "1/1/16")
  {
    decimal temp = (decimal)connection.FromDataPoint("9.001", state);
    Console.WriteLine("New Event: device " + address + " has status " + temp);
    return;
  }
}
ThomasLammens commented 7 years ago

Hi Abel,

Thank you very much for your reply, it was a big help to us.

Kind regards, Thomas