예제 #1
0
        /// <summary>
        /// 寄存器数据解析
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static List <string> DTDatalearning(string rev)
        {
            List <string> Data = new List <string>();

            if (string.IsNullOrEmpty(rev))
            {
                return(Data);
            }
            rev = rev.Replace("\r", "");
            string ss        = HexStr(rev);
            string highOrder = "";
            string lowOrder  = "";

            for (int i = 0; i < ss.Length / 4; i++)
            {
                //if (i == 0)
                //{
                //    highOrder = ss.Substring(0, 2);//高位数据
                //    lowOrder = ss.Substring( 2, 2);//低位数据
                //}
                //else
                //{
                //    highOrder = ss.Substring((i * 4), 2);//高位数据  09100910
                //    lowOrder = ss.Substring((i * 4) + 2, 2);//低位数据
                //}
                highOrder = ss.Substring((i * 4), 2);     //高位数据  09100910
                lowOrder  = ss.Substring((i * 4) + 2, 2); //低位数据


                Data.Add(DecimalConversion.HexToTen(lowOrder + highOrder).ToString());
            }
            return(Data);
        }
예제 #2
0
        /// <summary>
        /// 解析弹夹条码
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static string ReadClipBarBarcode(string rev)
        {
            if (string.IsNullOrEmpty(rev))
            {
                return("ERROR");
            }
            rev = rev.Replace("\r", "");
            int    lenth   = 0;
            string ss      = HexStr(rev);
            string barcode = "";

            for (int i = 0; i < ss.Length / 2; i++)
            {
                string str = ss.Substring(i * 2, 2);
                if (i == 0)
                {
                    if (str.ToUpper() == "0D" && i > 0)
                    {
                        return(barcode);
                    }
                    lenth = DecimalConversion.HexToTen(str);
                }
                barcode += DecimalConversion.HexStringToASCII(str).Replace("\n", "").Replace("\r", "").Replace("\0", "").Replace("", "").Replace("", "");
            }
            barcode = barcode.Replace("00000000000000000000000000000000", "ERROR").Replace("", "").ToUpper();
            if (!barcode.Contains("ERROR"))
            {
                barcode = barcode.Substring(0, lenth);
            }
            if (string.IsNullOrEmpty(barcode) || barcode.Contains("ERROR"))
            {
                barcode = "ERROR";
            }
            return(barcode);
        }
예제 #3
0
        /// <summary>
        /// 写入单个寄存器的值
        /// </summary>
        /// <param name="beginAddress">地址</param>
        /// <param name="values">值</param>
        /// <returns></returns>
        public static string DTAddressWriteConvert(int beginAddress, int values)
        {
            string address    = "%01#WDD";
            string writeValue = DecimalConversion.Ten2Hex(values.ToString()).PadLeft(4, '0');

            address  = address + beginAddress.ToString().PadLeft(5, '0') + beginAddress.ToString().PadLeft(5, '0');
            address += writeValue.Substring(2, 2) + writeValue.Substring(0, 2);
            return(address + "**");
        }
예제 #4
0
        /// <summary>
        /// 解析多个寄存器解析出来拼接成字符串   例如条码解析
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static string ReadDTValueToStr(string rev)
        {
            //地址 %01#RDD0030100309**
            string ss      = PanasonnicSplitJoint.DTValues(rev);
            string barcode = "";

            for (int i = 0; i < ss.Length / 2; i++)
            {
                string str = ss.Substring(i * 2, 2);
                barcode += DecimalConversion.HexStringToASCII(str);
            }
            return(barcode);
        }
예제 #5
0
        /// <summary>
        /// 解析寄存器读取的值
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static List <string> ReadDTValue(string rev)
        {
            List <string> list = new List <string>();

            //地址 %01#RDD0030100309**
            rev = PanasonnicSplitJoint.DTValues(rev);
            for (int i = 0; i < rev.Length / 2; i++)
            {
                string str = rev.Substring(i * 2, 2);
                list.Add(DecimalConversion.HexStringToASCII(str));
            }
            return(list);
        }
예제 #6
0
        /// <summary>
        /// 写入多个寄存器的值
        /// </summary>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static string DTAddressWriteConvert(int beginAddress, List <string> values)
        {
            string address = "%01#WDD";// "%01#RDD0030100309**";

            //string writeValue = DecimalConversion.Ten2Hex(values.ToString()).PadLeft(4, '0');
            address = address + beginAddress.ToString().PadLeft(5, '0') + (beginAddress + values.Count).ToString().PadLeft(5, '0');
            for (int i = 0; i < values.Count; i++)
            {
                string value = DecimalConversion.Ten2Hex(values[i]).PadLeft(4, '0');
                address += value.Substring(2, 2) + value.Substring(0, 2);
            }
            return(address + "**");
        }
예제 #7
0
        public static List <string> RuleDatalearning(string data)
        {
            List <string> list = new List <string>();

            for (int i = data.Length - 1; i >= 0; i--)
            {
                string s = data[i].ToString();
                if (s == "1")
                {
                    list.Add(DecimalConversion.Ten2Hex((data.Length - i - 1).ToString()));
                }
            }
            return(list);
        }
예제 #8
0
        /// <summary>
        /// 解析一个寄存器数据
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static int DTDatalearningOne(string rev)
        {
            if (string.IsNullOrEmpty(rev))
            {
                return(-1);
            }
            rev = rev.Replace("\r", "");
            string ss = HexStr(rev);

            //string highOrder = "";
            //string lowOrder = "";
            //highOrder = ss.Substring((0), 2);//高位数据  09100910
            //lowOrder = ss.Substring((0) + 2, 2);//低位数据
            return(DecimalConversion.HexToTen(ss.Substring((0) + 2, 2) + ss.Substring((0), 2)));
        }
예제 #9
0
        /// <summary>
        /// 读取处理得到条码
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static string ReadBarcode(string rev)
        {
            if (string.IsNullOrEmpty(rev))
            {
                return("ERROR");
            }
            rev = rev.Replace("\r", "");
            string ss      = HexStr(rev);
            string barcode = "";

            for (int i = 0; i < ss.Length / 2; i++)
            {
                string str = ss.Substring(i * 2, 2);
                if (str.ToUpper() == "0D" && i > 0)
                {
                    return(barcode);
                }
                barcode += DecimalConversion.HexStringToASCII(str).Replace("\n", "").Replace("\r", "").Replace("\0", "").Replace("", "");
            }
            return(barcode.Replace("00000000000000000000000000000000", "ERROR").ToUpper());
        }
예제 #10
0
        /// <summary>
        /// 寄存器数据解析到字典
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static Dictionary <int, string> DTDatalearningToDictionary(string rev)
        {
            Dictionary <int, string> data = new Dictionary <int, string>();

            if (string.IsNullOrEmpty(rev))
            {
                return(data);
            }
            rev = rev.Replace("\r", "");
            string ss        = HexStr(rev);
            string highOrder = "";
            string lowOrder  = "";

            for (int i = 0; i < ss.Length / 4; i++)
            {
                highOrder = ss.Substring((i * 4), 2);     //高位数据  09100910
                lowOrder  = ss.Substring((i * 4) + 2, 2); //低位数据
                data.Add(i, DecimalConversion.HexToTen(lowOrder + highOrder).ToString());
            }
            return(data);
        }