public int WriteCard(string cardData) { IntPtr hadler = Init(); int rs = 0; if (hadler.ToInt32() == 0) { MyMsg.MsgInfo("端口打开失败!"); return(-1); } try { StringBuilder sb = new StringBuilder(1024); byte _Voltage = Convert.ToByte(0x30); int i = K101_DLL.K101_IcCardPowerOn(hadler, false, Convert.ToByte(0), _Voltage, sb); if (i != 0) { MyMsg.MsgInfo("IC卡上电失败"); return(-1); } byte[] _PWData = new byte[3]; _PWData[0] = Convert.ToByte("FF", 16); _PWData[1] = Convert.ToByte("FF", 16); _PWData[2] = Convert.ToByte("FF", 16); i = K101_DLL.K101_SLE4442VerifyPWD(hadler, false, Convert.ToByte(0), _PWData, sb); if (i != 0) { MyMsg.MsgInfo("SLE4442卡片验证密码失败"); return(-1); } string msg = Pub.Encrypt(cardData, "SOFT-HIS"); byte[] _data = Encoding.ASCII.GetBytes(msg); i = K101_DLL.K101_SLE4442Write(hadler, false, Convert.ToByte(0), 27, 88, _data, sb); if (i != 0) { MyMsg.MsgInfo("写入SLE4442卡片数据失败"); return(-1); } i = K101_DLL.K101_IcCardPowerOff(hadler, false, Convert.ToByte(0), sb); if (i != 0) { MyMsg.MsgInfo("IC卡下电失败"); return(-1); } return(0); } catch (Exception ex) { throw new Exception(ex.Message); } finally { ClosePort(hadler); } }