コード例 #1
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
 private string ResKeywords(devObj devobj, string state)
 {
     string str = "���ݴ���";
     if ("��������" == devobj.Buss || "һ��ͨ" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "�����ɹ���"; break;
             case "80": str = "ͨѶ�������"; break;
             case "81": str = "δ֪����"; break;
             case "82": str = "���ȴ���"; break;
             case "83": str = "�Ƿ����ݣ�"; break;
             case "86": str = "�޿���"; break;
             case "87": str = "�������"; break;
             case "88": str = "δ��ʼ���Ŀ���"; break;
             case "89": str = "δ��֤�Ŀ���"; break;
             case "8A": str = "���"; break;
             case "8B": str = "ģ�����"; break;
         }
         return str;
     }
     else if ("ͣ����" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "�����ɹ���"; break;
             case "80": str = "ͨѶ�������"; break;
             case "81": str = "δ֪����"; break;
             case "82": str = "���ȴ���"; break;
             case "83": str = "��Ч���ݣ�"; break;
             case "85": str = "���¼�¼��"; break;
             case "88": str = "�����������"; break;
             case "89": str = "�����ڵİ�������"; break;
         }
         return str;
     }
     else if ("�Ž�" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "�����ɹ���"; break;
             case "80": str = "ͨѶ�������"; break;
             case "81": str = "δ֪����"; break;
             case "82": str = "���ȴ���"; break;
             case "83": str = "��Ч���ݣ�"; break;
             case "84": str = "�����������"; break;
             case "85": str = "���¼�¼��"; break;
             case "88": str = "�����������"; break;
             case "89": str = "�����ڵİ�������"; break;
             case "90": str = "��Чʱ�Σ�"; break;
         }
         return str;
     }
     else if ("����" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "�����ɹ���"; break;
             case "80": str = "ͨѶ�������"; break;
             case "81": str = "δ֪����"; break;
             case "82": str = "���ȴ���"; break;
             case "83": str = "��Ч���ݣ�"; break;
             case "84": str = "�����������"; break;
             case "85": str = "���¼�¼��"; break;
             case "86": str = "���ŷǷ���"; break;
             case "87": str = "����������"; break;
             case "88": str = "�����������"; break;
             case "89": str = "�����ڵİ�������"; break;
             case "90": str = "��Ч������ʱ�Σ�"; break;
         }
         return str;
     }
     switch (devobj.Command)
     {
         case "��ʼ��":
         case "����ϵͳʱ��":
         case "���״̬":
             switch (state)
             {
                 case "00": str = "�����ɹ���"; break;
                 case "80": str = "ͨѶ�������"; break;
                 case "81": str = "δ֪����"; break;
                 case "82": str = "���ȴ���"; break;
                 case "83": str = "��Ч���ݣ�"; break;
                 case "85": str = "���¼�¼��"; break;
                 case "88": str = "�����������"; break;
                 case "89": str = "�����ڵİ�������"; break;
             }
             break;
         default:
             switch (state)
             {
                 case "00": str = "�����ɹ���"; break;
                 case "80": str = "ͨѶ�������"; break;
                 case "81": str = "δ֪����"; break;
                 case "82": str = "���ȴ���"; break;
                 case "83": str = "��Ч���ݣ�"; break;
                 case "85": str = "���¼�¼��"; break;
                 case "88": str = "�����������"; break;
                 case "89": str = "�����ڵİ�������"; break;
             }
             break;
     }
     return str;
 }
コード例 #2
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
 private devObj setDevObj(string devpms)
 {
     devObj devobj = new devObj();
     devobj.ID = basefun.valtag(devpms, "devid");
     devobj.ControlNo = basefun.toIntval(basefun.valtag(devpms, "controlno"));
     devobj.Buss = basefun.valtag(devpms, "buss");
     devobj.IP = basefun.valtag(devpms, "ip");
     devobj.Mode = basefun.toIntval(basefun.valtag(devpms, "mode")) - 1;
     devobj.Port = basefun.valtag(devpms, "port");
     if (devobj.Mode == 0)
         devobj.Port = ComPort(devobj.Port);
     devobj.Paritymode = basefun.valtag(devpms, "parity");
     devobj.LH = basefun.valtag(devpms, "LH") == "1" ? true : false;
     devobj.Exchanges = basefun.valtag(devpms, "exchange");
     devobj.Command = basefun.valtag(devpms, "cmd");
     devobj.WeekRule = basefun.valtag(devpms, "weekrule");
     devobj.IsAsc = basefun.valtag(devpms, "isasc") == "1" ? true : false;
     devobj.PreCommand = basefun.valtag(devpms, "precmd");
     devobj.Return = basefun.valtag(devpms, "return");
     devobj.parity = paritypm(basefun.valtag(devpms, "paritycom"));
     devobj.baudRate = basefun.toIntval((basefun.valtag(devpms, "baudrate")));
     int dbit = basefun.toIntval(basefun.valtag(devpms, "databits"));
     devobj.DataBits = (dbit == 0) ? 8 : dbit;
     devobj.stopBits = stopbitpm(basefun.valtag(devpms, "stopbits"));
     //���ڲ���
     return devobj;
 }
コード例 #3
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// ���ݷ���ֵ�IJ����ṹ�������ֵ,������У��,������״ֵ̬
        /// </summary>
        /// <param name="strResult">���ѻ������ַ���</param>
        /// <returns></returns>
        public string AnalysisEateryResults(string strResult, string strpms, devObj devobj, ref string state)
        {
            if (string.IsNullOrEmpty(strResult))
                return null;
            //ȡ���ؽ���IJ����ṹ
            //���㷵��ֵ�����۳���
            string[] arrpm = strpms.Split(';');
            int ilength = 0;
            int verlength = 0;  //У���ֵ��ֽ���
            int bit0len = 0;    //У���ֵ��ֽ���
            int bit1len = 0;    //У���ֵ��ֽ���
            for (int i = 0; i < arrpm.Length; i++)
            {
                NameObjectList lst = NameValueTag(arrpm[i]);
                if (i == 0) bit0len = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                if (i == arrpm.Length - 1) bit1len = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                if (lst.Keys[0] == "{����}") verlength = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                ilength = ilength + basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8; //�ֽ���
            }
            if (strResult.Length / 2 != ilength) return null;                             //��������ַ������Ȳ�����8������Ч����
            //У����,������ԣ��򷵻ؿ�

            CrcClass crc = new CrcClass();
            string vstr = strResult.Substring(bit0len * 2, strResult.Length - bit0len * 2 - bit1len * 2 - verlength * 2);
            if ("0" == devobj.Paritymode)
                vstr = exchangeLH(crc.CRCXOR(vstr), devobj.LH);
            else
                vstr = exchangeLH(crc.CRCSUM(vstr), devobj.LH);
            if (strResult.Substring(strResult.Length - bit1len * 2 - verlength * 2, verlength * 2).ToLower() != vstr.ToLower())
                return null;

            string[] strResults = String16ToArry(strResult);
            //����ת���ĸ�ʽҪ�������ֵ����
            string svalue = getValByHmFormat(strpms, strResults, devobj, ref state);
            //string rdata = strRtnData.Substring(4, strRtnData.Length - 4);
            //if (state == "00") return String16ToArry(rdata);
            return svalue;
        }
コード例 #4
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        private string InfoTomyDate(string s, pmObj pmobj, devObj devobj)
        {
            DateTime mydate = System.DateTime.Now;
            string yy = mydate.Year.ToString().Substring(0, 2);
            string[] a = String16ToArry(s, 16);
            switch (pmobj.Format.Trim())
            {
                case "yyMMdd":
                case "yyyyMMdd":
                    a = String16ToArry(s);
                    if (pmobj.Formats != "")
                    {
                        int n = 0;
                        string[] yformat = pmobj.Formats.Split('#');
                        for (int m = 0; m < yformat.Length; m++)
                            n = n + basefun.toIntval(yformat[m]);
                        n = n / 8;
                        s = "";
                        for (int m = 0; m < n; m++) s = s + a[m];
                        s = this.exchangeLH(s, devobj.LH);       //ת��
                        string[] ax = String16ToArry(s);
                        //ת��Ϊ������
                        s = "";
                        for (int m = 0; m < ax.Length; m++)
                        {
                            string s2 = Convert.ToString(Convert.ToInt32(sVal16To10(ax[m])), 2);
                            s2 = ComplementingBits(s2, 8, true, true);
                            s = s + s2;
                        }
                        //�����ʽλ����
                        string[] datas = new string[yformat.Length];
                        string strdata = "";
                        int im = 0;
                        for (int m = 0; m < yformat.Length; m++)
                        {
                            string str0 = s.Substring(im, basefun.toIntval(yformat[m]));
                            datas[m] = this.sVal16To10(this.sVal2To16(str0, 1));
                            im = im + basefun.toIntval(yformat[m]);
                            strdata = strdata + "-" + datas[m];
                        }
                        s = strdata.Substring(1);
                    }
                    else
                    {
                        if (a.Length == 3)
                        {
                            s = "";
                            for (int i = 0; i < 3; i++)
                                s += "-" + Convert.ToInt16(a[i], 16).ToString();
                            s = s.Substring(1);
                        }
                    }
                    if (pmobj.Format.Trim() == "yyyyMMdd")
                        s = yy + s;
                    break;
                case "hhmmss":
                    a = String16ToArry(s);
                    if (pmobj.Formats != "")
                    {
                        int n = 0;
                        string[] yformat = pmobj.Formats.Split('#');
                        for (int m = 0; m < yformat.Length; m++)
                            n = n + basefun.toIntval(yformat[m]);
                        n = n / 8;
                        s = "";
                        for (int m = 0; m < n; m++) s = s + a[m];
                        s = this.exchangeLH(s, devobj.LH);       //ת��
                        string[] ax = String16ToArry(s);
                        //ת��Ϊ������
                        s = "";
                        for (int m = 0; m < ax.Length; m++)
                        {
                            string s2 = Convert.ToString(Convert.ToInt32(sVal16To10(ax[m])), 2);
                            s2 = ComplementingBits(s2, 8, true, true);
                            s = s + s2;
                        }
                        //�����ʽλ����
                        string[] datas = new string[yformat.Length];
                        string strdata = "";
                        int im = 0;
                        for (int m = 0; m < yformat.Length; m++)
                        {
                            string str0 = s.Substring(im, basefun.toIntval(yformat[m]));
                            datas[m] = this.sVal16To10(this.sVal2To16(str0, 1));
                            im = im + basefun.toIntval(yformat[m]);
                            strdata = strdata + ":" + datas[m];
                        }
                        s = strdata.Substring(1);
                    }
                    else
                    {
                        if (a.Length == 3)
                            s = a[0] + ":" + a[1] + ":" + a[3];
                    }
                    break;
                case "hhmm":
                    if (a.Length == 2)
                        s = a[0] + ":" + a[1];
                    break;
                case "yyMMddhhmmss":
                    if (a.Length > 5)
                        s = a[0] + "-" + a[1] + "-" + a[2] + " " + a[3] + ":" + a[4] + ":" + a[5];
                    break;
                case "yyyyMMDD":
                case "YYYYMMDD":
                    if (a.Length > 2)
                        s = yy + a[0] + "-" + a[1] + "-" + a[2];
                    break;
                case "yyyyMMddhhmmss":
                    if (a.Length > 5)
                        s = yy + a[0] + "-" + a[1] + "-" + a[2] + " " + a[3] + ":" + a[4] + ":" + a[5];
                    break;
                case "yyyyMMdd+hhmmss":   //����+ʱ���ͣ�������λ��ʽ���д���,����λ��ʽΪ 7#4#5+5#6#5
                    string[] xformat = null;
                    string[] tformat = null;
                    a = String16ToArry(s);
                    if (pmobj.Formats.IndexOf("+") > -1)
                    {
                        xformat = pmobj.Formats.Split('+');
                        tformat = pmobj.Format.Split('+');
                    }
                    string[] arrDatas = new string[tformat.Length];
                    int mn = 0;
                    for (int ix = 0; ix < xformat.Length; ix++)
                    {
                        int n = 0;
                        string[] yformat = xformat[ix].Split('#');

                        for (int m = 0; m < yformat.Length; m++) n = n + basefun.toIntval(yformat[m]);
                        n = n / 8; s = "";
                        for (int m = mn; m < n + mn; m++) s = s + a[m];
                        mn = mn + n;
                        s = this.exchangeLH(s, devobj.LH);       //ת��
                        string[] ax = String16ToArry(s);
                        //ת��Ϊ������
                        s = "";
                        for (int m = 0; m < ax.Length; m++)
                        {
                            string s2 = Convert.ToString(Convert.ToInt32(sVal16To10(ax[m])), 2);
                            s2 = ComplementingBits(s2, 8, true, true);
                            s = s + s2;
                        }
                        //�����ʽλ����
                        string[] datas = new string[yformat.Length];
                        string strdata = "";
                        int im = 0;
                        for (int m = 0; m < yformat.Length; m++)
                        {
                            string str0 = s.Substring(im, basefun.toIntval(yformat[m]));
                            datas[m] = this.sVal16To10(this.sVal2To16(str0, 1));
                            im = im + basefun.toIntval(yformat[m]);
                            if (tformat[ix] == "yyyyMMdd") strdata = strdata + "-" + datas[m];
                            else strdata = strdata + ":" + datas[m];
                        }
                        arrDatas[ix] = strdata.Substring(1, strdata.Length - 1);
                    }
                    s = yy + arrDatas[0] + " " + arrDatas[1];
                    break;
                case "yyyyMMddWWhhmmss":
                    if (pmobj.DataType == "dateword")
                    {
                        string[] a1 = String16ToArry(s);
                        switch (devobj.WeekRule)
                        {
                            case "1":
                                if (a1.Length > 6)
                                    s = yy + a1[0] + "-" + a1[1] + "-" + a1[2] + " " + a1[4] + ":" + a1[5] + ":" + a1[6]
                                    + " " + GetWeekBy1(a1[3]);
                                break;
                            default:
                                if (a.Length > 6)
                                    s = yy + a1[0] + "-" + a1[1] + "-" + a1[2] + " " + a1[4] + ":" + a1[5] + ":" + a1[6]
                                    + " " + this.GetWeekByHZ(a1[3]);
                                break;
                        }
                    }
                    else
                    {
                        switch (devobj.WeekRule)
                        {
                            case "1":
                                if (a.Length > 6)
                                    s = yy + a[0] + "-" + a[1] + "-" + a[2] + " " + a[4] + ":" + a[5] + ":" + a[6]
                                    + " " + GetWeekBy1(a[3]);
                                break;
                            default:
                                if (a.Length > 6)
                                    s = yy + a[0] + "-" + a[1] + "-" + a[2] + " " + a[4] + ":" + a[5] + ":" + a[6]
                                    + " " + this.GetWeekByHZ(a[3]);
                                break;
                        }
                    }
                    break;
                case "yyMMddWWhhmmss":
                    switch (devobj.WeekRule)
                    {
                        case "1":
                            if (a.Length > 6)
                                s = a[0] + "-" + a[1] + "-" + a[2] + " " + a[4] + ":" + a[5] + ":" + a[6]
                                + " " + GetWeekBy1(a[3]);
                            break;
                        case "2":
                            if (a.Length > 6)
                                s = a[0] + "-" + a[1] + "-" + a[2] + " " + a[4] + ":" + a[5] + ":" + a[6]
                                + " " + this.GetWeekByHZ(a[3]);
                            break;
                    }
                    break;
            }
            return s;
        }
コード例 #5
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// �ɴ��ڷ��ص��ַ�����hmtag�ַ��������滮��ģʽ��ֵ
        /// </summary>
        /// <param name="format">��ʽ���ַ���</param>
        /// <param name="udpinfos">���ڷ��ص�����</param>
        /// <returns></returns>
        public string getValByHmFormat(string formats, string[] udpinfos, devObj devobj, ref string vtag)
        {
            if (udpinfos == null || formats == null) return null;
            string rtn = "";
            string[] xformats = formats.Split(';');
            int ipos = 0;
            for (int i = 0; i < xformats.Length; i++)
            {
                string[] arr = xformats[i].Split(',');
                string vname = getVarNameByHmStr(arr[0]);
                pmObj pmobj = new pmObj();
                pmobj.Name = getVarNameByHmStr(arr[0]);
                pmobj.Len = toIntval(valtag(xformats[i], "{len}"));
                pmobj.DataType = valtag(xformats[i], "{datatype}");
                pmobj.Format = valtag(xformats[i], "{format}");
                pmobj.Formats = valtag(xformats[i], "{formats}");
                pmobj.Scale = toFloatValue(valtag(xformats[i], "{scale}")) == 0 ? 1 : toFloatValue(valtag(xformats[i], "{scale}"));
                pmobj.Add = toIntval(valtag(xformats[i], "{add}"));

                /*
                int ilen = toIntval(valtag(xformats[i], "{len}"));
                string format = valtag(xformats[i], "{format}");
                string aformats = valtag(xformats[i], "{formats}");
                int ibytes = ilen / 8;
                string datatype = valtag(xformats[i], "{datatype}");
                int icale = basefun.toIntval(valtag(xformats[i], "{scale}"));
                if (icale == 0) icale = 1;
                 */
                string s = getValueByUpdInfos(udpinfos, ipos, pmobj);

                ipos = ipos + pmobj.Len;
                switch (pmobj.DataType.ToLower())
                {
                    case "datetime":
                        s = InfoTomyDate(s, pmobj, devobj);
                        break;
                    case "float":
                    case "double":
                        s = this.exchangeLH(s, devobj.LH);
                        s = Convert.ToInt32(sVal16To10(s)).ToString();
                        if (pmobj.Format == "") pmobj.Format = "{0:.00}";
                        if (pmobj.Format.IndexOf("{") > -1)
                            s = string.Format(pmobj.Format, Convert.ToDouble(s) * pmobj.Scale);
                        else
                            s = string.Format("{" + pmobj.Format + "}", Convert.ToDouble(s) * pmobj.Scale);
                        break;
                    case "bit":
                        s = this.exchangeLH(s, devobj.LH);
                        s = sVal16To10(s);
                        s = ComplementingBits(Convert.ToString(Convert.ToInt64(s), 2), pmobj.Len, true);
                        break;
                    case "integer":
                    case "int":
                        s = this.exchangeLH(s, devobj.LH);
                        long _iv = Convert.ToInt64(Convert.ToInt64(sVal16To10(s)) * pmobj.Scale);
                        s = _iv.ToString();
                        break;
                    case "string":
                        s = this.exchangeLH(s, devobj.LH);
                        break;
                    default:
                        s = this.exchangeLH(s, devobj.LH);
                        s = Convert.ToInt64(sVal16To10(s)).ToString();
                        break;
                }
                xformats[i] = setvaltag(xformats[i], vname, s);
                vtag = setvaltag(vtag, vname, s);
                rtn = rtn + ";" + xformats[i];
            }
            if (rtn.Length > 0)
                rtn = rtn.Substring(1);
            return rtn;
        }
コード例 #6
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// ����ʱ������ַ���ʾnoHE�Ķ����ȷ���Ƿ��Ѱ�����δ����֡ͷ֡β�����ݷ���ֵ�IJ����ṹ�������ֵ,������У��,������״ֵ̬
        /// </summary>
        /// <param name="strResult">�������Ľ���ַ���</param>
        /// <param name="strpms">�������ü���</param>
        /// <param name="devobj">�豸����</param>
        /// <param name="noHE">����֡ͷ֡β��״̬��</param>
        /// <param name="state">������еķ���״ֵ̬</param>
        /// <returns></returns>
        public string AnalysisEateryResults(string strResult, string strpms, devObj devobj, Boolean noHE, ref string state)
        {
            if (string.IsNullOrEmpty(strResult))
                return null;
            //ȡ���ؽ���IJ����ṹ
            //���㷵��ֵ�����۳���
            string[] arrpm = strpms.Split(';');
            int ilength = 0;
            int verlength = 0;  //У���ֵ��ֽ���
            int bit0len = 0;
            int bit1len = 0;
            for (int i = 0; i < arrpm.Length; i++)
            {
                if (noHE)
                {
                    if (i == 0 || i == arrpm.Length - 1) continue;
                }
                NameObjectList lst = NameValueTag(arrpm[i]);
                if (i == 0) bit0len = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                if (i == arrpm.Length - 1) bit1len = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                if (lst.Keys[0] == "{����}") verlength = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                ilength = ilength + basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8; //�ֽ���
            }
            if (strResult.Length / 2 < ilength && 14 == strResult.Length)
            {
                strpms = "@{֡ͷ}=02,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{�豸��ַ}=,@{len}=8,@{datatype}=string,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{״̬}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{�����}=0,@{len}=16,@{datatype}=long,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{У����}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{֡β}=03,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=";
                return AnalysisEateryResults(strResult, strpms, devobj, noHE, ref state);
            }
            if (strResult.Length / 2 < ilength && 16 == strResult.Length)
            {
                strpms = "@{֡ͷ}=02,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{�豸��ַ}=,@{len}=8,@{datatype}=string,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{���Ƴ�}=01,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{���ȳ�}=2,@{len}=8,@{datatype}=int,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{״̬}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{�����}=0,@{len}=8,@{datatype}=long,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{У����}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{֡β}=03,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=";
                return AnalysisEateryResults(strResult, strpms, devobj, noHE, ref state);
            }
            if (strResult.Length / 2 != ilength) return null;                             //��������ַ������Ȳ�����8������Ч����
            //У����,������ԣ��򷵻ؿ�

            CrcClass crc = new CrcClass();
            string xor = "";
            switch (devobj.Paritymode)
            {
                case "0":
                    xor = crc.CRCXOR(strResult.Substring(bit0len * 2, strResult.Length - bit0len * 2 - bit1len * 2 - verlength * 2));
                    break;
                case "1":
                    xor = crc.CRCSUM(strResult.Substring(bit0len * 2, strResult.Length - bit0len * 2 - bit1len * 2 - verlength * 2));
                    break;
            }
            //����У���ֳ���δ��λ����,�ݲ�������У�����ж�
            string _xor = this.ComplementingBits(xor, verlength * 2, true, true);
            string vstr = exchangeLH(_xor, devobj.LH);
            //if (strResult.Substring(strResult.Length - bit1len * 2 - verlength * 2, verlength * 2).ToLower() != vstr.ToLower())
            //    return null;

            string[] strResults = String16ToArry(strResult);
            //����ת���ĸ�ʽҪ�������ֵ����
            string svalue = getValByHmFormat(strpms, strResults, devobj, noHE, ref state);
            //string rdata = strRtnData.Substring(4, strRtnData.Length - 4);
            //if (state == "00") return String16ToArry(rdata);
            return svalue;
        }
コード例 #7
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        public string GetInfo(string devpms, string cmdpms, string datapms, string OutString, ref string state, ref string cmdstring)
        {
            devObj devobj = new devObj();
            string cmdstr = CommandString(devpms, cmdpms, datapms, ref devobj);
            if (basefun.IsCorrenctIP(devobj.IP) == false) return null;
            if (devobj.Delay == 0) devobj.Delay = 2000;
            byte[] bytOutBuffer;
            if (devobj.IsAsc)
            {
                string strhead = cmdstr.Substring(0, 2);
                string strend = cmdstr.Substring(cmdstr.Length - 2, 2);
                cmdstr = cmdstr.Substring(2, cmdstr.Length - 2);
                cmdstr = cmdstr.Substring(0, cmdstr.Length - 2);
                bytOutBuffer = getAscByteBy16s(cmdstr, strhead, strend);
            }
            else
                bytOutBuffer = getByteBy16s(cmdstr);
            IPEndPoint RemoteIpEndPoint = SetIPEndPoint(devobj.IP, basefun.toIntval(devobj.Port), devobj.Mode);
            byte[] bytReceiveBuffer;
            using (UdpClient udpClient = new UdpClient())
            {
                udpClient.Send(bytOutBuffer, bytOutBuffer.Length, RemoteIpEndPoint);
                IPEndPoint from = new IPEndPoint(IPAddress.Any, 0);
                IAsyncResult result = udpClient.BeginReceive(null, this);
                result.AsyncWaitHandle.WaitOne(devobj.Delay, false);
                if (!result.IsCompleted)
                {
                    udpClient.Close();
                    return null;
                }
                bytReceiveBuffer = udpClient.EndReceive(result, ref from);
                string udpInfo = "";
                if (devobj.IsAsc)
                {
                    string info = "";
                    char[] cbuff = new char[bytReceiveBuffer.Length - 2];
                    for (int i = 1; i < bytReceiveBuffer.Length - 1; i++)
                    {
                        cbuff[i - 1] = (char)bytReceiveBuffer[i];
                        info += Convert.ToString(cbuff[i - 1]);
                    }
                    //ȥ��֡ͷ��֡β
                    udpInfo = info;
                }
                else
                    udpInfo = get16sByByte(bytReceiveBuffer, true);

                //�ָ�ת���ַ�
                if (devobj.Exchanges != "")
                {
                    string[] strExs = devobj.Exchanges.Split('#');
                    for (int i = 0; i < strExs.Length; i++)
                    {
                        string[] _a = strExs[i].Split('/');
                        udpInfo = SpecialRestore(udpInfo, _a[1], _a[0]);
                    }
                }
                //ȡ����ֵ16��������,������
                //udpInfo = "7E7AF08110091227000012200100000000DCDE0F909B137D0100FF00000000F4060D";

                string infos = AnalysisEateryResults(udpInfo, OutString, devobj, true, ref state);
                udpClient.Close();
                return infos;
            }
        }
コード例 #8
0
ファイル: ComClass.cs プロジェクト: thisisvoa/GranityApp2.5
        /// <summary>
        /// 根据返回值的参数结构解析结果值,含多重校验,并返回状态值
        /// </summary>
        /// <param name="strResult">消费机返回字符串</param>
        /// <returns></returns>
        public string AnalysisEateryResults(string strResult, string strpms, devObj devobj, ref string state)
        {
            if (string.IsNullOrEmpty(strResult))
                return null;
            //取返回结果的参数结构
            //计算返回值的理论长度
            string[] arrpm = strpms.Split(';');
            int ilength = 0;
            int verlength = 0;  //校验字的字节数
            int bit0len = 0;    //校验字的字节数
            int bit1len = 0;    //校验字的字节数
            for (int i = 0; i < arrpm.Length; i++)
            {
                NameObjectList lst = NameValueTag(arrpm[i]);
                if (i == 0) bit0len = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                if (i == arrpm.Length - 1) bit1len = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                if (lst.Keys[0] == "{校验字}") verlength = basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8;
                ilength = ilength + basefun.toIntval(lst.AllStringValues[1].ToLower()) / 8; //字节数
            }
            if (strResult.Length / 2 != ilength) return null;                             //如果返回字符串长度不大于8,则无效返回
            //校验字,如果不对,则返回空

            CrcClass crc = new CrcClass();
            string vstr = strResult.Substring(bit0len * 2, strResult.Length - bit0len * 2 - bit1len * 2 - verlength * 2);
            if ("0" == devobj.Paritymode)
                vstr = exchangeLH(crc.CRCXOR(vstr), devobj.LH);
            else
                vstr = exchangeLH(crc.CRCSUM(vstr), devobj.LH);
            if (strResult.Substring(strResult.Length - bit1len * 2 - verlength * 2, verlength * 2).ToLower() != vstr.ToLower())
                return null;

            string[] strResults = String16ToArry(strResult);
            //根据转出的格式要求处理返回值集合
            string svalue = getValByHmFormat(strpms, strResults, devobj, ref state);
            //string rdata = strRtnData.Substring(4, strRtnData.Length - 4);
            //if (state == "00") return String16ToArry(rdata);
            return svalue;
        }
コード例 #9
0
        /// <summary>
        /// 设置设备指令,使用dvID做指令ID
        /// </summary>
        /// <param name="tpl">协议类型</param>
        /// <param name="cmd">指令</param>
        /// <param name="tagdata">数据参数,使用tag标记格式</param>
        public bool setCommand(string tpl, string cmd, string tagdata)
        {
            //if (string.IsNullOrEmpty(tpl) || string.IsNullOrEmpty(cmd) || CmdState.Response == this.CheckState())
            //    return false;

            PtlParam ptlParam = new PtlParam();
            if (PTLParam.ContainsKey(tpl + ":" + cmd))
                ptlParam = PTLParam[tpl + ":" + cmd];
            else
            {
                Estar.Common.Tools.NameObjectList ps = new Estar.Common.Tools.NameObjectList();
                ps["tpl"] = tpl;
                ps["cmd"] = cmd;
                if (null == this.query)
                    return false;
                DataTable tab = this.query.getTable(dbItem, ps);
                if (null == tab || tab.Rows.Count < 1)
                    return false;
                //从数据库中取出的参数转换成tag格式参数
                DataColumnCollection dbcols = tab.Columns;
                if (!dbcols.Contains("type") || !dbcols.Contains("pms"))
                    return false;
                foreach (DataRow dr in tab.Rows)
                {
                    if (DBNull.Value == dr["type"])
                        continue;
                    string pmtype = Convert.ToString(dr["type"]);
                    switch (pmtype)
                    {
                        case "协议":
                            ptlParam.pmdevice = Convert.ToString(dr["pms"]);
                            break;
                        case "Input":
                            ptlParam.pminput += Convert.ToString(dr["pms"]) + ";";
                            break;
                        case "Output":
                            ptlParam.pmout += Convert.ToString(dr["pms"]) + ";";
                            break;
                    }
                }
                if (ptlParam.pmdevice.EndsWith(";"))
                    ptlParam.pmdevice = ptlParam.pmdevice.Substring(0, ptlParam.pmdevice.Length - 1);
                if (string.IsNullOrEmpty(ptlParam.pmdevice)) return false;
                if (ptlParam.pminput.EndsWith(";"))
                    ptlParam.pminput = ptlParam.pminput.Substring(0, ptlParam.pminput.Length - 1);
                if (ptlParam.pmout.EndsWith(";"))
                    ptlParam.pmout = ptlParam.pmout.Substring(0, ptlParam.pmout.Length - 1);
                ptlParam.pmdevice = ptlParam.pmdevice.Replace(";;", ";");
                ptlParam.pminput = ptlParam.pminput.Replace(";;", ";");
                ptlParam.pmout = ptlParam.pmout.Replace(";;", ";");
                if (!PTLParam.ContainsKey(tpl + ":" + cmd))
                    try { PTLParam.Add(tpl + ":" + cmd, ptlParam); }
                    catch { }
            }
            this.inputParam = ptlParam.pminput;
            this.outterParam = ptlParam.pmout;
            this.responseFormat = "";
            //根据协议组成通讯指令
            string pmdevice = basefun.setvaltag(ptlParam.pmdevice, "devid", basefun.valtag(tagdata, "设备地址"));
            dvParam.Command = "";
            string cmdstr = "";
            if (string.IsNullOrEmpty(tagdata))
                dvParam = this.setDevObj(pmdevice);
            else
                cmdstr = comparse.CommandString(pmdevice, ptlParam.pminput, tagdata, ref dvParam);
            IsAscii = dvParam.IsAsc;
            Exchanges = dvParam.Exchanges;
            if (string.IsNullOrEmpty(dvParam.Buss))
                dvParam.Buss = tpl;
            if (string.IsNullOrEmpty(dvParam.Command))
                dvParam.Command = cmd;
            //没有数据参数,则只获取格式参数,便于解析结果
            if (string.IsNullOrEmpty(tagdata))
                return true;
            //转义成字节,使用""""代替原来帧头帧尾的处理
            if (dvParam.IsAsc)
            {
                if (cmdstr.StartsWith("02") && cmdstr.EndsWith("03"))
                    cmdstr = "" + cmdstr.Substring(2, cmdstr.Length - 4) + "";

                return this.setCommand(cmdstr);
            }
            return this.setCommand(cmdstr, true);
        }
コード例 #10
0
 /// <summary>
 /// 获取协议通用信息
 /// </summary>
 /// <param name="pmdevice">协议配置tag值</param>
 /// <returns>返回设备通讯通用信息实例</returns>
 private devObj setDevObj(string pmdevice)
 {
     devObj devobj = new devObj();
     devobj.ID = basefun.valtag(pmdevice, "devid");
     devobj.ControlNo = basefun.toIntval(basefun.valtag(pmdevice, "controlno"));
     devobj.Buss = basefun.valtag(pmdevice, "buss");
     devobj.IP = basefun.valtag(pmdevice, "ip");
     devobj.Mode = basefun.toIntval(basefun.valtag(pmdevice, "mode")) - 1;
     devobj.Port = basefun.valtag(pmdevice, "port");
     if (devobj.Mode == 0 && !devobj.Port.ToUpper().StartsWith("COM"))
         devobj.Port = "COM" + devobj.Port;
     devobj.Paritymode = basefun.valtag(pmdevice, "parity");
     devobj.LH = basefun.valtag(pmdevice, "LH") == "1" ? true : false;
     devobj.Exchanges = basefun.valtag(pmdevice, "exchange");
     devobj.Command = basefun.valtag(pmdevice, "cmd");
     devobj.WeekRule = basefun.valtag(pmdevice, "weekrule");
     devobj.IsAsc = basefun.valtag(pmdevice, "isasc") == "1" ? true : false;
     devobj.PreCommand = basefun.valtag(pmdevice, "precmd");
     devobj.Return = basefun.valtag(pmdevice, "return");
     devobj.parity = Parity.None;
     switch (basefun.valtag(pmdevice, "paritycom").ToLower())
     {
         case "none": devobj.parity = Parity.None; break;
         case "even": devobj.parity = Parity.Even; break;
         case "mark": devobj.parity = Parity.Mark; break;
         case "odd": devobj.parity = Parity.Odd; break;
         case "space": devobj.parity = Parity.Space; break;
     }
     devobj.baudRate = basefun.toIntval((basefun.valtag(pmdevice, "baudrate")));
     int dbit = basefun.toIntval(basefun.valtag(pmdevice, "databits"));
     devobj.DataBits = (dbit == 0) ? 8 : dbit;
     devobj.stopBits = StopBits.One;
     switch (basefun.valtag(pmdevice, "stopbits").ToLower())
     {
         case "none": devobj.stopBits = StopBits.None; break;
         case "one": devobj.stopBits = StopBits.One; break;
         case "onepoint": devobj.stopBits = StopBits.OnePointFive; break;
         case "two": devobj.stopBits = StopBits.Two; break;
     }
     //串口参数
     return devobj;
 }
コード例 #11
0
ファイル: ComClass.cs プロジェクト: thisisvoa/GranityApp2.5
        /// <summary>
        /// 处理时,结果字符串示noHE的定义而确定是否已包含或未包含帧头帧尾。根据返回值的参数结构解析结果值,含多重校验,并返回状态值
        /// </summary>
        /// <param name="strResult">待解析的结果字符串</param>
        /// <param name="strpms">参数配置集合</param>
        /// <param name="devobj">设备参数</param>
        /// <param name="noHE">包含帧头帧尾的状态字</param>
        /// <param name="state">结果集中的返回状态值</param>
        /// <returns></returns>
        public string AnalysisEateryResults(string strResult, string strpms, devObj devobj, Boolean noHE, ref string state)
        {
            if (string.IsNullOrEmpty(strResult))
                return null;
            //取返回结果的参数结构
            //计算返回值的理论长度
            string[] arrpm = strpms.Split(';');
            int ilength = 0;
            int verlength = 0;  //校验字的字节数
            int bit0len = 0;
            int bit1len = 0;
            for (int i = 0; i < arrpm.Length; i++)
            {
                if (noHE)
                {
                    if (i == 0 || i == arrpm.Length - 1) continue;
                }
                NameObjectList lst = NameValueTag(arrpm[i]);
                string strval = lst.AllStringValues[1].ToLower();
                if (i == 0) bit0len = basefun.toIntval(strval) / 8;
                if (i == arrpm.Length - 1) bit1len = basefun.toIntval(strval) / 8;
                if (lst.Keys[0] == "{校验字}") verlength = basefun.toIntval(strval) / 8;
                ilength += basefun.toIntval(strval) / 8; //字节数
            }
            if (strResult.Length / 2 < ilength && 14 == strResult.Length)
            {
                strpms="@{帧头}=02,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{设备地址}=,@{len}=8,@{datatype}=string,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{状态}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{命令长度}=0,@{len}=16,@{datatype}=long,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{校验字}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{帧尾}=03,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=";
                return AnalysisEateryResults(strResult, strpms, devobj, noHE, ref state);
            }
            if (strResult.Length / 2 < ilength && 16 == strResult.Length)
            {
                strpms = "@{帧头}=02,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{设备地址}=,@{len}=8,@{datatype}=string,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{控制场}=01,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{长度场}=2,@{len}=8,@{datatype}=int,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{状态}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{命令长度}=0,@{len}=8,@{datatype}=long,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{校验字}=,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=;@{帧尾}=03,@{len}=8,@{datatype}=word,@{format}=,@{formats}=,@{scale}=,@{subitems}=";
                return AnalysisEateryResults(strResult, strpms, devobj, noHE, ref state);
            }
            if (strResult.Length / 2 != ilength)
                return null;                             //如果返回字符串长度不大于8,则无效返回
            //校验字,如果不对,则返回空

            CrcClass crc = new CrcClass();
            string xor = "";
            switch (devobj.Paritymode)
            {
                case "0":
                    xor = crc.CRCXOR(strResult.Substring(bit0len * 2, strResult.Length - bit0len * 2 - bit1len * 2 - verlength * 2));
                    break;
                case "1":
                    xor = crc.CRCSUM(strResult.Substring(bit0len * 2, strResult.Length - bit0len * 2 - bit1len * 2 - verlength * 2));
                    break;
            }
            //修正校验字长度未补位错误,暂不对数据校验码判断
            string _xor = this.ComplementingBits(xor, verlength * 2, true, true);
            string vstr = exchangeLH(_xor, devobj.LH);
            //if (strResult.Substring(strResult.Length - bit1len * 2 - verlength * 2, verlength * 2).ToLower() != vstr.ToLower())
            //    return null;

            string[] strResults = String16ToArry(strResult);
            //根据转出的格式要求处理返回值集合
            string svalue = getValByHmFormat(strpms, strResults, devobj, noHE, ref state);
            //string rdata = strRtnData.Substring(4, strRtnData.Length - 4);
            //if (state == "00") return String16ToArry(rdata);
            return svalue;
        }
コード例 #12
0
ファイル: ComClass.cs プロジェクト: thisisvoa/GranityApp2.5
 private string ResKeywords(devObj devobj, string state)
 {
     string str = "数据错误!";
     if ("卡务中心" == devobj.Buss || "一卡通" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "操作成功!"; break;
             case "80": str = "通讯命令错误!"; break;
             case "81": str = "未知错误!"; break;
             case "82": str = "长度错误!"; break;
             case "83": str = "非法数据!"; break;
             case "86": str = "无卡!"; break;
             case "87": str = "密码错误!"; break;
             case "88": str = "未初始化的卡!"; break;
             case "89": str = "未认证的卡!"; break;
             case "8A": str = "写错误!"; break;
             case "8B": str = "模块错误!"; break;
         }
         return str;
     }
     else if ("停车场" == devobj.Buss)
     {
         switch (state)
         {
             case "00":  str = "操作成功!";      break;
             case "80":  str = "通讯命令错误!";  break;
             case "81":  str = "未知错误!";      break;
             case "82":  str = "长度错误!";      break;
             case "83":  str = "无效数据!";      break;
             case "85":  str = "无新记录!";      break;
             case "88":  str = "白名单溢出!";    break;
             case "89": str = "不存在的白名单!"; break;
         }
         return str;
     }
     else if ("门禁" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "操作失败!"; break;
             case "01": str = "操作成功!"; break;
             case "80": str = "通讯命令错误!"; break;
             case "81": str = "未知错误!"; break;
             case "82": str = "长度错误!"; break;
             case "83": str = "无效数据!"; break;
             case "84": str = "黑名单溢出!"; break;
             case "85": str = "无新记录!"; break;
             case "88": str = "白名单溢出!"; break;
             case "89": str = "不存在的白名单!"; break;
             case "90": str = "无效时段!"; break;
         }
         return str;
     }
     else if ("消费" == devobj.Buss)
     {
         switch (state)
         {
             case "00": str = "操作成功!"; break;
             case "80": str = "通讯命令错误!"; break;
             case "81": str = "未知错误!"; break;
             case "82": str = "长度错误!"; break;
             case "83": str = "无效数据!"; break;
             case "84": str = "黑名单溢出!"; break;
             case "85": str = "无新记录!"; break;
             case "86": str = "卡号非法!"; break;
             case "87": str = "白名单错误!"; break;
             case "88": str = "白名单溢出!"; break;
             case "89": str = "不存在的白名单!"; break;
             case "90": str = "无效的消费时段!"; break;
         }
         return str;
     }
     switch (devobj.Command)
     {
         case "初始化":
         case "加载系统时间":
         case "检测状态":
             switch (state)
             {
                 case "00": str = "操作成功!"; break;
                 case "80": str = "通讯命令错误!"; break;
                 case "81": str = "未知错误!"; break;
                 case "82": str = "长度错误!"; break;
                 case "83": str = "无效数据!"; break;
                 case "85": str = "无新记录!"; break;
                 case "88": str = "白名单溢出!"; break;
                 case "89": str = "不存在的白名单!"; break;
             }
             break;
         default:
             switch (state)
             {
                 case "00": str = "操作成功!"; break;
                 case "80": str = "通讯命令错误!"; break;
                 case "81": str = "未知错误!"; break;
                 case "82": str = "长度错误!"; break;
                 case "83": str = "无效数据!"; break;
                 case "85": str = "无新记录!"; break;
                 case "88": str = "白名单溢出!"; break;
                 case "89": str = "不存在的白名单!"; break;
             }
             break;
     }
     return str;
 }
コード例 #13
0
ファイル: ComClass.cs プロジェクト: thisisvoa/GranityApp2.5
        public string GetInfo(string devpms, string cmdpms, string datapms, string OutString, ref string state)
        {
            devObj devobj = new devObj();
            string cmdstr = CommandString(devpms, cmdpms, datapms, ref devobj);
            if (basefun.IsCorrenctIP(devobj.IP) == false) return null;
            if (devobj.Delay == 0) devobj.Delay = 2000;
            byte[] bytOutBuffer;
            if (devobj.IsAsc)
            {
                string strhead = cmdstr.Substring(0, 2);
                string strend = cmdstr.Substring(cmdstr.Length - 2, 2);
                cmdstr = cmdstr.Substring(2, cmdstr.Length - 2);
                cmdstr = cmdstr.Substring(0, cmdstr.Length - 2);
                bytOutBuffer = getAscByteBy16s(cmdstr, strhead, strend);
            }
            else
                bytOutBuffer = getByteBy16s(cmdstr);
            //string strasc = "";
            //for (int i = 0; i < bytOutBuffer.Length; i++)
            //{
            //    strasc = bytOutBuffer[i].
            //}
            byte[] bytReceiveBuffer;

            //----- UDP ------//
            if (devobj.Mode == 0)
            {
                SerialCommi serialcom = new SerialCommi();
                serialcom.SetProtocolParam("COM1", devobj.baudRate, devobj.Delay);
                bytReceiveBuffer = serialcom.SendCommand(cmdstr,true);
            }
            else
            {
                IPEndPoint RemoteIpEndPoint = SetIPEndPoint(devobj.IP, basefun.toIntval(devobj.Port), devobj.Mode);
                UdpClient udpClient = new UdpClient();
                udpClient.Send(bytOutBuffer, bytOutBuffer.Length, RemoteIpEndPoint);

                IPEndPoint from = new IPEndPoint(IPAddress.Any, 0);
                IAsyncResult result = udpClient.BeginReceive(null, this);
                result.AsyncWaitHandle.WaitOne(devobj.Delay, false);
                if (!result.IsCompleted)
                {
                    udpClient.Close();
                    return null;
                }
                bytReceiveBuffer = udpClient.EndReceive(result, ref from);
                udpClient.Close();
            }
            //-----------------


            string udpInfo = "";
            if (devobj.IsAsc)
            {
                string info = "";
                char[] cbuff = new char[bytReceiveBuffer.Length - 2];
                for (int i = 1; i < bytReceiveBuffer.Length - 1; i++)
                {
                    cbuff[i - 1] = (char)bytReceiveBuffer[i];
                    info += Convert.ToString(cbuff[i - 1]);
                }
                //去掉帧头和帧尾
                udpInfo = info;
            }
            else
                udpInfo = get16sByByte(bytReceiveBuffer, true);

            //恢复转义字符 
            if (devobj.Exchanges != "")
            {
                string[] strExs = devobj.Exchanges.Split('#');
                for (int i = 0; i < strExs.Length; i++)
                {
                    string[] _a = strExs[i].Split('/');
                    udpInfo = SpecialRestore(udpInfo, _a[1], _a[0]);
                }
            }
            //取返回值16进制数组,并解析
            string infos = AnalysisEateryResults(udpInfo, OutString, devobj, true, ref state);
            return infos;

        }
コード例 #14
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// �����豸�����������������ͨѶ�����ַ���
        /// </summary>
        /// <param name="devpms">�豸�������ϼ���</param>
        /// <param name="cmdpms">ָ��������ϼ���</param>
        /// <returns>ͨѶ�ַ���</returns>
        public string CommandString(string devpms, string cmdpms, string datapms, ref devObj devobj)
        {
            //�����豸����
            string[] datapmss = datapms.Split(',');
            devobj = setDevObj(devpms);
            string strpm = "";
            string[] arrpm = cmdpms.Split(';');
            string str = "";
            int ilength = 0;
            pmObj pmXorObj = new pmObj();
            for (int i = 0; i < arrpm.Length; i++)
            {

                string[] arr = arrpm[i].Split(',');

                NameObjectList lst = NameValueTag(arrpm[i]);
                pmObj pmobj = new pmObj();
                pmobj.Name = getVarNameByHmStr(arr[0]);
                pmobj.Len = toIntval(valtag(arrpm[i], "{len}"));
                pmobj.DataType = valtag(arrpm[i], "{datatype}");
                pmobj.Format = valtag(arrpm[i], "{format}");
                if (pmobj.Format.StartsWith("��"))
                    pmobj.Format = pmobj.Format.Substring(1);
                pmobj.Formats = valtag(arrpm[i], "{formats}");
                pmobj.Scale = toFloatValue(valtag(arrpm[i], "{scale}")) == 0 ? 1 : toFloatValue(valtag(arrpm[i], "{scale}"));
                //pmobj.Scale = toIntval(valtag(arrpm[i], "{scale}")) == 0 ? 1 : toIntval(valtag(arrpm[i], "{scale}"));
                pmobj.Add = toIntval(valtag(arrpm[i], "{add}"));
                pmobj.SubItems = valtag(arrpm[i], "{subitems}");
                pmobj.Value = lst.AllStringValues[0].ToLower();

                string strlh = valtag(arrpm[i], "{lh}");
                if (strlh == "") pmobj.LH = devobj.LH;
                else
                {
                    if (strlh == "0") pmobj.LH = false;
                    else pmobj.LH = true;
                }
                if (lst.Keys[0] == "{�豸��ַ}")
                {
                    if (pmobj.DataType == "word")
                        str = str + exchangeLH(devobj.ID, pmobj.LH);
                    else
                        str = str + exchangeLH(sVal10To16(devobj.ID, pmobj.Len / 8), pmobj.LH);
                    continue;
                }
                string svalue = pmobj.Value; //ֵ
                ilength = basefun.toIntval(lst.AllStringValues[1].ToLower()); //�
                string datetype = lst.AllStringValues[2].ToLower(); //��������
                string format = lst.AllStringValues[3]; //��ʽ
                //int icale = basefun.toIntval(lst.AllStringValues[5].ToLower()); //��������
                //if (icale == 0) icale = 1;
                switch (datetype)
                {
                    case "string":
                        if (pmobj.Value == "" || pmobj.Value == "?")
                            svalue = basefun.valtag(datapms, pmobj.Name);

                        long _iv = basefun.toIntval(svalue);
                        svalue = this.sVal10To16(_iv.ToString());
                        break;
                    case "asc":
                        if (pmobj.Value == "" || pmobj.Value == "?")
                            svalue = (basefun.valtag(datapms, pmobj.Name)).Trim();
                        svalue = AscToCharactor(svalue);
                        int _lenerr = (pmobj.Len / 8 - svalue.Length / 2);
                        if (_lenerr % 2 == 0)
                        {
                            string strsign = "";
                            for (int ib = 0; ib < _lenerr; ib++)
                            {
                                strsign = strsign + "20";
                            }
                            svalue = strsign + svalue;
                        }
                        break;
                    case "asc2":
                        if (pmobj.Value == "" || pmobj.Value == "?")
                            svalue = (basefun.valtag(datapms, pmobj.Name)).Trim();
                        svalue = AscToCharactor(svalue);
                        _lenerr = (pmobj.Len / 8 - svalue.Length / 2);
                        if (_lenerr % 2 == 0)
                        {
                            string strsign = "";
                            for (int ib = 0; ib < _lenerr; ib++)
                            {
                                strsign = strsign + "20";
                            }
                            svalue = strsign + svalue;
                        }
                        if (svalue.Length > 16)
                            svalue = svalue.Substring(0, 16);
                        break;
                    case "int":
                    case "long":
                    case "integer":
                        if (pmobj.SubItems != "")
                        {
                            string[] subs = pmobj.SubItems.Split('+');
                            int isubs = 0;
                            string _sbit = "";
                            for (int m = 0; m < subs.Length; m++)
                            {
                                string[] asubs = subs[m].Split('=');
                                string[] asubpms = asubs[1].Split('#');
                                string subValue = asubpms[0];
                                if (subValue == "" || subValue == "?")
                                    subValue = basefun.valtag(datapms, asubs[0]);
                                if (string.IsNullOrEmpty(subValue))
                                    subValue = "0";
                                int iSublen = basefun.toIntval(asubpms[1]);
                                string subDataType = asubpms[2];
                                string subFormat = asubpms[3];
                                string subScale = asubpms[4];
                                switch (subDataType.ToLower())
                                {
                                    case "double":
                                        //תΪ������
                                        if (subFormat == "") subFormat = "{0:.00}";
                                        if (subFormat.IndexOf("{") > -1)
                                        {
                                            subValue = string.Format(subFormat, Convert.ToDouble(subValue) * pmobj.Scale);
                                        }
                                        else
                                            subValue = string.Format("{" + subFormat + "}", Convert.ToDouble(subValue) * pmobj.Scale);
                                        subValue = basefun.toIntval(subValue).ToString();
                                        subValue = sVal10To2(subValue, iSublen);
                                        break;
                                    case "integer":
                                    case "int":
                                        subValue = sVal10To2(subValue, iSublen);
                                        break;
                                    default:
                                        subValue = subValue;
                                        break;
                                }
                                //rtns = basefun.setvaltag(rtns, asubs[0], subValue);
                                _sbit = _sbit + subValue;
                            }
                            svalue = this.sVal10To16(Convert.ToInt32(_sbit, 2).ToString());
                        }
                        else
                        {
                            if (pmobj.Value == "" || pmobj.Value == "?")
                                svalue = basefun.valtag(datapms, pmobj.Name);
                            if (string.IsNullOrEmpty(svalue))
                                svalue = "0";
                            long _lv = Convert.ToInt64(basefun.toIntval64(svalue) * pmobj.Scale);
                            svalue = this.sVal10To16(_lv.ToString());
                            if (pmobj.Format == "db")
                            {
                                svalue = basefun.toIntval64(svalue).ToString() + basefun.toIntval64(svalue).ToString();
                            }
                        }
                        break;
                    case "float":
                    case "double":
                        if (pmobj.Value == "" || pmobj.Value == "?")
                            svalue = basefun.valtag(datapms, pmobj.Name);
                        if (string.IsNullOrEmpty(svalue))
                            svalue = "0";
                        if (pmobj.Format.IndexOf("{") > -1)
                            svalue = string.Format(pmobj.Format, Convert.ToDouble(svalue) * pmobj.Scale);
                        else if (!string.IsNullOrEmpty(pmobj.Format))
                            svalue = string.Format("{" + pmobj.Format + "}", Convert.ToDouble(svalue) * pmobj.Scale);
                        else
                            svalue = Convert.ToInt32(Convert.ToDouble(svalue) * pmobj.Scale).ToString();
                        svalue = basefun.toIntval(svalue).ToString();
                        svalue = this.sVal10To16(svalue, "F".PadLeft(pmobj.Len / 4, 'F'));
                        break;
                    case "bit":
                        //�ѻ�����=1#1#String##+�ѻ�ʱ��=0.1#15#Double#{0:.0}#10;
                        if (pmobj.SubItems != "")
                        {
                            string[] subs = pmobj.SubItems.Split('+');
                            int isubs = 0;
                            string _sbit = "";
                            for (int m = 0; m < subs.Length; m++)
                            {
                                string[] asubs = subs[m].Split('=');
                                string[] asubpms = asubs[1].Split('#');
                                string subValue = asubpms[0];
                                if (subValue == "" || subValue == "?")
                                    subValue = basefun.valtag(datapms, pmobj.Name + ".{" + asubs[0] + "}");
                                int iSublen = basefun.toIntval(asubpms[1]);
                                string subDataType = asubpms[2];
                                string subFormat = asubpms[3];
                                string subScale = asubpms[4];
                                switch (subDataType.ToLower())
                                {
                                    case "double":
                                        //תΪ������
                                        if (string.IsNullOrEmpty(subValue))
                                            subValue = "0";
                                        if (subFormat == "") subFormat = "{0:.00}";
                                        if (subFormat.IndexOf("{") > -1)
                                        {
                                            subValue = string.Format(subFormat, Convert.ToDouble(subValue) * 10);
                                        }
                                        else
                                            subValue = string.Format("{" + subFormat + "}", Convert.ToDouble(subValue) * pmobj.Scale);
                                        subValue = sVal10To2(subValue, iSublen);
                                        break;
                                    case "integer":
                                    case "int":
                                        if (string.IsNullOrEmpty(subValue))
                                            subValue = "0";
                                        subValue = sVal10To2(subValue, iSublen);
                                        break;
                                    default:
                                        subValue = subValue;
                                        break;
                                }
                                //rtns = basefun.setvaltag(rtns, asubs[0], subValue);
                                _sbit = _sbit + subValue;
                            }
                            try
                            {
                                svalue = this.sVal10To16(Convert.ToInt32(_sbit, 2).ToString());
                            }
                            catch (Exception ex) { svalue = "00"; };
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(svalue)) svalue = "0";
                            if (pmobj.Value == "" || pmobj.Value == "?")
                                svalue = basefun.valtag(datapms, pmobj.Name);
                            if (string.IsNullOrEmpty(svalue))
                            {
                                return "";
                            }
                            svalue = this.sVal10To16(Convert.ToInt32(svalue, 2).ToString());
                        }
                        break;
                    case "date":
                    case "datetime":
                        if (pmobj.Value == "" || pmobj.Value == "?")
                            svalue = basefun.valtag(datapms, pmobj.Name);
                        if (string.IsNullOrEmpty(svalue))
                            svalue = DateTime.Now.ToString();
                        if (format.EndsWith("~BCD"))
                            svalue = basefun.toBCDDatetime(svalue, format);
                        else
                            svalue = basefun.toHexDatetime(svalue, format);
                        break;
                    default:
                        if (pmobj.Value == "" || pmobj.Value == "?")
                            svalue = basefun.valtag(datapms, pmobj.Name);

                        break;
                }

                if (ilength == 0) ilength = 8 * svalue.Length / 2;
                if (lst.Keys[0] == "{����}")
                {
                    pmXorObj = pmobj;
                    break;
                }
                if (svalue == "") svalue = "0";
                svalue = ComplementingBits(svalue, ilength);
                if (!format.EndsWith("~BCD"))
                    svalue = exchangeLH(svalue, pmobj.LH);
                str = str + svalue;
                Debug.WriteLine(str);
            }

            // -- ĩβ����У���� --
            CrcClass crc = new CrcClass();
            string xor = "";
            switch (devobj.Paritymode)
            {
                case "0":
                    xor = crc.CRCXOR(str.Substring(2, str.Length - 2));
                    break;
                case "1":
                    xor = crc.CRCSUM(str.Substring(2, str.Length - 2));
                    break;
            }
            string vstr = exchangeLH(ComplementingBits(xor, ilength), pmXorObj.LH);
            //����ת���ַ����Բ�����֡ͷ��֡β���ֽڽ���ת�崦��
            str = str.Substring(2, str.Length - 2) + vstr;
            str = transferWords(str, devobj.Exchanges);

            NameObjectList lst0 = NameValueTag(arrpm[0]);
            NameObjectList lst1 = NameValueTag(arrpm[arrpm.Length - 1]);
            string strCmd = lst0.AllStringValues[0] + str + lst1.AllStringValues[0];
            strCmd = strCmd.ToUpper();
            return strCmd;
        }
コード例 #15
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// �ɴ��ڷ��ص��ַ�����hmtag�ַ��������滮��ģʽ��ֵ.�ɲ���ֵnoHE�ֱ��Ƿ���֡ͷ��֡β
        /// </summary>
        /// <param name="format">��ʽ���ַ���</param>
        /// <param name="udpinfos">���ڷ��ص�����</param>
        /// <param name="devobj">�豸������</param>
        /// <param name="noHE">����ֵ��true- ������֡ͷ��֡β</param>
        /// <param name="vtag">���ص�״ֵ̬</param>
        /// <returns>���ص������ַ���</returns>
        public string getValByHmFormat(string formats, string[] udpinfos, devObj devobj, Boolean noHE, ref string vtag)
        {
            if (udpinfos == null || formats == null) return null;
            string rtn = "";
            string[] xformats = formats.Split(';');
            int ipos = 0;
            string rtns = "";
            for (int i = 0; i < xformats.Length; i++)
            {
                if (noHE)
                    if (i == 0 || i == xformats.Length - 1) continue;
                string[] arr = xformats[i].Split(',');
                string vname = getVarNameByHmStr(arr[0]);
                pmObj pmobj = new pmObj();
                pmobj.Name = getVarNameByHmStr(arr[0]);
                pmobj.Len = toIntval(valtag(xformats[i], "{len}"));
                pmobj.DataType = valtag(xformats[i], "{datatype}");
                pmobj.Format = valtag(xformats[i], "{format}");
                pmobj.Formats = valtag(xformats[i], "{formats}");
                pmobj.Scale = toFloatValue(valtag(xformats[i], "{scale}")) == 0.0 ? 1.0 : toFloatValue(valtag(xformats[i], "{scale}"));
                pmobj.Add = toIntval(valtag(xformats[i], "{add}"));
                pmobj.SubItems = valtag(xformats[i], "{subitems}");
                string strlh = valtag(xformats[i], "{lh}");
                if (strlh == "") pmobj.LH = devobj.LH;

                /*
                int ilen = toIntval(valtag(xformats[i], "{len}"));
                string format = valtag(xformats[i], "{format}");
                string aformats = valtag(xformats[i], "{formats}");
                int ibytes = ilen / 8;
                string datatype = valtag(xformats[i], "{datatype}");
                int icale = basefun.toIntval(valtag(xformats[i], "{scale}"));
                if (icale == 0) icale = 1;
                 */
                string s = getValueByUpdInfos(udpinfos, ipos, pmobj);
                ipos = ipos + pmobj.Len;
                switch (pmobj.DataType.ToLower())
                {
                    case "datetime":
                    case "date":
                    case "dateword":
                        if (pmobj.Format.EndsWith("~BCD"))
                            s = basefun.toDatetimeBCD(s, pmobj.Format);
                        else
                        {
                            s = this.exchangeLH(s, pmobj.LH);
                            s = basefun.toDatetime(s, pmobj.Format);
                        }
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        break;
                    case "float":
                    case "double":
                        s = this.exchangeLH(s, pmobj.LH);
                        if (pmobj.Format.StartsWith("��"))
                        {
                            pmobj.Format = pmobj.Format.Substring(1);
                            int h = Convert.ToInt16(s.Substring(0, 1), 16);
                            if (h > 7)
                                s = s.PadLeft(16, 'F');
                        }
                        s = Convert.ToInt64(sVal16To10(s)).ToString();
                        if (pmobj.Format == "") pmobj.Format = "{0:.00}";
                        if (pmobj.Format.IndexOf("{") > -1)
                            s = string.Format(pmobj.Format, Convert.ToDouble(s) * pmobj.Scale);
                        else
                            s = string.Format("{" + pmobj.Format + "}", Convert.ToDouble(s) * pmobj.Scale);
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        break;
                    case "float16":
                    case "double16":
                        s = this.exchangeLH(s, pmobj.LH);
                        s = Convert.ToInt32(sVal16To10(s)).ToString();
                        if (pmobj.Format == "") pmobj.Format = "{0:.00}";
                        if (pmobj.Format.IndexOf("{") > -1)
                            s = string.Format(pmobj.Format, Convert.ToDouble(s) * pmobj.Scale);
                        else
                            s = string.Format("{" + pmobj.Format + "}", Convert.ToDouble(s) * pmobj.Scale);
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        break;
                    case "bit":

                        s = this.exchangeLH(s, pmobj.LH);
                        s = sVal16To10(s);
                        s = ComplementingBits(Convert.ToString(Convert.ToInt64(s), 2), pmobj.Len, true, true);
                        //Billy
                        /*
                        if (s == "10000001" || s == "10000000")
                        {
                            s = "00000000";
                        }
                        */
                        //�ѻ�����=1#String#+�ѻ�ʱ��=15#Double#{0:.0}
                        if (pmobj.SubItems != "")
                        {
                            string[] subs = pmobj.SubItems.Split('+');
                            int isubs = 0;
                            for (int m = 0; m < subs.Length; m++)
                            {
                                string[] asubs = subs[m].Split('=');
                                string[] asubpms = asubs[1].Split('#');
                                int iSublen = basefun.toIntval(asubpms[1]);
                                string subDataType = asubpms[2];
                                string subFormat = asubpms[3];
                                string subValue = s.Substring(isubs, iSublen);
                                switch (subDataType.ToLower())
                                {
                                    case "datetime":
                                    case "date":
                                        subValue = Convert.ToString(Convert.ToInt64(subValue, 2), 16);
                                        subValue = ComplementingBits(subValue, 16);
                                        if (subFormat == "") subFormat = "hhmm";
                                        subValue = InfoTomyDate(subValue, subFormat, true);
                                        break;
                                    case "double":
                                        subValue = Convert.ToInt32(subValue, 2).ToString();
                                        if (subFormat == "") subFormat = "{0:.00}";
                                        //�˴�δ�ӱ������з���
                                        if (subFormat.IndexOf("{") > -1)
                                        {
                                            subValue = string.Format(subFormat, Convert.ToDouble(subValue) / 10);
                                        }
                                        else
                                            subValue = string.Format("{" + subFormat + "}", Convert.ToDouble(subValue) * pmobj.Scale);

                                        break;
                                    case "integer":
                                    case "int":
                                        subValue = Convert.ToInt32(subValue, 2).ToString();
                                        break;
                                    default:
                                        subValue = Convert.ToInt32(subValue, 2).ToString();
                                        break;
                                }
                                rtns = basefun.setvaltag(rtns, asubs[0], subValue);
                                isubs = isubs + iSublen;
                            }
                        }
                        else
                        {
                            rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        }
                        break;
                    case "integer":
                    case "int":
                        s = this.exchangeLH(s, pmobj.LH);
                        long _iv = Convert.ToInt64(Convert.ToInt64(sVal16To10(s)) * pmobj.Scale);
                        s = _iv.ToString();
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        break;
                    case "asc":
                        s = this.exchangeLH(s, pmobj.LH);
                        byte[] bs = new byte[s.Length / 2];
                        for (int p = 0; p < bs.Length; p++)
                            bs[p] = Convert.ToByte(s.Substring(p * 2, 2), 16);
                        s = Encoding.GetEncoding("GB2312").GetString(bs);
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s.Trim());
                        break;
                    case "word":
                        s = this.exchangeLH(s, pmobj.LH);
                        if (vname == "{״̬}")
                        {
                            s = ResKeywords(devobj, s);
                            vtag = s;
                            if (s.Contains("�����ɹ�") || s.Contains("���¼�¼"))
                                rtns = basefun.setvaltag(rtns, "Success", "true");
                            else
                                rtns = basefun.setvaltag(rtns, "Success", "false");
                        }
                        else
                        {
                            switch (pmobj.Format)
                            {
                                case "{0}-{1}-{2}-{3}-{4}":
                                    string[] arrip = this.String16ToArry(s, 16);
                                    string str = "";
                                    for (int m = 0; m < arrip.Length; m++)
                                    {
                                        str = str + "-" + this.sVal10To16(basefun.toIntval(arrip[m]).ToString());
                                    }
                                    s = str.Substring(1, str.Length - 1);
                                    break;
                                case "db":
                                    s = s.Substring(1);
                                    break;
                            }
                        }
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        break;
                    default:
                        s = this.exchangeLH(s, pmobj.LH);
                        if (pmobj.Format == "{0}.{1}.{2}.{3}")
                        {
                            string[] arrip = this.String16ToArry(s, 16);
                            string str = "";
                            for (int m = 0; m < arrip.Length; m++)
                            {
                                str = str + "." + basefun.toIntval(arrip[m]).ToString();
                            }
                            s = str.Substring(1, str.Length - 1);
                        }
                        else
                            s = Convert.ToInt64(sVal16To10(s)).ToString();
                        rtns = basefun.setvaltag(rtns, pmobj.Name, s);
                        break;
                }
                xformats[i] = setvaltag(xformats[i], vname, s);
                rtn = rtn + ";" + xformats[i];
            }
            //�Ž�ʱ�з�����ɹ�
            if (!string.IsNullOrEmpty(rtns) && "�Ž�" == devobj.Buss)
                rtns = basefun.setvaltag(rtns, "Success", "true");
            if (rtn.Length > 0)
                rtn = rtn.Substring(1);
            rtns = rtns.Trim();
            return rtns;
        }
コード例 #16
0
ファイル: ComClass.cs プロジェクト: BillyWu/Granitypark
 public string GetCmdStr(string devpms, string cmdpms, string datapms, string OutString, ref string state)
 {
     devObj devobj = new devObj();
     return CommandString(devpms, cmdpms, datapms, ref devobj);
 }
コード例 #17
0
ファイル: CmdProtocol.cs プロジェクト: BillyWu/Granitypark
        /// <summary>
        /// �����豸ָ��,ʹ��dvID��ָ��ID
        /// </summary>
        /// <param name="tpl">������</param>
        /// <param name="cmd">ָ��</param>
        /// <param name="tagdata">���ݲ���,ʹ��tag��Ǹ�ʽ</param>
        public bool setCommand(string tpl, string cmd, string tagdata)
        {
            if (string.IsNullOrEmpty(tpl) || string.IsNullOrEmpty(cmd) || CmdState.Response == this.CheckState())
                return false;

            PtlParam ptlParam = new PtlParam();
            if (PTLParam.ContainsKey(tpl + ":" + cmd))
                ptlParam = PTLParam[tpl + ":" + cmd];
            else
            {
                Estar.Common.Tools.NameObjectList ps = new Estar.Common.Tools.NameObjectList();
                ps["tpl"] = tpl;
                ps["cmd"] = cmd;
                if (null == this.query)
                    return false;
                DataTable tab = this.query.getTable(dbItem, ps);
                if (null == tab || tab.Rows.Count < 1)
                    return false;
                //�����ݿ���ȡ���IJ���ת����tag��ʽ����
                DataColumnCollection dbcols = tab.Columns;
                if (!dbcols.Contains("type") || !dbcols.Contains("pms"))
                    return false;
                foreach (DataRow dr in tab.Rows)
                {
                    if (DBNull.Value == dr["type"])
                        continue;
                    string pmtype = Convert.ToString(dr["type"]);
                    switch (pmtype)
                    {
                        case "��":
                            ptlParam.pmdevice = Convert.ToString(dr["pms"]);
                            break;
                        case "Input":
                            ptlParam.pminput += Convert.ToString(dr["pms"]) + ";";
                            break;
                        case "Output":
                            ptlParam.pmout += Convert.ToString(dr["pms"]) + ";";
                            break;
                    }
                }
                if (ptlParam.pmdevice.EndsWith(";"))
                    ptlParam.pmdevice = ptlParam.pmdevice.Substring(0, ptlParam.pmdevice.Length - 1);
                if (string.IsNullOrEmpty(ptlParam.pmdevice)) return false;
                if (ptlParam.pminput.EndsWith(";"))
                    ptlParam.pminput = ptlParam.pminput.Substring(0, ptlParam.pminput.Length - 1);
                if (ptlParam.pmout.EndsWith(";"))
                    ptlParam.pmout = ptlParam.pmout.Substring(0, ptlParam.pmout.Length - 1);
                ptlParam.pmdevice = ptlParam.pmdevice.Replace(";;", ";");
                ptlParam.pminput = ptlParam.pminput.Replace(";;", ";");
                ptlParam.pmout = ptlParam.pmout.Replace(";;", ";");
                if (!PTLParam.ContainsKey(tpl + ":" + cmd))
                    PTLParam.Add(tpl + ":" + cmd, ptlParam);
            }
            this.inputParam = ptlParam.pminput;
            this.outterParam = ptlParam.pmout;
            this.responseFormat = "";
            //����Э�����ͨѶָ��
            string pmdevice = basefun.setvaltag(ptlParam.pmdevice, "devid", basefun.valtag(tagdata, "�豸��ַ"));
            dvParam.Command = "";
            string cmdstr = "";
            if (string.IsNullOrEmpty(tagdata))
                dvParam = this.setDevObj(pmdevice);
            else
                cmdstr = comparse.CommandString(pmdevice, ptlParam.pminput, tagdata, ref dvParam);
            IsAscii = dvParam.IsAsc;
            Exchanges = dvParam.Exchanges;
            if (string.IsNullOrEmpty(dvParam.Buss))
                dvParam.Buss = tpl;
            if (string.IsNullOrEmpty(dvParam.Command))
                dvParam.Command = cmd;
            //û�����ݲ���,��ֻ��ȡ��ʽ����,���ڽ������
            if (string.IsNullOrEmpty(tagdata))
                return true;
            //ת����ֽ�,ʹ��""""����ԭ��֡ͷ֡β�Ĵ���
            if (dvParam.IsAsc)
            {
                if (cmdstr.StartsWith("02") && cmdstr.EndsWith("03"))
                    cmdstr = "" + cmdstr.Substring(2, cmdstr.Length - 4) + "";
                return this.setCommand(cmdstr);
            }
            return this.setCommand(cmdstr, true);
        }