//发卡 public static bool destribute_card_M1(string company_code, string cardCode) { if (!connect_card_machine("M1")) { return(false); } ulong snr = 0; char mode = '1'; ICRF.rf_card(icdev, mode, ref snr); byte[] key1 = new byte[20]; byte[] key2 = new byte[20]; string skey = "6a3530303033"; int keylen = skey.Length; key1 = Encoding.ASCII.GetBytes(skey); ICRF.a_hex(key1, key2, 12); int st = ICRF.rf_load_key(icdev, 1, 2, key2); if (st != 0) { MessageBox.Show("装载密码失败"); ICRF.rf_exit(icdev); return(false); } st = ICRF.rf_authentication(icdev, 1, 2); if (st != 0) { MessageBox.Show("验证密码失败"); ICRF.rf_exit(icdev); return(false); } string str = company_code + cardCode; byte[] data = Encoding.ASCII.GetBytes(str); //byte[] buff = new byte[16]; //st = IC4442.my_encrypt(data, buff); st = ICRF.rf_write(icdev, 9, data); if (st != 0) { BathClass.printErrorMsg("写卡失败!"); return(false); } st = ICRF.rf_beep(icdev, 20); st = ICRF.rf_exit(icdev); return(true); }
public static bool read_data_M1(string compnay_code, ref string card_str) { if (!connect_card_machine("M1")) { return(false); } ulong snr = 0; char mode = '1'; ICRF.rf_card(icdev, mode, ref snr); byte[] key1 = new byte[20]; byte[] key2 = new byte[20]; string skey = "6a3530303033"; //string skey = "FFFFFFFFFFFF"; if (verify_pwd_M1(skey)) { byte[] data = new byte[16]; byte[] p_dest = new byte[16]; for (int i = 0; i < 16; i++) { data[i] = 0; } for (int i = 0; i < 16; i++) { p_dest[i] = 0; } int st = ICRF.rf_read(icdev, 9, data); if (st == 0) { card_str = System.Text.Encoding.ASCII.GetString(data); if (!card_str.Contains(compnay_code)) { return(false); } card_str = card_str.Substring(compnay_code.Length); string tmpStr = ""; foreach (char c in card_str) { if (char.IsDigit(c)) { tmpStr += c; } } card_str = tmpStr; } else { MessageBox.Show("读取数据失败"); ICRF.rf_exit(icdev); return(false); } } else { ICRF.rf_exit(icdev); return(false); } ICRF.rf_exit(icdev); return(true); }