Beispiel #1
0
        //接收数据,开始解析,
        private void DataOn(byte[] data, SocketAsyncEventArgs socketAsync)
        {
            try
            {
                if (data.Length > 0)
                {
                    EndPoint remoteEndPoint = socketAsync.AcceptSocket.RemoteEndPoint;
                    RecieveLog.AddInfo(string.Concat(new string[]                                   { DateTime.Now.ToString(), " ->接收 [", remoteEndPoint.ToString(), "] :", PubFuncHelper.ByteToHexStr(data), "\r\n" }));
                    DLT698Message.FrameInfo frameInfo = new DLT698Message.FrameInfo();
                    DLT698Message           dLT       = new DLT698Message();

                    var x = new byte[data.Length - 36];
                    Array.Copy(data, 33, x, 0, data.Length - 36);
                    data = x;
                    if (dLT.Assert_Basic(data))                    //数据内容基本ok
                    {
                        dLT.ParseData(data, data.Length, ref frameInfo);
                        TCPClientInfo cl = new TCPClientInfo();
                        cl.Host = remoteEndPoint;
                        cl.Sock = socketAsync.AcceptSocket;
                        cl.A1   = frameInfo.A1;
                        cl.A2   = frameInfo.A2;



                        bool processed = BasicProcessMessage(data, socketAsync, remoteEndPoint, frameInfo, cl);
                        //
                        if (!processed && OnDLT698Message != null)
                        {
                            OnDLT698Message(this, new DLT698MessageEventArgs(dLT));
                        }
                    }
                }
            }
            catch
            {
            }
        }
 private void OnDataReceived(object sender, SocketAsyncEventArgs e)
 {
     try
     {
         if (e.BytesTransferred > 0)
         {
             EndPoint remoteEndPoint = e.RemoteEndPoint;
             byte[]   array          = new byte[e.BytesTransferred];
             Array.Copy(e.Buffer, 0, array, 0, e.BytesTransferred);
             RecieveLog.AddInfo(string.Concat(new string[]
             {
                 DateTime.Now.ToString(),
                 " ->接收(UDP) [",
                 remoteEndPoint.ToString(),
                 "] :",
                 this.ByteToHexStr(array),
                 "\r\n"
             }));
             DLT698Message.FrameInfo frameInfo = default(DLT698Message.FrameInfo);
             DLT698Message           dLT       = new DLT698Message();
             if (dLT.Assert_Basic(array))
             {
                 dLT.ParseData(array, e.BytesTransferred, ref frameInfo);
                 if (frameInfo.AFN == "02")
                 {
                     if (frameInfo.FN == "0003")
                     {
                         byte[] data = this.LogOK(frameInfo.A1, frameInfo.A2, frameInfo.FN, frameInfo.PSEQ);
                         LogMSG.AddInfo(string.Concat(new string[]
                         {
                             DateTime.Now.ToString(),
                             " ->终端(UDP) [",
                             remoteEndPoint.ToString(),
                             "] 心跳:",
                             this.ByteToHexStr(array),
                             "\r\n",
                             DateTime.Now.ToString(),
                             " ->回应(UDP) [",
                             remoteEndPoint.ToString(),
                             "] 心跳确认:",
                             this.ByteToHexStr(data),
                             "\r\n"
                         }), 7);
                         this.Send(data);
                     }
                 }
                 else
                 {
                     if (frameInfo.PRM == "0" & frameInfo.DIR == "1")
                     {
                         BufferManager.AddDataItem(frameInfo.A1, frameInfo.A2, array);
                     }
                     else
                     {
                         if (frameInfo.PRM == "1" & frameInfo.DIR == "1")
                         {
                             ActiveReportMsg.AddInfo(array);
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }