Exemplo n.º 1
0
 private string HexStrToGB2312(string strSrc)
 {
     Debug.Print("strSrc=" + strSrc);
     if (strSrc.Substring(0, 2) == "00")
     {
         strSrc = strSrc.Substring(2, 2);
     }
     byte[] bytes = PubFuncHelper.HexStrToByte(strSrc);
     return(Encoding.GetEncoding("GB2312").GetString(bytes));
 }
Exemplo n.º 2
0
 protected override void GetText()
 {
     this.Data             = "";
     this.dlt.MeterCortrol = this.comboBox2.Text.Trim();
     if (this.radioButton1.Checked)
     {
         this.dlt.IsRead = true;
     }
     else
     {
         this.dlt.IsRead = false;
     }
     this.dlt.MeterDataLength = 0;
     this.dlt.MeterIdentifier = this.comboBox3.Text.Trim();
     this.dlt.MeterAddress    = this.comboBox9.Text.Trim();
     this.dlt.MeterPassWord   = this.comboBox5.Text.Trim();
     this.dlt.MeterDataFormat = "";
     if (this.radioButton2.Checked)
     {
         if (this.checkBox1.Checked)
         {
             string meterSendDataInfo = PubFuncHelper.ASCIIToHexStr(this.textBox3.Text.Trim());
             this.dlt.MeterSendDataInfo = meterSendDataInfo;
         }
         else
         {
             this.dlt.MeterSendDataInfo = this.textBox3.Text.Trim();
         }
         this.dlt.OperatorID = ((this.comboBox3.Text.Trim().Length == 8) ? "00000000" : "");
     }
     else
     {
         this.dlt.MeterSendDataInfo = "";
         this.dlt.OperatorID        = "";
     }
     this.Data = this.ByteToHexStr(this.dlt.Get645Frame());
 }
Exemplo n.º 3
0
        public string DataPart_Data()
        {
            string text  = "";
            int    num   = (!string.IsNullOrEmpty(this.MeterSendDataInfo)) ? this.MeterSendDataInfo.Length : 0;
            int    num2  = (!string.IsNullOrEmpty(this.MeterDataFormat)) ? this.MeterDataFormat.Length : 0;
            string text2 = "";

            checked
            {
                if (num > 0)
                {
                    if (!this.IsRead)
                    {
                        if (num2 > 0)
                        {
                            string text3 = PubFuncHelper.StringFormat(this.MeterSendDataInfo.Trim(), this.MeterDataFormat.Trim());
                            if (text3.Length < this.MeterDataLength * 2)
                            {
                                text3 = text3.PadLeft(this.MeterDataLength * 2, '0');
                            }
                            for (int i = 1; i <= text3.Length; i++)
                            {
                                string text4 = text3.Substring(i - 1, 1);
                                if (PubFuncHelper.IsDataStr(text4))
                                {
                                    text2 += text4;
                                }
                            }
                            for (int i = text2.Length - 1; i >= 0; i -= 2)
                            {
                                text += this.Plus33H(Convert.ToByte(text2.Substring(i - 1, 2), 16)).ToString("X2");
                            }
                        }
                        else
                        {
                            if (num2 == 0)
                            {
                                if (this.MeterSendDataInfo.Length % 2 == 1)
                                {
                                    this.MeterSendDataInfo = "0" + this.MeterSendDataInfo;
                                }
                                if (this.MeterDataLength == 0)
                                {
                                    this.MeterDataLength = 1;
                                }
                                string text3 = this.MeterSendDataInfo.PadLeft(2 * this.MeterDataLength, '0');
                                for (int i = 1; i <= text3.Length; i++)
                                {
                                    string text4 = text3.Substring(i - 1, 1);
                                    if (PubFuncHelper.IsDataStr(text4))
                                    {
                                        text2 += text4;
                                    }
                                }
                                for (int i = text2.Length - 1; i >= 0; i -= 2)
                                {
                                    text += this.Plus33H(Convert.ToByte(text2.Substring(i - 1, 2), 16)).ToString("X2");
                                }
                            }
                        }
                    }
                    else
                    {
                        text += this.Plus33H(Convert.ToByte(this.MeterSendDataInfo, 16)).ToString("X2");
                    }
                }
                this.Len_Data = text.Length / 2;
                return(text);
            }
        }
Exemplo n.º 4
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
            {
            }
        }
Exemplo n.º 5
0
 private bool BasicProcessMessage(byte[] data, SocketAsyncEventArgs socketAsync, EndPoint remoteEndPoint, DLT698Message.FrameInfo frameInfo, TCPClientInfo cl)
 {
     if (frameInfo.AFN == AFN.链路接口检测)
     {
         if (frameInfo.FN == "0001")
         {
             byte[] array = DLT698Message.CreateLogOKMessage(frameInfo.A1, frameInfo.A2, frameInfo.FN, frameInfo.PSEQ, this.Tpv);
             LogMSG.AddInfo(string.Concat(new string[] { DateTime.Now.ToString(), " ->终端 [", remoteEndPoint.ToString(), "] 登录:", PubFuncHelper.ByteToHexStr(data), "\r\n", DateTime.Now.ToString(), " ->回应 [", remoteEndPoint.ToString(), "] 登录确认:", PubFuncHelper.ByteToHexStr(array), "\r\n" }), 6);
             socketAsync.AcceptSocket.Send(array);
             socketAsync.UserToken = cl;
             lock (this.clients)
             {
                 if (!this.clients.Exists((TCPClientInfo gcl) => gcl.Host == cl.Host))
                 {
                     this.clients.Add(cl);
                 }
             }
         }
         else
         {
             if (frameInfo.FN == "0003")
             {
                 byte[] array = DLT698Message.CreateLogOKMessage(frameInfo.A1, frameInfo.A2, frameInfo.FN, frameInfo.PSEQ, this.Tpv);
                 LogMSG.AddInfo(string.Concat(new string[] { DateTime.Now.ToString(), " ->终端 [", remoteEndPoint.ToString(), "] 心跳:", PubFuncHelper.ByteToHexStr(data), "\r\n", DateTime.Now.ToString(), " ->回应 [", remoteEndPoint.ToString(), "] 心跳确认:", PubFuncHelper.ByteToHexStr(array), "\r\n" }), 7);
                 socketAsync.AcceptSocket.Send(array);
             }
         }
         return(true);
     }
     else
     {
         if (frameInfo.PRM == "0" & frameInfo.DIR == "1")
         {
             BufferManager.AddDataItem(frameInfo.A1, frameInfo.A2, data);
         }
         else
         {
             if (frameInfo.PRM == "1" & frameInfo.DIR == "1")
             {
                 ActiveReportMsg.AddInfo(data);
             }
         }
         return(false);
     }
     //return frameInfo;
 }
Exemplo n.º 6
0
        public string OperaRec(string Value, string type)
        {
            checked
            {
                string result;
                if (string.IsNullOrEmpty(Value))
                {
                    result = "";
                }
                else
                {
                    string text  = string.Empty;
                    string text2 = DataConvert.ReverseStr(Value);
                    string text3 = type.ToUpper();
                    switch (text3)
                    {
                    case "BIN":
                    {
                        int num = DataConvert.HexToInt(text2);
                        text = num.ToString();
                        break;
                    }

                    case "":
                    case "BCD":
                        text = text2;
                        break;

                    case "HEX":
                        text = Value;
                        break;

                    case "BS":
                    case "BS8":
                    case "BS16":
                    case "BS24":
                    case "BS32":
                    case "BS64":
                    {
                        string text4 = string.Empty;
                        for (int i = 0; i < text2.Length; i += 2)
                        {
                            text4 += PubFuncHelper.HexToBin(text2.Substring(i, 2));
                        }
                        text = DataConvert.ReverseStr(text4, 1);
                        break;
                    }

                    case "ASCII":
                        text = DataConvert.HexStrToASCII(Value);
                        break;

                    case "A1":
                    {
                        string text5 = DataConvert.ReverseStr(Value);
                        string text6 = string.Empty;
                        text6 = text6 + text5.Substring(0, 2) + "年";
                        int    num2      = int.Parse(text5.Substring(2, 1), NumberStyles.HexNumber);
                        string arg_354_0 = text6;
                        int    num       = num2 & 1;
                        text6 = arg_354_0 + num.ToString() + text5.Substring(3, 1) + "月";
                        text6 = text6 + text5.Substring(4, 2) + "日";
                        text6 = text6 + text5.Substring(6, 2) + "时";
                        text6 = text6 + text5.Substring(8, 2) + "分";
                        text6 = text6 + text5.Substring(10, 2) + "秒";
                        text  = text6;
                        break;
                    }

                    case "A7":
                        text = text2.Substring(0, 3) + "." + text2.Substring(3, 1);
                        break;

                    case "A8":
                    case "A10":
                    case "A12":
                    case "A27":
                        text = text2;
                        break;

                    case "A11":
                        text = text2.Substring(0, 6) + "." + text2.Substring(6, 2);
                        break;

                    case "A13":
                        text = text2.Substring(0, 4) + "." + text2.Substring(4, 4);
                        break;

                    case "A14":
                        text = text2.Substring(0, 6) + "." + text2.Substring(6, 4);
                        break;

                    case "A15":
                        text = string.Concat(new string[]
                        {
                            text2.Substring(0, 2),
                            "年",
                            text2.Substring(2, 2),
                            "月",
                            text2.Substring(4, 2),
                            "日",
                            text2.Substring(6, 2),
                            "时",
                            text2.Substring(8, 2),
                            "分",
                            text2.Substring(10, 2),
                            "秒"
                        });
                        break;

                    case "A16":
                        text = string.Concat(new string[]
                        {
                            text2.Substring(0, 2),
                            "日",
                            text2.Substring(2, 2),
                            "时",
                            text2.Substring(4, 2),
                            "分",
                            text2.Substring(6, 2),
                            "秒"
                        });
                        break;

                    case "A17":
                        text = string.Concat(new string[]
                        {
                            text2.Substring(0, 2),
                            "月",
                            text2.Substring(2, 2),
                            "日",
                            text2.Substring(4, 2),
                            "时",
                            text2.Substring(6, 2),
                            "分"
                        });
                        break;

                    case "A18":
                        text = string.Concat(new string[]
                        {
                            text2.Substring(0, 2),
                            "日",
                            text2.Substring(2, 2),
                            "时",
                            text2.Substring(4, 2),
                            "分"
                        });
                        break;

                    case "A19":
                        text = text2.Substring(0, 2) + "时" + text2.Substring(2, 2) + "分";
                        break;

                    case "A20":
                        text = string.Concat(new string[]
                        {
                            text2.Substring(0, 2),
                            "年",
                            text2.Substring(2, 2),
                            "月",
                            text2.Substring(4, 2),
                            "日"
                        });
                        break;

                    case "A21":
                        text = text2.Substring(0, 2) + "年" + text2.Substring(2, 2) + "月";
                        break;

                    case "A22":
                        text = text2.Substring(0, 1) + "." + text2.Substring(1, 1);
                        break;

                    case "A23":
                        text = text2.Substring(0, 2) + "." + text2.Substring(2, 4);
                        break;

                    case "A24":
                        text = text2.Substring(0, 2) + "日" + text2.Substring(2, 2) + "时";
                        break;

                    case "A26":
                        text = text2.Substring(0, 1) + "." + text2.Substring(1, 3);
                        break;
                    }
                    if (text.ToUpper().IndexOf("EE") >= 0)
                    {
                        text = "";
                    }
                    result = text;
                }
                return(result);
            }
        }
Exemplo n.º 7
0
        public string OperaSend(string Value, int Num, string type)
        {
            checked
            {
                string result;
                if (string.IsNullOrEmpty(Value) & type.Trim().ToUpper() != "ASCII")
                {
                    result = "";
                }
                else
                {
                    string text = string.Empty;
                    Value = Value.Trim();
                    string text2 = type.ToUpper();
                    switch (text2)
                    {
                    case "BIN":
                    {
                        long   num2      = long.Parse(Value);
                        string arg_323_0 = "X";
                        int    num       = Num * 2;
                        string val       = num2.ToString(arg_323_0 + num.ToString());
                        text = DataConvert.ReverseStr(val);
                        break;
                    }

                    case "":
                    case "BCD":
                        text = DataConvert.ReverseStr(Value.PadLeft(Num * 2, '0'));
                        break;

                    case "HEX":
                        text = Value.PadRight(Num * 2, '0');
                        break;

                    case "BS":
                    case "BS8":
                    case "BS16":
                    case "BS24":
                    case "BS32":
                    case "BS64":
                    {
                        string text3 = DataConvert.ReverseStr(Value, 1);
                        string text4 = string.Empty;
                        for (int i = 0; i < text3.Length; i += 8)
                        {
                            text4 += PubFuncHelper.BinToHex(text3.Substring(i, 8)).ToString("X2");
                        }
                        text += DataConvert.ReverseStr(text4);
                        break;
                    }

                    case "ASCII":
                        text = DataConvert.ASCIIToHexStr(Value).PadRight(Num * 2, '0');
                        break;

                    case "A2":
                    case "A3":
                    case "A4":
                    case "A5":
                    case "A6":
                    case "A9":
                    case "A25":
                        text = Value;
                        break;

                    case "A1":
                    {
                        Value = Value.Replace("年", "-");
                        Value = Value.Replace("月", "-");
                        Value = Value.Replace("日", " ");
                        Value = Value.Replace("时", ":");
                        Value = Value.Replace("分", ":");
                        Value = Value.Replace("秒", "");
                        string   text5    = string.Empty;
                        DateTime dateTime = DateTime.Parse(Value);
                        int      num      = dateTime.Second;
                        text5 = num.ToString("00");
                        string arg_49C_0 = text5;
                        num   = dateTime.Minute;
                        text5 = arg_49C_0 + num.ToString("00");
                        string arg_4BA_0 = text5;
                        num   = dateTime.Hour;
                        text5 = arg_4BA_0 + num.ToString("00");
                        string arg_4D8_0 = text5;
                        num   = dateTime.Day;
                        text5 = arg_4D8_0 + num.ToString("00");
                        int num3 = (int)dateTime.DayOfWeek;
                        if (num3 == 0)
                        {
                            num3 = 7;
                        }
                        num    = dateTime.Month;
                        text5 += (int.Parse(num.ToString(), NumberStyles.HexNumber) | num3 << 5).ToString("X2");
                        string arg_54D_0 = text5;
                        num   = dateTime.Year;
                        text5 = arg_54D_0 + num.ToString("0000").Substring(2, 2);
                        text  = text5;
                        break;
                    }

                    case "A7":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:000.0}", decimal.Parse(Value));
                        text5 = text5.Replace(".", "");
                        text5 = DataConvert.ReverseStr(text5);
                        text  = text5;
                        break;
                    }

                    case "A8":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:0000}", decimal.Parse(Value));
                        text5 = text5.Replace(".", "");
                        text5 = DataConvert.ReverseStr(text5);
                        text  = text5;
                        break;
                    }

                    case "A10":
                        text = DataConvert.ReverseStr(Value.PadLeft(6, '0'));
                        break;

                    case "A11":
                        text = DataConvert.ReverseStr(Value.PadLeft(8, '0'));
                        break;

                    case "A12":
                        text = DataConvert.ReverseStr(Value.PadLeft(12, '0'));
                        break;

                    case "A13":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:0000.0000}", decimal.Parse(Value));
                        text5 = text5.Replace(".", "");
                        text5 = DataConvert.ReverseStr(text5);
                        text  = text5;
                        break;
                    }

                    case "A14":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:000000.0000}", decimal.Parse(Value));
                        text5 = text5.Replace(".", "");
                        text5 = DataConvert.ReverseStr(text5);
                        text  = text5;
                        break;
                    }

                    case "A15":
                        Value = Value.Replace("年", "-");
                        Value = Value.Replace("月", "-");
                        Value = Value.Replace("日", " ");
                        Value = Value.Replace("时", ":");
                        Value = Value.Replace("分", ":");
                        Value = Value.Replace("秒", "");
                        text  = DataConvert.ReverseStr(Convert.ToDateTime(Value).ToString("yyMMddHHmm"));
                        break;

                    case "A16":
                    case "A17":
                    case "A18":
                    case "A19":
                        Value = Value.Replace("年", "-");
                        Value = Value.Replace("月", "-");
                        Value = Value.Replace("日", " ");
                        Value = Value.Replace("时", ":");
                        Value = Value.Replace("分", ":");
                        Value = Value.Replace("秒", "");
                        Value = Value.Replace(" ", "");
                        Value = Value.Replace(":", "");
                        Value = Value.Replace("-", "");
                        Value = Value.Replace(".", "");
                        text  = DataConvert.ReverseStr(Value);
                        break;

                    case "A20":
                        Value = Value.Replace("年", "-");
                        Value = Value.Replace("月", "-");
                        Value = Value.Replace("日", " ");
                        Value = Value.Replace("时", ":");
                        Value = Value.Replace("分", ":");
                        Value = Value.Replace("秒", "");
                        text  = DataConvert.ReverseStr(Convert.ToDateTime(Value).ToString("yyMMdd"));
                        break;

                    case "A21":
                        Value = Value.Replace("年", "-");
                        Value = Value.Replace("月", "-");
                        Value = Value.Replace("日", " ");
                        Value = Value.Replace("时", ":");
                        Value = Value.Replace("分", ":");
                        Value = Value.Replace("秒", "");
                        Value = Convert.ToDateTime(Value).ToString("yy-MM");
                        Value = Value.Replace(" ", "");
                        Value = Value.Replace(":", "");
                        Value = Value.Replace("-", "");
                        Value = Value.Replace(".", "");
                        text  = DataConvert.ReverseStr(Value);
                        break;

                    case "A22":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:0.0}", float.Parse(Value));
                        text  = text5.Replace(".", "");
                        break;
                    }

                    case "A23":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:00.0000}", float.Parse(Value));
                        text5 = text5.Replace(".", "");
                        text  = DataConvert.ReverseStr(text5);
                        break;
                    }

                    case "A24":
                        Value = Value.Replace("年", "-");
                        Value = Value.Replace("月", "-");
                        Value = Value.Replace("日", " ");
                        Value = Value.Replace("时", ":");
                        Value = Value.Replace("分", ":");
                        Value = Value.Replace("秒", "");
                        Value = Value.Replace(" ", "");
                        Value = Value.Replace(":", "");
                        Value = Value.Replace("-", "");
                        Value = Value.Replace(".", "");
                        text  = DataConvert.ReverseStr(Value);
                        break;

                    case "A26":
                    {
                        string text5 = string.Empty;
                        text5 = string.Format("{0:0.000}", float.Parse(Value));
                        text5 = text5.Replace(".", "");
                        text  = DataConvert.ReverseStr(text5);
                        break;
                    }

                    case "A27":
                        Value = Value.Replace(" ", "");
                        Value = Value.Replace(":", "");
                        Value = Value.Replace("-", "");
                        Value = Value.Replace(".", "");
                        text  = DataConvert.ReverseStr(Value.PadLeft(8, '0'));
                        break;
                    }
                    result = text;
                }
                return(result);
            }
        }