Example #1
0
        /// <summary>
        /// 读取卡的返回数据
        /// </summary>
        /// <param name="data">基于TCardRecv的子类,用于保存返回数据</param>
        /// <param name="TimeOut">超时的毫秒数</param>
        /// <returns>读取成功返回True,否则返回False</returns>
        public static bool ReadData(int id, TCardRecv data, int TimeOut)
        {
            byte[] buf  = new byte[15];
            string Head = "";
            int    size = 0;

            while (size < buf.Length)
            {
                //if (size > 0) FUNC.Sleep(10);

                int i = ReadBytes(id, buf, size, buf.Length - size, TimeOut);

                if (i == 0)
                {
                    return(false);          //读超时
                }
                size = size + i;

                Debug.WriteLine(string.Format("Card.ReadData:({0}) {1} ", size, FUNC.BytesToString(buf)));

                if (size >= 3)    //超过三字节,判断wat起始标记
                {
                    char[] ch = new char[] { Convert.ToChar(buf[0]), Convert.ToChar(buf[1]), Convert.ToChar(buf[2]) };
                    Head = new string(ch, 0, 3);

                    if (Head.ToLower() != "wat")   //起始字节不是wat,去掉一个字节,继续读取
                    {
                        for (int j = 0; j < size - 1; j++)
                        {
                            buf[j] = buf[j + 1];    //前移一个字节
                        }

                        size = size - 1;
                    }
                }
            }
            ;

            byte c = FUNC.CRC8(buf, 0, 14);

            if (c != buf[14])
            {
                return(false);
            }

            data.Head = Head;
            data.Addr = buf[3];

            for (int i = 0; i < 10; i++)
            {
                data[i] = buf[i + 4];
            }

            return(true);
        }
Example #2
0
 /// <summary>
 /// ToString()方法重载
 /// </summary>
 /// <returns>以字符串方式返回数组内容</returns>
 public override String ToString()
 {
     return(FUNC.BytesToString(Data));
 }