Ejemplo n.º 1
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 + "**");
        }
Ejemplo n.º 2
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);

            return(DecimalConversion.HexToTen(ss.Substring((0) + 2, 2) + ss.Substring((0), 2)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 解析多个寄存器解析出来拼接成字符串   例如条码解析
        /// </summary>
        /// <param name="rev"></param>
        /// <returns></returns>
        public static string ReadDTValueToStr(string rev)
        {
            //地址 %01#RDD0030100309**
            string ss      = PLCAddressHelper.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);
        }
Ejemplo n.º 4
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 = PLCAddressHelper.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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 写入多个寄存器的值
        /// </summary>
        /// <param name="beginAddress"></param>
        /// <param name="endAddress"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static string DTAddressWriteConvert(int beginAddress, int endAddress, 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') + endAddress.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 + "**");
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }