public void ReceiveCallback(IAsyncResult ar)
 {
     try
     {
         var myUdp         = (UdpState)ar.AsyncState;
         var receiveString = Encoding.ASCII.GetString(myUdp.UdpClient.EndReceive(ar, ref myUdp.Ep));
         receiveString = myUdp.Ep.Address.ToString() + "\n" + receiveString.Replace("\r\n", "\n");
         myUdp.UdpClient.BeginReceive(ReceiveCallback, myUdp);
         var strsplits = receiveString.Split('\n');
         if (strsplits.Length != 5)
         {
             return;
         }
         if (!strsplits[1].Contains("EPC232"))
         {
             return;
         }
         var ds = new UdpClinetMsg
         {
             IpAddress  = strsplits[0],
             Name       = strsplits[1],
             MacAddress = strsplits[2],
             MasterPort = strsplits[3]
         };
         if (NewLogMsg == null)
         {
             return;
         }
         NewLogMsg(this, ds);
     }
     catch (Exception)
     {
         //ignored
     }
 }
Example #2
0
        private void UdpServerDiscoverer_NewLogMsg(object sender, UdpClinetMsg e)
        {
            void Action()
            {
                if ((e.MasterPort == Properties.Settings.Default.EPCPort.ToString()) && (e.IpAddress == Properties.Settings.Default.EPCAddress.ToString()))
                {
                    leds.chkLedConnection = true;
                }
                else
                {
                    leds.chkLedConnection = false;
                }

                //elipseFill(LEDConnection, serialParse.chkLedConnection);
                elipseFillCheck();

                // Create list of devices that ensure connection
                var lst = new List <UdpClinetMsg> {
                    e
                };

                gridDevices.ItemsSource = lst;
                gridDevices.UpdateLayout();
            }

            Main.Dispatcher.BeginInvoke((Action)Action);
        }