private void timerReadCard_Tick(object sender, EventArgs e) { this.timerReadCard.Stop(); #if DEBUG Console.WriteLine(System.DateTime.Now.ToString() + "首页开始监视刷卡!!!"); #endif int st = -1; short port = (short)Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["RfidCard_Port"].ToString()); if (icdev < 0) { if (port != 100) { SerialPort serialPort = new SerialPort("com" + (port + 1).ToString(), 9600, System.IO.Ports.Parity.None, 8, StopBits.One); serialPort.Close(); } icdev = RfidImporter.dc_init(port, 115200);//第一个参数100为USB口,0为串口一,1为串口二等等。 if (icdev <= 0) { return; } } if (!hasRead) { //装载密码 byte[] nkey = new byte[6] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; byte[] nkey2 = new byte[6] { 0x68, 0x69, 0x70, 0x69, 0x61, 0x6f }; int i; for (i = 0; i <= 15; i++) //装载0-15扇区密码 { if (i == 3) { st = RfidImporter.dc_load_key(icdev, 0, i, nkey2);//第二个参数0代表使用密码A,第三个参数5代表扇区号 } else { st = RfidImporter.dc_load_key(icdev, 0, i, nkey);//第二个参数0代表使用密码A,第三个参数5代表扇区号 } if (st != 0) { //this.listBox1.Items.Add("扇区" + i + "装载密码 dc_load_key error!"); return; } // this.listBox1.Items.Add("扇区" + i + "装载密码 dc_load_key OK!"); } hasRead = true; } st = RfidImporter.dc_card(icdev, '0', ref CardSerialNo);//第二个参数0指单卡操作,1指多卡操作。 if (st != 0) { // this.listBox1.Items.Add("寻卡 失败!"); this.timerReadCard.Start(); return; } // this.listBox1.Items.Add("寻卡成功!"); //this.listBox1.Items.Add("卡序列号:" + CardSerialNo); //string nkey = "FFFFFFFFFFFF"; string nkeystr = "68697069616F"; //校验密码 5扇区21块操作 //dc_authentication_passaddr_hex //dc_authentication_pass_hex // st = dc_authentication(icdev, 0, 3); //st=dc_authentication_passaddr_hex(icdev, 0, 3, nkey); st = RfidImporter.dc_authentication_pass_hex(icdev, 0, 3, nkeystr); if (st != 0) { //this.listBox1.Items.Add("扇区3校验密码失败!"); this.timerReadCard.Start(); GlobalTools.PopFlashCardError(); return; } //this.listBox1.Items.Add("扇区3校验密码 OK!"); StringBuilder sdata2 = new StringBuilder(); int block = 12; //byte[] sdata1 = new byte[32]; // //st = dc_read_hex(icdev, block, ref sdata1[0]); //dc_read st = RfidImporter.dc_read_hex(icdev, block, sdata2); // st = dc_read(icdev, block, sdata2); if (st != 0) { //this.listBox1.Items.Add("块3的Hex方式读值 dc_read error!"); this.timerReadCard.Start(); GlobalTools.PopFlashCardError(); return; } // this.listBox1.Items.Add(" 块3的值(Hex方式)为:" + sdata2); string card = string.Empty; for (int i = 1; i <= 10; i++) { card += sdata2[i * 2 - 1].ToString(); } // card = "0100407983";//cs0002 // this.txtUserName.Text = card;// +"|" + CardSerialNo; ///TODO:是否自动登陆 if (card.Length == 10) { if (GlobalTools.LoginAccount(card)) { this.QuitReadCard(); GlobalTools.ReturnUserAccout(); } } else { #region 测试通过的代码 /* * if (icdev < 0) * { * icdev = dc_init(0, 115200);//第一个参数100为USB口,0为串口一,1为串口二等等。 * if (icdev <= 0) * { * this.listBox1.Items.Add("初始化端口失败!"); * return; * } * this.listBox1.Items.Add("初始化端口成功!"); * } * //装载密码 * byte[] nkey = new byte[6] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; * byte[] nkey2 = new byte[6] { 0x68, 0x69, 0x70, 0x69, 0x61, 0x6f }; * int i; * for (i = 0; i <= 15; i++) //装载0-15扇区密码 * { * if (i == 3) * { * st = dc_load_key(icdev, 0, i, nkey2);//第二个参数0代表使用密码A,第三个参数5代表扇区号 * } * else * st = dc_load_key(icdev, 0, i, nkey);//第二个参数0代表使用密码A,第三个参数5代表扇区号 * if (st != 0) * { * this.listBox1.Items.Add("扇区" + i + "装载密码 dc_load_key error!"); * return; * } * this.listBox1.Items.Add("扇区" + i + "装载密码 dc_load_key OK!"); * } * * ulong CardSerialNo = 0; * st = dc_card(icdev, '0', ref CardSerialNo);//第二个参数0指单卡操作,1指多卡操作。 * * if (st != 0) * { * this.listBox1.Items.Add("寻卡 失败!"); * return; * } * this.listBox1.Items.Add("寻卡成功!"); * this.listBox1.Items.Add("卡序列号:" + CardSerialNo); * * //string nkey = "FFFFFFFFFFFF"; * string nkeystr = "68697069616F"; * //校验密码 5扇区21块操作 * //dc_authentication_passaddr_hex * //dc_authentication_pass_hex * // st = dc_authentication(icdev, 0, 3); * //st=dc_authentication_passaddr_hex(icdev, 0, 3, nkey); * * st = dc_authentication_pass_hex(icdev, 0, 3, nkeystr); * if (st != 0) * { * this.listBox1.Items.Add("扇区3校验密码失败!"); * return; * } * this.listBox1.Items.Add("扇区3校验密码 OK!"); * * * StringBuilder sdata2 = new StringBuilder(); * int block = 12; * //byte[] sdata1 = new byte[32]; * // * //st = dc_read_hex(icdev, block, ref sdata1[0]); * //dc_read * st = dc_read_hex(icdev, block, sdata2); * // st = dc_read(icdev, block, sdata2); * if (st != 0) * { * this.listBox1.Items.Add("块3的Hex方式读值 dc_read error!"); * return; * } * this.listBox1.Items.Add(" 块3的值(Hex方式)为:" + sdata2); * */ #endregion this.timerReadCard.Start(); } }