update ping implementation
authorStricted <info@stricted.net>
Thu, 12 Jan 2017 03:24:02 +0000 (04:24 +0100)
committerStricted <info@stricted.net>
Thu, 12 Jan 2017 03:24:02 +0000 (04:24 +0100)
SpeedportHybridControl.Implementations/util.cs
SpeedportHybridControl/MainWindow.xaml.cs

index 5c8210de48390a1e739f98eea79689af314e3cd0..74ee8388f5bd22673c9824b71c106855b97f8a11 100644 (file)
@@ -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");
+                               }
                        }
                }
     }
index 65183cf4ca15e78ded4d0da8163863a84ed2989b..f88e7745cd5c14021bbc5e86d05e9f3165b73152 100644 (file)
@@ -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);
+                       }
+                       */
+               }
     }
 }