Esempio n. 1
0
 //关闭读卡器
 public void Close()
 {
     iStatus   = RFCardCommon.SeRFIDpub_Close(_Hcom, _RAddr);
     iStatus   = 1;
     _Hcom     = -1;
     _CardCode = "";
     tmTrick.Stop();
     tmTrick.Close();
     SetUIValue = null;
 }
Esempio n. 2
0
        //写卡
        public short RfWrite(string strRemoteCardCode)
        {
            short status = -1;

            if (_Hcom > 0)
            {
                _CardCode = "";
                tmTrick.Stop();
                //定义电子标签读卡器参数
                byte   QValue = 2, Bank = 1, Point = 0, DataLen = 12;
                byte[] TagData = new byte[12];
                TagData = GetHexBytes(strRemoteCardCode.PadLeft(24, '0'));
                status  = RFCardCommon.SeRFIDGen2_Write(_Hcom, _RAddr, QValue, Bank, Point, DataLen, ref TagData[0]);
                if (status == 0)
                {
                    tmTrick.Start();
                }
            }
            return(status);



            //tmTrick.Stop();
            //byte[] m_byPwd = GetHexBytes("88888888");
            //short status = -1;
            //byte[] bydata = new byte[12];
            //status=RFCardCommon.SeRFIDpub_SysTagAuthorizationQuery(_Hcom, 0, ref bydata[0]);
            //if (status== 0)
            //{
            //    if (bydata[0] != 0)
            //    {
            //        bydata = GetHexBytes(strRemoteCardCode.PadLeft(24, '0'));
            //        if (RFCardCommon.SeRFIDGen2_Write(_Hcom, 0, 4, 1, 0, 12, ref bydata[0]) == 0
            //            && RFCardCommon.SeRFIDpub_SysTagAuthorizationSet(_Hcom, 0) == 0)
            //        {
            //            status = RFCardCommon.SeRFIDGen2_Write(_Hcom, 0, 4, 0, 0, 4, ref m_byPwd[0]);
            //            if (status == 0)
            //            {
            //                status = -1;
            //                if (RFCardCommon.SeRFIDGen2_Write(_Hcom, 0, 4, 0, 0, 4, ref m_byPwd[0]) == 0
            //                    && RFCardCommon.SeRFIDGen2_Lock(_Hcom, 0, 4, ref m_byPwd[0], 1, 0, 96, ref bydata[0]) == 0
            //                    && RFCardCommon.SeRFIDGen2_Lock(_Hcom, 0, 4, ref m_byPwd[0], 0, 0, 96, ref bydata[0]) == 0
            //                    && RFCardCommon.SeRFIDGen2_Lock(_Hcom, 0, 4, ref m_byPwd[0], 4, 0, 96, ref bydata[0]) == 0
            //                    && RFCardCommon.SeRFIDGen2_Lock(_Hcom, 0, 4, ref m_byPwd[0], 3, 0, 96, ref bydata[0]) == 0)
            //                {
            //                    status = 0;
            //                }
            //            }
            //        }
            //    }
            //}
            //tmTrick.Start();
            //return status;
        }
Esempio n. 3
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="strPort"></param>
 /// <param name="boudRate"></param>
 /// <param name="bAddr"></param>
 /// <returns></returns>
 public short Initialize(string strPort, string boudRate)
 {
     _Port     = strPort;
     _BoudRate = ChangeBoudRate(boudRate);
     if (iStatus != 0)
     {
         iStatus = RFCardCommon.SeRFIDpub_Open(ref _Hcom, _Port);
         if (iStatus == 0)
         {
             iStatus          = RFCardCommon.SeRFIDpub_SysSetBaudRate(_Hcom, _RAddr, _BoudRate);
             tmTrick.Interval = 200;
             tmTrick.Elapsed += new System.Timers.ElapsedEventHandler(RfRead);
             tmTrick.Enabled  = true;
             tmTrick.Start();
         }
     }
     return(iStatus);
 }
Esempio n. 4
0
 //读取功率
 public string GetRF()
 {
     iStatus = RFCardCommon.SeRFIDpub_SysRFQuery(_Hcom, _RAddr, ref _rf);
     return(_rf.ToString());
     //return iStatus;
 }
Esempio n. 5
0
 //设置功率
 public short SetRF(byte rf)
 {
     iStatus = RFCardCommon.SeRFIDpub_SysRFSet(_Hcom, _RAddr, rf);
     _rf     = rf;
     return(iStatus);
 }
Esempio n. 6
0
        //读卡
        void RfRead(object sender, EventArgs e)
        {
            //------------------------------------单标签读方式(start)--------------------------------------------
            //try
            //{
            //    byte[] TagData = new byte[13];
            //    byte QValue = 2;
            //    byte[] TagID = new byte[25];
            //    byte TagCount = 0;
            //    byte Bank = 1, Point = 0, ReadLen = 12;//标签号的块地址,与块内偏移量,以及标签长度
            //    byte MaskLength = 0;//用于匹配的长为0,即不匹配标签,对所有标签都进行操作
            //    byte[] Mask = new byte[16];
            //    iStatus = RFCardCommon.SeRFIDGen2_MultiReadID(_Hcom, _RAddr, QValue, 0, Mask, ref TagCount);
            //    if (iStatus == 0)
            //    {
            //        tmTrick.Stop();
            //        iStatus = RFCardCommon.SeRFIDpub_BufGetTagNum(_Hcom, _RAddr, ref TagCount);
            //        if (TagCount > 0)
            //        {
            //            for (int i = 0; i < TagCount; i++)
            //            {
            //                iStatus = RFCardCommon.SeRFIDpub_BufGetOneAndClear(_Hcom, _RAddr, ref TagID[0]);
            //                string strID = "";
            //                if (iStatus == 0)
            //                {
            //                    for (int j = 1; j < 13; j++)
            //                    {
            //                        //if (TagID[j] < 16)
            //                        //    strID = strID;
            //                        strID = strID + Convert.ToString(TagID[j], 16);
            //                    }
            //                    if (!_CardCode.Contains(strID) && strID != "000000000000")
            //                    {
            //                        _CardCode = _CardCode + strID + ",";
            //                    }
            //                    if (SetUIValue != null)
            //                    {
            //                        SetUIValue(sender, e);
            //                    }
            //                }
            //            }
            //        }
            //        tmTrick.Start();
            //    }
            //    iStatus = RFCardCommon.SeRFIDGen2_End(_Hcom, _RAddr);
            //}
            //catch
            //{ }
            //------------------------------------单标签读方式(e n d)--------------------------------------------



            //------------------------------------多标签读方式(start)--------------------------------------------
            try
            {
                byte[] TagData = new byte[13];
                byte   QValue = 4;
                byte   Bank = 1, Point = 0, ReadLen = 12; //标签号的块地址,与块内偏移量,以及标签长度
                byte   MaskLength = 0;                    //用于匹配的长为0,即不匹配标签,对所有标签都进行操作
                byte[] Mask       = new byte[16];

                tmTrick.Stop();

                if (iStatus == 0 && RFCardCommon.SeRFIDGen2_MultiRead(_Hcom, _RAddr, QValue, Bank, Point, ReadLen, MaskLength, Mask) == 0 && RFCardCommon.SeRFIDpub_BufGetTagNum(_Hcom, _RAddr, ref TagCount) == 0)
                {
                    for (int i = 1; i <= TagCount; i++)
                    {
                        if (iStatus == 0 && RFCardCommon.SeRFIDpub_BufGetOneAndClear(_Hcom, _RAddr, ref TagData[0]) == 0)
                        {
                            if (TagData.Length == 13)
                            {
                                string strRemoteCardCode = "";
                                for (int j = 1; j < TagData.Length; j++)
                                {
                                    try
                                    {
                                        short  BTagData = TagData[j];
                                        string data     = Convert.ToString(TagData[j], 16);
                                        strRemoteCardCode = strRemoteCardCode + data.PadLeft(2, '0');
                                    }
                                    catch
                                    {
                                        break;
                                    }
                                }
                                //暂时用最后10位
                                strRemoteCardCode = strRemoteCardCode.Substring(14);
                                if (!_CardCode.Contains(strRemoteCardCode) && strRemoteCardCode != "000000000000")
                                {
                                    _CardCode = _CardCode + strRemoteCardCode + ",";
                                }
                                if (SetUIValue != null)
                                {
                                    SetUIValue(sender, e);
                                }
                            }
                        }
                    }
                }
                tmTrick.Start();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            //------------------------------------多标签读方式(e n d)--------------------------------------------
        }