• VB.Net读写NFC Ntag标签源码


    读写器介绍 :USB液显ISO14443-A读写器 RFID读写器 M1/S50/S70/F08/ULtralight-淘宝网 (taobao.com)https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.13.69f6e728nD9A5a&id=18645603742


    Public Class Form1
        Inherits System.Windows.Forms.Form

    #Region " Windows 窗体设计器生成的代码 "

        Public Sub New()
            MyBase.New()

            '该调用是 Windows 窗体设计器所必需的。
            InitializeComponent()

            '在 InitializeComponent() 调用之后添加任何初始化

        End Sub

        '窗体重写 dispose 以清理组件列表。
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Windows 窗体设计器所必需的
        Private components As System.ComponentModel.IContainer

        '注意: 以下过程是 Windows 窗体设计器所必需的
        '可以使用 Windows 窗体设计器修改此过程。
        '不要使用代码编辑器修改它。
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents Button2 As System.Windows.Forms.Button
        Friend WithEvents Button3 As System.Windows.Forms.Button
        Friend WithEvents Button4 As System.Windows.Forms.Button
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents blockadd As System.Windows.Forms.NumericUpDown
        Friend WithEvents beginp As System.Windows.Forms.NumericUpDown
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
        Friend WithEvents Button6 As System.Windows.Forms.Button
        Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
        Friend WithEvents Button7 As System.Windows.Forms.Button
        Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
        Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
        Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
        Friend WithEvents TabPage3 As System.Windows.Forms.TabPage
        Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
        Friend WithEvents Button8 As System.Windows.Forms.Button
        Friend WithEvents Button9 As System.Windows.Forms.Button
        Friend WithEvents Button10 As System.Windows.Forms.Button
        Friend WithEvents Button11 As System.Windows.Forms.Button
        Friend WithEvents Button13 As System.Windows.Forms.Button
        Friend WithEvents Button12 As System.Windows.Forms.Button
        Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
        Friend WithEvents Label4 As System.Windows.Forms.Label
        Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
        Friend WithEvents Button14 As System.Windows.Forms.Button
        Friend WithEvents Limitau As System.Windows.Forms.NumericUpDown
        Friend WithEvents Label6 As System.Windows.Forms.Label
        Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
        Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
        Friend WithEvents Label5 As System.Windows.Forms.Label
        Friend WithEvents Label3 As System.Windows.Forms.Label
        Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
        Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
        Friend WithEvents RichTextBox2 As System.Windows.Forms.RichTextBox
        Friend WithEvents Label8 As System.Windows.Forms.Label
        Friend WithEvents Label7 As System.Windows.Forms.Label
        Friend WithEvents TextBox8 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
        Friend WithEvents CheckBox3 As System.Windows.Forms.CheckBox
        Friend WithEvents Label10 As System.Windows.Forms.Label
        Friend WithEvents Label9 As System.Windows.Forms.Label
        Friend WithEvents rwps As System.Windows.Forms.NumericUpDown
        Friend WithEvents rwbeginp As System.Windows.Forms.NumericUpDown
        Friend WithEvents Button5 As System.Windows.Forms.Button
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
            Me.Button1 = New System.Windows.Forms.Button()
            Me.Button2 = New System.Windows.Forms.Button()
            Me.Button3 = New System.Windows.Forms.Button()
            Me.Button4 = New System.Windows.Forms.Button()
            Me.Button5 = New System.Windows.Forms.Button()
            Me.TextBox1 = New System.Windows.Forms.TextBox()
            Me.Label1 = New System.Windows.Forms.Label()
            Me.blockadd = New System.Windows.Forms.NumericUpDown()
            Me.beginp = New System.Windows.Forms.NumericUpDown()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.TextBox2 = New System.Windows.Forms.TextBox()
            Me.TextBox3 = New System.Windows.Forms.TextBox()
            Me.Button6 = New System.Windows.Forms.Button()
            Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
            Me.Button7 = New System.Windows.Forms.Button()
            Me.TabControl1 = New System.Windows.Forms.TabControl()
            Me.TabPage1 = New System.Windows.Forms.TabPage()
            Me.Button13 = New System.Windows.Forms.Button()
            Me.Button12 = New System.Windows.Forms.Button()
            Me.Button11 = New System.Windows.Forms.Button()
            Me.Button10 = New System.Windows.Forms.Button()
            Me.Button9 = New System.Windows.Forms.Button()
            Me.TextBox4 = New System.Windows.Forms.TextBox()
            Me.Button8 = New System.Windows.Forms.Button()
            Me.TabPage2 = New System.Windows.Forms.TabPage()
            Me.Label10 = New System.Windows.Forms.Label()
            Me.Label9 = New System.Windows.Forms.Label()
            Me.rwps = New System.Windows.Forms.NumericUpDown()
            Me.rwbeginp = New System.Windows.Forms.NumericUpDown()
            Me.Label8 = New System.Windows.Forms.Label()
            Me.Label7 = New System.Windows.Forms.Label()
            Me.TextBox8 = New System.Windows.Forms.TextBox()
            Me.TextBox7 = New System.Windows.Forms.TextBox()
            Me.CheckBox3 = New System.Windows.Forms.CheckBox()
            Me.RichTextBox2 = New System.Windows.Forms.RichTextBox()
            Me.Button14 = New System.Windows.Forms.Button()
            Me.Limitau = New System.Windows.Forms.NumericUpDown()
            Me.Label6 = New System.Windows.Forms.Label()
            Me.TextBox6 = New System.Windows.Forms.TextBox()
            Me.CheckBox2 = New System.Windows.Forms.CheckBox()
            Me.Label5 = New System.Windows.Forms.Label()
            Me.Label3 = New System.Windows.Forms.Label()
            Me.ComboBox1 = New System.Windows.Forms.ComboBox()
            Me.TextBox5 = New System.Windows.Forms.TextBox()
            Me.CheckBox1 = New System.Windows.Forms.CheckBox()
            Me.TabPage3 = New System.Windows.Forms.TabPage()
            Me.PictureBox1 = New System.Windows.Forms.PictureBox()
            Me.Label4 = New System.Windows.Forms.Label()
            CType(Me.blockadd, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.beginp, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.TabControl1.SuspendLayout()
            Me.TabPage1.SuspendLayout()
            Me.TabPage2.SuspendLayout()
            CType(Me.rwps, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.rwbeginp, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.Limitau, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.TabPage3.SuspendLayout()
            CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(57, 229)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(120, 32)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "读4个页  >>"
            '
            'Button2
            '
            Me.Button2.Location = New System.Drawing.Point(57, 267)
            Me.Button2.Name = "Button2"
            Me.Button2.Size = New System.Drawing.Size(120, 32)
            Me.Button2.TabIndex = 1
            Me.Button2.Text = "写1个页  >>"
            '
            'Button3
            '
            Me.Button3.Location = New System.Drawing.Point(57, 131)
            Me.Button3.Name = "Button3"
            Me.Button3.Size = New System.Drawing.Size(120, 32)
            Me.Button3.TabIndex = 2
            Me.Button3.Text = "读卡序列号 >>"
            '
            'Button4
            '
            Me.Button4.Location = New System.Drawing.Point(57, 34)
            Me.Button4.Name = "Button4"
            Me.Button4.Size = New System.Drawing.Size(120, 32)
            Me.Button4.TabIndex = 3
            Me.Button4.Text = "让设备发出声响"
            '
            'Button5
            '
            Me.Button5.Location = New System.Drawing.Point(57, 72)
            Me.Button5.Name = "Button5"
            Me.Button5.Size = New System.Drawing.Size(345, 32)
            Me.Button5.TabIndex = 4
            Me.Button5.Text = "读出设备全球唯一的设备编号,作为加密狗用"
            '
            'TextBox1
            '
            Me.TextBox1.Location = New System.Drawing.Point(183, 138)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(175, 21)
            Me.TextBox1.TabIndex = 5
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label1.Location = New System.Drawing.Point(65, 196)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(112, 16)
            Me.Label1.TabIndex = 7
            Me.Label1.Text = "读写起始页号:"
            '
            'blockadd
            '
            Me.blockadd.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.blockadd.Location = New System.Drawing.Point(183, 191)
            Me.blockadd.Name = "blockadd"
            Me.blockadd.Size = New System.Drawing.Size(54, 26)
            Me.blockadd.TabIndex = 8
            Me.blockadd.Value = New Decimal(New Integer() {4, 0, 0, 0})
            '
            'beginp
            '
            Me.beginp.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.beginp.Location = New System.Drawing.Point(69, 49)
            Me.beginp.Name = "beginp"
            Me.beginp.Size = New System.Drawing.Size(55, 23)
            Me.beginp.TabIndex = 10
            Me.beginp.Value = New Decimal(New Integer() {12, 0, 0, 0})
            '
            'Label2
            '
            Me.Label2.AutoSize = True
            Me.Label2.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label2.Location = New System.Drawing.Point(23, 167)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(59, 12)
            Me.Label2.TabIndex = 9
            Me.Label2.Text = "卡序列号:"
            '
            'TextBox2
            '
            Me.TextBox2.Location = New System.Drawing.Point(184, 236)
            Me.TextBox2.Name = "TextBox2"
            Me.TextBox2.Size = New System.Drawing.Size(218, 21)
            Me.TextBox2.TabIndex = 11
            '
            'TextBox3
            '
            Me.TextBox3.Location = New System.Drawing.Point(184, 274)
            Me.TextBox3.MaxLength = 8
            Me.TextBox3.Name = "TextBox3"
            Me.TextBox3.Size = New System.Drawing.Size(77, 21)
            Me.TextBox3.TabIndex = 12
            '
            'Button6
            '
            Me.Button6.Location = New System.Drawing.Point(90, 263)
            Me.Button6.Name = "Button6"
            Me.Button6.Size = New System.Drawing.Size(344, 32)
            Me.Button6.TabIndex = 13
            Me.Button6.Text = "轻松读卡,最多一次12块 "
            '
            'RichTextBox1
            '
            Me.RichTextBox1.Location = New System.Drawing.Point(89, 188)
            Me.RichTextBox1.Name = "RichTextBox1"
            Me.RichTextBox1.Size = New System.Drawing.Size(727, 67)
            Me.RichTextBox1.TabIndex = 14
            Me.RichTextBox1.Text = ""
            '
            'Button7
            '
            Me.Button7.Location = New System.Drawing.Point(471, 263)
            Me.Button7.Name = "Button7"
            Me.Button7.Size = New System.Drawing.Size(345, 32)
            Me.Button7.TabIndex = 15
            Me.Button7.Text = "轻松写卡,最多一次11块 "
            '
            'TabControl1
            '
            Me.TabControl1.Controls.Add(Me.TabPage1)
            Me.TabControl1.Controls.Add(Me.TabPage2)
            Me.TabControl1.Controls.Add(Me.TabPage3)
            Me.TabControl1.Location = New System.Drawing.Point(1, 1)
            Me.TabControl1.Name = "TabControl1"
            Me.TabControl1.SelectedIndex = 0
            Me.TabControl1.Size = New System.Drawing.Size(861, 426)
            Me.TabControl1.TabIndex = 16
            '
            'TabPage1
            '
            Me.TabPage1.Controls.Add(Me.Button13)
            Me.TabPage1.Controls.Add(Me.Button12)
            Me.TabPage1.Controls.Add(Me.Button11)
            Me.TabPage1.Controls.Add(Me.Button10)
            Me.TabPage1.Controls.Add(Me.Button9)
            Me.TabPage1.Controls.Add(Me.TextBox4)
            Me.TabPage1.Controls.Add(Me.Button8)
            Me.TabPage1.Controls.Add(Me.Button4)
            Me.TabPage1.Controls.Add(Me.Button5)
            Me.TabPage1.Controls.Add(Me.Button3)
            Me.TabPage1.Controls.Add(Me.TextBox1)
            Me.TabPage1.Controls.Add(Me.TextBox3)
            Me.TabPage1.Controls.Add(Me.Button1)
            Me.TabPage1.Controls.Add(Me.blockadd)
            Me.TabPage1.Controls.Add(Me.TextBox2)
            Me.TabPage1.Controls.Add(Me.Label1)
            Me.TabPage1.Controls.Add(Me.Button2)
            Me.TabPage1.Location = New System.Drawing.Point(4, 22)
            Me.TabPage1.Name = "TabPage1"
            Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
            Me.TabPage1.Size = New System.Drawing.Size(853, 400)
            Me.TabPage1.TabIndex = 0
            Me.TabPage1.Text = "NTAG21x页读写函数      "
            Me.TabPage1.UseVisualStyleBackColor = True
            '
            'Button13
            '
            Me.Button13.ForeColor = System.Drawing.Color.Red
            Me.Button13.Location = New System.Drawing.Point(452, 327)
            Me.Button13.Name = "Button13"
            Me.Button13.Size = New System.Drawing.Size(337, 32)
            Me.Button13.TabIndex = 19
            Me.Button13.Text = "锁定16页及之后的页(锁死数据后无法恢复)"
            '
            'Button12
            '
            Me.Button12.ForeColor = System.Drawing.Color.Red
            Me.Button12.Location = New System.Drawing.Point(452, 278)
            Me.Button12.Name = "Button12"
            Me.Button12.Size = New System.Drawing.Size(337, 32)
            Me.Button12.TabIndex = 18
            Me.Button12.Text = "锁定3~15页(锁死数据后无法恢复)"
            '
            'Button11
            '
            Me.Button11.Location = New System.Drawing.Point(452, 229)
            Me.Button11.Name = "Button11"
            Me.Button11.Size = New System.Drawing.Size(337, 32)
            Me.Button11.TabIndex = 17
            Me.Button11.Text = "读取卡单向计数器的值"
            '
            'Button10
            '
            Me.Button10.Location = New System.Drawing.Point(452, 180)
            Me.Button10.Name = "Button10"
            Me.Button10.Size = New System.Drawing.Size(337, 32)
            Me.Button10.TabIndex = 16
            Me.Button10.Text = "读取卡的签名信息,可以验证卡是否NXP正版卡"
            '
            'Button9
            '
            Me.Button9.Location = New System.Drawing.Point(452, 131)
            Me.Button9.Name = "Button9"
            Me.Button9.Size = New System.Drawing.Size(337, 32)
            Me.Button9.TabIndex = 15
            Me.Button9.Text = "读取卡的版本号及型号"
            '
            'TextBox4
            '
            Me.TextBox4.Location = New System.Drawing.Point(184, 334)
            Me.TextBox4.MaxLength = 8
            Me.TextBox4.Name = "TextBox4"
            Me.TextBox4.Size = New System.Drawing.Size(77, 21)
            Me.TextBox4.TabIndex = 14
            Me.TextBox4.Text = "12345678"
            '
            'Button8
            '
            Me.Button8.Location = New System.Drawing.Point(57, 327)
            Me.Button8.Name = "Button8"
            Me.Button8.Size = New System.Drawing.Size(120, 32)
            Me.Button8.TabIndex = 13
            Me.Button8.Text = "卡密码认证  >>"
            '
            'TabPage2
            '
            Me.TabPage2.Controls.Add(Me.Label10)
            Me.TabPage2.Controls.Add(Me.Label9)
            Me.TabPage2.Controls.Add(Me.rwps)
            Me.TabPage2.Controls.Add(Me.rwbeginp)
            Me.TabPage2.Controls.Add(Me.Label8)
            Me.TabPage2.Controls.Add(Me.Label7)
            Me.TabPage2.Controls.Add(Me.TextBox8)
            Me.TabPage2.Controls.Add(Me.TextBox7)
            Me.TabPage2.Controls.Add(Me.CheckBox3)
            Me.TabPage2.Controls.Add(Me.RichTextBox2)
            Me.TabPage2.Controls.Add(Me.Button14)
            Me.TabPage2.Controls.Add(Me.Limitau)
            Me.TabPage2.Controls.Add(Me.Label6)
            Me.TabPage2.Controls.Add(Me.TextBox6)
            Me.TabPage2.Controls.Add(Me.CheckBox2)
            Me.TabPage2.Controls.Add(Me.Label5)
            Me.TabPage2.Controls.Add(Me.Label3)
            Me.TabPage2.Controls.Add(Me.ComboBox1)
            Me.TabPage2.Controls.Add(Me.TextBox5)
            Me.TabPage2.Controls.Add(Me.CheckBox1)
            Me.TabPage2.Controls.Add(Me.Button6)
            Me.TabPage2.Controls.Add(Me.Label2)
            Me.TabPage2.Controls.Add(Me.beginp)
            Me.TabPage2.Controls.Add(Me.Button7)
            Me.TabPage2.Controls.Add(Me.RichTextBox1)
            Me.TabPage2.Location = New System.Drawing.Point(4, 22)
            Me.TabPage2.Name = "TabPage2"
            Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
            Me.TabPage2.Size = New System.Drawing.Size(853, 400)
            Me.TabPage2.TabIndex = 1
            Me.TabPage2.Text = "NTAG21x轻松读写函数      "
            Me.TabPage2.UseVisualStyleBackColor = True
            '
            'Label10
            '
            Me.Label10.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label10.Location = New System.Drawing.Point(30, 340)
            Me.Label10.Name = "Label10"
            Me.Label10.Size = New System.Drawing.Size(54, 53)
            Me.Label10.TabIndex = 35
            Me.Label10.Text = "串口读写器的调试指令:"
            '
            'Label9
            '
            Me.Label9.AutoSize = True
            Me.Label9.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label9.Location = New System.Drawing.Point(23, 191)
            Me.Label9.Name = "Label9"
            Me.Label9.Size = New System.Drawing.Size(59, 12)
            Me.Label9.TabIndex = 34
            Me.Label9.Text = "页内数据:"
            '
            'rwps
            '
            Me.rwps.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.rwps.Location = New System.Drawing.Point(506, 157)
            Me.rwps.Name = "rwps"
            Me.rwps.Size = New System.Drawing.Size(55, 23)
            Me.rwps.TabIndex = 33
            Me.rwps.Value = New Decimal(New Integer() {10, 0, 0, 0})
            '
            'rwbeginp
            '
            Me.rwbeginp.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.rwbeginp.Location = New System.Drawing.Point(344, 156)
            Me.rwbeginp.Name = "rwbeginp"
            Me.rwbeginp.Size = New System.Drawing.Size(58, 23)
            Me.rwbeginp.TabIndex = 32
            Me.rwbeginp.Value = New Decimal(New Integer() {30, 0, 0, 0})
            '
            'Label8
            '
            Me.Label8.AutoSize = True
            Me.Label8.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label8.Location = New System.Drawing.Point(446, 167)
            Me.Label8.Name = "Label8"
            Me.Label8.Size = New System.Drawing.Size(65, 12)
            Me.Label8.TabIndex = 31
            Me.Label8.Text = "读写页数:"
            '
            'Label7
            '
            Me.Label7.AutoSize = True
            Me.Label7.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label7.Location = New System.Drawing.Point(257, 167)
            Me.Label7.Name = "Label7"
            Me.Label7.Size = New System.Drawing.Size(89, 12)
            Me.Label7.TabIndex = 30
            Me.Label7.Text = "读写起始页号:"
            '
            'TextBox8
            '
            Me.TextBox8.Location = New System.Drawing.Point(88, 158)
            Me.TextBox8.Name = "TextBox8"
            Me.TextBox8.Size = New System.Drawing.Size(130, 21)
            Me.TextBox8.TabIndex = 29
            '
            'TextBox7
            '
            Me.TextBox7.Location = New System.Drawing.Point(344, 131)
            Me.TextBox7.MaxLength = 8
            Me.TextBox7.Name = "TextBox7"
            Me.TextBox7.Size = New System.Drawing.Size(59, 21)
            Me.TextBox7.TabIndex = 28
            Me.TextBox7.Text = "12345678"
            '
            'CheckBox3
            '
            Me.CheckBox3.AutoSize = True
            Me.CheckBox3.Location = New System.Drawing.Point(89, 135)
            Me.CheckBox3.Name = "CheckBox3"
            Me.CheckBox3.Size = New System.Drawing.Size(258, 16)
            Me.CheckBox3.TabIndex = 27
            Me.CheckBox3.Text = "选择先认证卡密码才能继续操作,认证密码:"
            Me.CheckBox3.UseVisualStyleBackColor = True
            '
            'RichTextBox2
            '
            Me.RichTextBox2.Location = New System.Drawing.Point(89, 336)
            Me.RichTextBox2.Name = "RichTextBox2"
            Me.RichTextBox2.Size = New System.Drawing.Size(728, 47)
            Me.RichTextBox2.TabIndex = 26
            Me.RichTextBox2.Text = ""
            '
            'Button14
            '
            Me.Button14.BackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer))
            Me.Button14.Location = New System.Drawing.Point(23, 78)
            Me.Button14.Name = "Button14"
            Me.Button14.Size = New System.Drawing.Size(793, 30)
            Me.Button14.TabIndex = 25
            Me.Button14.Text = "按以上参数设置卡密码及保护机制"
            Me.Button14.UseVisualStyleBackColor = False
            '
            'Limitau
            '
            Me.Limitau.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Limitau.Location = New System.Drawing.Point(699, 46)
            Me.Limitau.Name = "Limitau"
            Me.Limitau.Size = New System.Drawing.Size(55, 23)
            Me.Limitau.TabIndex = 24
            '
            'Label6
            '
            Me.Label6.AutoSize = True
            Me.Label6.Location = New System.Drawing.Point(513, 54)
            Me.Label6.Name = "Label6"
            Me.Label6.Size = New System.Drawing.Size(191, 12)
            Me.Label6.TabIndex = 23
            Me.Label6.Text = "允许密码错误次数(0为不限次):"
            '
            'TextBox6
            '
            Me.TextBox6.Location = New System.Drawing.Point(448, 48)
            Me.TextBox6.MaxLength = 8
            Me.TextBox6.Name = "TextBox6"
            Me.TextBox6.Size = New System.Drawing.Size(59, 21)
            Me.TextBox6.TabIndex = 22
            Me.TextBox6.Text = "12345678"
            '
            'CheckBox2
            '
            Me.CheckBox2.AutoSize = True
            Me.CheckBox2.Location = New System.Drawing.Point(238, 53)
            Me.CheckBox2.Name = "CheckBox2"
            Me.CheckBox2.Size = New System.Drawing.Size(216, 16)
            Me.CheckBox2.TabIndex = 21
            Me.CheckBox2.Text = "选择开启读操作密码保护,新密码:"
            Me.CheckBox2.UseVisualStyleBackColor = True
            '
            'Label5
            '
            Me.Label5.AutoSize = True
            Me.Label5.Location = New System.Drawing.Point(130, 54)
            Me.Label5.Name = "Label5"
            Me.Label5.Size = New System.Drawing.Size(113, 12)
            Me.Label5.TabIndex = 20
            Me.Label5.Text = "页开始有密码保护,"
            '
            'Label3
            '
            Me.Label3.AutoSize = True
            Me.Label3.Location = New System.Drawing.Point(45, 54)
            Me.Label3.Name = "Label3"
            Me.Label3.Size = New System.Drawing.Size(17, 12)
            Me.Label3.TabIndex = 19
            Me.Label3.Text = "从"
            '
            'ComboBox1
            '
            Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
            Me.ComboBox1.ForeColor = System.Drawing.Color.Red
            Me.ComboBox1.FormattingEnabled = True
            Me.ComboBox1.Items.AddRange(New Object() {"开启密码保护功能", "取消密码保护功能"})
            Me.ComboBox1.Location = New System.Drawing.Point(395, 16)
            Me.ComboBox1.Name = "ComboBox1"
            Me.ComboBox1.Size = New System.Drawing.Size(146, 20)
            Me.ComboBox1.TabIndex = 18
            '
            'TextBox5
            '
            Me.TextBox5.Location = New System.Drawing.Point(325, 15)
            Me.TextBox5.MaxLength = 8
            Me.TextBox5.Name = "TextBox5"
            Me.TextBox5.Size = New System.Drawing.Size(59, 21)
            Me.TextBox5.TabIndex = 17
            Me.TextBox5.Text = "12345678"
            '
            'CheckBox1
            '
            Me.CheckBox1.AutoSize = True
            Me.CheckBox1.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.CheckBox1.Location = New System.Drawing.Point(71, 19)
            Me.CheckBox1.Name = "CheckBox1"
            Me.CheckBox1.Size = New System.Drawing.Size(258, 16)
            Me.CheckBox1.TabIndex = 16
            Me.CheckBox1.Text = "选择先认证卡密码才能继续操作,认证密码:"
            Me.CheckBox1.UseVisualStyleBackColor = True
            '
            'TabPage3
            '
            Me.TabPage3.Controls.Add(Me.PictureBox1)
            Me.TabPage3.Location = New System.Drawing.Point(4, 22)
            Me.TabPage3.Name = "TabPage3"
            Me.TabPage3.Size = New System.Drawing.Size(853, 400)
            Me.TabPage3.TabIndex = 2
            Me.TabPage3.Text = "NTAG21x卡数据结构说明      "
            Me.TabPage3.UseVisualStyleBackColor = True
            '
            'PictureBox1
            '
            Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
            Me.PictureBox1.Location = New System.Drawing.Point(3, 3)
            Me.PictureBox1.Name = "PictureBox1"
            Me.PictureBox1.Size = New System.Drawing.Size(850, 397)
            Me.PictureBox1.TabIndex = 0
            Me.PictureBox1.TabStop = False
            '
            'Label4
            '
            Me.Label4.AutoSize = True
            Me.Label4.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
            Me.Label4.ForeColor = System.Drawing.Color.Blue
            Me.Label4.Location = New System.Drawing.Point(240, 439)
            Me.Label4.Name = "Label4"
            Me.Label4.Size = New System.Drawing.Size(360, 16)
            Me.Label4.TabIndex = 18
            Me.Label4.Text = "建议将OUR_MIFARE.dll复制到应用程序同一目录下"
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
            Me.ClientSize = New System.Drawing.Size(863, 463)
            Me.Controls.Add(Me.Label4)
            Me.Controls.Add(Me.TabControl1)
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "Form1"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "NTAG21x卡读写器例子程序"
            CType(Me.blockadd, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.beginp, System.ComponentModel.ISupportInitialize).EndInit()
            Me.TabControl1.ResumeLayout(False)
            Me.TabPage1.ResumeLayout(False)
            Me.TabPage1.PerformLayout()
            Me.TabPage2.ResumeLayout(False)
            Me.TabPage2.PerformLayout()
            CType(Me.rwps, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.rwbeginp, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.Limitau, System.ComponentModel.ISupportInitialize).EndInit()
            Me.TabPage3.ResumeLayout(False)
            CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub

    #End Region

    1. Module Module1
    2.     '让设备发出声响函数声明
    3.     Public Declare Function pcdbeep Lib "OUR_MIFARE.dll" (ByVal xms As Long) As Byte
    4.     '读取设备编号函数声明
    5.     Public Declare Function pcdgetdevicenumber Lib "OUR_MIFARE.dll" (ByRef devicenumber As Byte) As Byte
    6.     '寻卡选卡激活卡
    7.     Public Declare Function piccrequest_ul Lib "OUR_MIFARE.dll" (ByRef devicenumber As Byte) As Byte
    8.     '读块
    9.     Public Declare Function piccread_ul Lib "OUR_MIFARE.dll" (ByVal blockaddr As Byte, ByRef piccdata As Byte) As Byte
    10.     '写块
    11.     Public Declare Function piccwrite_ul Lib "OUR_MIFARE.dll" (ByVal blockaddr As Byte, ByRef piccdata As Byte) As Byte
    12.     'ntag21x卡的密码认证
    13.     Public Declare Function piccauthkey_ntag Lib "OUR_MIFARE.dll" (ByRef picckey As Byte, ByRef piccntagpack As Byte) As Byte
    14.     '读取卡版本信息
    15.     Public Declare Function piccgetversion_ntag Lib "OUR_MIFARE.dll" (ByRef piccversiondata As Byte) As Byte
    16.     '读取卡的签字信息
    17.     Public Declare Function piccreadsig_ntag Lib "OUR_MIFARE.dll" (ByRef piccsigdata As Byte) As Byte
    18.     '读取卡的单向操作计数器(操作流水号)
    19.     Public Declare Function piccreadcnt_ntag Lib "OUR_MIFARE.dll" (ByRef picccntdata As Byte) As Byte
    20.     '锁定页数据
    21.     Public Declare Function picclock_ntag Lib "OUR_MIFARE.dll" (ByVal locktype As Byte, ByRef mypicclockdata As Byte) As Byte
    22.     '初始化卡
    23.     Public Declare Function piccinit_ntag Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByRef serial As Byte, ByRef picckey As Byte, ByRef piccdata As Byte) As Byte
    24.     '轻松读卡
    25.     Public Declare Function piccreadex_ntag Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByRef serial As Byte, ByRef picckey As Byte, ByVal blockaddr As Byte, ByVal blocksize As Byte, ByRef piccdata As Byte) As Byte
    26.     '轻松写卡
    27.     Public Declare Function piccwriteex_ntag Lib "OUR_MIFARE.dll" (ByVal ctrlword As Byte, ByRef serial As Byte, ByRef picckey As Byte, ByVal blockaddr As Byte, ByVal blocksize As Byte, ByRef piccdata As Byte) As Byte
    28.     '控制字定义,控制字指定,控制字的含义请查看本公司网站提供的动态库说明
    29.     Public Const BLOCK0_EN = &H1 '操作第0块
    30.     Public Const BLOCK1_EN = &H2 '操作第1块
    31.     Public Const BLOCK2_EN = &H4 '操作第2块
    32.     Public Const NEEDSERIAL = &H8 '仅对指定序列号的卡号操作
    33.     Public Const EXTERNKEY = &H10 '需要在参数中指定认证密码
    34.     Public Const NEEDHALT = &H20 '操作后休眠该卡,必须拿开卡再放回感应区才能重新感应到卡
    35. End Module

       

    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         '轻松读卡
    3.         '技术支持:
    4.         '网站:
    5.         Dim status As Byte '存放返回值
    6.         Dim mypiccserial(7) As Byte '卡序列号
    7.         Dim i As Integer
    8.         Dim cardidhex As String
    9.         Dim mypiccdata(0 To 15) As Byte '读卡的数据缓冲,Ultralight卡及NTAG21x卡的数组长度必须为16个字节,写卡的为4个字节
    10.         Dim myblockaddr As Byte '起始块地址
    11.         status = piccrequest_ul(mypiccserial(0))
    12.         Select Case status
    13.             Case 0
    14.                 pcdbeep(50)
    15.                 cardidhex = ""
    16.                 For i = 0 To 6
    17.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    18.                 Next
    19.                 TextBox1.Text = cardidhex
    20.                 myblockaddr = CByte(blockadd.Value)
    21.                 status = piccread_ul(myblockaddr, mypiccdata(0))
    22.                 If status = 0 Then
    23.                     cardidhex = ""
    24.                     For i = 0 To 15
    25.                         cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccdata(i)), 2)
    26.                     Next
    27.                     TextBox2.Text = cardidhex
    28.                     MsgBox("读卡成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    29.                 Else
    30.                     MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    31.                 End If
    32.             Case 8
    33.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    34.             Case 23
    35.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    36.             Case Else
    37.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    38.         End Select
    39.         '返回解释
    40.         '#define ERR_REQUEST 8'寻卡错误
    41.         '#define ERR_READSERIAL 9'读序列吗错误
    42.         '#define ERR_SELECTCARD 10'选卡错误
    43.         '#define ERR_LOADKEY 11'装载密码错误
    44.         '#define ERR_AUTHKEY 12'密码认证错误
    45.         '#define ERR_READ 13'读卡错误
    46.         '#define ERR_WRITE 14'写卡错误
    47.         '#define ERR_NONEDLL 21'没有动态库
    48.         '#define ERR_DRIVERORDLL 22'动态库或驱动程序异常
    49.         '#define ERR_DRIVERNULL 23'驱动程序错误或尚未安装
    50.         '#define ERR_TIMEOUT 24'操作超时,一般是动态库没有反映
    51.         '#define ERR_TXSIZE 25'发送字数不够
    52.         '#define ERR_TXCRC 26'发送的CRC错
    53.         '#define ERR_RXSIZE 27'接收的字数不够
    54.         '#define ERR_RXCRC 28'接收的CRC错
    55.     End Sub
    56.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    57.         '读取设备编号,可做为软件加密狗用,也可以根据此编号在公司网站上查询保修期限
    58.         '技术支持:
    59.         '网站:
    60.         Dim status As Byte '存放返回值
    61.         Dim devno(3) As Byte '设备编号
    62.         status = pcdgetdevicenumber(devno(0))
    63.         If status = 0 Then
    64.             pcdbeep(50)
    65.             MsgBox(CStr(devno(0)) + "-" + CStr(devno(1)) + "-" + CStr(devno(2)) + "-" + CStr(devno(3)))
    66.         End If
    67.         '返回解释
    68.         '#define ERR_REQUEST 8'寻卡错误
    69.         '#define ERR_READSERIAL 9'读序列吗错误
    70.         '#define ERR_SELECTCARD 10'选卡错误
    71.         '#define ERR_LOADKEY 11'装载密码错误
    72.         '#define ERR_AUTHKEY 12'密码认证错误
    73.         '#define ERR_READ 13'读卡错误
    74.         '#define ERR_WRITE 14'写卡错误
    75.         '#define ERR_NONEDLL 21'没有动态库
    76.         '#define ERR_DRIVERORDLL 22'动态库或驱动程序异常
    77.         '#define ERR_DRIVERNULL 23'驱动程序错误或尚未安装
    78.         '#define ERR_TIMEOUT 24'操作超时,一般是动态库没有反映
    79.         '#define ERR_TXSIZE 25'发送字数不够
    80.         '#define ERR_TXCRC 26'发送的CRC错
    81.         '#define ERR_RXSIZE 27'接收的字数不够
    82.         '#define ERR_RXCRC 28'接收的CRC错
    83.     End Sub
    84.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    85.         pcdbeep(50)
    86.     End Sub
    87.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    88.         '轻松写卡
    89.         '技术支持:
    90.         '网站:
    91.         '轻松读卡
    92.         '技术支持:
    93.         '网站:
    94.         Dim status As Byte '存放返回值
    95.         Dim mypiccserial(7) As Byte '卡序列号
    96.         Dim i As Integer
    97.         Dim cardidhex, writstr As String
    98.         Dim mypiccdata(0 To 3) As Byte '写卡的数据缓冲,Ultralight卡及NTAG21x卡的数组长度必须为16个字节,写卡的为4个字节
    99.         Dim myblockaddr As Byte '起始块地址
    100.         If Len(Trim(TextBox3.Text)) < 8 Then
    101.             i = MsgBox("写卡信息不足,是否在后面自动补0?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "提示")
    102.             If i <> vbOK Then
    103.                 TextBox3.Select()
    104.                 Exit Sub
    105.             Else
    106.                 TextBox3.Text = Strings.Left(Trim(TextBox3.Text) + "00000000", 8)
    107.                 writstr = Strings.Left(Trim(TextBox3.Text) + "00000000", 8)
    108.             End If
    109.         Else
    110.             writstr = Trim(TextBox3.Text)
    111.         End If
    112.         status = piccrequest_ul(mypiccserial(0))
    113.         Select Case status
    114.             Case 0
    115.                 cardidhex = ""
    116.                 For i = 0 To 6
    117.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    118.                 Next
    119.                 TextBox1.Text = cardidhex
    120.                 For i = 0 To 3
    121.                     mypiccdata(i) = CByte("&H" & Mid(writstr, i * 2 + 1, 2))
    122.                 Next
    123.                 myblockaddr = CByte(blockadd.Value)
    124.                 status = piccwrite_ul(myblockaddr, mypiccdata(0))
    125.                 If status = 0 Then
    126.                     pcdbeep(50)
    127.                     MsgBox("写卡成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    128.                 ElseIf status = 14 Then
    129.                     MsgBox("写卡失败!可能页已经锁死不可再修改或要认证密码。", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    130.                 Else
    131.                     MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    132.                 End If
    133.             Case 8
    134.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    135.             Case 23
    136.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    137.             Case Else
    138.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    139.         End Select
    140.         '返回解释
    141.         '#define ERR_REQUEST 8'寻卡错误
    142.         '#define ERR_READSERIAL 9'读序列吗错误
    143.         '#define ERR_SELECTCARD 10'选卡错误
    144.         '#define ERR_LOADKEY 11'装载密码错误
    145.         '#define ERR_AUTHKEY 12'密码认证错误
    146.         '#define ERR_READ 13'读卡错误
    147.         '#define ERR_WRITE 14'写卡错误
    148.         '#define ERR_NONEDLL 21'没有动态库
    149.         '#define ERR_DRIVERORDLL 22'动态库或驱动程序异常
    150.         '#define ERR_DRIVERNULL 23'驱动程序错误或尚未安装
    151.         '#define ERR_TIMEOUT 24'操作超时,一般是动态库没有反映
    152.         '#define ERR_TXSIZE 25'发送字数不够
    153.         '#define ERR_TXCRC 26'发送的CRC错
    154.         '#define ERR_RXSIZE 27'接收的字数不够
    155.         '#define ERR_RXCRC 28'接收的CRC错
    156.     End Sub
    157.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    158.         Dim status As Byte '存放返回值
    159.         Dim mypiccserial(7) As Byte '卡序列号
    160.         Dim i As Integer
    161.         Dim cardidhex As String
    162.         status = piccrequest_ul(mypiccserial(0))
    163.         Select Case status
    164.             Case 0
    165.                 pcdbeep(50)
    166.                 cardidhex = ""
    167.                 For i = 0 To 6
    168.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    169.                 Next
    170.                 TextBox1.Text = cardidhex
    171.                 MsgBox("读卡序列号成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    172.             Case 8
    173.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    174.             Case 23
    175.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    176.             Case Else
    177.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    178.         End Select
    179.         '返回解释
    180.         '#define ERR_REQUEST 8'寻卡错误
    181.         '#define ERR_READSERIAL 9'读序列吗错误
    182.         '#define ERR_SELECTCARD 10'选卡错误
    183.         '#define ERR_LOADKEY 11'装载密码错误
    184.         '#define ERR_AUTHKEY 12'密码认证错误
    185.         '#define ERR_READ 13'读卡错误
    186.         '#define ERR_WRITE 14'写卡错误
    187.         '#define ERR_NONEDLL 21'没有动态库
    188.         '#define ERR_DRIVERORDLL 22'动态库或驱动程序异常
    189.         '#define ERR_DRIVERNULL 23'驱动程序错误或尚未安装
    190.         '#define ERR_TIMEOUT 24'操作超时,一般是动态库没有反映
    191.         '#define ERR_TXSIZE 25'发送字数不够
    192.         '#define ERR_TXCRC 26'发送的CRC错
    193.         '#define ERR_RXSIZE 27'接收的字数不够
    194.         '#define ERR_RXCRC 28'接收的CRC错
    195.     End Sub
    196.     Private Sub TextBox3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox3.KeyPress
    197.         If (e.KeyChar >= "0" And e.KeyChar <= "9") Or (e.KeyChar >= "A" And e.KeyChar <= "F") Or (e.KeyChar >= "a" And e.KeyChar <= "f") Then    '控制只能输入16进制数
    198.             e.Handled = False
    199.         Else
    200.             e.Handled = True
    201.         End If
    202.     End Sub
    203.     Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    204.         '轻松读卡
    205.         '技术支持:
    206.         '网站:
    207.         Dim i As Integer
    208.         Dim cardidhex, authkey, Str As String
    209.         Dim status, myctrlword, comedc As Byte '存放返回值
    210.         Dim mypiccserial(7) As Byte '卡序列号
    211.         Dim mypicckey(0 To 3) As Byte '认证密码
    212.         Dim mypiccdata(0 To 47) As Byte '读卡的数据缓冲,Ultralight卡及NTAG21x卡的数组长度必须为16个字节,写卡的为4个字节
    213.         Dim myblockaddr As Byte '起始块地址
    214.         Dim myblocksize As Byte '总块数
    215.         If CheckBox3.Checked Then
    216.             If Len(Trim(TextBox7.Text)) < 8 Then
    217.                 i = MsgBox("卡认证密码位数不足!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    218.                 If i <> vbOK Then
    219.                     TextBox7.Select()
    220.                     Exit Sub
    221.                 End If
    222.             Else
    223.                 authkey = Trim(TextBox7.Text)
    224.                 For i = 0 To 3
    225.                     mypicckey(i) = CByte("&H" & Mid(authkey, i * 2 + 1, 2))
    226.                 Next
    227.             End If
    228.             myctrlword = &H10  '需要认证卡密码后再继续
    229.         Else
    230.             myctrlword = 0
    231.         End If
    232.         myblockaddr = CByte(rwbeginp.Value)
    233.         myblocksize = CByte(rwps.Value)
    234.         '-------------------------------------------------------------------------
    235.         '输出串口模块调式码
    236.         comedc = &H1B
    237.         Str = "0F1B"
    238.         '控制字
    239.         Str = Str + Strings.Right("00" + Hex(myctrlword), 2)
    240.         comedc = comedc Xor myctrlword
    241.         '卡号
    242.         For i = 0 To 6
    243.             Str = Str + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    244.             comedc = comedc Xor mypiccserial(i)
    245.         Next i
    246.         '密码
    247.         For i = 0 To 3
    248.             Str = Str + Strings.Right("00" + Hex(mypicckey(i)), 2)
    249.             comedc = comedc Xor mypicckey(i)
    250.         Next i
    251.         '起始页号
    252.         Str = Str + Strings.Right("00" + Hex(myblockaddr), 2)
    253.         comedc = comedc Xor myblockaddr
    254.         '起读写页数
    255.         Str = Str + Strings.Right("00" + Hex(myblocksize), 2)
    256.         comedc = comedc Xor myblocksize
    257.         '校验码
    258.         Str = Str + Strings.Right("00" + Hex(comedc), 2)
    259.         RichTextBox2.Text = Str
    260.         '-------------------------------------------------------------------------
    261.         status = piccreadex_ntag(myctrlword, mypiccserial(0), mypicckey(0), myblockaddr, myblocksize, mypiccdata(0))
    262.         Select Case status
    263.             Case 0
    264.                 pcdbeep(50)
    265.                 cardidhex = ""
    266.                 For i = 0 To 6
    267.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    268.                 Next
    269.                 TextBox8.Text = cardidhex
    270.                 cardidhex = ""
    271.                 For i = 0 To myblocksize * 4 - 1
    272.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccdata(i)), 2)
    273.                 Next
    274.                 RichTextBox1.Text = cardidhex
    275.                 MsgBox("读卡成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    276.             Case 8
    277.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    278.             Case 12
    279.                 MsgBox("密码错误!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    280.             Case 13
    281.                 MsgBox("读卡失败,可能需要验证密码!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    282.             Case 23
    283.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    284.             Case Else
    285.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    286.         End Select
    287.     End Sub
    288.     Private Sub RichTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox1.KeyPress  '输入栏只能输入16进制数
    289.         If (e.KeyChar >= "0" And e.KeyChar <= "9") Or (e.KeyChar >= "A" And e.KeyChar <= "F") Or (e.KeyChar >= "a" And e.KeyChar <= "f") Then    '控制只能输入16进制数
    290.             e.Handled = False
    291.         Else
    292.             e.Handled = True
    293.         End If
    294.     End Sub
    295.     Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    296.         '技术支持:
    297.         '网站:
    298.         Dim i As Integer
    299.         Dim cardidhex, authkey, Str, writstr As String
    300.         Dim status, myctrlword, comedc As Byte '存放返回值
    301.         Dim mypiccserial(7) As Byte '卡序列号
    302.         Dim mypicckey(0 To 3) As Byte '认证密码
    303.         Dim mypiccdata(0 To 47) As Byte '读卡的数据缓冲,Ultralight卡及NTAG21x卡的数组长度必须为16个字节,写卡的为4个字节
    304.         Dim myblockaddr As Byte '起始块地址
    305.         Dim myblocksize As Byte '总块数
    306.         If rwps.Value < 1 Or rwps.Value > 11 Then
    307.             MsgBox("写卡页数必须大于0,小于12!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    308.             Exit Sub
    309.         End If
    310.         myblockaddr = CByte(rwbeginp.Value)
    311.         myblocksize = CByte(rwps.Value)
    312.         If CheckBox3.Checked Then
    313.             If Len(Trim(TextBox7.Text)) < 8 Then
    314.                 i = MsgBox("卡认证密码位数不足!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    315.                 If i <> vbOK Then
    316.                     TextBox7.Select()
    317.                     Exit Sub
    318.                 End If
    319.             Else
    320.                 authkey = Trim(TextBox7.Text)
    321.                 For i = 0 To 3
    322.                     mypicckey(i) = CByte("&H" & Mid(authkey, i * 2 + 1, 2))
    323.                 Next
    324.             End If
    325.             myctrlword = &H10  '需要认证卡密码后再继续
    326.         Else
    327.             myctrlword = 0
    328.         End If
    329.         If Len(Trim(RichTextBox1.Text)) < myblocksize * 4 * 2 Then
    330.             i = MsgBox("写卡信息不足,是否在后面自动补0?", MsgBoxStyle.Question + MsgBoxStyle.OkCancel, "提示")
    331.             If i <> vbOK Then
    332.                 RichTextBox1.Select()
    333.                 Exit Sub
    334.             Else
    335.                 RichTextBox1.Text = Strings.Left(Trim(RichTextBox1.Text) + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", myblocksize * 4 * 2)
    336.                 writstr = Strings.Left(Trim(RichTextBox1.Text) + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", myblocksize * 4 * 2)
    337.             End If
    338.         Else
    339.             writstr = Trim(RichTextBox1.Text)
    340.         End If
    341.         For i = 0 To myblocksize * 4 - 1
    342.             mypiccdata(i) = CByte("&H" & Mid(writstr, i * 2 + 1, 2))
    343.         Next
    344.         '-------------------------------------------------------------------------
    345.         '输出串口模块调式码
    346.         comedc = &H1C
    347.         Str = "3B1C"
    348.         '控制字
    349.         Str = Str + Strings.Right("00" + Hex(myctrlword), 2)
    350.         comedc = comedc Xor myctrlword
    351.         '卡号
    352.         For i = 0 To 6
    353.             Str = Str + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    354.             comedc = comedc Xor mypiccserial(i)
    355.         Next i
    356.         '密码
    357.         For i = 0 To 3
    358.             Str = Str + Strings.Right("00" + Hex(mypicckey(i)), 2)
    359.             comedc = comedc Xor mypicckey(i)
    360.         Next i
    361.         '起始页号
    362.         Str = Str + Strings.Right("00" + Hex(myblockaddr), 2)
    363.         comedc = comedc Xor myblockaddr
    364.         '起读写页数
    365.         Str = Str + Strings.Right("00" + Hex(myblocksize), 2)
    366.         comedc = comedc Xor myblocksize
    367.         For i = 0 To 43
    368.             Str = Str + Strings.Right("00" + Hex(mypiccdata(i)), 2)
    369.             comedc = comedc Xor mypiccdata(i)
    370.         Next
    371.         '校验码
    372.         Str = Str + Strings.Right("00" + Hex(comedc), 2)
    373.         RichTextBox2.Text = Str
    374.         '-------------------------------------------------------------------------
    375.         status = piccwriteex_ntag(myctrlword, mypiccserial(0), mypicckey(0), myblockaddr, myblocksize, mypiccdata(0))
    376.         Select Case status
    377.             Case 0
    378.                 pcdbeep(50)
    379.                 cardidhex = ""
    380.                 For i = 0 To 6
    381.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    382.                 Next
    383.                 TextBox8.Text = cardidhex
    384.                 MsgBox("写卡成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    385.             Case 8
    386.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    387.             Case 12
    388.                 MsgBox("密码错误!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    389.             Case 14
    390.                 MsgBox("写卡失败,可能需要验证密码或页已经锁定!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    391.             Case 23
    392.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    393.             Case Else
    394.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    395.         End Select
    396.     End Sub
    397.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    398.         ComboBox1.SelectedIndex = 1
    399.     End Sub
    400.     Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    401.         Dim status As Byte '存放返回值
    402.         Dim mypiccserial(7) As Byte '卡序列号
    403.         Dim i As Integer
    404.         Dim cardidhex, keystr As String
    405.         Dim mypicckey(0 To 3) As Byte '4字节卡认证密码
    406.         Dim mypiccntagpack(0 To 1) As Byte '2字节确认码
    407.         If Len(Trim(TextBox4.Text)) <> 8 Then
    408.             TextBox4.Select()
    409.             MsgBox("认证密码必须是4个字节8位数字!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    410.             Exit Sub
    411.         Else
    412.             keystr = Trim(TextBox4.Text)
    413.         End If
    414.         status = piccrequest_ul(mypiccserial(0))
    415.         Select Case status
    416.             Case 0
    417.                 pcdbeep(50)
    418.                 cardidhex = ""
    419.                 For i = 0 To 6
    420.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    421.                 Next
    422.                 TextBox8.Text = cardidhex
    423.                 For i = 0 To 3
    424.                     mypicckey(i) = CByte("&H" & Mid(keystr, i * 2 + 1, 2))
    425.                 Next
    426.                 status = piccauthkey_ntag(mypicckey(0), mypiccntagpack(0))
    427.                 If status = 0 Then
    428.                     MsgBox("卡密码认证成功!确认码为:" + Strings.Right("00" + Hex(mypiccntagpack(0)), 2) + Strings.Right("00" + Hex(mypiccntagpack(1)), 2), MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    429.                 ElseIf status = 12 Then
    430.                     MsgBox("卡密码认证错误,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    431.                 Else
    432.                     MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    433.                 End If
    434.             Case 8
    435.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    436.             Case 23
    437.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    438.             Case Else
    439.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    440.         End Select
    441.     End Sub
    442.     Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
    443.         Dim status As Byte '存放返回值
    444.         Dim mypiccserial(7) As Byte '卡序列号
    445.         Dim piccversiondata(7) As Byte '卡版本信息
    446.         Dim i As Integer
    447.         Dim cardidhex As String
    448.         status = piccrequest_ul(mypiccserial(0))
    449.         Select Case status
    450.             Case 0
    451.                 pcdbeep(50)
    452.                 cardidhex = ""
    453.                 For i = 0 To 6
    454.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    455.                 Next
    456.                 TextBox1.Text = cardidhex
    457.                 status = piccgetversion_ntag(piccversiondata(0))
    458.                 If status = 0 Then
    459.                     cardidhex = ""
    460.                     For i = 0 To 7
    461.                         cardidhex = cardidhex + Strings.Right("00" + Hex(piccversiondata(i)), 2)
    462.                     Next
    463.                     MsgBox("卡版本信息:" + cardidhex, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    464.                 Else
    465.                     MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    466.                 End If
    467.             Case 8
    468.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    469.             Case 23
    470.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    471.             Case Else
    472.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    473.         End Select
    474.     End Sub
    475.     Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
    476.         Dim status As Byte '存放返回值
    477.         Dim mypiccserial(7) As Byte '卡序列号
    478.         Dim piccsigdata(31) As Byte '卡签字信息
    479.         Dim i As Integer
    480.         Dim cardidhex As String
    481.         status = piccrequest_ul(mypiccserial(0))
    482.         Select Case status
    483.             Case 0
    484.                 pcdbeep(50)
    485.                 cardidhex = ""
    486.                 For i = 0 To 6
    487.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    488.                 Next
    489.                 TextBox1.Text = cardidhex
    490.                 status = piccreadsig_ntag(piccsigdata(0))
    491.                 If status = 0 Then
    492.                     cardidhex = ""
    493.                     For i = 0 To 31
    494.                         cardidhex = cardidhex + Strings.Right("00" + Hex(piccsigdata(i)), 2)
    495.                     Next
    496.                     MsgBox("卡签字信息:" + cardidhex, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    497.                 Else
    498.                     MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    499.                 End If
    500.             Case 8
    501.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    502.             Case 23
    503.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    504.             Case Else
    505.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    506.         End Select
    507.     End Sub
    508.     Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
    509.         Dim status As Byte '存放返回值
    510.         Dim mypiccserial(7) As Byte '卡序列号
    511.         Dim mypicccntdata(2) As Byte '卡操作的单向计数器(卡操作流水号)
    512.         Dim i As Integer
    513.         Dim cardidhex As String
    514.         status = piccrequest_ul(mypiccserial(0))
    515.         Select Case status
    516.             Case 0
    517.                 pcdbeep(50)
    518.                 cardidhex = ""
    519.                 For i = 0 To 6
    520.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    521.                 Next
    522.                 TextBox1.Text = cardidhex
    523.                 status = piccreadcnt_ntag(mypicccntdata(0))
    524.                 If status = 0 Then
    525.                     cardidhex = ""
    526.                     For i = 0 To 2
    527.                         cardidhex = cardidhex + Strings.Right("00" + Hex(mypicccntdata(i)), 2)
    528.                     Next
    529.                     MsgBox("卡操作的单向计数器:" + cardidhex, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    530.                 ElseIf status = 13 Then
    531.                     MsgBox("    可能是计数器功能尚未启用或卡本身不支持计数功能,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    532.                 Else
    533.                     MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    534.                 End If
    535.             Case 8
    536.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    537.             Case 23
    538.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    539.             Case Else
    540.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    541.         End Select
    542.     End Sub
    543.     Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
    544.         Dim status As Byte '存放返回值
    545.         Dim mypiccserial(7) As Byte '卡序列号
    546.         Dim mypicclockdata(3) As Byte '写卡的为4个字节
    547.         Dim i, answ As Integer
    548.         Dim cardidhex As String
    549.         status = piccrequest_ul(mypiccserial(0))
    550.         Select Case status
    551.             Case 0
    552.                 pcdbeep(50)
    553.                 cardidhex = ""
    554.                 For i = 0 To 6
    555.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    556.                 Next
    557.                 TextBox1.Text = cardidhex
    558.                 answ = MsgBox("    确定要锁死本卡的0~15页吗?锁死后这些页的数据不能再更改。", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "提示")
    559.                 If answ = vbOK Then
    560.                     mypicclockdata(0) = 0        '除非您确认了解这几个字节的意思,否则不要随修改
    561.                     mypicclockdata(1) = 0
    562.                     mypicclockdata(2) = &HF9
    563.                     mypicclockdata(3) = 0
    564.                     status = picclock_ntag(0, mypicclockdata(0))   '锁定0~15d页
    565.                     If status = 0 Then
    566.                         pcdbeep(50)
    567.                         MsgBox("0~15页锁定位写入成功!!!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    568.                     ElseIf status = 14 Then
    569.                         MsgBox("写卡失败!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    570.                     Else
    571.                         MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    572.                     End If
    573.                 End If
    574.             Case 8
    575.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    576.             Case 23
    577.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    578.             Case Else
    579.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    580.         End Select
    581.     End Sub
    582.     Private Sub TextBox4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox4.KeyPress
    583.         If (e.KeyChar >= "0" And e.KeyChar <= "9") Or (e.KeyChar >= "A" And e.KeyChar <= "F") Or (e.KeyChar >= "a" And e.KeyChar <= "f") Then   '控制只能输入16进制数
    584.             e.Handled = False
    585.         Else
    586.             e.Handled = True
    587.         End If
    588.     End Sub
    589.     Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
    590.         Dim status As Byte '存放返回值
    591.         Dim mypiccserial(7) As Byte '卡序列号
    592.         Dim mypicclockdata(3) As Byte '写卡的为4个字节
    593.         Dim i, answ As Integer
    594.         Dim cardidhex As String
    595.         status = piccrequest_ul(mypiccserial(0))
    596.         Select Case status
    597.             Case 0
    598.                 pcdbeep(50)
    599.                 cardidhex = ""
    600.                 For i = 0 To 6
    601.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    602.                 Next
    603.                 TextBox1.Text = cardidhex
    604.                 answ = MsgBox("    确定要锁死本卡16页以后的数据吗?锁死后这些页的数据不能再更改。", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "提示")
    605.                 If answ = vbOK Then
    606.                     mypicclockdata(0) = &H1      '除非您确认了解这几个字节的意思,否则不要随修改
    607.                     mypicclockdata(1) = &H1
    608.                     mypicclockdata(2) = 0
    609.                     mypicclockdata(3) = 0
    610.                     status = picclock_ntag(1, mypicclockdata(0))   '锁定0~15d页
    611.                     If status = 0 Then
    612.                         pcdbeep(50)
    613.                         MsgBox("16以后的页锁定位写入成功!!!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    614.                     ElseIf status = 14 Then
    615.                         MsgBox("写卡失败!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    616.                     Else
    617.                         MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    618.                     End If
    619.                 End If
    620.             Case 8
    621.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    622.             Case 23
    623.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    624.             Case Else
    625.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    626.         End Select
    627.     End Sub
    628.     Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
    629.         Dim status, myctrlword, comedc As Byte '存放返回值
    630.         Dim mypiccserial(7) As Byte '卡序列号
    631.         Dim i As Integer
    632.         Dim cardidhex, authkey, Str As String
    633.         Dim mypicckey(0 To 3) As Byte '认证密码
    634.         Dim mypiccdata(0 To 15) As Byte '初始化卡参数
    635.         If CheckBox1.Checked Then
    636.             If Len(Trim(TextBox5.Text)) < 8 Then
    637.                 i = MsgBox("卡认证密码位数不足!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    638.                 If i <> vbOK Then
    639.                     TextBox5.Select()
    640.                     Exit Sub
    641.                 End If
    642.             Else
    643.                 authkey = Trim(TextBox5.Text)
    644.                 For i = 0 To 3
    645.                     mypicckey(i) = CByte("&H" & Mid(authkey, i * 2 + 1, 2))
    646.                 Next
    647.             End If
    648.             myctrlword = &H10  '需要认证卡密码后再继续
    649.         Else
    650.             myctrlword = 0
    651.         End If
    652.         If ComboBox1.SelectedIndex = 0 Then      '开启卡的密码保护功能
    653.             If Len(Trim(TextBox6.Text)) < 8 Then
    654.                 i = MsgBox("卡新密码位数不足!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    655.                 If i <> vbOK Then
    656.                     TextBox6.Select()
    657.                     Exit Sub
    658.                 End If
    659.             Else
    660.                 authkey = Trim(TextBox6.Text)
    661.                 For i = 0 To 3
    662.                     mypiccdata(i + 8) = CByte("&H" & Mid(authkey, i * 2 + 1, 2))
    663.                 Next
    664.             End If
    665.             mypiccdata(12) = &H16  'PACK
    666.             mypiccdata(13) = &H16  'PACK
    667.             mypiccdata(14) = 0     'RFUI
    668.             mypiccdata(15) = 0     'RFUI
    669.             myctrlword = myctrlword + 4  '  //'更新控制字
    670.             mypiccdata(0) = 0      'MIRROR
    671.             mypiccdata(1) = 0      'RFUI
    672.             mypiccdata(2) = 0      'MIRROR_PAGE
    673.             mypiccdata(3) = beginp.Value  'AUTH0
    674.             myctrlword = myctrlword + 1 '更新控制字
    675.             mypiccdata(4) = Limitau.Value Mod 8 'AUTH0
    676.             If CheckBox2.Checked Then
    677.                 mypiccdata(4) = mypiccdata(4) + &H80
    678.             End If
    679.             '启用计数器
    680.             mypiccdata(5) = 0
    681.             mypiccdata(6) = 0
    682.             mypiccdata(7) = 0
    683.             myctrlword = myctrlword + 2  '更新控制字
    684.         Else
    685.             mypiccdata(0) = &H0 'MIRROR
    686.             mypiccdata(1) = &H0 'RFUI
    687.             mypiccdata(2) = &H0 'MIRROR_PAGE
    688.             mypiccdata(3) = &HFF 'AUTH0
    689.             myctrlword = myctrlword + &H1 '更新控制字
    690.             mypiccdata(4) = &H0
    691.             mypiccdata(5) = &H0
    692.             mypiccdata(6) = &H0
    693.             mypiccdata(7) = &H0
    694.             myctrlword = myctrlword + &H2 '更新控制字
    695.         End If
    696.         '-------------------------------------------------------------------------
    697.         '输出串口模块调式码
    698.         comedc = &H16
    699.         Str = "1D16"
    700.         '控制字
    701.         Str = Str + Strings.Right("00" + Hex(myctrlword), 2)
    702.         comedc = comedc Xor myctrlword
    703.         '卡号
    704.         For i = 0 To 6
    705.             Str = Str + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    706.             comedc = comedc Xor mypiccserial(i)
    707.         Next i
    708.         '密码
    709.         For i = 0 To 3
    710.             Str = Str + Strings.Right("00" + Hex(mypicckey(i)), 2)
    711.             comedc = comedc Xor mypicckey(i)
    712.         Next i
    713.         '数据
    714.         For i = 0 To 15
    715.             Str = Str + Strings.Right("00" + Hex(mypiccdata(i)), 2)
    716.             comedc = comedc Xor mypiccdata(i)
    717.         Next i
    718.         '校验码
    719.         Str = Str + Strings.Right("00" + Hex(comedc), 2)
    720.         RichTextBox2.Text = Str
    721.         '-------------------------------------------------------------------------
    722.         status = piccinit_ntag(myctrlword, mypiccserial(0), mypicckey(0), mypiccdata(0))
    723.         Select Case status
    724.             Case 0
    725.                 pcdbeep(50)
    726.                 cardidhex = ""
    727.                 For i = 0 To 6
    728.                     cardidhex = cardidhex + Strings.Right("00" + Hex(mypiccserial(i)), 2)
    729.                 Next
    730.                 TextBox8.Text = cardidhex
    731.                 MsgBox("初始化卡成功!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "提示")
    732.             Case 8
    733.                 MsgBox("请将卡放在感应区!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    734.             Case 12
    735.                 MsgBox("密码错误!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    736.             Case 14
    737.                 MsgBox("设置失败,可能需要验证密码!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    738.             Case 23
    739.                 MsgBox("请连上USB读写器!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    740.             Case Else
    741.                 MsgBox("操作异常,返回代码:" + Str(status), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "提示")
    742.         End Select
    743.     End Sub
    744.     Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
    745.     End Sub
    746.     Private Sub TextBox5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox5.KeyPress
    747.         If (e.KeyChar >= "0" And e.KeyChar <= "9") Or (e.KeyChar >= "A" And e.KeyChar <= "F") Or (e.KeyChar >= "a" And e.KeyChar <= "f") Then   '控制只能输入16进制数
    748.             e.Handled = False
    749.         Else
    750.             e.Handled = True
    751.         End If
    752.     End Sub
    753.     Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
    754.     End Sub
    755.     Private Sub TextBox6_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox6.KeyPress
    756.         If (e.KeyChar >= "0" And e.KeyChar <= "9") Or (e.KeyChar >= "A" And e.KeyChar <= "F") Or (e.KeyChar >= "a" And e.KeyChar <= "f") Then   '控制只能输入16进制数
    757.             e.Handled = False
    758.         Else
    759.             e.Handled = True
    760.         End If
    761.     End Sub
    762.     Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
    763.     End Sub
    764.     Private Sub TextBox7_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox7.KeyPress
    765.         If (e.KeyChar >= "0" And e.KeyChar <= "9") Or (e.KeyChar >= "A" And e.KeyChar <= "F") Or (e.KeyChar >= "a" And e.KeyChar <= "f") Then   '控制只能输入16进制数
    766.             e.Handled = False
    767.         Else
    768.             e.Handled = True
    769.         End If
    770.     End Sub
    771.     Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged
    772.     End Sub
    773.     Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
    774.     End Sub
    775. End Class

  • 相关阅读:
    Flutter高仿微信-第37篇-单聊-红包
    YOLOv7改进:全网原创首发 | 多尺度空洞注意力(MSDA) | 中科院一区顶刊 DilateFormer 2023.9
    面试官:单核 CPU 支持 Java 多线程吗?为什么?被问懵了!
    MySQL-数据库的操作
    开源云原生平台对比 KubeSphere vs Rainbond
    计算机网络第2章(物理层)
    linux并发服务器 —— 多进程并发 - 进程间的通信及实践(五)
    C#面:请解释ASP.NET中的web页面与其隐藏类之间的关系
    mysql高级语句
    解决hadoop使用put上传报错问题
  • 原文地址:https://blog.csdn.net/zhangjin7422/article/details/125513424