示例#1
0
        /// <summary>
        /// 关闭串口
        /// </summary>
        /// <returns></returns>
        public bool DisConnect()
        {
            // 关闭串口
            int iRet = StaticClassReaderB.CloseSpecComPort(Port);

            //
            if (iRet == 0)
            {
                Port      = -1;
                FrmHandle = -1;
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 修改密码 销毁密码
        /// 谨慎操作 用于销毁标签
        /// </summary>
        /// <param name="epc"></param>
        /// <param name="old_pwd"></param>
        /// <param name="new_pwd"></param>
        public static void ChangeAdminPwd(string epc, string old_pwd, string new_pwd)
        {
            if (!IsOper)
            {
                throw new Exception("请先打开串口");
            }
            if (string.IsNullOrEmpty(epc) || string.IsNullOrEmpty(old_pwd) || string.IsNullOrEmpty(new_pwd))
            {
                throw new Exception("请补全信息");
            }
            if (old_pwd.Length != 8 || new_pwd.Length != 8)
            {
                throw new Exception("密码长度要为8位");
            }
            byte WrittenDataNum = 0;
            byte ENum           = Convert.ToByte(epc.Length / 4);
            byte EPClen         = Convert.ToByte(ENum * 2);

            byte[] bEPC = new byte[ENum];
            bEPC = RFIDResources.HexStringToByteArray(epc);

            bPassWord = RFIDResources.HexStringToByteArray(old_pwd);
            byte Wnum = Convert.ToByte(new_pwd.Length / 4);

            byte[] WriteData = new byte[Wnum * 2];
            WriteData = RFIDResources.HexStringToByteArray(new_pwd);
            byte WriteDataLen = Convert.ToByte(Wnum * 2);

            int flag = StaticClassReaderB.WriteCard_G2(ref ComAdr, bEPC,
                                                       RFIDResources.MemReser, 0x0, WriteDataLen, WriteData,
                                                       bPassWord, 0, 0, 0, WrittenDataNum, EPClen, ref errcode, handle);

            if (flag != 0)
            {
                if (errcode > -1)
                {
                    throw new Exception(RFIDResources.GetErrorCodeDesc(errcode));
                }
                else
                {
                    throw new Exception(RFIDResources.GetReturnCodeDesc(flag));
                }
            }

            SetRegiSec(epc, new_pwd);
        }
示例#3
0
        public static string ReadDataOfTID(string epc, string pwd)
        {
            if (!IsOper)
            {
                throw new Exception("请先打开串口");
            }
            if (string.IsNullOrEmpty(epc) || string.IsNullOrEmpty(pwd))
            {
                throw new Exception("请补全信息");
            }
            if (pwd.Length != 8)
            {
                throw new Exception("密码长度要为8位");
            }

            byte ENum   = Convert.ToByte(epc.Length / 4);
            byte EPCLen = Convert.ToByte(epc.Length / 2);

            byte[] bEPC = new byte[ENum];
            bEPC = RFIDResources.HexStringToByteArray(epc);

            bPassWord = RFIDResources.HexStringToByteArray(pwd);
            byte Num = Convert.ToByte(12);

            byte[] bData = new byte[320];

            int flag = StaticClassReaderB.ReadCard_G2(ref ComAdr, bEPC, RFIDResources.MemTID, 0x00
                                                      , Num, bPassWord, 0, 0, 0, bData, EPCLen, ref errcode, handle);

            if (flag != 0)
            {
                if (errcode > -1)
                {
                    throw new Exception(RFIDResources.GetErrorCodeDesc(errcode));
                }
                else
                {
                    throw new Exception(RFIDResources.GetReturnCodeDesc(flag));
                }
            }
            byte[] daw = new byte[Num * 2];
            Array.Copy(bData, daw, Num * 2);
            string str = RFIDResources.ByteArrayToHexString(daw);

            return(str);
        }
示例#4
0
        /// <summary>
        /// 设置桌面发卡器功率
        /// </summary>
        /// <param name="powerDb">功率对应db值,范围1-18,桌面发卡器一般采用默认值</param>
        /// <returns></returns>
        public bool SetPowerDbm(int powerDb)
        {
            int  fCmdRet  = -1;
            byte powerDbm = (byte)powerDb;

            // 设置桌面发卡器功率
            fCmdRet = StaticClassReaderB.SetPowerDbm(ref ComAdr, powerDbm, FrmHandle);

            if (fCmdRet == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        public bool OpenConnection()
        {
            try
            {
                comAddress = Convert.ToByte("FF", 16);
                baudRate   = Convert.ToByte(5);

                powerDbm = Convert.ToByte(_readerProfile.PowerDbm);

                port = 0;
                int openResult;

                openResult = 30;
                //  Cursor = Cursors.WaitCursor;

                comAddress = Convert.ToByte("FF", 16);
                baudRate   = Convert.ToByte(5);
                if (_readerProfile.ComPort == ComPort.Auto)
                {
                    openResult =
                        StaticClassReaderB.AutoOpenComPort(ref port, ref comAddress, baudRate,
                                                           ref comPortIndex); //automatically detects a com port and connects it with the reader
                }
                else
                {
                    comPortIndex = (int)_readerProfile.ComPort;
                    openResult   = StaticClassReaderB.OpenComPort(comPortIndex, ref comAddress, baudRate,
                                                                  ref comPortIndex);
                }
                openComIndex = comPortIndex;

                if (openResult == 0)
                {
                    return(true);
                }
                logger.Error("Serial Communication Error or Occupied - result code : {0}", openResult);
                MessageBox.Show("Serial Communication Error or Occupied - result code: " + openResult);
            }
            catch (Exception ex)
            {
                logger.Error("Open connection: {0}, {1}", ex.Message, ex.ToString());
                MessageBox.Show("Serial Communication Error or Occupied - exception message " + ex.Message);
            }

            return(false);
        }
示例#6
0
        public string WriteEpc()
        {
            lock (_locker)
            {
                #region ReaderRequirements

                byte   WordPtr = 1, ENum;
                byte   Mem            = 1;
                byte   WNum           = 0;
                byte   EPClength      = 0;
                byte   Writedatalen   = 0;
                int    WrittenDataNum = 0;
                byte[] CardData       = new byte[320];
                byte[] writedata      = new byte[230];

                byte MaskFlag = 0, MaskAdd = 0, MaskLen = 0;

                var fPassword = RfidConversion.HexStringToByteArray("00000000");

                #endregion ReaderRequirements

                var epcVal = Read_Epc();

                #region Setup GUID

                var guid = Guid.NewGuid().ToString().Replace("-", null).ToUpper(); //32 characters long
                guid      = guid + epcVal.Substring(epcVal.Length - 4);
                ENum      = Convert.ToByte(epcVal.Length / 4);
                EPClength = Convert.ToByte(ENum * 2);
                byte[] EPC = new byte[ENum];

                WNum = Convert.ToByte(guid.Length / 4);
                byte[] Writedata = new byte[WNum * 2];

                Writedata    = RfidConversion.HexStringToByteArray(guid);
                Writedatalen = Convert.ToByte(WNum * 2);

                #endregion Setup GUID

                _fCmdRet = StaticClassReaderB.WriteCard_G2(ref Reader.ComAddrr, EPC, Mem, WordPtr,
                                                           Writedatalen, Writedata, fPassword, MaskAdd, MaskLen, MaskFlag, WrittenDataNum,
                                                           EPClength, ref Reader.ErrorCode, Reader.ComAddrr);

                return(guid);
            }
        }
示例#7
0
        private void BtnOpenPort_Click(object sender, RoutedEventArgs e)
        {
            int port = 0;

            fComAdr = System.Convert.ToByte("FF", 16);
            //fBaud = System.Convert.ToByte('5');  //5 - 576000
            fBaud = 5;
            int openResultCode = 30;

            //string openResultStr = "Nothing Happened";

            try
            {
                openResultCode = StaticClassReaderB.AutoOpenComPort(ref port, ref fComAdr, fBaud, ref fOpenComIndex);
                //fOpenComIndex = frmcomportindex;

                if (openResultCode == 0)
                {
                    ComOpen = true;
                }
                else if ((fCmdRet == 0x35) | (fCmdRet == 0x30)) //0011 1001 | 0011 0000
                {
                    StaticClassReaderB.CloseSpecComPort(fOpenComIndex);
                    ComOpen = false;
                }
            }
            finally
            {
                //LbStatInfo.Content = System.Convert.ToString(GetReturnCodeDesc(openResultCode));
                //LbStatPort.Content = "COM:" + System.Convert.ToString(port);
                //LbStatBaud.Content = "Baud:" + System.Convert.ToString(fBaud);
                //LbStatReaderType.Content = "Type:";
                //LbStatResultCode.Content = "RCode:" + System.Convert.ToString(openResultCode);
                //LbStatAddr.Content = "Addr:" + System.Convert.ToString(fComAdr);
                //LbStatPower.Content = "Pow:";

                //LbReturn.Content =
                //    "COM = " + System.Convert.ToString(port) + "\n"
                //    + "fComAdr = " + System.Convert.ToString(fComAdr) + "\n"
                //    + "fOpenComIndex = " +System.Convert.ToString(fOpenComIndex) + "\n"
                //    + "openResultCode = " + System.Convert.ToString(openResultCode);

                //openResultStr = GetReturnCodeDesc(openResultCode);
                //MessageBox.Show(openResultStr);
            }
        }
示例#8
0
        /// <summary>
        /// 查询标签EPC或TID信息
        /// </summary>
        /// <param name="TIDFlag">TID地址</param>
        /// <param name="AdrTID">以字为单位的TID长度</param>
        /// <param name="LenTID">标志位,0表示查询EPC,1表示查询TID</param>
        /// <returns></returns>
        public string Inventory_G2(byte TIDFlag, byte AdrTID, byte LenTID)
        {
            if (Port == 0)
            {
                return("");
            }
            // 一字节的EPC的长度+ EPC的字节数组表示
            byte[] EPC = new byte[5000];

            // 返回的EPC的实际字节数
            int Totallen = 0;

            // 查询到的标签数量
            int CardNum = 0;
            int iCount  = 0;
            // TID地址
            //byte AdrTID = 0;
            // 以字为单位的TID长度
            //byte LenTID = 8;
            // 标志位,0表示查询EPC,1表示查询TID
            //byte TIDFlag = 1;

            string hexEPC = "";

            while (iCount < 100)
            {
                int fCmdRet = StaticClassReaderB.Inventory_G2(ref ComAdr, AdrTID, LenTID, TIDFlag, EPC, ref Totallen, ref CardNum, FrmHandle);
                if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4) | (fCmdRet == 0xFB))//代表已查找结束
                {
                    byte[] daw = new byte[Totallen];
                    Array.Copy(EPC, daw, Totallen);
                    string temps = ByteArrayToHexString(daw);
                    //
                    if (CardNum > 0)
                    {
                        int EPClen = daw[0];
                        hexEPC = temps.Substring(2, EPClen * 2);

                        break;
                    }
                }
                iCount++;
            }
            return(hexEPC);
        }
示例#9
0
        /// <summary>
        /// 打开指定端口
        /// </summary>
        /// <param name="port"></param>
        public static void OpenCard(int port)
        {
            if (IsOper)
            {
                throw new Exception("串口已打开");
            }
            int flag = StaticClassReaderB.OpenComPort(port, ref ComAdr,
                                                      Convert.ToByte(RFIDResources._57600bps), ref handle);

            if (flag == 0)
            {
                IsOper = true;
            }
            else
            {
                throw new Exception(RFIDResources.GetReturnCodeDesc(flag));
            }
        }
示例#10
0
        public static Boolean Open(Int32 serialPort, byte deviceId, byte baudRateCode)
        {
            Int32 handle = 0;

            var result = StaticClassReaderB.OpenComPort(serialPort, ref deviceId, baudRateCode, ref handle);

            DictionaryAdd(serialPort, deviceId, baudRateCode, handle);

            var success = result == 0;

            if (!success)
            {
                var msg = $"UHF端口打开失败! {Environment.NewLine}serialPort:[{serialPort.ToString()}] deviceId:[{deviceId.ToString()}]"
                          + $" baudRateCode:[{baudRateCode.ToString()}] OpenResult:[{result.ToString()}]";
            }

            return(success);
        }
示例#11
0
        /// <summary>
        /// 14443AAnticol 获取卡号
        /// </summary>
        /// <returns></returns>
        public bool Anticoll14443A()
        {
            int  fCmdRet   = 0x30;
            byte reserved  = 0;
            byte errorCode = 0;

            fCmdRet = StaticClassReaderB.ISO14443AAnticoll(ref readerAddr, reserved, SNR, ref errorCode, portFrmIndex);

            if (fCmdRet == 0)
            {
                string ReaderNumber = ByteArrayToHexString(SNR).Replace(" ", "");
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        public LongRangeRFID()
        {
            _ComAddr = Convert.ToByte("FF", 16);
            _Baud    = Convert.ToByte("5", 10);
            var ok = StaticClassReaderB.AutoOpenComPort(ref _Port, ref _ComAddr, _Baud, ref _PortHandle);

            if (ok != 0) // zero is sucess
            {
                throw new InvalidOperationException("Port cannot be opened. Long RFID");
            }

            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += Bw_DoWork;
            bw.WorkerReportsProgress = true;
            bw.ProgressChanged      += Bw_ProgressChanged;
            bw.RunWorkerAsync();
        }
示例#13
0
 /// <summary>
 /// 关闭读卡器网口连接
 /// </summary>
 /// <returns></returns>
 public bool CloseNetPort()
 {
     if (portFrmIndex > 1023)
     {
         int fCmdRet = StaticClassReaderB.CloseNetPort(portFrmIndex);
         if (fCmdRet == 0)
         {
             portFrmIndex = -1;
             SetStatus(false);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
示例#14
0
        /// <summary>
        /// 14443ARequest 获取卡类型
        /// </summary>
        /// <returns></returns>
        public bool Request14443A()
        {
            int fCmdRet = 0x30;

            byte[] Data      = new byte[2];
            byte   errorCode = 0;

            fCmdRet = StaticClassReaderB.ISO14443ARequest(ref readerAddr, 1, Data, ref errorCode, portFrmIndex);
            if (fCmdRet == 0)
            {
                string ReaderType = ByteArrayToHexString(Data).Replace(" ", "");
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#15
0
文件: SgUrb3RW.cs 项目: qq5013/ZAOJU3
        /// <summary>
        /// 连接
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            int re = StaticClassReaderB.OpenNetPort((int)netPort, ipStr, ref comAddr, ref portHandle);

            if (re == 0x35)
            {
                StaticClassReaderB.CloseNetPort(portHandle);
                re = StaticClassReaderB.OpenNetPort((int)netPort, ipStr, ref comAddr, ref portHandle);
            }
            if (re == 0x00)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#16
0
        /// <summary>
        /// 14443ASelect 获取卡容量大小
        /// </summary>
        /// <returns></returns>
        public bool Select14443A()
        {
            int  fCmdRet   = 0x30;
            byte errorCode = 0;
            byte size      = 0;

            fCmdRet = StaticClassReaderB.ISO14443ASelect(ref readerAddr, SNR, ref size, ref errorCode, portFrmIndex);

            if (fCmdRet == 0)
            {
                string ReaderSize = Convert.ToString(size, 16);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#17
0
        private bool Request()
        {
            int fCmdRet = 0x30;

            byte[] Data      = new byte[2];
            byte   errorCode = 0;

            fCmdRet = StaticClassReaderB.ISO14443ARequest(ref this.comAddr, 1, Data, ref errorCode, this.readHandle);

            if (fCmdRet == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#18
0
        /// <summary>
        /// 读用户区数据,返回ascii字符串
        /// </summary>
        /// <param name="hexEPC">十六进制epc字符串</param>
        /// <param name="offset">十进制偏移字数</param>
        /// <param name="readNum">十进制读取字数</param>
        /// <returns></returns>
        public string ReadUserData(string hexEPC, string offset, string readNum)
        {
            string userData = "";

            if (Port == 0)
            {
                return("");
            }

            //if (Port == 0 || hexEPC.Length <= 0)
            //{
            //    return "";
            //}

            if (offset.Length <= 0 || readNum.Length <= 0)
            {
                return("");
            }
            //
            byte maskFlag = 0;
            byte maskadr  = 0;
            byte maskLen  = 0;

            byte[] EPC = new byte[hexEPC.Length / 2];
            EPC = HexStringToByteArray(hexEPC);
            byte Mem     = 0x03;//用户区
            byte WordPtr = Convert.ToByte(offset.Trim(), 10);
            byte Num     = Convert.ToByte(readNum);

            byte[] fPassWord  = HexStringToByteArray("00000000");
            byte[] Data       = new byte[1320];
            byte   EPClength  = (Byte)EPC.Length;
            Int32  ferrorcode = -1;
            //
            Int32 fCmdRet = StaticClassReaderB.ReadCard_G2(ref ComAdr, EPC, Mem, WordPtr, Num, fPassWord, maskadr, maskLen, maskFlag, Data, EPClength, ref ferrorcode, FrmHandle);

            if (fCmdRet == 0)
            {
                byte[] daw = new byte[Num * 2];
                Array.Copy(Data, daw, Num * 2);
                userData = ByteArrayToString(daw);
            }
            return(userData);
        }
示例#19
0
        /// <summary>
        /// 写标签
        /// </summary>
        /// <param name="epc"></param>
        /// <param name="pwd"></param>
        public static void WriteEPC(string epc, string pwd)
        {
            if (!IsOper)
            {
                throw new Exception("请先打开串口");
            }
            if (string.IsNullOrEmpty(epc))
            {
                throw new Exception("EPC不能为空");
            }
            if (epc.Length % 2 != 0)
            {
                throw new Exception("EPC长度必须是2的倍数");
            }
            if (string.IsNullOrEmpty(pwd))
            {
                throw new Exception("密码不能为空");
            }
            if (pwd.Length != 8)
            {
                throw new Exception("密码长度要为8位");
            }

            byte epcLen = Convert.ToByte(epc.Length / 2);
            byte eNum   = Convert.ToByte(epc.Length / 4);

            byte[] EPC = new byte[eNum];
            EPC       = RFIDResources.HexStringToByteArray(epc);
            bPassWord = RFIDResources.HexStringToByteArray(pwd);
            int flag = StaticClassReaderB.WriteEPC_G2(ref ComAdr, bPassWord, EPC, epcLen,
                                                      ref errcode, handle);

            if (flag != 0)
            {
                if (errcode > -1)
                {
                    throw new Exception(RFIDResources.GetErrorCodeDesc(errcode));
                }
                else
                {
                    throw new Exception(RFIDResources.GetReturnCodeDesc(flag));
                }
            }
        }
示例#20
0
        /// <summary>
        ///  打开读写器
        /// </summary>
        /// <param name="pRfidCfg"></param>
        private bool OpenReader(RfidCfg pRfidCfg)
        {
            bool rtn = false;

            try
            {
                if (pRfidCfg.ConType == DeviceConType.Net)
                {
                    int temp = ReaderB.StaticClassReaderB.OpenNetPort(int.Parse(pRfidCfg.Port), pRfidCfg.Ip, ref _readerAddr, ref _readerHandel);
                    if (temp != 0)
                    {
                        RFIDReaderLogger.Error(string.Format("打开RFID读写器失败。IP={0},端口={1}", pRfidCfg.Ip, pRfidCfg.Port), pRfidCfg.Ip);
                    }
                    else
                    {
                        rtn = true;
                    }
                }
                else //if (pRfidCfg.ConType == "串口")
                {
                    byte indexBaud = GetBaudrateIndex(pRfidCfg.Baudrate);
                    comPort = int.Parse(pRfidCfg.ComPort.ToUpper().Replace("COM", ""));
                    if (indexBaud != byte.MaxValue)
                    {
                        int temp = StaticClassReaderB.OpenComPort(comPort, ref _readerAddr, indexBaud, ref _readerHandel);
                        if (temp != 0)
                        {
                            RFIDReaderLogger.Error(string.Format("打开RFID读写器失败。ComPort={0}", pRfidCfg.ComPort), pRfidCfg.ComPort);
                        }
                        else
                        {
                            rtn = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                RFIDReaderLogger.Error("连接RFID读写器异常。", pRfidCfg.Ip, ex);
            }

            return(rtn);
        }
示例#21
0
文件: SgUrb3RW.cs 项目: qq5013/ZAOJU3
        private byte[] Inventory_EPC()
        {
            byte[] EPC      = new byte[64];
            int    Totallen = 0;
            int    CardNum  = 0;
            int    fCmdRet  = StaticClassReaderB.Inventory_G2(ref comAddr, 0, 0, 0, EPC, ref Totallen, ref CardNum, portHandle);

            if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4) | (fCmdRet == 0xFB))//代表已查找结束
            {
                byte   epcLen   = EPC[0];
                byte[] validEPC = new byte[epcLen];
                Array.Copy(EPC, 1, validEPC, 0, epcLen);
                return(validEPC);
            }
            else
            {
                return(null);
            }
        }
示例#22
0
        public bool Connect()
        {
            if (port > 0)
            {
                StaticClassReaderB.CloseSpecComPort(FrmHandle);
            }
            ActiveAllCom();
            int iRet = StaticClassReaderB.AutoOpenComPort(ref port, ref ComAdr, Baud, ref FrmHandle);

            if (iRet == 0)
            {
                isConnected = 1;
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#23
0
        //7-3.读取主动模式数据
        private string getActiveModeData(byte fComAdr, int frmcomportindex)
        {
            byte[] data       = new byte[100];
            int    dataLength = 0;
            string temps      = "";

            fCmdRet = StaticClassReaderB.ReadActiveModeData(data, ref dataLength, frmcomportindex);

            int count = dataLength / 24;

            for (int i = 0; i < count; i++)
            {
                byte[] daw = new byte[19];
                Array.Copy(data, 7, daw, 0, 19);                //从data第7个字节开始复制到daw,复制19字节
                temps = ByteArrayToHexString(daw);              //7-5.字节转为十六进制
            }

            return(temps);
        }
示例#24
0
        public void Test()
        {
            var  serialPort = 3;
            byte deviceId   = 1;
            byte baudRate   = 5;
            var  handle     = 0;

            var result = StaticClassReaderB.OpenComPort(serialPort, ref deviceId, baudRate, ref handle);

            Console.WriteLine("open的返回值:{result.ToString()}");
            Console.WriteLine("设备id:{deviceId.ToString()}");
            Console.WriteLine("句柄:{handle.ToString()}");

            if (0 == result)
            {
                byte   addrTID    = 0;
                byte   lenOfTID   = 0;
                byte   flagTID    = 0;
                byte[] buffer     = new byte[100];
                int    dataLen    = 0;
                int    labelCount = 0;
                //读标签
                result = StaticClassReaderB.Inventory_G2(ref deviceId, addrTID, lenOfTID, flagTID, buffer, ref dataLen, ref labelCount, handle);

                Console.WriteLine("查询的返回值:{result.ToString()}");
                Console.WriteLine("labelCount:{labelCount.ToString()}");
                Console.WriteLine("dataLen:{dataLen.ToString()}");

                if (labelCount > 0)
                {
                    var pos       = 0;
                    var data      = buffer.Take(dataLen).ToArray();
                    var rawString = BitConverter.ToString(data).Replace("-", "");
                    for (int i = 0; i < labelCount; i++)
                    {
                        var len = data[pos];
                        var str = rawString.Substring(pos * 2 + 2, len * 2);
                        Console.WriteLine("标签:{str}");
                        pos += len + 1;
                    }
                }
            }
        }
示例#25
0
        private static void SetRegiSec(string epc, string pwd)
        {
            if (string.IsNullOrEmpty(epc) || string.IsNullOrEmpty(pwd))
            {
                throw new Exception("请补全信息");
            }
            if (pwd.Length != 8)
            {
                throw new Exception("密码长度要为8位");
            }

            byte Enum   = Convert.ToByte(epc.Length / 4);
            byte EPClen = Convert.ToByte(epc.Length / 2);

            byte[] bEPC = new byte[Enum];
            bEPC = RFIDResources.HexStringToByteArray(epc);

            bPassWord = RFIDResources.HexStringToByteArray(pwd);

            List <byte> lis = new List <byte>()
            {
                0x00, 0x01, 0x02, 0x04
            };

            foreach (byte b in lis)
            {
                int flag = StaticClassReaderB.SetCardProtect_G2(ref ComAdr, bEPC, b, 0x02, bPassWord
                                                                , 0, 0, 0, EPClen, ref errcode, handle);
                if (flag != 0)
                {
                    if (errcode > -1)
                    {
                        throw new Exception(RFIDResources.GetErrorCodeDesc(errcode));
                    }
                    else
                    {
                        throw new Exception(RFIDResources.GetReturnCodeDesc(flag));
                    }
                }

                Thread.Sleep(10);
            }
        }
示例#26
0
        //
        //返回第一个标签,如果没读到的话返回空
        //
        public static String read_com(object openComIndex)
        {
            int fOpenComIndex = (int)openComIndex;
            int CardNum = 0;
            int Totallen = 0;
            int EPClen, m;

            byte[] EPC = new byte[5000];
            int    CardIndex;
            string temps;
            string sEPC;
            byte   AdrTID  = 0;
            byte   LenTID  = 0;
            byte   TIDFlag = 0;
            int    fCmdRet;
            byte   fComAdr = 0xff;

            fCmdRet = StaticClassReaderB.Inventory_G2(ref fComAdr, AdrTID, LenTID, TIDFlag, EPC, ref Totallen, ref CardNum, fOpenComIndex);
            if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4) | (fCmdRet == 0xFB))//代表已查找结束,
            {
                byte[] daw = new byte[Totallen];
                Array.Copy(EPC, daw, Totallen);
                temps = ByteArrayToHexString(daw);
                m     = 0;
                if (CardNum == 0)
                {
                    return(null);
                }
                for (CardIndex = 0; CardIndex < CardNum; CardIndex++)//返回第一个标签
                {
                    EPClen = daw[m];
                    sEPC   = temps.Substring(m * 2 + 2, EPClen * 2);
                    m      = m + EPClen + 1;
                    if (sEPC.Length != EPClen * 2)
                    {
                        return(null);
                    }
                    return(sEPC);
                }
            }
            return(null);
        }
示例#27
0
        //public void timeStart()
        //{
        //    timerRead.Start();
        //}

        //public void timeStop()
        //{
        //    timerRead.Stop();
        //}

        public bool SetAnt(DeviceUsing ant1, DeviceUsing ant2, DeviceUsing ant3, DeviceUsing ant4)
        {
            bool blRet = false;

            try
            {
                byte ANT = 0;
                if (ant1 == DeviceUsing.启用)
                {
                    ANT = Convert.ToByte(ANT | 1);
                }
                if (ant2 == DeviceUsing.启用)
                {
                    ANT = Convert.ToByte(ANT | 2);
                }
                if (ant3 == DeviceUsing.启用)
                {
                    ANT = Convert.ToByte(ANT | 4);
                }
                if (ant4 == DeviceUsing.启用)
                {
                    ANT = Convert.ToByte(ANT | 8);
                }
                int iRet = StaticClassReaderB.SetAntennaMultiplexing(ref fComAdr, ANT, frmcomportindex);
                if (iRet == 0)
                {
                    blRet = true;
                }
                else
                {
                    blRet = false;
                }
            }
            catch (Exception ex)
            {
                if (frmMain.blDebug)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
            return(blRet);
        }
示例#28
0
        public void ClosePort()
        {
            int    port = fOpenComIndex;
            string temp;

            fCmdRet = StaticClassReaderB.CloseSpecComPort(port);
            if (fCmdRet == 0)
            {
                fComAdr = 0xFF;
                //StaticClassReaderB.OpenComPort(port, ref fComAdr, fBaud, ref frmcomportindex);
                fOpenComIndex = frmcomportindex;
                fOpenComIndex = -1;

                Console.WriteLine("Successfully Close COM" + port);
            }
            else
            {
                Console.WriteLine("Error : Serial Communication Error. Can't Close COM Port.");
            }
        }
示例#29
0
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="str">写入的数据</param>
        /// <param name="blockNumber">扇区</param>
        /// <param name="sectorNumber">块区</param>
        /// <returns></returns>
        public bool Write14443(string str, int sectorNumber, int blockNumber)
        {
            byte block = 0, errorCode = 0;

            byte[] data    = new byte[16];
            int    fCmdRet = 0x30;

            if (sectorNumber > 32)
            {
                block = (byte)(128 + (sectorNumber - 32) * 16 + blockNumber);
            }
            else
            {
                block = (byte)(sectorNumber * 4 + blockNumber);
            }
            str     = StringToHexString(str);
            data    = HexStringToByteArray(str);
            fCmdRet = StaticClassReaderB.ISO14443AWrite(ref readerAddr, block, data, ref errorCode, portFrmIndex);
            return(fCmdRet == 0);
        }
示例#30
0
        /// <summary>
        /// 关闭设备
        /// </summary>
        /// <returns></returns>
        public bool CloseCom()
        {
            try
            {
                SetStatus(false);

                StaticClassReaderB.CloseSpecComPort(this.Com);

                return(true);
            }
            catch (Exception ex)
            {
                if (OnScanError != null)
                {
                    OnScanError(ex);
                }
            }

            return(false);
        }