コード例 #1
0
ファイル: Package.cs プロジェクト: ninwjf/MJ-mysqlGS
        /// <summary>
        /// 解包-扇区查询包
        /// </summary>
        /// <param name="bArrBag"></param>
        /// <returns></returns>
        public static bool ParseBag_ChsSel(byte[] bArrBag, ref CardData objCardData, out string strErrMsg)
        {
            bool bIfSucc = false;

            objCardData = new CardData();
            strErrMsg   = "";

            try
            {
                //55 FF 00 12 20 01 00 00 00 00 06 12 34 00 01 F0 00 1D 00 9C 00 00 6D 刷卡头刷卡上传
                //数据位
                byte bCode = bArrBag[5];
                strErrMsg = GetFaultInfoByCode(bCode);
                if (strErrMsg.Equals(""))
                {
                    //解析扇区信息
                    int iBeginIndex = 6;
                    int j           = 0;
                    for (int i = 0; i <= 15; i++)
                    {
                        j = Convert.ToInt32(ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]));
                        objCardData.listChsInfo[j].Add(i);
                    }

                    //解析卡号
                    byte[] bArrCardNo = new byte[4];
                    for (int i = bArrCardNo.Length - 1; i >= 0; i--)
                    {
                        bArrCardNo[i] = bArrBag[iBeginIndex++];
                    }
                    objCardData.CardNo = Functions.ConverToUInt(bArrCardNo);//低字节在前,高字节在后

                    bIfSucc = true;
                }
            }
            catch (Exception err)
            {
                strErrMsg = err.Message;
            }
            return(bIfSucc);
        }
コード例 #2
0
ファイル: Package.cs プロジェクト: ninwjf/MJ-mysqlGS
        /// <summary>
        /// 解包(读卡响应包)
        /// </summary>
        /// <param name="bArrBag"></param>
        /// <returns></returns>
        public static bool ParseBag_ReadCard(byte[] bArrBag, ref CardData objCardData, out string strErrMsg)
        {
            bool bIfSucc = false;

            objCardData = new CardData();
            strErrMsg   = "";
            try
            {
                //数据位
                byte bCode = bArrBag[5];
                strErrMsg = GetFaultInfoByCode(bCode);
                if (strErrMsg.Equals(""))
                {
                    //解析卡号
                    int    iBeginIndex = 6;
                    byte[] bArrCardNo  = new byte[4];
                    for (int i = bArrCardNo.Length - 1; i >= 0; i--)
                    {
                        bArrCardNo[i] = bArrBag[iBeginIndex++];
                    }
                    objCardData.CardNo = Functions.ConverToUInt(bArrCardNo);//低字节在前,高字节在后

                    //空卡直接返回 年月日为零则是空卡
                    if (int.Parse(bArrBag[15].ToString()) +
                        int.Parse(bArrBag[16].ToString()) +
                        int.Parse(bArrBag[17].ToString()) +
                        int.Parse(bArrBag[18].ToString()) == 0)
                    {
                        objCardData.CardType = 6;
                    }
                    else
                    {
                        //解析区编码
                        objCardData.AreaCode = Convert.ToInt32(ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]));
                        //解析栋编码
                        objCardData.BuildCode = Convert.ToInt32(ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]));
                        //解析单元编码
                        objCardData.UnitCode = Convert.ToInt32(ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]));
                        //解析楼层编码
                        int iFloorCode = Convert.ToInt32(ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]));
                        //解析房间编码
                        objCardData.RoomCode = (iFloorCode * 100) + Convert.ToInt32(ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]));

                        //解析日期
                        //解析年
                        string strYear = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]) + ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        //解析月
                        string strMonth = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        //解析日
                        string strDay = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        objCardData.ExpiryDate = Functions.ConvertToUnixTime(Convert.ToDateTime(string.Format("{0}-{1}-{2} 00:00:00", strYear, strMonth, strDay)));

                        //解析卡片类型
                        objCardData.CardType = Convert.ToInt32(bArrBag[iBeginIndex++]);

                        //解析预留 6个字节
                        //iBeginIndex += 6;
                        //新卡预留信息为开卡时间与及当前写扇区,旧卡信息为空
                        //bArrBag[iBeginIndex].ToString();
                        string strBeginYear  = "20" + ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        string strBeginMonth = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        string strBeginDay   = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        string strBeginHour  = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        string strBeginMin   = ScaleConverter.Byte2HexStr(bArrBag[iBeginIndex++]);
                        string chsStr        = bArrBag[iBeginIndex++].ToString();

                        //月份为00表示旧卡
                        if (strBeginMonth.CompareTo("00") != 0 && strBeginMonth.CompareTo("0") != 0)
                        {
                            objCardData.BeginDate = Functions.ConvertToUnixTime(Convert.ToDateTime(string.Format("{0}-{1}-{2} {3}:{4}:00", strBeginYear, strBeginMonth, strBeginDay, strBeginHour, strBeginMin)));
                        }

                        //扇区00也表示旧卡, 防止乱写情况还是做个判断
                        if (chsStr.CompareTo("00") != 0 && chsStr.CompareTo("0") != 0)
                        {
                            objCardData.listChsInfo[1].Add(Convert.ToInt32(chsStr));
                        }
                        else
                        {
                            objCardData.listChsInfo[1].Add(1);
                        }

                        //解析序号 16个字节
                        byte[] bArrSerialNo = new byte[16];
                        Array.Copy(bArrBag, iBeginIndex, bArrSerialNo, 0, bArrSerialNo.Length);
                        objCardData.SerialNo = ScaleConverter.ByteArr2HexStr(bArrSerialNo).Replace(" ", "");
                    }
                    bIfSucc = true;
                }
            }
            catch (Exception err)
            {
                strErrMsg = err.Message;
            }
            return(bIfSucc);
        }