示例#1
0
        public async void readData()
        {
            IPEndPoint       endpoint = new IPEndPoint(IPAddress.Any, 0);
            UdpReceiveResult res      = await udpClient.ReceiveAsync();

            SMCEndpoint = res.RemoteEndPoint;
            byte[] buffer = res.Buffer;

            string str = Encoding.ASCII.GetString(buffer);

            ReceivedMessage?.Invoke(str);
        }
        /// <summary>
        /// Listen to server.
        /// </summary>
        public void ListenToServer()
        {
            String message = null;

            //Create task to handle listening.
            Task task = new Task(() =>
            {
                try
                {
                    //While there is no request to stop listening.
                    while (!m_stopListening)
                    {
                        //Receive message from server.
                        message = Receive();
                        //Notify that message recieved.
                        NotifyMessage?.Invoke(message);
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message + message);
                }
            });

            task.Start();
        }
        public async void readDataasync()
        {
            try
            {
                UdpReceiveResult res = await udpClient.ReceiveAsync();

                SMCEndpoint = res.RemoteEndPoint;
                byte[] buffer = res.Buffer;

                string str = Encoding.Unicode.GetString(buffer);

                ReceivedMessage?.Invoke(str);

                LogMessage(str);
            }
            catch (Exception ex) { LogMessage(ex.Message); }
        }
示例#4
0
 /// <summary>
 /// 使用方法 Mes.NotifyMessage += SetNotifyMessage;  SetNotifyMessage(string message, SolidColorBrush fc)
 /// </summary>
 /// <param name="message"></param>
 /// <param name="color"></param>
 public static void Notify(string message, SolidColorBrush color = null)
 {
     if (color == null)
     {
         color = Brushes.Black;
     }
     //NotifyMessage?.Invoke(DateTime.Now.ToString("MM月dd日 HH:mm:ss :\r\n") + message, color);
     NotifyMessage?.Invoke(message, color);
 }
        public async void readData()
        {
            udpClient.Connect(SMCEndpoint);
            byte[] buffer = Encoding.Unicode.GetBytes("stesttss");
            udpClient.Send(buffer, buffer.Length);

            //  IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);
            UdpReceiveResult res = await udpClient.ReceiveAsync();

            SMCEndpoint = res.RemoteEndPoint;
            //  byte[]
            buffer = res.Buffer;

            string str = Encoding.ASCII.GetString(buffer);

            SendData(str);
            ReceivedMessage?.Invoke(str);
        }
示例#6
0
 /// <summary>
 /// 使用方法 Mes.NotifyMessage += SetNotifyMessage;  SetNotifyMessage(string message, SolidColorBrush fc)
 /// </summary>
 /// <param name="message"></param>
 /// <param name="color"></param>
 public static void Notify(string message)
 {
     //NotifyMessage?.Invoke(DateTime.Now.ToString("MM月dd日 HH:mm:ss :\r\n") + message, color);
     NotifyMessage?.Invoke(message);
 }
示例#7
0
 private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     NotifyMessage?.Invoke(SerialPort1.ReadExisting());
 }
示例#8
0
 private void OnNotifyMessage(string message)
 {
     NotifyMessage?.Invoke(this, new EventArgs <string>(message));
 }