private void toolStripButton3_Click(object sender, EventArgs e)
        {
            // 打开设备
            if (opened)
            {
                return;
            }
            Int32         result;
            StringBuilder errorText = new StringBuilder(maxErrorTextLen);

            /*参数1为端口号。1表示串口1,2表示串口2,依次类推。1001表示USB。0表示自动选择。
             * 参数2为标志位。0x02表示启用重复读卡。0x04表示读卡后接着读取新地址。
             * 各个数值可以用“按位或”运算符组合起来。
             * 参数3为波特率。使用串口阅读器的程序应正确设置此参数。出厂机器的波特率一般为115200。
             */
            result = Card2.OpenCardReader(1001, 2, 115200);
            if (result == 0)
            {
                // textResult.Text = Convert.ToString(result);
                Card2.GetErrorTextW(errorText, maxErrorTextLen);
                opened    = true;
                this.Text = frmTextOpen;
                // textDescription.Text = errorText.ToString();
            }
            else
            {
                MessageBox.Show("设备连接失败!\n请检查并确认设备已正确连接", "设备连接错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            // 关闭设备
            if (!opened)
            {
                return;
            }
            Int32         result;
            StringBuilder errorText = new StringBuilder(maxErrorTextLen);

            //读完卡后,必须关闭设备。
            result = Card2.CloseCardReader();
            // textResult.Text = Convert.ToString(result);
            Card2.GetErrorTextW(errorText, maxErrorTextLen);
            opened    = false;
            this.Text = frmTextClose;
            // textDescription.Text = errorText.ToString();
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            // 读卡并填写
            if (!opened)
            {
                MessageBox.Show("请先打开设备!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Int32         result;
            String        imagePath;
            StringBuilder errorText = new StringBuilder(maxErrorTextLen);

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            imagePath = Path.GetTempPath() + "image.bmp";
            //当程序打开设备后,可以多次调用读取信息函数。
            result = Card2.GetPersonMsgW(ref person, imagePath);
            // textResult.Text = Convert.ToString(result);
            Card2.GetErrorTextW(errorText, maxErrorTextLen);
            // textDescription.Text = errorText.ToString();

            if (0 == result)
            {
                birthday   = ConvertDate(person.birthday, 1);
                validDate  = ConvertDate(person.validStart, 2) + "-";
                validDate += ConvertDate(person.validEnd, 2);
                image      = new Bitmap(imagePath);
            }
            else
            {
                // birthday = "";
                // validDate = "";
                MessageBox.Show("请将身份证正确放置在读卡器上!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                webNew[tabControl1.SelectedIndex].Document.GetElementById("zjhm").SetAttribute("value", person.cardId);
                webNew[tabControl1.SelectedIndex].Document.GetElementById("xm").SetAttribute("value", person.name);
                webNew[tabControl1.SelectedIndex].Document.GetElementById("csrq").SetAttribute("value", birthday);

                string address      = person.address;
                string province     = "四川省";
                string modifiedAddr = address;

                if (address.Contains(province))
                {
                    modifiedAddr = string.Empty;
                    int index = address.IndexOf(province);
                    modifiedAddr = address.Insert(index + province.Length, "达州市");
                }

                webNew[tabControl1.SelectedIndex].Document.GetElementById("djzsxx").SetAttribute("value", modifiedAddr);
                webNew[tabControl1.SelectedIndex].Document.GetElementById("lxzsxx").SetAttribute("value", modifiedAddr);

                webNew[tabControl1.SelectedIndex].Document.GetElementById("yzbm").SetAttribute("value", "635200");
            }
            catch (Exception ex)
            {
                MessageBox.Show("请打开至正确网页!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }