public static void Main(string[] args) { /*test output werte richtig anzeigen * testen knx connection unten abschalten * auf nas probiren*/ _connection = new KnxConnectionTunneling("192.168.100.250", 3671, "192.168.100.194", 3671) { Debug = false }; //_connection = new KnxConnectionTunneling("192.168.100.250", 3671, "172.17.0.2", 3672) { Debug = true }; //_connection = new KnxConnectionTunneling("192.168.100.250", 3671, "192.168.100.90", 3672) { Debug = false }; /*DOCKER NAS*/ //_connection = new KnxConnectionTunneling("192.168.100.250", 3671, "192.168.100.172", 3671) { Debug = false }; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxEventDelegate += Event; _connection.KnxStatusDelegate += Status; _connection.Connect(); Console.WriteLine("Done. Press [ENTER] to finish"); //Console.ReadLine(); //Console.WriteLine("send"); //_connection.Action("2/1/3", true); //Console.ReadLine(); //_connection.Action("2/1/3", false); Console.ReadLine(); _connection.KnxDisconnectedDelegate -= Disconnected; _connection.Disconnect(); Environment.Exit(0); }
private static void Disconnected() { Console.WriteLine("Disconnected! Reconnecting"); if (_connection == null) { return; } Thread.Sleep(1000); _connection.Connect(); }
/// <summary> /// Connect to the remote host using the specified port. /// </summary> public KnxClientHelper Connect() { if (knxClient != null) { knxClient.Disconnect(); } if (knxEndPoint == null) { knxClient = new KnxConnectionRouting(); } else { if (knxEndPoint.RemoteIp != null && knxEndPoint.LocalIp != null) { if (knxClient == null) { knxClient = new KnxConnectionTunneling(knxEndPoint.RemoteIp, knxEndPoint.RemotePort, knxEndPoint.LocalIp, knxEndPoint.LocalPort); } } else if (knxEndPoint.LocalIp != null && knxEndPoint.LocalPort > 0) { if (knxClient == null) { knxClient = new KnxConnectionRouting(knxEndPoint.LocalIp, knxEndPoint.LocalPort); } } else if (knxEndPoint.LocalIp != null && knxEndPoint.LocalPort == 0) { if (knxClient == null) { knxClient = new KnxConnectionRouting(knxEndPoint.LocalIp); } } else if (knxEndPoint.LocalPort > 0) { if (knxClient == null) { knxClient = new KnxConnectionRouting(knxEndPoint.LocalPort); } } } if (!string.IsNullOrWhiteSpace(actionMessageCode)) { knxClient.ActionMessageCode = (byte)new ByteConverter().ConvertFromString(actionMessageCode); } knxClient.Connect(); knxClient.KnxConnectedDelegate += knxClient_Connected; knxClient.KnxDisconnectedDelegate += knxClient_Disconnected; knxClient.KnxEventDelegate += knxClient_EventReceived; knxClient.KnxStatusDelegate += knxClient_StatusReceived; return(this); }
public bool Connect() { _connection = new KnxConnectionTunneling("192.168.10.101", 3671, "192.168.10.140", 3671) { Debug = false }; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxEventDelegate += Event; _connection.KnxStatusDelegate += Status; _connection.Connect(); OnInterfaceModulesChanged(this.GetDomain()); return(true); }
private static void Main() { _connection = new KnxConnectionRouting { Debug = false, ActionMessageCode = 0x29 }; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxEventDelegate += Event; _connection.KnxStatusDelegate += Status; _connection.Connect(); LightOnOff(); Console.WriteLine("Done. Press [ENTER] to finish"); Console.Read(); Environment.Exit(0); }
private static void Main() { _connection = new KnxConnectionTunneling("10.0.250.20", 3671, "10.0.253.5", 3671) { Debug = false }; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxEventDelegate += Event; _connection.KnxStatusDelegate += Status; _connection.Connect(); Console.WriteLine("Done. Press [ENTER] to finish"); Console.Read(); _connection.KnxDisconnectedDelegate -= Disconnected; _connection.Disconnect(); Environment.Exit(0); }
private static void Main() { _logFile = new StreamWriter("telegrams.txt"); _connection = new KnxConnectionRouting { Debug = false, ActionMessageCode = 0x29 }; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxEventDelegate += Event; _connection.KnxStatusDelegate += Status; _connection.Connect(); //LightOnOff(); //BlindUpDown1(); //BlindUpDown2(); //TemperatureSetpoint(); Console.WriteLine("Done. Press [ENTER] to finish"); Console.Read(); _logFile.Dispose(); Environment.Exit(0); }
/// <summary> /// Connect to the remote host using the specified port. /// </summary> /// <param name="port">Port number.</param> public KnxClientHelper Connect() { if (knxClient != null) { knxClient.Disconnect(); } if (knxEndPoint == null) { knxClient = new KnxConnectionRouting(); } else { if (knxEndPoint.RemoteIp != null && knxEndPoint.LocalIp != null) { knxClient = new KnxConnectionTunneling(knxEndPoint.RemoteIp, knxEndPoint.RemotePort, knxEndPoint.LocalIp, knxEndPoint.LocalPort); } else if (knxEndPoint.LocalIp != null && knxEndPoint.LocalPort > 0) { knxClient = new KnxConnectionRouting(knxEndPoint.LocalIp, knxEndPoint.LocalPort); } else if (knxEndPoint.LocalIp != null && knxEndPoint.LocalPort == 0) { knxClient = new KnxConnectionRouting(knxEndPoint.LocalIp); } else if (knxEndPoint.LocalPort > 0) { knxClient = new KnxConnectionRouting(knxEndPoint.LocalPort); } } knxClient.Connect(); knxClient.KnxConnectedDelegate += knxClient_Connected; knxClient.KnxDisconnectedDelegate += knxClient_Disconnected; knxClient.KnxEventDelegate += knxClient_EventReceived; knxClient.KnxStatusDelegate += knxClient_StatusReceived; return(this); }
public void Test() { KNXLib.Log._logger.DebugEventEndpoint += Log; KNXLib.Log._logger.InfoEventEndpoint += Log; KNXLib.Log._logger.WarnEventEndpoint += Log; KNXLib.Log._logger.ErrorEventEndpoint += Log; //var connection = new KnxConnectionRouting("192.128.1.100"); _connection = new KnxConnectionTunneling("192.128.1.100", 3671, "192.128.1.1", 3671); _connection.Debug = true; _connection.KnxConnectedDelegate += Connected; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxStatusDelegate += Status; _connection.KnxEventDelegate += Event; _connection.Connect(); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.Action("0/0/6", false); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.Action("0/0/6", true); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.RequestStatus("1.1.50"); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.RequestStatus("1.1.51"); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.RequestStatus("1.1.30"); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.RequestStatus("1.1.31"); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); //_connection.RequestStatus("1.1.32"); //Task.Run(() => //{ // Thread.Sleep(10000); //}).Wait(); Task.Run(() => { var _run = true; while (_run) { Thread.Sleep(100); } }).Wait(); _connection.Disconnect(); Task.Run(() => { Thread.Sleep(10000); }).Wait(); //connection.KnxEventDelegate += Event; //connection.Action("1/1/50", false); //Task.Delay(5000).Wait(); //connection.Action("1/1/50", true); //Task.Delay(5000).Wait(); }
public void Init() { lock (_runLock) { if (_run) { return; } _run = true; } _connection = new KnxConnectionTunneling("192.168.1.100", 3671, "192.168.1.101", 3671); _connection.Debug = true; _connection.KnxDisconnectedDelegate += Disconnected; _connection.KnxConnectedDelegate += Connected; _connection.KnxStatusDelegate += Status; _connection.KnxEventDelegate += Event; #region Never ending loop Task.Factory.StartNew(() => { //var doAction = true; //var address = "0/0/1"; //var state = true; //Repeat daily var rrule = new RecurrencePattern(FrequencyType.Daily, 1); double offsetOn = 0.5; //SP should become 20.5 double offsetOff = -2; //SP should become 18 var calendar = new Ical.Net.Calendar(); List <MyCalendarEvent> myCalendarEvents = new List <MyCalendarEvent>(); //off var e_00__6_30 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 0, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 6, 30, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_00__6_30); myCalendarEvents.Add(e_00__6_30); //on var e_6_30__8 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 6, 30, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 8, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_6_30__8); myCalendarEvents.Add(e_6_30__8); //off var e_8__12 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 8, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 12, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_8__12); myCalendarEvents.Add(e_8__12); //on var e_12__14 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 12, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 14, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_12__14); myCalendarEvents.Add(e_12__14); //off var e_14__17 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 14, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 17, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_14__17); myCalendarEvents.Add(e_14__17); //on var e_17__18_30 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 17, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 18, 30, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_17__18_30); myCalendarEvents.Add(e_17__18_30); //off var e_18_30__20_30 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 18, 30, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 20, 30, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_18_30__20_30); myCalendarEvents.Add(e_18_30__20_30); //on var e_20_30__22 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 20, 30, 0)), End = new CalDateTime(new DateTime(2021, 1, 4, 22, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOn, }; calendar.Events.Add(e_20_30__22); myCalendarEvents.Add(e_20_30__22); //off var e_22__00 = new MyCalendarEvent { Start = new CalDateTime(new DateTime(2021, 1, 4, 22, 0, 0)), End = new CalDateTime(new DateTime(2021, 1, 5, 0, 0, 0)), RecurrenceRules = new List <RecurrencePattern> { rrule }, Offset = offsetOff, }; calendar.Events.Add(e_22__00); myCalendarEvents.Add(e_22__00); var serializer = new CalendarSerializer(); var serializedCalendar = serializer.SerializeToString(calendar); var searchStart = DateTime.Now.Date; var searchEnd = searchStart.AddDays(1); List <EventOccurrency> events = GetEventOccurrencies(myCalendarEvents, calendar, searchStart, searchEnd); foreach (var myEvent in events) { _logger.LogInformation("Event: {0} - {1}, offset: {2}", myEvent.Start, myEvent.End, myEvent.Offset); } EventOccurrency currentEvent = null; while (_run) { if (!_connected) { InitGroups(); _logger.LogInformation("Connecting"); _connection.Connect(); Task.Delay(5000).GetAwaiter().GetResult(); StartupCaldaia(); //var readOnlyGroupAddresses = Groups.Values.Where(g => g.Direction == KnxGroupDirection.OUTPUT).Select(g => g.Address).ToList(); //foreach (var readOnlyGroupAddress in readOnlyGroupAddresses) //{ // if (!_connected) // { // break; // } // _connection.RequestStatus(readOnlyGroupAddress); // Task.Run(() => // { // Thread.Sleep(1000); // }).Wait(); //} //_connection.Action("2/1/11", true); //Task.Delay(2000).GetAwaiter().GetResult(); //_connection.RequestStatus("2/1/11"); //if (_connected) //{ // var dpValue = _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.HVAC], "3"); // _connection.Action("2/1/4", dpValue); // var dpTempValue = _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.TEMPERATURE], "1"); // _connection.Action("2/1/13", dpTempValue); // var _2_1_xAddresses = Groups.Values.Where(v => v.Address.StartsWith("2/1/")).ToList(); // foreach (var _2_1_xAddress in _2_1_xAddresses) // { // _connection.RequestStatus(_2_1_xAddress.Address); // Task.Delay(200).GetAwaiter().GetResult(); // } // //Task.Delay(2000).GetAwaiter().GetResult(); // //_connection.RequestStatus("2/1/4"); //} } var now = DateTime.Now; if (now >= searchEnd) { searchStart = now.Date; searchEnd = searchStart.AddDays(1); _logger.LogInformation("Changing day: {0} - {1}", searchStart, searchEnd); events = GetEventOccurrencies(myCalendarEvents, calendar, searchStart, searchEnd); foreach (var myEvent in events) { _logger.LogInformation("Event: {0} - {1}, offset: {2}", myEvent.Start, myEvent.End, myEvent.Offset); } } //now < searchEnd else if (currentEvent == null || currentEvent.End <= now) { _logger.LogInformation("Set current event: {0}", now); events.RemoveAll(e => e.End <= now); if (events.Any()) { currentEvent = events.OrderBy(e => e.Start).First(); _logger.LogInformation("Event: {0} - {1}, offset: {2}", currentEvent.Start, currentEvent.End, currentEvent.Offset); var offsetString = currentEvent.Offset.ToString(CultureInfo.InvariantCulture); var dpTempValue = _connection.ToDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.TEMPERATURE], offsetString); _connection.Action("2/1/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/2/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/3/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/4/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/5/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); _connection.Action("2/6/13", dpTempValue); Task.Delay(200).GetAwaiter().GetResult(); } } Task.Delay(100).GetAwaiter().GetResult(); } }); #endregion }