示例#1
0
        public static bool TryParse(byte[] bytes, out string errorMessage, out FCS result)
        {
            result       = null;
            errorMessage = "";
            bool canParse = bytes.Length == 4;

            if (!canParse)
            {
                errorMessage = "数据长度错误";
            }
            else
            {
                result       = new FCS();
                result.bytes = bytes;
            }

            return(canParse);
        }
示例#2
0
        /// <summary>
        /// 尝试将字符串格式的解析为 FCS 格式
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="errorMessage">如果解析出错,会返回错误信息</param>
        /// <param name="result">如果解析出错,result=null</param>
        /// <returns>是否解析成功</returns>
        public static bool TryParse(string str, out string errorMessage, out FCS result)
        {
            result = null;
            bool canParse = CanParse(str, out errorMessage);

            if (canParse)
            {
                result       = new FCS();
                result.bytes = new byte[4];

                var hexs = str.Split(' ');
                result.bytes[0] = Convert.ToByte(hexs[0], 16);
                result.bytes[1] = Convert.ToByte(hexs[1], 16);
                result.bytes[2] = Convert.ToByte(hexs[2], 16);
                result.bytes[3] = Convert.ToByte(hexs[3], 16);
            }

            return(canParse);
        }