private static ICardIssueDevice GetDevice(out CardIssueConfig config) { config = SysConfig.GetCardIssueConfig(); ICardIssueDevice issDevice = null; switch (config.cardIssueModel) { case CardIssueModel.HY_EM800A: issDevice = new MF800ACardIssueDevice(); break; case CardIssueModel.USB_INTCARD: issDevice = new USBInCardIssueDevice(); break; } return(issDevice); }
public static bool ReadCard(out string num, out string wgNum, out string errorMsg) { num = null; wgNum = null; errorMsg = null; CardIssueConfig config; ICardIssueDevice issDevice = CardIssueDeviceHelper.GetDevice(out config); if (issDevice == null) { errorMsg = "未成功初始化读卡器,请检查读卡器配置!"; return(false); } using (issDevice) { try { issDevice.OpenCom(config.comPort, config.comBuad); num = issDevice.ReadCardX(); issDevice.Close(); if (num == null) { errorMsg = "未读取到卡号!"; return(false); } else { wgNum = num; if (config.cardIssueModel == CardIssueModel.HY_EM800A) { wgNum = DataHelper.ToWGAccessCardNo(num); } return(true); } } catch (Exception ex) { errorMsg = "读取卡号异常:" + ex.Message; log.Error("读取卡号异常:", ex); return(false); } } }
private void btnOpenOrClose_Click(object sender, EventArgs e) { if (device == null) { try { device = new MF800ACardIssueDevice(); device.OpenCom((cbComPort.SelectedIndex + 1), ComBuad.CBR_14400); btnOpenOrClose.Text = "关闭"; } catch (Exception ex) { device = null; MessageBox.Show(ex.Message); } } else { device.Close(); device = null; btnOpenOrClose.Text = "打开"; } }