/// <summary> /// 验证打开的端口 /// </summary> /// <returns></returns> public bool OpneOrClose() { bUsbPort = false; for (Int16 i = 1001; i < 1016; i++) { if (GetUpi.SDT_OpenPort(i) == 144) { bUsbPort = true; EdziPortID = i; break; } } return(bUsbPort); }
/// <summary> /// 执行 /// </summary> public void GO() { rtnTemp = GetUpi.SDT_StartFindIDCard(EdziPortID, ref pucIIN, EdziIfOpen); if (rtnTemp == 159) { rtnTemp = GetUpi.SDT_SelectIDCard(EdziPortID, ref pucSN, EdziIfOpen); if (rtnTemp != 144) { rtnTemp = GetUpi.SDT_ClosePort(EdziPortID); } else { ReadWriteMsg(); // LoadControlsByTimer(); } } }
/// <summary> /// 读取身份证信息入类 /// </summary> public void ReadWriteMsg() { FileInfo objFile = new FileInfo("wz.txt"); if (objFile.Exists) { objFile.Attributes = FileAttributes.Normal; objFile.Delete(); } objFile = new FileInfo("zp.wlt"); if (objFile.Exists) { objFile.Attributes = FileAttributes.Normal; objFile.Delete(); } objFile = new FileInfo("zp.bmp"); if (objFile.Exists) { objFile.Attributes = FileAttributes.Normal; objFile.Delete(); } try { rtnTemp = GetUpi.SDT_ReadBaseMsgToFile(EdziPortID, "wz.txt", ref puiCHMsgLen, "zp.wlt", ref puiPHMsgLen, EdziPortID); } catch (Exception ex) { string m = ex.Message; } if (rtnTemp != 144) { rtnTemp = GetUpi.SDT_ClosePort(EdziPortID); return; } rtnTemp = GetUpi.SDT_ClosePort(EdziPortID); FileInfo f = new FileInfo("wz.txt"); FileStream fs = f.OpenRead(); byte[] bt = new byte[fs.Length]; fs.Read(bt, 0, (int)fs.Length); fs.Close(); fs.Dispose(); f.Delete(); if (bUsbPort) { rtnTemp = GetUpi.GetBmp("zp.wlt", 2); } else { rtnTemp = GetUpi.GetBmp("zp.wlt", 1); } string str = System.Text.UnicodeEncoding.Unicode.GetString(bt); string name = System.Text.UnicodeEncoding.Unicode.GetString(bt, 0, 30).Trim(); string Sex_Code = System.Text.UnicodeEncoding.Unicode.GetString(bt, 30, 2).Trim(); string sexName = string.Empty; switch (Sex_Code) { case "1": sexName = "男"; break; default: sexName = "女"; break; } string mation_code = System.Text.UnicodeEncoding.Unicode.GetString(bt, 32, 4).Trim(); string mation_name = GetNation(mation_code); string strBird = System.Text.UnicodeEncoding.Unicode.GetString(bt, 36, 16).Trim(); strBird = Convert.ToDateTime(strBird.Substring(0, 4) + "年" + strBird.Substring(4, 2) + "月" + strBird.Substring(6) + "日").ToShortDateString(); string address = System.Text.UnicodeEncoding.Unicode.GetString(bt, 52, 70).Trim(); string IdentificationCode = System.Text.UnicodeEncoding.Unicode.GetString(bt, 122, 36).Trim(); string DealDepartment = System.Text.UnicodeEncoding.Unicode.GetString(bt, 158, 30).Trim(); string strTem = System.Text.UnicodeEncoding.Unicode.GetString(bt, 188, bt.GetLength(0) - 188).Trim(); string DealDate = Convert.ToDateTime(strTem.Substring(0, 4) + "年" + strTem.Substring(4, 2) + "月" + strTem.Substring(6, 2) + "日").ToShortDateString(); strTem = strTem.Substring(8); string maxdate = string.Empty; if (strTem.Trim() != "长期") { maxdate = Convert.ToDateTime(strTem.Substring(0, 4) + "年" + strTem.Substring(4, 2) + "月" + strTem.Substring(6, 2) + "日").ToShortDateString(); } else { maxdate = DateTime.MaxValue.ToShortDateString(); } objFile = new FileInfo("zp.bmp"); if (objFile.Exists) { Image img = Image.FromFile("zp.bmp"); Image PIC_Image = (System.Drawing.Image)img.Clone(); System.IO.MemoryStream m = new MemoryStream(); img.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] PIC_Byte = m.ToArray(); m.Close(); m.Dispose(); PIC_Image.Dispose(); // byte[] data = null; using (MemoryStream ms = new MemoryStream()) { using (Bitmap bitmap = new Bitmap(img)) { bitmap.Save(ms, img.RawFormat); ms.Position = 0; data = new byte[ms.Length]; ms.Read(data, 0, Convert.ToInt32(ms.Length)); ms.Flush(); } } string Buffer = Convert.ToBase64String(data.ToArray()); //byte[] ImgByte = Convert.FromBase64String(Buffer); //MemoryStream ms = new MemoryStream(ImgByte); //Image image = Image.FromStream(ms); ///人员信息 user = new UserMessage() { PIC = Buffer, Name = name, Sex = sexName, NationName = mation_name, BirdTh = Convert.ToDateTime(strBird), IdentificationCode = IdentificationCode, DealDate = Convert.ToDateTime(DealDate), MaxDate = Convert.ToDateTime(maxdate), Address = address, DealDepartment = DealDepartment }; img.Dispose(); img = null; } }