Exemple #1
0
        private void btn_CascSelect_Click(object sender, RoutedEventArgs e)
        {
            bool status = false;

            //把前一个防碰撞命令返回的UID(包含级联志)赋值给选择主机命令的UID(4 字节)
            for (int i = 0; i < RFIDHelper.cardID.Length; i++)
            {
                RFIDHelper.PiccSelect[5 + i] = RFIDHelper.cardID[i];
            }
            //把计算好的BCC码赋值给选择字节数组
            RFIDHelper.PiccSelect[RFIDHelper.PiccSelect.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccSelect);
            status = RFIDHelper.cmdCom(RFIDHelper.PiccSelect, RFIDHelper.buffer_PiccSelect);
            //判断从机应答状态是否为0和帧结束符是否为3
            if (status)
            {
                //string temp = "SELECT * FROM authorization";
                //StringBuilder temp2 = DataBaseHelper.QueryData(temp);
                //string[] temp3 = temp2.ToString().Split(' ');
                //for (int i = 0; i < temp3.Length; i++)
                //{
                //    //字符串数组转换为字节数组,十六进制转为十进制
                //    MacthingCardID[i] = byte.Parse(temp3[i]);
                //}
                //Enumerable.SequenceEqual()
                //把卡ID显示出来(4 字节,低字节在先),十进制转为十六进制,如果高位没有值,就用0代替
                tb_Hint.Text = "选择成功!\n" + "卡ID:" + RFIDHelper.showCardID();
            }
            else
            {
                tb_Hint.Text = "选择失败!";
            }
        }
Exemple #2
0
        private void btn_SendCmd01_Click(object sender, RoutedEventArgs e)
        {
            bool status = false;

            switch (cbBox_Cmd01.SelectedIndex)//判断下拉框选择的是哪个命令
            {
            case 0:
            {
                RFIDHelper.GetDvcInfo[RFIDHelper.GetDvcInfo.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.GetDvcInfo);
                status = RFIDHelper.cmdCom(RFIDHelper.GetDvcInfo, RFIDHelper.buffer_GetDvcInfo);
                if (status)
                {
                    tb_Hint.Text = "读设备信息成功!";
                }
                else
                {
                    tb_Hint.Text = "读设备信息失败!";
                }
            }
            break;

            case 1:
            {
                RFIDHelper.PCDConfig[RFIDHelper.PCDConfig.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PCDConfig);
                status = RFIDHelper.cmdCom(RFIDHelper.PCDConfig, RFIDHelper.buffer_PCDConfig);
                if (status)
                {
                    tb_Hint.Text = "配置读卡芯片成功!";
                }
                else
                {
                    tb_Hint.Text = "配置读卡芯片失败!";
                }
            }
            break;

            case 2:
            {
                RFIDHelper.PCDClose[RFIDHelper.PCDClose.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PCDClose);
                status = RFIDHelper.cmdCom(RFIDHelper.PCDClose, RFIDHelper.buffer_PCDClose);
                if (status)
                {
                    tb_Hint.Text = "关闭读卡芯片成功!";
                }
                else
                {
                    tb_Hint.Text = "关闭读卡芯片失败!";
                }
            }
            break;
            }
        }
Exemple #3
0
        private void btn_ActivateCard_Click(object sender, RoutedEventArgs e)
        {
            bool piccWrite_block04_Status = false;
            bool piccWrite_block05_Status = false;

            RFIDHelper.PiccWrite_Block04[4] = 0x20;//写卡块号04数据

            int money = Convert.ToInt32(tb_Money.Text.Trim());

            RFIDHelper.PiccWrite_Block04[5] = (byte)money;
            RFIDHelper.PiccWrite_Block04[6] = (byte)(money >> 8);

            string student_NumberStr = tb_StudentNumber.Text.Trim();

            byte[] student_Number = new byte[student_NumberStr.Length];
            for (int i = 0; i < student_NumberStr.Length; i++)
            {
                //通过字符串拆分的方法,把字符串的值一个一个赋值到数组中,也可以把字符串中的一个或者多个值,拆分为一个值,赋值到数组中
                student_Number[i] = Convert.ToByte(student_NumberStr.Substring(i, 1));
                RFIDHelper.PiccWrite_Block04[i + 7] = student_Number[i]; //10字节存放学号
            }


            RFIDHelper.PiccWrite_Block04[RFIDHelper.PiccWrite_Block04.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccWrite_Block04);
            piccWrite_block04_Status = RFIDHelper.cmdCom(RFIDHelper.PiccWrite_Block04, RFIDHelper.buffer_PiccWrite_Block04);

            RFIDHelper.PiccWrite_Block05[4] = 0x21;//写卡块号05数据

            byte[] sex = Encoding.UTF8.GetBytes(tb_Six.Text.Trim());
            for (int i = 0; i < sex.Length; i++)
            {
                RFIDHelper.PiccWrite_Block05[i + 5] = sex[i];
            }

            byte[] name = Encoding.UTF8.GetBytes(tb_Name.Text.Trim());
            for (int i = 0; i < name.Length; i++)
            {
                RFIDHelper.PiccWrite_Block05[i + 8] = name[i];
            }

            RFIDHelper.PiccWrite_Block05[RFIDHelper.PiccWrite_Block05.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccWrite_Block05);
            piccWrite_block05_Status = RFIDHelper.cmdCom(RFIDHelper.PiccWrite_Block05, RFIDHelper.buffer_PiccWrite_Block05);

            if (piccWrite_block04_Status && piccWrite_block05_Status)
            {
                MessageBox.Show("开卡成功!", "提示");
            }
            else
            {
                MessageBox.Show("开卡失败!", "提示");
            }
        }
Exemple #4
0
        private void btn_Halt_Click(object sender, RoutedEventArgs e)
        {
            bool status = false;

            RFIDHelper.PiccHalt[RFIDHelper.PiccHalt.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccHalt);
            status = RFIDHelper.cmdCom(RFIDHelper.PiccHalt, RFIDHelper.buffer_PiccHalt);
            if (status)
            {
                tb_Hint.Text = "暂停成功,操作需重新激活!";
            }
            else
            {
                tb_Hint.Text = "暂停失败!";
            }
        }
Exemple #5
0
        private void btn_CascAnticoll_Click(object sender, RoutedEventArgs e)
        {
            bool status = false;

            RFIDHelper.PiccAnticoll[RFIDHelper.PiccAnticoll.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccAnticoll);
            status = RFIDHelper.cmdCom(RFIDHelper.PiccAnticoll, RFIDHelper.buffer_PiccAnticoll);
            if (status)
            {
                tb_Hint.Text = " 防碰撞成功!\n" + "卡ID:" + RFIDHelper.showCardID();
            }
            else
            {
                tb_Hint.Text = "设备没应答!";
            }
        }
Exemple #6
0
        private void btn_Request_Click(object sender, RoutedEventArgs e)
        {
            bool status = false;

            RFIDHelper.PiccRequest[RFIDHelper.PiccRequest.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccRequest);
            status = RFIDHelper.cmdCom(RFIDHelper.PiccRequest, RFIDHelper.buffer_PiccRequest);
            if (status)
            {
                tb_Hint.Text = "请求成功!";
            }
            else
            {
                tb_Hint.Text = "请求失败!";
            }
        }
Exemple #7
0
        private void btn_Query_Click(object sender, RoutedEventArgs e)
        {
            bool piccRead_Block04_Status = false;
            bool piccRead_Block05_Status = false;

            RFIDHelper.PiccRead_Block04[RFIDHelper.PiccRead_Block04.Length - 3] = 0x016;
            RFIDHelper.PiccRead_Block04[RFIDHelper.PiccRead_Block04.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccRead_Block04);
            piccRead_Block04_Status = RFIDHelper.cmdCom(RFIDHelper.PiccRead_Block04, RFIDHelper.buffer_PiccRead_Block04);

            RFIDHelper.PiccRead_Block05[RFIDHelper.PiccRead_Block05.Length - 3] = 0x017;
            RFIDHelper.PiccRead_Block05[RFIDHelper.PiccRead_Block05.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccRead_Block05);
            piccRead_Block05_Status = RFIDHelper.cmdCom(RFIDHelper.PiccRead_Block05, RFIDHelper.buffer_PiccRead_Block05);

            if (piccRead_Block04_Status && piccRead_Block05_Status)
            {
                string show_StudentNumber = "";
                for (int i = 0; i < 10; i++)
                {
                    show_StudentNumber += RFIDHelper.buffer_PiccRead_Block04[i + 6].ToString();
                }
                lb_ShowStudentNumber.Content = "学号:" + show_StudentNumber;
                lb_ShowMoney.Content         = "金额:" + Convert.ToString(RFIDHelper.buffer_PiccRead_Block04[4] +
                                                                        RFIDHelper.buffer_PiccRead_Block04[5] * 256);
                try
                {
                    byte[] show_Name = new byte[12];
                    for (int i = 0; i < show_Name.Length; i++)
                    {
                        show_Name[i] = RFIDHelper.buffer_PiccRead_Block04[i + 7];
                    }
                    lb_ShowName.Content = "姓名:" + Encoding.UTF8.GetString(show_Name);
                    byte[] show_Sex = new byte[3];
                    for (int i = 0; i < show_Sex.Length; i++)
                    {
                        show_Sex[i] = RFIDHelper.buffer_PiccRead_Block04[i + 4];
                    }
                    lb_ShowSex.Content = "性别:" + Encoding.UTF8.GetString(show_Sex);
                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show("数组名不能为空!", "错误");
                }
            }
            else
            {
                MessageBox.Show("查询失败!", "提示");
            }
        }
Exemple #8
0
        private void btn_AuthKey_Click(object sender, RoutedEventArgs e)
        {
            bool   status = false;
            byte   block_Num;
            string str = tb_BlockAddress.Text.ToString().Trim();//从tb_BlockAddress读数据

            if (str.Contains('.') || str == "")
            {
                MessageBox.Show("不能输入小数或输入为空");
                return;
            }
            else
            {
                block_Num = Convert.ToByte(str);
                if (block_Num >= 0 && block_Num <= 63)
                {
                    RFIDHelper.PiccAuthKey[RFIDHelper.PiccAuthKey.Length - 3] = block_Num;
                }
                else
                {
                    MessageBox.Show("请输入0-63之间的正整数");
                    return;
                }
            }
            if (rb_SecretKeyA.IsChecked == true)
            {
                RFIDHelper.PiccAuthKey[4] = 0x60;
            }
            else
            {
                RFIDHelper.PiccAuthKey[4] = 0x61;
            }

            //卡序列号
            for (int i = 0; i < RFIDHelper.cardID.Length; i++)
            {
                RFIDHelper.PiccAuthKey[5 + i] = RFIDHelper.cardID[i];
            }

            //从tb_SecretKey中获取密钥
            gettb_SecretKey(RFIDHelper.PiccAuthKey);

            RFIDHelper.PiccAuthKey[RFIDHelper.PiccAuthKey.Length - 2] = RFIDHelper.bcc_Calc(RFIDHelper.PiccAuthKey);
            status = RFIDHelper.cmdCom(RFIDHelper.PiccAuthKey, RFIDHelper.buffer_PiccAuthKey);
            if (status)
            {
                hwcms_Window.Show(); //开启热水卡系统
                this.Hide();         //隐藏门禁系统
                if (rb_SecretKeyA.IsChecked == true)
                {
                    tb_Hint.Text = "密钥A验证成功!";
                }
                else
                {
                    tb_Hint.Text = "密钥B验证成功!";
                }
            }
            else
            {
                tb_Hint.Text = "验证失败!";
            }
        }