/// <summary> /// 卡机内是否有卡 /// </summary> /// <returns></returns> public static bool CardUsable() { bool iss = false; int handle = 0; try { string port = SysConfigHelper.readerNode("CRT310Port"); StringBuilder info = new StringBuilder(1024); handle = CRT310.CommOpen("COM" + port); //读卡器状态 Byte atPosition = new byte(); Byte frontSetting = new byte(); Byte rearSetting = new byte(); //读取状态 int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting); if ((atPosition == 0x4b) || (atPosition == 0x4a)) { iss = true; } } catch (Exception e) { throw new Exception("系统异常"); } finally { CRT310.CommClose(handle); } return(iss); }
/// <summary> /// 电动读卡器吞卡 /// </summary> public static void swallowCard() { int handle = 0; try { string port = SysConfigHelper.readerNode("CRT310Port"); StringBuilder info = new StringBuilder(260); handle = CRT310.CommOpen("COM" + port); //读卡器状态 Byte atPosition = new byte(); Byte frontSetting = new byte(); Byte rearSetting = new byte(); //读取状态 int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting); if ((atPosition == 0x4b) || (atPosition == 0x4a)) { //进卡控制,不进卡 CRT310.CRT310_CardSetting(handle, 0x1, 0x1); //弹卡 CRT310.CRT310_Reset(handle, 2); SysBLL.isSwallowCard = "9999"; } } catch (Exception e) { throw new Exception("系统异常"); } finally { CRT310.CommClose(handle); } }
//public override Card getCardInfo(string cardNo) //{ // //TODO 调用万通卡查询余额的方法,返回卡片信息 // return null; //} //public override bool Recharge(string cardNo, int gasValue) //{ // throw new NotImplementedException(); //} //public override bool Recharge(string cardNo, double moneyCount) //{ // //TODO 调用拉卡拉消费的方法 // //TODO 调用拉卡拉消费的方法,如果失败,提示错误,跳出方法 // //TODO 调用拉卡拉消费的方法,如果成功,调用万通卡的充值方法 // return false; //} /// <summary> /// 调用读卡器,拿到万通卡卡号 /// </summary> /// <returns></returns> public string GetCardNo() { string port = SysConfigHelper.readerNode("CRT310Port"); StringBuilder info = new StringBuilder(260); int handle = CRT310.CommOpen("COM" + port); try { //进卡控制 CRT310.CRT310_CardSetting(handle, 0x3, 0x1); //停卡位置 CRT310.CRT310_CardPosition(handle, 0x4); Byte atPosition = new byte(); Byte frontSetting = new byte(); Byte rearSetting = new byte(); //读取状态 int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting);//卡没插好,怎么办 Byte cpuType = new byte(); Byte[] exdata = new byte[1024]; int exdataLen = 0; //CPU卡复位 CRT310.CPU_ColdReset(handle, 0x0, ref cpuType, exdata, ref exdataLen); executeAPDU(handle, "00A40000023F00"); executeAPDU(handle, "00A40000023F20"); string cardNoSource = executeAPDU(handle, "00B0950000"); //进卡控制 CRT310.CRT310_CardSetting(handle, 0x1, 0x1); string result = DecryptCardNo(cardNoSource); return(result); } catch (Exception e) { throw new WtException(WtExceptionCode.Card.WT_READ_CARD, e.Message); } finally { //关闭端口 CRT310.CommClose(handle); } }
/// <summary> /// 电动读卡器退卡 /// </summary> public static void backCard() { int handle = 0; try { string port = SysConfigHelper.readerNode("CRT310Port"); StringBuilder info = new StringBuilder(1024); handle = CRT310.CommOpen("COM" + port); //进卡控制,不进卡 CRT310.CRT310_CardSetting(handle, 0x1, 0x1); //读卡器状态 Byte atPosition = new byte(); Byte frontSetting = new byte(); Byte rearSetting = new byte(); //读取状态 int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting); if ((atPosition == 0x4a) || (atPosition == 0x4b) || (atPosition == 0x4c) || (atPosition == 0x4d) || (atPosition == 0x46) || (atPosition == 0x47) || (atPosition == 0x48)) { //弹卡 CRT310.CRT310_Reset(handle, 1); SysBLL.Player("请保管好您的卡片.wav"); } //进卡控制,不进卡 CRT310.CRT310_CardSetting(handle, 0x1, 0x1); CRT310.TT_EjectCard(0, new StringBuilder()); } catch (ThreadAbortException ex) { log.Write("error:电动读卡器退卡:" + ex.Message); } catch (Exception e) { throw new Exception("系统异常"); } finally { CRT310.CommClose(handle); } }