/// <summary> /// 设置读写器为ISO14443A模式。 /// </summary> public bool Change14443() { int ret = 0x30; ret = StaticClassReaderA.ChangeToISO14443A(ref _readerAddr, _portIndex); if (ret == 0) { return(true); } else { Loger.Error(GetReturnCodeMessage(ret)); return(false); } }
/// <summary> /// 打开串口 /// </summary> public bool OpenComPort() { int ret = 0x30; byte fbaud = 0; //用该值设置或更改串口通讯控件的波特率 _autoOpenComPort = Convert.ToBoolean(ConfigurationManager.AppSettings["AutoOpenComPort"]); if (_autoOpenComPort) { ret = StaticClassReaderA.AutoOpenComPort(ref _comPort, ref _readerAddr, fbaud, ref _portIndex); //自动连接串口 } else { _comPort = Convert.ToInt32(ConfigurationManager.AppSettings["ComPort"]); for (int i = 0; i <= 3; i++) { fbaud = Convert.ToByte(i); ret = StaticClassReaderA.OpenComPort(_comPort, ref _readerAddr, fbaud, ref _portIndex); } } if (ret == 0x30 || ret == 0x35)//端口已经打开 { CloseComPort(); ret = 0x30; if (_autoOpenComPort) { ret = StaticClassReaderA.AutoOpenComPort(ref _comPort, ref _readerAddr, fbaud, ref _portIndex); //自动连接串口 } else { for (int i = 0; i <= 3; i++) { fbaud = Convert.ToByte(i); ret = StaticClassReaderA.OpenComPort(_comPort, ref _readerAddr, fbaud, ref _portIndex); } } } if (ret == 0) { return(true); } else { Loger.Error(GetReturnCodeMessage(ret)); return(false); } }
/// <summary> /// 读取有效范围内14443A卡的序列号。 /// </summary> /// <param name="hid">14443A卡的序列号。</param> /// public bool GetHid(ref string hid) { int ret = 0x30; byte[] sn = new byte[4]; ret = StaticClassReaderA.GetUIDofHID(ref _readerAddr, sn, _portIndex); if (ret == 0) { hid = ByteArrayToHexString(sn); return(true); } else { Loger.Error(GetReturnCodeMessage(ret)); return(false); } }
/// <summary> /// 检查有效范围内是否有符合协议的电子标签存在。 /// </summary> /// <param name="uidList">符合协议的电子标签序列号集合</param> public bool GetUidList(out IEnumerable <string> uidList) { int ret = 0x30; byte state = 6; //默认不带AFI的InventoryScan byte afi = 0; //当查询命令为Selected模式时,需要输入电子标签的AFI数值。 byte[] dsfidAndUid = new byte[2300]; //指向输出数组变量,每个数组单元为9个字节,包括8个字节的UID和1个字节的DSFID信息。数组中的有效数据总量为CardNum*9个字节。 byte cardNumber = 0; //电子标签的张数。 ret = StaticClassReaderA.Inventory(ref _readerAddr, ref state, ref afi, dsfidAndUid, ref cardNumber, _portIndex); switch (ret) { case 0x0A: case 0x0B: case 0x0E: { Array.Resize(ref dsfidAndUid, cardNumber * 9); string str = ByteArrayToHexString(dsfidAndUid); if (ret == 0x0E || ret == 0x0B) { uidList = Enumerable.Range(0, cardNumber).Select(i => str.Substring(18 * i, 18).Substring(2, 16)); return(true); } } break; default: { Loger.Error(GetReturnCodeMessage(ret)); } break; } uidList = Enumerable.Empty <string>(); return(false); }
public void CloseComPort() { StaticClassReaderA.CloseSpecComPort(_portIndex); }