public IdentityInfo ReadCard() { StringBuilder readData = new StringBuilder(256); int returnCode = 0; int returnConde2 = 0; int returnConde3 = 0; byte[] CardPUCIIN = new byte[255]; byte[] pucManaMsg = new byte[255]; byte[] pucCHMsg = new byte[255]; byte[] pucPHMsg = new byte[3024]; UInt32 puiCHMsgLen = 0; UInt32 puiPHMsgLen = 0; //BP 盒转口控制 nCommPort = BpIdentity.CommPortToInt(this.PortName); BpIdentity.ChangeTo(nCommPort, bpControlFlag, nBaudRate); try { //开始找卡 returnCode = IdentityCardReaderDllWrapper.SDT_StartFindIDCard(nCommPort, CardPUCIIN, 1); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (returnCode != 0x9f) { switch (returnCode) { case 128: throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败"); case 1: throw new DeviceException(this.DeviceId, "-2", "端口打开失败"); default: throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败"); } } try { //选卡 returnConde2 = IdentityCardReaderDllWrapper.SDT_SelectIDCard(nCommPort, pucManaMsg, 1); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (returnConde2 != 0x90) { switch (returnConde2) { case 128: throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败"); case 1: throw new DeviceException(this.DeviceId, "-2", "端口打开失败"); default: throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败"); } } try { //读取固定信息 returnConde3 = IdentityCardReaderDllWrapper.SDT_ReadBaseMsg(nCommPort, pucCHMsg, ref puiCHMsgLen, pucPHMsg, ref puiPHMsgLen, 1); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString()); } if (returnConde3 != 0x90) { switch (returnConde3) { case 128: throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败"); case 1: throw new DeviceException(this.DeviceId, "-2", "端口打开失败"); default: throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败"); } } return(getIdentityInfo(pucCHMsg)); }
public void ExportPhoto(string photoPath) { StringBuilder readData = new StringBuilder(256); int returnCode = 0; int returnConde2 = 0; int returnConde3 = 0; byte[] CardPUCIIN = new byte[255]; byte[] pucManaMsg = new byte[255]; byte[] pucCHMsg = new byte[255]; byte[] pucPHMsg = new byte[3024]; UInt32 puiCHMsgLen = 0; UInt32 puiPHMsgLen = 0; //BP 盒转口控制 char bpControlFlag = 'A'; nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag); BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate); try { //开始找卡 returnCode = IdentityCardReaderDllWrapper.SDT_StartFindIDCard(nCommPort, CardPUCIIN, 1); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", "寻卡" + e.Message.ToString()); } if (returnCode != 0x9f) { switch (returnCode) { case 128: throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败"); case 1: throw new DeviceException(this.DeviceId, "-2", "端口打开失败"); default: throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败"); } } try { //选卡 returnConde2 = IdentityCardReaderDllWrapper.SDT_SelectIDCard(nCommPort, pucManaMsg, 1); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", "选卡" + e.Message.ToString()); } if (returnConde2 != 0x90) { switch (returnConde2) { case 128: throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败"); case 1: throw new DeviceException(this.DeviceId, "-2", "端口打开失败"); default: throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败"); } } try { //读取固定信息 returnConde3 = IdentityCardReaderDllWrapper.SDT_ReadBaseMsg(nCommPort, pucCHMsg, ref puiCHMsgLen, pucPHMsg, ref puiPHMsgLen, 1); } catch (Exception e) { throw new DeviceException(this.DeviceId, "-9999", "读取" + e.Message.ToString()); } if (returnConde3 != 0x90) { switch (returnConde3) { case 128: throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败"); case 1: throw new DeviceException(this.DeviceId, "-2", "端口打开失败"); default: throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败"); } } //处理图像信息。 //string path = "C:\\zlz.wlt"; string path = photoPath + ".wlt"; File.Delete(path); FileStream fs = File.Open(path, FileMode.Append); fs.Write(pucPHMsg, 0, pucPHMsg.Length); fs.Close(); int wlt = IdentityCardReaderDllWrapper.GetBmp(path, 2); if (wlt == 1) { // Bitmap image = new Bitmap("C:\\zlz.bmp"); Bitmap image = new Bitmap(photoPath + ".bmp"); image.Save(photoPath + ".jpg ", System.Drawing.Imaging.ImageFormat.Jpeg); image.Dispose(); } }