lifeemotions / knx.net

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

new bug #41

Open farizmaw opened 6 years ago

farizmaw commented 6 years ago

Hello, I tested this program with the latest version 1.1.10: 1- The name Status does not exist , so I removed the line. 2- when I remove the cable , the Disconnected respond after 20 to 40 sec . 3- after I return the cable , the connected respond after 20 to 40 sec . with the following Exception :

screenshot 51

please help. Thanks

using System; using KNXLib; using System.Threading;

namespace KNXTest {
class Program { public static int u1; static KnxConnectionTunneling conn; static void Main(string[] args) { u1 = 0;
try { conn = new KnxConnectionTunneling("172.21.2.85", 3671, "172.21.3.32", 3671); conn.SetLockIntervalMs(10); conn.Connect(); Console.WriteLine(" conn try wait 1 "); Thread.Sleep(1000); conn.KnxConnectedDelegate += Connected;
// conn.KnxStatusDelegate += Status; conn.KnxDisconnectedDelegate += Disconnected;
conn.KnxEventDelegate += Event; while (true) { conn.RequestStatus("2/2/4"); Thread.Sleep(10); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.ReadKey(); throw e; } } private static void Connected() { // if (u1 == 0) { Console.WriteLine(" conection is now " ); u1 = 1; } } private static void Disconnected() { // if (u1 == 1) { u1 = 0;

        if (conn == null)
        {
            Console.WriteLine("ERR: KNX Disconnected. Connection NULL");
        }
        else
        {
            Console.WriteLine("Disconnected from KNX.");
            Console.WriteLine("Disconnected. Attempting Reconnect in 1 seconds.");
            Thread.Sleep(1000);
            conn.Connect();
                conn.Connect(); Console.WriteLine(" wait 1 "); Thread.Sleep(1000);
            }
        }
    }
    static void Event(string address, string state)
    {
        Console.WriteLine("New Event: device " + address + " has status " + state);
        if (address == "2/2/4")
        {                              
            decimal temp = (decimal)conn.FromDataPoint("9.001", state);
            Console.WriteLine("New Event: sensor " + address + " has status " + temp);
        }
        if (address == "2/1/50")
        {                             
            Console.WriteLine("New Event: sw 50 " + address + " has status ");
            decimal temp = (decimal)conn.FromDataPoint("5.001", state);
            Console.WriteLine(temp);
        }
        if (address == "2/1/51")
        {                            
            Console.WriteLine("New Event: sw 51 " + address + " has status ");
            decimal temp = (decimal)conn.FromDataPoint("5.001", state);
            Console.WriteLine(temp);
        }
    }
}

}