Exemplo n.º 1
0
        private void ReceiveMessage(object obj)
        {
            IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Any, 7215);

            while (true)
            {
                try
                {
                    byte[] bytRecv = udpcRecv.Receive(ref remoteIpep);
                    string message = Encoding.UTF8.GetString(bytRecv, 0, bytRecv.Length);
                    //    MessageBox.Show("收到指令:" + code);
                    LogHelper.Log.Info("收到指令1:" + message);
                    message = message.Substring(0, message.LastIndexOf("*") + 1);
                    message = "$" + DesCode.DESDecode(message.Substring(1, message.Length - 2), "YN200916") + "*";
                    if (message == null || message.Equals("") || message.Length < 5 || !message.Substring(0, 5).Equals("$A712"))
                    {
                        continue;
                    }

                    currentStateCode = message;
                }
                catch (Exception ex)
                {
                    //    MessageBox.Show(ex.ToString());
                    continue;;
                }
            }
        }
Exemplo n.º 2
0
 private void sendMessage(string code)
 {
     try
     {
         code = "$" + DesCode.DESEncode(code.Substring(1, code.Length - 2), "YN200916") + "*";
         byte[]     sendbytes  = Encoding.UTF8.GetBytes(code);
         var        path       = AppDomain.CurrentDomain.BaseDirectory + "config.ini";
         IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Parse(INIFile.GetValue("cfg", "equipmentip", path)), 7015); // 发送到的IP地址和端口号
         LogHelper.Log.Info("Q-----------");
         int i = udpcRecv.Send(sendbytes, sendbytes.Length, remoteIpep);
     }
     catch (System.Exception ex)
     {
         //
     }
 }
Exemplo n.º 3
0
        private void sendMessage(string code)
        {
            try
            {
                code = "$" + DesCode.DESEncode(code.Substring(1, code.Length - 2), "YN200916") + "*";
                byte[] sendbytes = Encoding.UTF8.GetBytes(code);

                IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Parse(NEIni.ReadValue(".\\config.ini", "cfg", "equipmentip", "")), 7015); // 发送到的IP地址和端口号
                NELog.WriteLog("Q-----------");
                int i = udpcRecv.Send(sendbytes, sendbytes.Length, remoteIpep);
            }
            catch (System.Exception ex)
            {
                //
            }
        }
Exemplo n.º 4
0
        private void ReceiveMessage(object obj)
        {
            IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Any, 0);

            while (true)
            {
                try
                {
                    byte[] bytRecv = udpcRecv.Receive(ref remoteIpep);
                    printIPAddress = remoteIpep.Address;
                    string message = Encoding.UTF8.GetString(bytRecv, 0, bytRecv.Length);
                    if ("123456".Equals(message))
                    {
                        MessageBox.Show("收到指令:" + message);
                        return;
                    }
                    NELog.WriteLog("收到指令2:" + message + "-");

                    if (message == null || message.Equals("") || message.Length < 5)
                    {
                        continue;
                    }

                    message = message.Substring(0, message.LastIndexOf("*") + 1);
                    message = "$" + DesCode.DESDecode(message.Substring(1, message.Length - 2), "YN200916") + "*";

                    if (!message.Substring(0, 5).Equals("$Q703") && !message.Substring(0, 5).Equals("$Q701"))
                    {
                        continue;
                    }
                    mySyncdQ.Enqueue(message);
                }
                catch (Exception ex)
                {
                    //    MessageBox.Show(ex.ToString());
                    NELog.WriteLog(ex.ToString());
                    continue;
                }
            }
        }