/// <summary>
        /// 修改秘钥
        /// </summary>
        void EditPwd()
        {
            List <byte> byteList = new List <byte>();

            //长度字
            byteList.Add(0x00);
            byteList.Add(0x1C);
            //通讯地址
            byteList.Add(0x00);
            //命令字
            byteList.Add(0x22);
            //数据域
            byteList.Add(0x00);                                                   //秘钥标示
            byteList.Add(0x13);                                                   //第4区第3块区域(尾块)
            byteList.AddRange(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); //秘钥A的旧秘钥
            byteList.AddRange(new byte[] { 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5 }); //秘钥A的新秘钥
            byteList.AddRange(new byte[] { 0xFF, 0x07, 0x80, 0x69 });             //控制位
            byteList.AddRange(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }); //秘钥B
            //校验字
            byteList.Add(XOR.GetByte(byteList.ToArray()));

            //实现接收委托
            m_spr = new SerialPortReceive(delegate(string received)
            {
                this.Dispatcher.Invoke(new Action(delegate()
                {
                    deleageEditPwd();
                }));
            });

            send(byteList.ToArray());
        }
        /// <summary>
        /// 写卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void but_writecard_Click(object sender, RoutedEventArgs e)
        {
            deleageEditPwd = new DeleageEditPwd(delegate()
            {
                List <byte> byteList = new List <byte>();
                //长度字
                byteList.Add(0x00);
                byteList.Add(0x2D);
                //通讯地址
                byteList.Add(0x00);
                //命令字
                byteList.Add(0x2B);
                //数据域
                byteList.Add(0x00);
                byteList.Add(0x10);
                byteList.Add(0x02);
                byteList.Add(0xF0);
                byteList.Add(0xE1);
                byteList.Add(0xD2);
                byteList.Add(0xC3);
                byteList.Add(0xB4);
                byteList.Add(0xA5);
                byte[] bytes = ASCIIEncoding.UTF8.GetBytes(text_write.Text.ToString());
                byteList.AddRange(bytes);
                for (int i = bytes.Length; i < 32; i++)
                {
                    byteList.Add(0x00);
                }
                //校验字
                byteList.Add(XOR.GetByte(byteList.ToArray()));

                text_rData.AppendText(string.Join(" ", byteList.ConvertAll(new Converter <byte, string>(delegate(byte t)
                {
                    string str = Convert.ToString(t, 16);
                    return(str.Length % 2 != 0 ? "0" + str : str);
                }))) + "\r\n");

                //实现接收委托
                m_spr = new SerialPortReceive(delegate(string received)
                {
                    this.Dispatcher.Invoke(new Action(delegate()
                    {
                        text_rData.AppendText(received + "\r\n"); //注意:回车换行必须这样写,单独使用"\r"和"\n"都不会有效果
                        string[] arr = received.Split(' ');
                        if (Convert.ToByte(arr[3], 16) != byteList[3])
                        {
                            MessageBox.Show("命令执行失败!", "error");
                        }
                        else
                        {
                            MessageBox.Show("写卡成功!", "information");
                        }
                    }));
                });

                send(byteList.ToArray());
            });
            EditPwd();
        }
        /// <summary>
        /// 读卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void but_readcard_Click(object sender, RoutedEventArgs e)
        {
            deleageEditPwd = new DeleageEditPwd(delegate()
            {
                List <byte> byteList = new List <byte>();
                //长度字
                byteList.Add(0x00);
                byteList.Add(0x0D);
                //通讯地址
                byteList.Add(0x00);
                //命令字
                byteList.Add(0x2A);
                //数据域
                byteList.Add(0x00);
                byteList.Add(0x10);
                byteList.Add(0x02);
                byteList.Add(0xF0);
                byteList.Add(0xE1);
                byteList.Add(0xD2);
                byteList.Add(0xC3);
                byteList.Add(0xB4);
                byteList.Add(0xA5);
                //校验字
                byteList.Add(XOR.GetByte(byteList.ToArray()));

                text_rData.AppendText(string.Join(" ", byteList.ConvertAll(new Converter <byte, string>(delegate(byte t)
                {
                    string str = Convert.ToString(t, 16);
                    return(str.Length % 2 != 0 ? "0" + str : str);
                }))) + "\r\n");

                //实现接收委托
                m_spr = new SerialPortReceive(delegate(string received)
                {
                    this.Dispatcher.Invoke(new Action(delegate()
                    {
                        text_rData.AppendText(received + "\r\n"); //注意:回车换行必须这样写,单独使用"\r"和"\n"都不会有效果
                        string[] arr = received.Split(' ');
                        if (Convert.ToByte(arr[3], 16) != byteList[3])
                        {
                            MessageBox.Show("读卡失败!", "error");
                        }
                        else
                        {
                            string[] number = new string[18];
                            Array.Copy(arr, 4, number, 0, 18);
                            byte[] bytes = number.ToList().ConvertAll(new Converter <string, byte>(delegate(string t)
                            {
                                return(Convert.ToByte(t, 16));
                            })).ToArray();
                            text_read.Text = ASCIIEncoding.ASCII.GetString(bytes);
                        }
                    }));
                });

                send(byteList.ToArray());
            });
            EditPwd();
        }
        /// <summary>
        /// 恢复出厂
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void but_reset_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult mbr = MessageBox.Show("确定将读卡器恢复出厂设置吗?", "消息提示", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

            if (mbr == MessageBoxResult.OK)
            {
                List <byte> byteList = new List <byte>();
                //长度字
                byteList.Add(0x00);
                byteList.Add(0x09);
                //通讯地址
                byteList.Add(0x00);
                //命令字
                byteList.Add(0x0F);
                //数据域
                byteList.Add(0x52);
                byteList.Add(0x45);
                byteList.Add(0x53);
                byteList.Add(0x45);
                byteList.Add(0x54);
                //校验字
                byteList.Add(XOR.GetByte(byteList.ToArray()));

                text_rData.AppendText(string.Join(" ", byteList.ConvertAll(new Converter <byte, string>(delegate(byte t)
                {
                    string str = Convert.ToString(t, 16);
                    return(str.Length % 2 != 0 ? "0" + str : str);
                }))) + "\r\n");

                //实现接收委托
                m_spr = new SerialPortReceive(delegate(string received)
                {
                    this.Dispatcher.Invoke(new Action(delegate()
                    {
                        text_rData.AppendText(received + "\r\n"); //注意:回车换行必须这样写,单独使用"\r"和"\n"都不会有效果
                        string[] arr = received.Split(' ');
                        if (Convert.ToByte(arr[3], 16) != byteList[3])
                        {
                            MessageBox.Show("恢复出厂设置执行失败!", "error");
                        }
                        else
                        {
                            MessageBox.Show("恢复出厂设置成功,请重新上电后点击“设置模块”!", "information");
                        }
                    }));
                });

                send(byteList.ToArray());
            }
        }
        void SetOnFindcardAndOut()
        {
            List <byte> byteList = new List <byte>();

            //长度字
            byteList.Add(0x00);
            byteList.Add(0x05);
            //通讯地址
            byteList.Add(0x00);
            //命令字
            byteList.Add(0x1E);
            //数据域
            byteList.Add(0x0C);
            //校验字
            byteList.Add(XOR.GetByte(byteList.ToArray()));

            text_rData.AppendText(string.Join(" ", byteList.ConvertAll(new Converter <byte, string>(delegate(byte t)
            {
                string str = Convert.ToString(t, 16);
                return(str.Length % 2 != 0 ? "0" + str : str);
            }))) + "\r\n");

            //实现接收委托
            m_spr = new SerialPortReceive(delegate(string received)
            {
                this.Dispatcher.Invoke(new Action(delegate()
                {
                    text_rData.AppendText(received + "\r\n"); //注意:回车换行必须这样写,单独使用"\r"和"\n"都不会有效果
                    string[] arr = received.Split(' ');
                    if (Convert.ToByte(arr[3], 16) != byteList[3])
                    {
                        MessageBox.Show("设置开机寻卡及输出失败!", "error");
                    }
                }));
            });

            send(byteList.ToArray());
        }