///// <summary> ///// 外接写卡函数 ///// </summary> ///// <param name="cardinfo"></param> ///// <param name="gasGardType"></param> ///// <returns></returns> public static int WriteCard(cardInfo cardinfo, int gasGardType) { if (!IsUse) { return(0); } cardInfo cardinfoTemp = new cardInfo(); string outError = ""; int res = 0; try { if (gasGardType == 0) { //天信 StringBuilder source = new StringBuilder(cardinfo.strDeCrypt); StringBuilder destination = new StringBuilder(65); IcSmartCard.XinaoEnCrypt(source, destination); string path = "Tancy_IC.dll"; int port = -1; if (Port.StartsWith("COM")) { port = int.Parse(Port.Substring(3)) - 1; } //int comHz = int.Parse(text_baud.Text); byte[] sPassWord = Encoding.ASCII.GetBytes(destination.ToString()); int iGasCount = int.Parse(cardinfo.gasCount); int iIcErroy = -1; string sErrMsg = null; IcSmartCard.WriteCard(path, port, Bps, sPassWord, ref iGasCount, ref iIcErroy, ref sErrMsg); res = iIcErroy; //res = GasCardReader0.EnCrypt(cardinfo.strDeCrypt, ref cardinfoTemp.strEnCrypt); if (res == 0) { //res = IcSmartCard.WriteCard(Port.ToString(), Bps.ToString(), cardinfoTemp.strEnCrypt, cardinfo.gasCount + 1, ref outError); return(res); } else { throw new Exception("天信写卡错误:" + sErrMsg); } } else if (gasGardType == 1) { //苍南 res = GasCardReader1.EnCrypt(cardinfo.strDeCrypt, ref cardinfoTemp.strEnCrypt); Log.Info("write enCrypt: " + cardinfoTemp.strEnCrypt); if (res == 0) { res = GasCardReader1.WriteCard(Port.ToString(), Bps.ToString(), cardinfoTemp.strEnCrypt, cardinfo.gasCount, ref outError); return(res); } else { throw new Exception("GasCardReader1.EnCrypt err"); } } else { throw new Exception("cardType Err"); } //else //{ // res = GasCardReader1.EnCrypt(cardinfo.strDeCrypt, ref cardinfoTemp.strEnCrypt); // if (res == 1) // { // res = GasCardReader0.EnCrypt(cardinfo.strDeCrypt, ref cardinfoTemp.strEnCrypt); // if (res != 0) // throw new Exception("GasCardReader0.EnCrypt err"); // res = GasCardReader0.WriteCard(Port.ToString(), Bps.ToString(), cardinfoTemp.strEnCrypt, cardinfo.gasCount + 1,ref outError); // return res; // } // else if (res == 0) // { // res = GasCardReader1.WriteCard(Port.ToString(), Bps.ToString(), cardinfoTemp.strEnCrypt, cardinfo.gasCount + 1,ref outError); // return res; // } // else // { // throw new Exception("GasCardReader1.EnCrypt err"); // } //} } catch (Exception ex) { Log.Error("[GasCardReaderHelper][WriteCard]Error!\n" + ex.ToString()); return(-1); } }