From 3a99b35332f4010167d39c163e6ce14e64d2cc97 Mon Sep 17 00:00:00 2001 From: Stricted Date: Thu, 12 Jan 2017 04:24:02 +0100 Subject: [PATCH] update ping implementation --- .../util.cs | 34 +++++++++++++------ SpeedportHybridControl/MainWindow.xaml.cs | 16 +++++++-- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/SpeedportHybridControl.Implementations/util.cs b/SpeedportHybridControl.Implementations/util.cs index 5c8210d..74ee838 100644 --- a/SpeedportHybridControl.Implementations/util.cs +++ b/SpeedportHybridControl.Implementations/util.cs @@ -7,6 +7,8 @@ using System.Net.NetworkInformation; using System.Net.Sockets; using System.Security.Cryptography; using System.Text; +using System.Threading; +using System.Windows; using System.Windows.Media; using System.Xml; @@ -245,12 +247,16 @@ namespace SpeedportHybridControl.Implementations public static bool checkLteModul () { Ping ping = new Ping(); - PingReply reply = ping.Send("172.10.10.1"); - - if (reply.Status == IPStatus.Success) + try { - return true; + PingReply reply = ping.Send("172.10.10.2", 2); + + if (reply.Status == IPStatus.Success) + { + return true; + } } + catch (PingException) { } return false; } @@ -259,12 +265,20 @@ namespace SpeedportHybridControl.Implementations { if (checkLteModul().Equals(true)) { - Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); - IPAddress serverAddr = IPAddress.Parse("172.10.10.1"); - IPEndPoint endPoint = new IPEndPoint(serverAddr, 1280); - byte[] cmd = Encoding.ASCII.GetBytes(Command); - sock.SendTo(cmd, endPoint); - sock.Close(); + try + { + Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + IPAddress serverAddr = IPAddress.Parse("172.10.10.1"); + IPEndPoint endPoint = new IPEndPoint(serverAddr, 1280); + byte[] cmd = Encoding.ASCII.GetBytes(Command); + sock.SendTo(cmd, endPoint); + sock.Close(); + } + catch (Exception) + { + new Thread(() => { MessageBox.Show("couldn't send Command to LTE Modul", MessageBoxButton.OK, MessageBoxImage.Error); }).Start(); + LogManager.WriteToLog("couldn't send Command to LTE Modul"); + } } } } diff --git a/SpeedportHybridControl/MainWindow.xaml.cs b/SpeedportHybridControl/MainWindow.xaml.cs index 65183cf..f88e774 100644 --- a/SpeedportHybridControl/MainWindow.xaml.cs +++ b/SpeedportHybridControl/MainWindow.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using SpeedportHybridControl.Implementations; +using System.Threading; +using System.Windows; namespace SpeedportHybridControl { @@ -10,6 +12,16 @@ namespace SpeedportHybridControl public MainWindow() { InitializeComponent(); - } + /* + if (util.checkLteModul()) + { + MessageBox.Show("ABC", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); + } + else + { + MessageBox.Show("DEF", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); + } + */ + } } } -- 2.20.1