/// <summary> /// 读取文件 /// </summary> /// <param name="fileName">文件名称</param> /// <param name="content">文件内容</param> /// <param name="msg">错误消息</param> /// <returns></returns> public static bool ReadFile(ushort fileID, out string contentOrMsg) { //默认进行身份验证 Auth(); try { return(cpuCard.ReadFile(fileID, out contentOrMsg)); } catch (Exception ex) { contentOrMsg = ex.Message; return(false); } }
/// <summary> /// 读取文件 /// </summary> /// <param name="fileName">文件名称</param> /// <param name="content">文件内容</param> /// <param name="msg">错误消息</param> /// <returns></returns> public static bool ReadFile(ushort fileID, out byte[] data, out string contentOrMsg) { data = new byte[0]; cardReader.OpenReader(out string msgInf); //默认进行身份验证 Auth(); try { //先选择根目录 cpuCard.SelectMF(); //选择创建的文件夹 cpuCard.SelectFileById(fileID); //选择文件 ApduMsg msg = cpuCard.SelectFileById(fixFileID); //文件不存在 if (msg.Code == "6A-82") { contentOrMsg = "文件不存在"; cpuCard.SelectMF(); return(false); } //读取 bool res = cpuCard.ReadFile(fixFileID, out data, out contentOrMsg); //再退出到根目录 cpuCard.SelectMF(); return(res); } catch (Exception ex) { contentOrMsg = ex.Message; return(false); } finally { cardReader.CloseReader(); // run.Close(); } }
private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; int max = Convert.ToInt32(textBox2.Text); DeCardReader deCardReader = new DeCardReader(); CpuCard CardReader = new CpuCard(deCardReader); for (ushort i = 1; i <= max; i++) { //ApduMsg msg = CardReader.SelectFileById(i); if (CardReader.ReadFile(i, out string msg)) { // DataSet ds = ZipHelper.GetDatasetByString(msg); textBox1.AppendText(i + "成功:" + msg + "\r\n"); } else { textBox1.AppendText(i + "失败:" + msg + "\r\n"); } } }
private void button11_Click(object sender, EventArgs e) { CardReader.ReadFile(GetFixFileID(), out string msg); txtRead.Text = msg; }