public void TunnelingActionFeedbackTest() { ResetEvent = new ManualResetEventSlim(); KnxConnection connection = new KnxConnectionTunneling("127.0.0.1", 3671, "127.0.0.1", 3672) { Debug = false }; connection.KnxEventDelegate += Event; connection.Connect(); Thread.Sleep(50); connection.Action(LightOnOffAddress, true); if (!ResetEvent.Wait(Timeout)) Assert.Fail("Didn't receive feedback from the action"); }
public void UpdateLightStatus() { foreach (var key in HttpContext.Application.AllKeys) if (key.StartsWith("LightStatus_", StringComparison.InvariantCulture)) HttpContext.Application.Remove(key); lock (knxLock) { var localAddress = ConfigurationManager.AppSettings["localAddress"]; var localPort = GetNextRandom(); var remoteAddress = ConfigurationManager.AppSettings["remoteAddress"]; var remotePort = int.Parse(ConfigurationManager.AppSettings["remotePort"]); var connection = new KnxConnectionTunneling(remoteAddress, remotePort, localAddress, localPort); try { connection.KnxStatusDelegate += ReceiveKnxStatus; connection.Connect(); Wait(500); var settings = GetSettings(); foreach (var setting in settings) { connection.RequestStatus(setting.StatusAddress); Wait(100); } //Wait so statuses can update for (int i = 0; i < 30; i++) { var receivedSettingsCount = HttpContext.Application.AllKeys.Count(item => item.StartsWith("LightStatus_", StringComparison.CurrentCulture)); Debug.WriteLine("i: " + i.ToString() + " Received settings count: " + receivedSettingsCount); if (settings.Count() == receivedSettingsCount) break; else Wait(1000); } } catch(Exception ex) { Debug.WriteLine("ERROR: " + ex.ToString()); } finally { if (connection != null) connection.Disconnect(); } } }
public JsonResult Ändra(string room, string lampa, string state) { var setting = GetSettings().FirstOrDefault(item => item.RoomNormalized.Equals(room, StringComparison.CurrentCultureIgnoreCase) && item.LampaNormalized.Equals(lampa, StringComparison.CurrentCultureIgnoreCase)); if (setting != null) { lock (knxLock) { var localAddress = ConfigurationManager.AppSettings["localAddress"]; var localPort = GetNextRandom(); var remoteAddress = ConfigurationManager.AppSettings["remoteAddress"]; var remotePort = int.Parse(ConfigurationManager.AppSettings["remotePort"]); var connection = new KnxConnectionTunneling(remoteAddress, remotePort, localAddress, localPort); try { connection.KnxConnectedDelegate += KnxConnected; connection.KnxEventDelegate += KnxEvent; connection.KnxStatusDelegate += KnxStatusEvent; connection.Connect(); Wait(100); foreach (var address in setting.Addresses) { if (address.OnValue == 1) { var value = (state.ToLower() == "on" ? true : false); //Only allow change if trying to turn off or the light is allowed to be turned on if (value == false || setting.CanTurnOn) connection.Action(address.Address, value); } else if (address.OnValue > 1) { var value = (state.ToLower() == "on" ? address.OnValue : 0); //Only allow change if trying to turn off or the light is allowed to be turned on if (value == 0 || setting.CanTurnOn) connection.Action(address.Address, value); } } Wait(100); } finally { if (connection != null) connection.Disconnect(); } } } return Json(""); }