Imports ReaderA
Imports System.Text
Imports System.Windows.Forms.Keys

Public Class FrmDL810DemoEN
    Private portIndex As Integer = -1
    Private readerAddr As Byte = &HFF           '读写器地址
    Private verInfo(1) As Byte                  '读写器版本信息 
    Private trType(1) As Byte                   '支持协议
    Private inventoryScanTime As Byte           '最大询查时间
    Private readerType As Byte                  '读写器型号
    Private fIsTestMode As Boolean = False      '是否正在进行测试模式
    Private UserDefineBlockSize As Byte = 0
    Private fIsScanMode As Boolean = False      '是否正在进行扫描模式
    Private DSFIDAndUIDList As String           '存储从开始询查到接收到0E之间的所有DSFID,UID 
    Private totalCardNumber As Byte = 0
    Private OK As Byte = &H0
    Private fIsAppClose As Boolean = False
    Private lengthError As Byte = &H1
    Private operationNotSupport As Byte = &H2
    Private dataRangError As Byte = &H3
    Private cmdNotOperation As Byte = &H4
    Private rfClosed As Byte = &H5
    Private EEPROM As Byte = &H6
    Private timeOut As Byte = &HA
    Private moreUID As Byte = &HB
    Private ISOError As Byte = &HC
    Private noElectronicTag As Byte = &HE
    Private operationError As Byte = &HF
    Private cmdNotSupport As Byte = &H1
    Private cmdNotIdentify As Byte = &H2
    Private errOperationNotSupport As Byte = &H3
    Private unknownError As Byte = &HF
    Private blockError As Byte = &H10
    Private blockLockedCntLock As Byte = &H11
    Private blockLockedCntWrite As Byte = &H12
    Private blockCntOperate As Byte = &H13
    Private blockCntLock As Byte = &H14
    Private communicationErr As Byte = &H30
    Private retCRCErr As Byte = &H31
    Private retDataErr As Byte = &H32
    Private communicationBusy As Byte = &H33
    Private executeCmdBusy As Byte = &H34
    Private comPortOpened As Byte = &H35
    Private comPortClose As Byte = &H36
    Private invalidHandle As Byte = &H37
    Private invalidPort As Byte = &H38

    Private Sub InitiComboBox()
        cbbComPortList.SelectedIndex = 0
        cbbOutput1Status.SelectedIndex = 0
        cbbOutput2Status.SelectedIndex = 0
        cbbRelayControl.SelectedIndex = 0
        cbbInventoryScanTimeToWrite.SelectedIndex = 27
        cbbAccessTimeToSet.SelectedIndex = 0
        cbbScanModeBlockCount.SelectedIndex = 1
        cbbScanModeByteCount.SelectedIndex = 1
        cbbScanModeEndMark.SelectedIndex = 0
        cbbScanModeSpaceMark.SelectedIndex = 0
        cbbScanModeStartBlock.SelectedIndex = 0
        cbbScanModeStartByte.SelectedIndex = 0
    End Sub
    Private Sub InitiButton()
        '自定义命令页
        gbpRelay.Enabled = False
        gbpOutput.Enabled = False
        gbpInput.Enabled = False
        gbpGetANT.Enabled = False
        gbpSetANT.Enabled = False
        gbpParseMode.Enabled = False
        gbpModulation.Enabled = False
        gbpGetReceiveChannel.Enabled = False
        gpbReaderInfo.Enabled = False
        gbpSetReceiveChannel.Enabled = False
        gbpWriteInventoryTime.Enabled = False
        gbpTagAccessTime.Enabled = False
        gbpWriteReaderAddress.Enabled = False
        '标签操作页
        gbpBlockOperation.Enabled = False
        gbpDSFID.Enabled = False
        gbpAFI.Enabled = False
        gbpOtherCmd.Enabled = False
        gbpRFSwitch.Enabled = False
        gbpInventorySingle.Enabled = False
        gbpInventoryMulti.Enabled = False
        btnGetSystemInfo.Enabled = False
        '测试模式页
        btnStartTestMode.Enabled = False
        btnStopTestMode.Enabled = False
        '扫描模式页
        btnStartScanMode.Enabled = False
        btnStopScanMode.Enabled = False
        btnDisplayOn.Enabled = False
        btnDisplayOff.Enabled = False
        gbpScanModeSetting.Enabled = False
        '自定义数据块长度
        gbpInventory.Enabled = False
        gbpUserBlockLength.Enabled = False
        gbpUserBlockOperation.Enabled = False
        gbpRFSwitch2.Enabled = False
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = False
        gbpTransparentRead.Enabled = False
        gbpTransparentWrite.Enabled = False
    End Sub 'InitializeBtnEnable

    Private Sub EnableButton()
        btnGetReaderInfo.Enabled = True
    End Sub

    Private Sub FrmDL810_00Demo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitiComboBox()
        InitiButton()
    End Sub
    Private Sub InitializeBtnEnable()
        '自定义命令页
        gbpRelay.Enabled = False
        gbpOutput.Enabled = False
        gbpInput.Enabled = False
        gbpGetANT.Enabled = False
        gbpSetANT.Enabled = False
        gbpParseMode.Enabled = False
        gbpModulation.Enabled = False
        gbpGetReceiveChannel.Enabled = False
        gpbReaderInfo.Enabled = False
        gbpSetReceiveChannel.Enabled = False
        gbpWriteInventoryTime.Enabled = False
        gbpTagAccessTime.Enabled = False
        gbpWriteReaderAddress.Enabled = False
        '标签操作页
        gbpBlockOperation.Enabled = False
        gbpDSFID.Enabled = False
        gbpAFI.Enabled = False
        gbpOtherCmd.Enabled = False
        gbpRFSwitch.Enabled = False
        gbpInventorySingle.Enabled = False
        gbpInventoryMulti.Enabled = False
        btnGetSystemInfo.Enabled = False
        '测试模式页
        btnStartTestMode.Enabled = False
        btnStopTestMode.Enabled = False
        '扫描模式页
        btnStartScanMode.Enabled = False
        btnStopScanMode.Enabled = False
        btnDisplayOn.Enabled = False
        btnDisplayOff.Enabled = False
        gbpScanModeSetting.Enabled = False
        '自定义数据块长度
        gbpInventory.Enabled = False
        gbpUserBlockLength.Enabled = False
        gbpUserBlockOperation.Enabled = False
        gbpRFSwitch2.Enabled = False
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = False
        gbpTransparentRead.Enabled = False
        gbpTransparentWrite.Enabled = False
    End Sub 'InitializeBtnEnable


    Private Sub DL810_37SREnable()
        'gbpRelay.Enabled = true;
        gbpOutput.Enabled = True
        'gbpInput.Enabled = true;
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        'gbpInventoryMulti.Enabled = true;
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        If String.Compare(tbReaderInfoVersion.Text, "06.00") > 0 Then
            gbpSpecifyRsptimeTransparentCmd.Enabled = True
            gbpTransparentRead.Enabled = True
            gbpTransparentWrite.Enabled = True
        Else
            If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
                TabControl1.TabPages.Remove(tpTransparentCmd)
            End If
        End If
        If TabControl1.TabPages.IndexOf(tpTestMode) >= 0 Then
            TabControl1.TabPages.Remove(tpTestMode)
        End If
    End Sub 'DL810_37SREnable

    Private Sub DL810_36SREnable()
        'gbpRelay.Enabled = true;
        gbpOutput.Enabled = True
        'gbpInput.Enabled = true;
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        'gbpInventoryMulti.Enabled = true;
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        gbpUserBlockLength.Enabled = True
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;
        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
        If TabControl1.TabPages.IndexOf(tpTestMode) >= 0 Then
            TabControl1.TabPages.Remove(tpTestMode)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_36SREnable

    Private Sub DL810_96AEnable()
        'gbpRelay.Enabled = true;
        'gbpOutput.Enabled = true;
        'gbpInput.Enabled = true;
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        gbpGetReceiveChannel.Enabled = True
        gpbReaderInfo.Enabled = True
        gbpSetReceiveChannel.Enabled = True
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        gbpUserBlockLength.Enabled = True
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        btnGetReceiveChannelStatus_Click(Nothing, Nothing)
        If tbReceiveChannelStatus.Text.IndexOf("TX/RX") >= 0 Or tbReceiveChannelStatus.Text.IndexOf("TX/RX + RXOnly") >= 0 Then '主通道
            '双通道
            gbpSpecifyRsptimeTransparentCmd.Enabled = True
            gbpTransparentRead.Enabled = True
            gbpTransparentWrite.Enabled = True
        Else
            If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
                TabControl1.TabPages.Remove(tpTransparentCmd)
            End If
        End If
    End Sub 'DL810_96AEnable

    Private Sub DL810_93TEnanle()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        gbpParseMode.Enabled = True
        gbpModulation.Enabled = True
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = True
        gbpTransparentRead.Enabled = True
        gbpTransparentWrite.Enabled = True
    End Sub 'DL810_93TEnanle


    Private Sub DL810_92TEnanle()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        gbpParseMode.Enabled = True
        gbpModulation.Enabled = True
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = True
        gbpTransparentRead.Enabled = True
        gbpTransparentWrite.Enabled = True
    End Sub 'DL810_92TEnanle


    Private Sub DL810_91TEnanle()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        gbpParseMode.Enabled = True
        gbpModulation.Enabled = True
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = True
        gbpTransparentRead.Enabled = True
        gbpTransparentWrite.Enabled = True
    End Sub 'DL810_91TEnanle


    Private Sub DL810_93AEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;  
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
    End Sub 'DL810_93AEnable

    Private Sub DL810_92AEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
    End Sub 'DL810_92AEnable

    Private Sub DL810_91FEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        gbpTagAccessTime.Enabled = True
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
    End Sub 'DL810_91FEnable


    Private Sub DL810_91Enable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        btnStartScanMode.Enabled = True
        btnStopScanMode.Enabled = True
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = True
        gbpScanModeSetting.Enabled = True
        '自定义数据块长度
        gbpInventory.Enabled = True
        gbpUserBlockLength.Enabled = True
        gbpUserBlockOperation.Enabled = True
        gbpRFSwitch2.Enabled = True
        '透明命令
        If String.Compare(tbReaderInfoVersion.Text, "06.00") > 0 Then
            gbpSpecifyRsptimeTransparentCmd.Enabled = True
            gbpTransparentRead.Enabled = True
            gbpTransparentWrite.Enabled = True
        Else
            If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
                TabControl1.TabPages.Remove(tpTransparentCmd)
            End If
        End If
    End Sub 'DL810_91Enable

    Private Sub DL810_03TEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        gbpParseMode.Enabled = True
        gbpModulation.Enabled = True
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = True
        gbpTransparentRead.Enabled = True
        gbpTransparentWrite.Enabled = True

        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_03TEnable

    Private Sub DL810_02TEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        gbpParseMode.Enabled = True
        gbpModulation.Enabled = True
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = True
        gbpTransparentRead.Enabled = True
        gbpTransparentWrite.Enabled = True

        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_02TEnable

    Private Sub DL810_01TEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        gbpParseMode.Enabled = True
        gbpModulation.Enabled = True
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        gbpSpecifyRsptimeTransparentCmd.Enabled = True
        gbpTransparentRead.Enabled = True
        gbpTransparentWrite.Enabled = True

        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_01TEnable

    Private Sub DL810_03AEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        gbpDSFID.Enabled = True
        gbpAFI.Enabled = True
        gbpOtherCmd.Enabled = True
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_03AEnable

    Private Sub DL810_02AEnable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        gbpGetANT.Enabled = True
        gbpSetANT.Enabled = True
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_02AEnable

    Private Sub DL810_01LiteEnable()
        'gbpRelay.Enabled = true;
        'gbpOutput.Enabled = true;
        'gbpInput.Enabled = true;
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        'gbpWriteInventoryTime.Enabled = true;
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        'gbpBlockOperation.Enabled = true;
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        btnResetToReady.Enabled = False
        btnStayQuite.Enabled = True
        btnSelect.Enabled = False
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True
        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        'gbpSpecifyRsptimeTransparentCmd.Enabled = true;
        'gbpTransparentRead.Enabled = true;
        'gbpTransparentWrite.Enabled = true;
        If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
            TabControl1.TabPages.Remove(tpTransparentCmd)
        End If
        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_01LiteEnable

    Private Sub DL810_01Enable()
        gbpRelay.Enabled = True
        gbpOutput.Enabled = True
        gbpInput.Enabled = True
        'gbpGetANT.Enabled = true;
        'gbpSetANT.Enabled = true;
        'gbpParseMode.Enabled = true;
        'gbpModulation.Enabled = true;
        'gbpGetReceiveChannel.Enabled = true;
        gpbReaderInfo.Enabled = True
        'gbpSetReceiveChannel.Enabled = true;
        gbpWriteInventoryTime.Enabled = True
        'gbpTagAccessTime.Enabled = true;
        gbpWriteReaderAddress.Enabled = True
        '标签操作页
        gbpBlockOperation.Enabled = True
        'gbpDSFID.Enabled = true;
        'gbpAFI.Enabled = true;
        'gbpOtherCmd.Enabled = true;
        gbpRFSwitch.Enabled = True
        gbpInventorySingle.Enabled = True
        gbpInventoryMulti.Enabled = True

        'btnGetSystemInfo.Enabled = true;
        '测试模式页
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = True
        '扫描模式页
        'btnStartScanMode.Enabled = true;
        'btnStopScanMode.Enabled = true;
        'btnDisplayOn.Enabled = true;
        'btnDisplayOff.Enabled = true;
        'gbpScanModeSetting.Enabled = true;
        '自定义数据块长度
        'gbpInventory.Enabled = true;
        'gbpUserBlockLength.Enabled = true;
        'gbpUserBlockOperation.Enabled = true;
        'gbpRFSwitch2.Enabled = true;
        '透明命令
        If String.Compare(tbReaderInfoVersion.Text, "06.00") > 0 Then
            gbpSpecifyRsptimeTransparentCmd.Enabled = True
            gbpTransparentRead.Enabled = True
            gbpTransparentWrite.Enabled = True
        Else
            If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
                TabControl1.TabPages.Remove(tpTransparentCmd)
            End If
        End If
        If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) >= 0 Then
            TabControl1.TabPages.Remove(tpCustomizeBlockLength)
        End If
        If TabControl1.TabPages.IndexOf(tpScanMode) >= 0 Then
            TabControl1.TabPages.Remove(tpScanMode)
        End If
    End Sub 'DL810_01Enable
    Private Sub btnGetReaderInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetReaderInfo.Click
        Dim fCmdRet As Integer

        If tbReaderAddr.Text = "" Then
            MessageBox.Show("Input ReaderAddress", "Information")
            Exit Sub
        End If
        readerAddr = CByte("&H" & tbReaderAddr.Text)
        fCmdRet = StaticClassReaderA.GetReaderInformation(readerAddr, verInfo, readerType, trType, inventoryScanTime, portIndex)
        tbReaderInfoInventoryScanTime.Clear()
        tbReaderInfoProtocol.Clear()
        tbReaderInfoType.Clear()
        tbReaderInfoVersion.Clear()
        tbReadInfoAddr.Clear()
        If fCmdRet = 0 Then
            tbReadInfoAddr.Text = Hex(readerAddr).PadLeft(2, "0")
            tbReaderInfoVersion.Text = verInfo(0).ToString().PadLeft(2, "0") & "." & verInfo(1).ToString().PadRight(2, "0")
            tbReaderInfoInventoryScanTime.Text = inventoryScanTime.ToString()
            tbReaderInfoType.Text = GetReaderType(readerType)
            If trType(1) = 8 Then
                tbReaderInfoProtocol.Text = "ISO/IEC 15693"
            End If
            If TabControl1.TabPages.IndexOf(tpTestMode) < 0 Then
                TabControl1.TabPages.Insert(1, tpTestMode)
            End If
            If TabControl1.TabPages.IndexOf(tpScanMode) < 0 Then
                TabControl1.TabPages.Insert(2, tpScanMode)
            End If
            If TabControl1.TabPages.IndexOf(tpCustomizeBlockLength) < 0 Then
                TabControl1.TabPages.Insert(3, tpCustomizeBlockLength)
            End If
            If TabControl1.TabPages.IndexOf(tpTransparentCmd) < 0 Then
                TabControl1.TabPages.Insert(4, tpTransparentCmd)
            End If

            Select Case tbReaderInfoType.Text
                Case "DL810_37"
                    DL810_37SREnable()
                Case "DL810_36", "DL810_36SC", "DL810_36CF"
                    DL810_36SREnable()
                Case "DL810_96A", "DL810_96"
                    DL810_96AEnable()
                Case "DL810_93T", "DL810_93T"
                    DL810_93TEnanle()
                Case "DL810_92T", "DL810_92T"
                    rbANT3.Enabled = False
                    rbANT4.Enabled = False
                    DL810_92TEnanle()
                Case "DL810_91T", "DL810_91T"
                    DL810_91TEnanle()
                Case "DL810_93A", "DL810_93A"
                    DL810_93AEnable()
                Case "DL810_92A", "DL810_92A"
                    rbANT3.Enabled = False
                    rbANT4.Enabled = False
                    DL810_92AEnable()
                Case "DL810_91F", "DL810_91F"
                    DL810_91FEnable()
                Case "DL810_91", "DL810_91"
                    DL810_91Enable()
                Case "DL810_03T", "DL810_03T"
                    DL810_03TEnable()
                Case "DL810_02T", "DL810_02T"
                    rbANT3.Enabled = False
                    rbANT4.Enabled = False
                    DL810_02TEnable()
                Case "DL810_01T", "DL810_01T"
                    DL810_01TEnable()
                Case "DL810_03A", "DL810_03A"
                    DL810_03AEnable()
                Case "DL810_02A", "DL810_02A"
                    rbANT3.Enabled = False
                    rbANT4.Enabled = False
                    DL810_02AEnable()
                Case "DL810_01Lite", "DL810_01Lite"
                    DL810_01LiteEnable()
                Case "DL810_01", "DL810_01"
                    DL810_01Enable()
            End Select

            If String.Compare(tbReaderInfoVersion.Text, "06.00") > 0 Or tbReaderInfoType.Text = "DL810_01T" Or _
               tbReaderInfoType.Text = "DL810_02T" Or tbReaderInfoType.Text = "DL810_03T" Or _
               tbReaderInfoType.Text = "DL810_91T" Or tbReaderInfoType.Text = "DL810_93T" Or _
               tbReaderInfoType.Text = "DL810_93T" Or tbReaderInfoType.Text = "DL810_92T" Or _
               tbReaderInfoType.Text = "DL810_01T" Or tbReaderInfoType.Text = "DL810_02T" Or _
               tbReaderInfoType.Text = "DL810_03T" Or tbReaderInfoType.Text = "DL810_91T" Or _
               tbReaderInfoType.Text = "DL810_92T" Or tbReaderInfoType.Text = "DL810_93T" Or _
               tbReaderInfoType.Text = "DL810_96" Or tbReaderInfoType.Text = "DL810_96A" Or _
               tbReaderInfoType.Text = "DL810_01TSC" Or tbReaderInfoType.Text = "DL810_91TSC" Then
                GetParseMode()
            End If

            btnReadMultiBlock.Enabled = False
            btnReadSingleBlock.Enabled = False
            btnWriteSingleBlock.Enabled = False
            btnLcokBlock.Enabled = False

            If tbReaderInfoType.Text = "DL810_96A" Then
                btnGetReceiveChannelStatus_Click(Nothing, Nothing)
                If tbReceiveChannelStatus.Text = "RXOnly" Then
                    If TabControl1.TabPages.IndexOf(tpTransparentCmd) >= 0 Then
                        TabControl1.TabPages.Remove(tpTransparentCmd)
                    End If
                End If
            End If
            If tbReaderInfoType.Text = "DL810_37" Or tbReaderInfoType.Text = "DL810_37SC" Or _
               tbReaderInfoType.Text = "DL810_36" Or tbReaderInfoType.Text = "DL810_36SR" Or _
               tbReaderInfoType.Text = "DL810_36CF" Then
                label16.Text = "LED"
                label15.Text = "Buzzer"
                cbbOutput1Status.Items.Clear()
                cbbOutput1Status.Items.Add("On")
                cbbOutput1Status.Items.Add("Off")
                cbbOutput1Status.SelectedIndex = 0

                cbbOutput2Status.Items.Clear()
                cbbOutput2Status.Items.Add("Green")
                cbbOutput2Status.Items.Add("Red")
                cbbOutput2Status.SelectedIndex = 0
            Else
                label16.Text = "Output2"
                label15.Text = "Output1"
                cbbOutput1Status.Items.Clear()
                cbbOutput1Status.Items.Add("Low")
                cbbOutput1Status.Items.Add("High")
                cbbOutput1Status.SelectedIndex = 0
                cbbOutput2Status.Items.Clear()
                cbbOutput2Status.Items.Add("Low")
                cbbOutput2Status.Items.Add("High")
                cbbOutput2Status.SelectedIndex = 0
            End If
            StatusBar1.Panels(1).Text = cbbAlreadyOpenedPortList.SelectedItem.ToString()
        End If

        AddCmdLog("Get Reader Information", fCmdRet)
    End Sub

    Private Sub GetParseMode()
        Dim fCmdRet As Integer
        Dim ParseMode As Byte = 0
        fCmdRet = StaticClassReaderA.GetParseMode(readerAddr, ParseMode, portIndex)
        If fCmdRet = 0 Then
            If ParseMode = &H1 Then
                rdbParseModeDPPM.Checked = True
                rdbParseModeDPPM.Enabled = False
                rdbModulation10.Checked = True
                rdbModulation10.Enabled = False
            End If
            If ParseMode = &H81 Then
                rdbParseModeDPPM.Checked = True
                rdbParseModeDPPM.Enabled = False
                rdbModulation100.Checked = True
                rdbModulation100.Enabled = False
            End If
            If ParseMode = &H0 Then
                rdbParseModeWPPM.Checked = True
                rdbParseModeWPPM.Enabled = False
                rdbModulation10.Checked = True
                rdbModulation10.Enabled = False
            End If
            If ParseMode = &H80 Then
                rdbParseModeWPPM.Checked = True
                rdbParseModeWPPM.Enabled = False
                rdbModulation100.Checked = True
                rdbModulation100.Enabled = False
            End If
        End If
        AddCmdLog("GetParseMode", fCmdRet)
    End Sub 'GetParseMode
    Private Function GetReaderType(ByVal readerType As Byte) As String
        Select Case readerType
            Case &H45
                Return "DL810_01"
            Case &H55
                Return "DL810_36"
            Case &H58
                Return "DL810_38"
            Case &H5C
                Return "DL810_36SC"
            Case &H46
                Return "DL810_01Lite"
            Case &H47
                Return "DL810_03A"
            Case &H71
                Return "DL810_03AD"
            Case &H48
                Return "DL810_36CF"
            Case &HA1
                Return "DL810_01"
            Case &HA2
                Return "DL810_03A"
            Case &HA6
                Return "DL810_01Lite"
            Case &H80
                Return "DL810_91D"
            Case &H5B
                Return "DL810_37"
            Case &H5D
                Return "DL810_37SC"
            Case &H90
                Return "DL810_91"
            Case &H30
                Return "DL810_91F"
            Case &H3A
                Return "DL810_96"
            Case &H3B
                Return "DL810_96A"
            Case &HA7
                Return "DL810_01D"
            Case &H4B
                Return "DL810_02AD"
            Case &HA3
                Return "DL810_02AD"
            Case &H81
                Return "DL810_92A"
            Case &H82
                Return "DL810_93A"
            Case &H93
                Return "DL810_91F"
            Case &H91
                Return "DL810_92A"
            Case &H92
                Return "DL810_93A"
            Case &H70           'version 06.00
                Return "DL810_01D"
            Case &H8B
                Return "DL810_03AGD"
            Case &H72
                Return "DL810_03AD"
            Case &H97
                Return "DL810_91D"
            Case &H7E
                Return "DL810_01T"
            Case &H7F
                Return "DL810_01T"
            Case &H8E
                Return "DL810_91T"
            Case &H8F
                Return "DL810_91T"
            Case &H83
                Return "DL810_92T"
            Case &H84
                Return "DL810_93T"
            Case &H74
                Return "DL810_02T"
            Case &H73
                Return "DL810_03T"
            Case &H98
                Return "DL810_02T"
            Case &H99
                Return "DL810_03T"
            Case &H9A
                Return "DL810_92T"
            Case &H9B
                Return "DL810_93T"
            Case &H8A
                Return "DL810_03AGD"
            Case &H50
                Return "DL810_01TSC"
            Case &H51
                Return "DL810_91T"
            Case Else
                Return ""
        End Select
    End Function 'GetReaderType

    Private Sub btnOpenComPort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenComPort.Click
        Dim portNum As Integer = -1
        Dim temp As String
        Dim fCmdRet As Integer = &H30

        Try
            btnOpenComPort.Enabled = False
            readerAddr = CByte("&H" & tbReaderAddr.Text)
            Cursor = Cursors.WaitCursor
            InitializeBtnEnable()
            If cbbComPortList.SelectedIndex = 0 Then
                fCmdRet = StaticClassReaderA.AutoOpenComPort(portNum, readerAddr, portIndex)
            Else
                If tbReaderAddr.Text = "" Then
                    MessageBox.Show("Input ReaderAddr", "Information")
                    Exit Sub
                End If
                temp = cbbComPortList.SelectedItem.ToString()
                portNum = CInt(temp.Substring(3, temp.Length - 3))
                fCmdRet = StaticClassReaderA.OpenComPort(portNum, readerAddr, portIndex)
            End If
            If fCmdRet = 0 Then
                cbbAlreadyOpenedPortList.Items.Add("COM" & portNum.ToString())
                cbbAlreadyOpenedPortList.SelectedIndex = cbbAlreadyOpenedPortList.Items.Count - 1
                StatusBar1.Panels(1).Text = "COM" & portNum.ToString()
                'btnGetReaderInfo_Click(Nothing, Nothing)
            Else
                MessageBox.Show("OpenComPort failed", "Communication")
            End If
        Finally
            AddCmdLog("OpenComPort", fCmdRet)
            btnOpenComPort.Enabled = True
            Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnCloseComPort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseComPort.Click
        Dim portNum As Integer = -1
        Dim temp As String
        Dim fCmdRet As Integer

        If cbbAlreadyOpenedPortList.Items.Count = 0 Or cbbAlreadyOpenedPortList.SelectedItem Is System.DBNull.Value Then
            MessageBox.Show("Select a Port", "Port")
            Exit Sub
        End If

        temp = cbbAlreadyOpenedPortList.SelectedItem.ToString()
        portNum = CInt(temp.Substring(3, temp.Length - 3))
        fCmdRet = StaticClassReaderA.CloseSpecComPort(portNum)
        If fCmdRet = 0 Then
            cbbAlreadyOpenedPortList.Items.Remove(cbbAlreadyOpenedPortList.SelectedItem)
            If cbbAlreadyOpenedPortList.Items.Count = 0 Then
                portIndex = -1
                StatusBar1.Panels(1).Text = "Port Closed"
                InitiButton()
                ClearLastInfo()
            Else
                cbbAlreadyOpenedPortList.SelectedIndex = 0
                StatusBar1.Panels(1).Text = cbbAlreadyOpenedPortList.SelectedItem.ToString()
            End If
            lbUIDList.Items.Clear()
            cbbUIDListforInfo.Items.Clear()
            cbbUserUidList.Items.Clear()
        End If
        AddCmdLog("CloseComPort", fCmdRet)
    End Sub

    Private Sub ClearLastInfo()
        tbReaderInfoInventoryScanTime.Text = ""
        tbReaderInfoProtocol.Text = ""
        tbReaderInfoType.Text = ""
        tbReaderInfoVersion.Text = ""
        tbReadInfoAddr.Text = ""
        tbSystemInfo.Text = ""
        tbSystemInfoData.Text = ""
        tbCmdTransparentRead.Text = ""
        tbResponeTransparentRead.Text = ""
        tbCmdTransparentSpecifyResponeTime.Text = ""
        tbResponeTransparentSpecifyResponeTime.Text = ""
        tbCmdTransparentWrite.Text = ""
        tbResponeTransparentWrite.Text = ""
        cbbWriteType.Items.Clear()
        cbbBlockNumToOperation.Items.Clear()
        cbbMaxBlockNum.Items.Clear()
        cbbBlockSize.Items.Clear()
        lbUIDList.Items.Clear()
        cbbUIDListforInfo.Items.Clear()
        cbbUserUidList.Items.Clear()
        lvTestMode.Items.Clear()
        cbbEndBlockNum.Items.Clear()
        cbbBeginBlok.Items.Clear()
        tbDataReaded.Text = ""
        tbDataToWrite.Text = ""
    End Sub

    Private Sub cbbAlreadyOpenedPortList_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbAlreadyOpenedPortList.SelectedValueChanged
        Dim temp As String
        InitializeBtnEnable()
        temp = cbbAlreadyOpenedPortList.SelectedItem.ToString()     '选择后的串口
        portIndex = CInt(temp.Substring(3, temp.Length - 3))
        StatusBar1.Panels(1).Text = temp
        readerAddr = &HFF
        btnGetReaderInfo_Click(Nothing, Nothing)
    End Sub

    Private Sub btnOpenRF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenRF.Click, button2.Click
        Dim fCmdRet As Integer

        fCmdRet = StaticClassReaderA.OpenRf(readerAddr, portIndex)
        AddCmdLog("Open RF", fCmdRet)
    End Sub

    Private Sub btnCloseRF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCloseRF.Click, button1.Click
        Dim fCmdRet As Integer

        fCmdRet = StaticClassReaderA.CloseRf(readerAddr, portIndex)
        AddCmdLog("Close RF", fCmdRet)
    End Sub

    Private Sub btnWriteAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteAddress.Click
        Dim newReaderAddr As Byte
        Dim fCmdRet As Integer

        If tbAddressToWrite.Text = "" Then
            MessageBox.Show("Input ReaderAddr", "Information")
            Exit Sub
        End If
        newReaderAddr = CByte("&H" & tbAddressToWrite.Text)
        fCmdRet = StaticClassReaderA.WriteComAdr(readerAddr, newReaderAddr, portIndex)
        If fCmdRet = 0 Then
            readerAddr = newReaderAddr
            btnGetReaderInfo_Click(Nothing, Nothing)
        End If
        AddCmdLog("Write Reader Address", fCmdRet)
    End Sub

    Private Sub btnSetOutputStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetOutputStatus.Click
        Dim fCmdRet As Integer
        Dim outputSetting As Byte

        outputSetting = cbbOutput1Status.SelectedIndex + cbbOutput2Status.SelectedIndex * 2
        fCmdRet = StaticClassReaderA.SetGeneralOutput(readerAddr, outputSetting, portIndex)
        AddCmdLog("SetGeneralOutput", fCmdRet)
    End Sub

    Private Sub btnGetInputStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetInputStatus.Click
        Dim fCmdRet As Integer
        Dim inputStatus As Byte

        tbInputStatus.Text = ""
        fCmdRet = StaticClassReaderA.GetGeneralInput(readerAddr, inputStatus, portIndex)
        If fCmdRet = 0 Then
            If inputStatus = 0 Then
                tbInputStatus.Text = "Low"
            ElseIf inputStatus = 1 Then
                tbInputStatus.Text = "High"
            End If
        End If
        AddCmdLog("GetGeneralInput", fCmdRet)
    End Sub

    Private Sub btnGetReceiveChannelStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetReceiveChannelStatus.Click
        Dim fCmdRet As Integer
        Dim receiveChannelStatu As Byte

        tbReceiveChannelStatus.Text = ""
        fCmdRet = StaticClassReaderA.GetReceiveChannelStatus(readerAddr, receiveChannelStatu, portIndex)
        If fCmdRet = 0 Then
            If receiveChannelStatu = 1 Then
                tbReceiveChannelStatus.Text = "RXOnly"
            ElseIf receiveChannelStatu = 2 Then
                tbReceiveChannelStatus.Text = "TX/RX + RXOnly"
            ElseIf receiveChannelStatu = 3 Then
                tbReceiveChannelStatus.Text = "TX/RX"
            End If
        End If
        AddCmdLog("GetReceiveChannelStatus", fCmdRet)
    End Sub

    Private Sub btnGetCurrentANT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCurrentANT.Click
        Dim fCmdRet As Integer
        Dim ANTStatus As Byte

        tbInputStatus.Text = ""
        fCmdRet = StaticClassReaderA.GetANTStatus(readerAddr, ANTStatus, portIndex)
        If fCmdRet = 0 Then
            If ANTStatus = 1 Then
                tbANTCurrentUsed.Text = "ANT1"
            ElseIf ANTStatus = 2 Then
                tbANTCurrentUsed.Text = "ANT2"
            ElseIf ANTStatus = 4 Then
                tbANTCurrentUsed.Text = "ANT3"
            ElseIf ANTStatus = 8 Then
                tbANTCurrentUsed.Text = "ANT4"
            End If
        End If
        AddCmdLog("Set Antenna", fCmdRet)
    End Sub

    Private Function DL810_00GetReturnCodeDesc(ByVal cmdRet As Integer) As String
        Select Case cmdRet
            Case lengthError
                Return "Command operand length error"
            Case operationNotSupport
                Return "Command not supported"
            Case dataRangError
                Return "Operation data range error"
            Case rfClosed
                Return "RF field is inactive"
            Case EEPROM
                Return "EEPROM operation error"
            Case timeOut
                Return "Inventoryscantime overflow"
            Case moreUID
                Return "Not all tag's UID are collected."
            Case ISOError
                Return "ISO error"
            Case noElectronicTag
                Return "No Tags"
            Case operationError
                Return "Operation error"
            Case communicationErr
                Return "Communication Error"
            Case retCRCErr
                Return "CRC checksummat Error"
            Case communicationBusy
                Return "Communication busy"
            Case cmdNotOperation
                Return "CMD can't execute at current"
            Case comPortOpened
                Return "Port Opend"
            Case comPortClose
                Return "Port Already Closed"
            Case invalidHandle
                Return "Invalid PortHandle"
            Case invalidPort
                Return "Invalid Port"
            Case OK
                Return "successfully"
            Case Else
                Return ""
        End Select
    End Function 'DL810_00GetReturnCodeDesc


    Private Function DL810_00GetErrorCodeDesc(ByVal errorCode As Byte) As String
        Select Case errorCode
            Case cmdNotSupport
                Return "Commands  not supported "
            Case cmdNotIdentify
                Return "Unknown Command "
            Case errOperationNotSupport
                Return "Operation not supported "
            Case unknownError
                Return "Unknown error "
            Case blockError
                Return "Block can't be used or does not exist "
            Case blockLockedCntLock, blockLockedCntWrite
                Return "Block is locked"
            Case blockCntOperate
                Return "Block can't be operated normally"
            Case blockCntLock
                Return "Block can't be locked normally"
            Case Else
                Return ""
        End Select
    End Function 'DL810_00GetErrorCodeDe

    Private Sub AddCmdLog(ByVal cmdStr As String, ByVal cmdRet As Integer, ByVal errorCode As Byte)
        Try
            StatusBar1.Panels(0).Text = ""
            StatusBar1.Panels(0).Text = DateTime.Now.ToLongTimeString() + " " + cmdStr + ": " + DL810_00GetReturnCodeDesc(cmdRet) + " " + DL810_00GetErrorCodeDesc(errorCode)
        Finally
        End Try
    End Sub 'AddCmdLog

    Private Sub AddCmdLog(ByVal cmdStr As String, ByVal cmdRet As Integer)
        Try
            If Not fIsAppClose Then
                StatusBar1.Panels(0).Text = ""
                StatusBar1.Panels(0).Text = DateTime.Now.ToLongTimeString() + " " + cmdStr + ": " + DL810_00GetReturnCodeDesc(cmdRet)
            End If
        Finally
        End Try
    End Sub 'AddCmdLog

    Private Sub btnSetRelay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetRelay.Click
        Dim fCmdRet As Integer
        Dim realySetting As Byte

        realySetting = cbbRelayControl.SelectedIndex
        fCmdRet = StaticClassReaderA.SetRelay(readerAddr, realySetting, portIndex)
        AddCmdLog("Set Realy", fCmdRet)
    End Sub

    Private Sub btnWriteInventoryScanTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteInventoryScanTime.Click
        Dim time As Byte
        Dim fCmdRet As Integer

        time = CByte(cbbInventoryScanTimeToWrite.SelectedItem.ToString())
        fCmdRet = StaticClassReaderA.WriteInventoryScanTime(readerAddr, time, portIndex)
        If fCmdRet = 0 Then
            btnGetReaderInfo_Click(Nothing, Nothing)
        End If
        AddCmdLog("Write InvnetoryScanTime", fCmdRet)
    End Sub

    Private Sub btnSetAccessTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetAccessTime.Click
        Dim time As Byte
        Dim fCmdRet As Integer

        time = CByte(cbbAccessTimeToSet.SelectedItem.ToString())
        fCmdRet = StaticClassReaderA.SetAccessTime(readerAddr, time, portIndex)
        AddCmdLog("SetAccessTime", fCmdRet)
    End Sub

    Private Sub btnGetAccessTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetAccessTime.Click
        Dim time As Byte
        Dim fCmdRet As Integer

        tbAccessTimeGetted.Text = ""
        fCmdRet = StaticClassReaderA.GetAccessTime(readerAddr, time, portIndex)
        If fCmdRet = 0 Then
            tbAccessTimeGetted.Text = time.ToString()
        End If
        AddCmdLog("GetAccessTime", fCmdRet)
    End Sub

    Private Function HexStringToByteArray(ByVal s As String) As Byte()
        s = s.Replace(" ", "")
        Dim buffer(s.Length / 2 - 1) As Byte
        Dim i As Integer
        For i = 0 To s.Length - 2 Step 2
            buffer(i / 2) = Convert.ToByte(s.Substring(i, 2), 16)
        Next
        Return buffer
    End Function

    Private Function ByteArrayToHexString(ByVal data() As Byte) As String
        Dim sb As New StringBuilder(data.Length * 3)
        Dim b As Byte
        For Each b In data
            sb.Append(Convert.ToString(b, 16).PadLeft(2, "0").PadRight(3, " "))
        Next
        Return sb.ToString().ToUpper()
    End Function

    Private Function GetState() As Byte

        Return CByte(IIf(rdbAddressMode.Checked, 0, 1))

    End Function

    Private Function GetState(ByVal writeType As String) As Byte

        If writeType.IndexOf("A") >= 0 Then
            Return CByte(IIf(rdbAddressMode.Checked, 0, 1))
        Else
            Return CByte(IIf(rdbAddressMode.Checked, 8, 9))
        End If

    End Function

    Private Function GetState(ByVal blocSize As Byte, ByVal writeType As String, ByVal isCheckWriteType As Boolean) As Byte
        If Not isCheckWriteType Then
            If blocSize = 4 Then
                Return CByte(IIf(rdbAddressMode.Checked, 0, 1))
            Else
                Return CByte(IIf(rdbAddressMode.Checked, 4, 5))
            End If
        Else
            If blocSize = 4 Then
                If writeType.IndexOf("A") >= 0 Then
                    Return CByte(IIf(rdbAddressMode.Checked, 0, 1))      'A类标签,每个块4字节
                Else
                    Return CByte(IIf(rdbAddressMode.Checked, 8, 9))      'B类标签,每个块4字节
                End If
            Else
                If writeType.IndexOf("A") >= 0 Then
                    Return CByte(IIf(rdbAddressMode.Checked, 4, 5))      'A类标签,每个块8字节
                Else
                    Return CByte(IIf(rdbAddressMode.Checked, &HC, &HD))  'B类标签,每个块8字节
                End If
            End If
        End If
    End Function

    Private Sub btnResetToReady_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetToReady.Click
        Dim fCmdRet As Byte
        Dim state As Byte
        Dim errorCode As Byte
        Dim UID() As Byte = {0, 0, 0, 0, 0, 0, 0, 0}

        If cbbUIDListforInfo.SelectedItem = Nothing Then
            MessageBox.Show("Select a UID", "Information")
            Exit Sub
        End If
        UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        state = GetState()
        fCmdRet = StaticClassReaderA.ResetToReady(readerAddr, state, UID, errorCode, portIndex)
        AddCmdLog("ResetToReady", fCmdRet)
    End Sub

    Private Sub btnInventoryNoAFI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInventoryNoAFI.Click, btnInventoryWithAFI.Click, btnUserInventoryWithAFI.Click, btnUserInventoryNoAFI.Click
        Dim fCmdRet As Integer = &H30
        Dim state As Byte = 0
        Dim AFI As Byte = 0
        Dim DSFIDAndUID(8) As Byte
        Dim cardNumber As Byte = 0
        Dim strDSFIDAndUID As String = ""

        cbbUIDListforInfo.Items.Clear()
        cbbUserUidList.Items.Clear()
        lbUIDList.Items.Clear()
        labelCardNum.Text = "0"
        tbSystemInfoData.Text = ""
        tbSystemInfo.Text = ""
        cbbWriteType.Items.Clear()
        cbbEndBlockNum.Items.Clear()
        cbbBeginBlok.Items.Clear()
        cbbBlockNumToOperation.Items.Clear()

        If sender Is btnInventoryWithAFI Then
            If tbAFI.Text = "" Then
                MessageBox.Show("Input AFI", "Information")
                Return
            End If
            AFI = Convert.ToByte(tbAFI.Text, 16)
            state = 1
        End If
        If sender Is btnUserInventoryWithAFI Then
            If tbUserAFI.Text = "" Then
                MessageBox.Show("Input AFI", "Information")
                Return
            End If
            AFI = Convert.ToByte(tbUserAFI.Text, 16)
            state = 1
        End If

        fCmdRet = StaticClassReaderA.Inventory(readerAddr, state, AFI, DSFIDAndUID, cardNumber, portIndex)
        If fCmdRet = 0 Then
            strDSFIDAndUID = ByteArrayToHexString(DSFIDAndUID).Replace(" ", "")
            cbbUIDListforInfo.Items.Add(strDSFIDAndUID.Substring(2, 16))
            cbbUIDListforInfo.SelectedIndex = 0
            cbbUserUidList.Items.Add(strDSFIDAndUID.Substring(2, 16))
            cbbUserUidList.SelectedIndex = 0
            lbUIDList.Items.Add(strDSFIDAndUID.Substring(0, 18))
            labelCardNum.Text = cardNumber.ToString()
        End If
        AddCmdLog("Invenory(Single)", fCmdRet)
    End Sub

    Private Sub btnNewInventoryScanNoAFI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewInventoryScanNoAFI.Click, btnNewInventoryScanWithAFI.Click, btnContinueInventoryScanWithAFI.Click, btnContinueInventoryScanNoAFI.Click, btnUserNewInventoryScanWithAFI.Click, btnUserNewInventoryScanNoAFI.Click, btnUserContinueInventoryScanWithAFI.Click, btnUserContinueInventoryScanNoAFI.Click
        Dim fCmdRet As Integer = &H30
        Dim i As Integer
        Dim state As Byte = 6           '默认不带AFI的InventoryScan
        Dim AFI As Byte = 0
        Dim DSFIDAndUID(2350) As Byte
        Dim cardNumber As Byte = 0
        Dim aListItem As New ListViewItem()
        Dim s As String = ""
        Dim FirmName As String = ""
        Dim strDSFIDAndUID As String = ""
        Dim BlockSize As Byte = 0
        Dim BlockNum As Byte = 0
        Dim TagType As String = ""

        cbbUIDListforInfo.Items.Clear()
        cbbUserUidList.Items.Clear()
        lbUIDList.Items.Clear()
        labelCardNum.Text = "0"
        tbSystemInfoData.Text = ""
        tbSystemInfo.Text = ""
        cbbWriteType.Items.Clear()
        cbbEndBlockNum.Items.Clear()
        cbbBeginBlok.Items.Clear()
        cbbBlockNumToOperation.Items.Clear()
        cbbMaxBlockNum.Items.Clear()
        cbbBlockSize.Items.Clear()

        If sender Is btnContinueInventoryScanNoAFI Then
            state = 2
        Else
            If sender Is btnNewInventoryScanWithAFI Then
                If TabControl1.SelectedIndex = 4 Then
                    If tbUserAFI.Text = "" Then
                        MessageBox.Show("Input AFI", "Information")
                        Return
                    End If
                    AFI = Convert.ToByte(tbUserAFI.Text, 16)
                Else
                    If tbAFI.Text = "" Then
                        MessageBox.Show("Input AFI", "Information")
                        Return
                    End If
                    AFI = Convert.ToByte(tbAFI.Text, 16)
                End If
                state = 7
            Else
                If sender Is btnContinueInventoryScanWithAFI Then
                    If TabControl1.SelectedIndex = 4 Then
                        If tbUserAFI.Text = "" Then
                            MessageBox.Show("Input AFI", "Information")
                            Return
                        End If
                        AFI = Convert.ToByte(tbUserAFI.Text, 16)
                    Else
                        If tbAFI.Text = "" Then
                            MessageBox.Show("Input AFI", "Information")
                            Return
                        End If
                        AFI = Convert.ToByte(tbAFI.Text, 16)
                    End If
                    state = 3
                End If
            End If
        End If
        fCmdRet = StaticClassReaderA.Inventory(readerAddr, state, AFI, DSFIDAndUID, cardNumber, portIndex)

        If fCmdRet = &HA Or fCmdRet = &HB Or fCmdRet = &HE Then
            Array.Resize(DSFIDAndUID, cardNumber * 9)
            strDSFIDAndUID = ByteArrayToHexString(DSFIDAndUID).Replace(" ", "")
            If fIsTestMode Then
                DeleteRepeatUID(strDSFIDAndUID, DSFIDAndUIDList)
                totalCardNumber = CByte(DSFIDAndUIDList.Length / 18)
                If fCmdRet = &HE Then
                    While lvTestMode.Items.Count < totalCardNumber '以下是为了不闪烁
                        aListItem = lvTestMode.Items.Add((lvTestMode.Items.Count + 1).ToString())
                        aListItem.SubItems.Add("")
                        aListItem.SubItems.Add("")
                        aListItem.SubItems.Add("")
                    End While
                    While lvTestMode.Items.Count > totalCardNumber      '
                        lvTestMode.Items.Remove(lvTestMode.Items((lvTestMode.Items.Count - 1)))
                    End While
                    For i = 0 To totalCardNumber - 1
                        aListItem = lvTestMode.Items(i)
                        GetTagInfo(Convert.ToByte(DSFIDAndUIDList.Substring(18 * i + 14, 2), 16), Convert.ToByte(DSFIDAndUIDList.Substring(18 * i + 16, 2), 16), FirmName, BlockSize, BlockNum, TagType)
                        ChangeSubItem(aListItem, 1, FirmName)

                        s = DSFIDAndUIDList.Substring(18 * i + 2, 16)
                        ChangeSubItem(aListItem, 2, s)
                        s = DSFIDAndUIDList.Substring(18 * i, 2)
                        ChangeSubItem(aListItem, 3, s)
                    Next i
                End If
                If fCmdRet = &HB Then
                    btnNewInventoryScanNoAFI_Click(btnContinueInventoryScanNoAFI, Nothing)
                End If
            Else
                If fCmdRet = &HE Or fCmdRet = &HB Then
                    For i = 0 To cardNumber - 1
                        s = strDSFIDAndUID.Substring(18 * i + 2, 16)
                        cbbUIDListforInfo.Items.Add(s)
                        cbbUserUidList.Items.Add(s)
                        lbUIDList.Items.Add(strDSFIDAndUID.Substring(18 * i, 18))
                        labelCardNum.Text = cardNumber.ToString()
                    Next i
                    If cardNumber > 0 Then
                        cbbUIDListforInfo.SelectedIndex = 0
                        cbbUserUidList.SelectedIndex = 0
                    End If
                End If
            End If
        End If
        If fIsTestMode And totalCardNumber <> 0 Then
            AddCmdLog(CType(sender, Button).Text, 0)
        Else
            AddCmdLog(CType(sender, Button).Text, fCmdRet)
        End If
    End Sub

    Private Sub ChangeSubItem(ByVal ListItem As ListViewItem, ByVal subItemIndex As Integer, ByVal ItemText As String)
        If ListItem.SubItems(subItemIndex).Text <> ItemText Then
            ListItem.SubItems(subItemIndex).Text = ItemText
        End If
    End Sub 'ChangeSubItem

    Private Sub DeleteRepeatUID(ByVal tempUIDString As String, ByRef unipueUIDString As String)
        Dim i As Integer
        Dim s As String
        For i = 0 To (tempUIDString.Length / 18) - 1
            s = tempUIDString.Substring(18 * i, 18)
            If unipueUIDString.IndexOf(s) < 0 Then
                unipueUIDString = unipueUIDString + s
            End If
        Next i
    End Sub 'DeleteRepeatUID

    Private Sub GetTagInfo(ByVal FirmCode As Byte, ByVal OtherCode As Byte, ByRef FirmName As String, ByRef BlockSize As Byte, ByRef BlockNum As Byte, ByRef TagType As String)
        Select Case FirmCode
            Case &H2
                BlockSize = 4
                BlockNum = 16
                TagType = "B"
                FirmName = "STMicroelectronics"
            Case &H4
                BlockSize = 4
                BlockNum = 28
                TagType = "B"
                FirmName = "Philips Semiconductors"
            Case &H5
                BlockSize = 4
                BlockNum = 58
                If OtherCode = &HE0 Then
                    BlockNum = 250
                Else
                    If OtherCode = &H60 Then
                        BlockNum = 58
                    End If
                End If
                TagType = "B"
                FirmName = "Infineon"
            Case &H7
                BlockSize = 4
                BlockNum = 64
                TagType = "A"
                FirmName = "Texas Instruments"
            Case &H8
                BlockSize = 8
                BlockNum = 250
                TagType = "A/B"
                FirmName = "Fujitsu"
            Case &H16
                BlockSize = 4
                BlockNum = 14
                TagType = "A"
                FirmName = "EM Microelectronic"
            Case Else
                FirmName = ""
        End Select
    End Sub 'GetTagInfo

    Private Sub btnGetSystemInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetSystemInfo.Click
        Dim fCmdRet As Integer = &H30
        Dim errorCode As Byte = 0
        Dim state As Byte = 0
        Dim informationFlag As Byte = 0
        Dim DSFID As Byte = 0
        Dim AFI As Byte = 0
        Dim ICReference As Byte = 0
        Dim UIDI As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim UIDO(7) As Byte
        Dim menorySize(1) As Byte
        Dim blockSize As Byte = 0
        Dim blockNum As Byte = 0
        Dim tagWriteType As String = ""
        Dim FirmName As String = ""
        Dim i As Integer

        'btnReadSingleBlock.Enabled = False
        'btnReadMultiBlock.Enabled = False
        'btnWriteSingleBlock.Enabled = False
        'btnLcokBlock.Enabled = False
        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        state = GetState()

        If rdbAddressMode.Checked Then
            UIDI = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        fCmdRet = StaticClassReaderA.GetSystemInformation(readerAddr, state, UIDI, informationFlag, UIDO, DSFID, AFI, menorySize, ICReference, errorCode, portIndex)
        tbSystemInfoData.Text = ""
        tbSystemInfo.Text = ""
        cbbWriteType.Items.Clear()
        cbbEndBlockNum.Items.Clear()
        cbbBeginBlok.Items.Clear()
        cbbBlockNumToOperation.Items.Clear()
        cbbMaxBlockNum.Items.Clear()
        cbbBlockSize.Items.Clear()
        If fCmdRet = 0 Then
            tbSystemInfoData.Text = ByteArrayToHexString(UIDO).Replace(" ", "")
            tbSystemInfo.Text = "UID0: " + ByteArrayToHexString(UIDO).Replace(" ", "")
            If (informationFlag And &H1) = &H1 Then
                tbSystemInfoData.Text = tbSystemInfoData.Text + " " + Convert.ToString(DSFID, 16).PadLeft(2, "0"c).ToUpper()
                tbSystemInfo.Text = tbSystemInfo.Text + " " + "DSFID: " + Convert.ToString(DSFID, 16).PadLeft(2, "0"c).ToUpper()
            End If
            If (informationFlag And &H2) = &H2 Then
                tbSystemInfoData.Text = tbSystemInfoData.Text + " " + Convert.ToString(AFI, 16).PadLeft(2, "0"c).ToUpper()
                tbSystemInfo.Text = tbSystemInfo.Text + " " + "AFI: " + Convert.ToString(AFI, 16).PadLeft(2, "0"c).ToUpper()
            End If
            If (informationFlag And &H4) = &H4 Then
                tbSystemInfoData.Text = tbSystemInfoData.Text + " " + ByteArrayToHexString(menorySize).Replace(" ", "")
                tbSystemInfo.Text = tbSystemInfo.Text + " " + "MemorySize: " + ByteArrayToHexString(menorySize).Replace(" ", "")
            End If
            If (informationFlag And &H8) = &H8 Then
                tbSystemInfoData.Text = tbSystemInfoData.Text + " " + Convert.ToString(ICReference, 16).PadLeft(2, "0"c).ToUpper()
                tbSystemInfo.Text = tbSystemInfo.Text + " " + "ICReference: " + Convert.ToString(ICReference, 16).PadLeft(2, "0"c).ToUpper()
            End If

            GetTagInfo(UIDO(6), UIDO(7), FirmName, blockSize, blockNum, tagWriteType)

            cbbWriteType.Items.Add("A")
            cbbWriteType.Items.Add("B")
            If tagWriteType.IndexOf("B") <> -1 Then
                cbbWriteType.SelectedIndex = 1
            Else
                cbbWriteType.SelectedIndex = 0
            End If
            cbbBlockSize.Items.Add("4")
            cbbBlockSize.Items.Add("8")
            If blockSize = 8 Then
                cbbBlockSize.SelectedIndex = 1
            Else
                cbbBlockSize.SelectedIndex = 0
            End If
            For i = 0 To 255
                cbbMaxBlockNum.Items.Add(i.ToString())
            Next i
            cbbMaxBlockNum.SelectedIndex = blockNum - 1

            StatusBar1.Panels(2).Text = FirmName + "," + "Type " + tagWriteType + ", " + blockSize.ToString() + " Bytes/Block, " + blockNum.ToString() + " Blocks"
        End If
        AddCmdLog("GetSystemInfomation", fCmdRet, errorCode)
    End Sub

    Private Sub btnWriteAFI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteAFI.Click
        Dim state As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim errorCode As Byte = 0
        Dim AFI As Byte = 0
        Dim fCmdRet As Integer = &H30

        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        If tbAFI.Text = "" Then
            MessageBox.Show("Input AFI", "Information")
            Return
        End If
        AFI = Convert.ToByte(tbAFI.Text, 16)
        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        state = GetState(cbbWriteType.SelectedText)
        fCmdRet = StaticClassReaderA.WriteAFI(readerAddr, state, UID, AFI, errorCode, portIndex)

        AddCmdLog("Wrtite AFI", fCmdRet, errorCode)
    End Sub

    Private Sub btnLockAFI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLockAFI.Click
        Dim state As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30

        If MessageBox.Show(Me, "Lock AFI ?", "Lock", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        state = GetState(cbbWriteType.SelectedText)
        fCmdRet = StaticClassReaderA.LockAFI(readerAddr, state, UID, errorCode, portIndex)

        AddCmdLog("Lock AFI", fCmdRet, errorCode)
    End Sub

    Private Sub btnWriteDSFID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteDSFID.Click
        Dim state As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim errorCode As Byte = 0
        Dim DSFID As Byte = 0
        Dim fCmdRet As Integer = &H30

        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        If tbDSFID.Text = "" Then
            MessageBox.Show("Input DSFID", "Information")
            Return
        End If
        DSFID = Convert.ToByte(tbDSFID.Text, 16)
        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        state = GetState(cbbWriteType.SelectedText)
        fCmdRet = StaticClassReaderA.WriteDSFID(readerAddr, state, UID, DSFID, errorCode, portIndex)

        AddCmdLog("Write DSFID", fCmdRet, errorCode)
    End Sub

    Private Sub btnLockDSFID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLockDSFID.Click
        Dim state As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30

        If MessageBox.Show(Me, "Lock DSFID ?", "Lock", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        state = GetState(cbbWriteType.SelectedText)
        fCmdRet = StaticClassReaderA.LockDSFID(readerAddr, state, UID, errorCode, portIndex)
        AddCmdLog("Lock DSFID", fCmdRet, errorCode)
    End Sub

    Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        Dim fCmdRet As Integer = &H30
        Dim errorCode As Byte = 0
        Dim uid(7) As Byte

        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        uid = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        fCmdRet = StaticClassReaderA.Select(readerAddr, uid, errorCode, portIndex)
        AddCmdLog("Select", fCmdRet, errorCode)
    End Sub

    Private Sub btnStayQuite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStayQuite.Click
        Dim fCmdRet As Integer = &H30
        Dim errorCode As Byte = 0
        Dim uid(7) As Byte

        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        uid = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        fCmdRet = StaticClassReaderA.StayQuiet(readerAddr, uid, errorCode, portIndex)
        AddCmdLog("StayQuiet", fCmdRet, errorCode)
    End Sub

    Private Sub bntSetActiveANT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntSetActiveANT.Click
        Dim fCmdRet As Integer = &H30
        Dim ANTSet As Byte = 0

        If rbANT1.Checked Then
            ANTSet = 1
        Else
            If rbANT2.Checked Then
                ANTSet = 2
            Else
                If rbANT3.Checked Then
                    ANTSet = 4
                Else
                    If rbANT4.Checked Then
                        ANTSet = 8
                    End If
                End If
            End If
        End If
        fCmdRet = StaticClassReaderA.SetActiveANT(readerAddr, ANTSet, portIndex)
        AddCmdLog("Set Active Antenna", fCmdRet)
    End Sub

    Private Sub btnSetReceiveChannel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetReceiveChannel.Click
        Dim fCmdRet As Integer = &H30
        Dim receiveChannelToSet As Byte = 0

        receiveChannelToSet = CByte(IIf(checkBSetRTXChannel.Checked, 1, 0) * 2 + (IIf(checkBSetRXChannel.Checked, 1, 0)))
        fCmdRet = StaticClassReaderA.SetReceiveChannel(readerAddr, receiveChannelToSet, portIndex)
        AddCmdLog("Set Receive Channel", fCmdRet)
    End Sub

    Private Sub cbbMaxBlockNum_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbMaxBlockNum.SelectedIndexChanged
        Dim i As Byte
        For i = 0 To cbbMaxBlockNum.SelectedIndex
            cbbBlockNumToOperation.Items.Add(i)
            cbbBeginBlok.Items.Add(i)
            cbbEndBlockNum.Items.Add(i.ToString())
        Next
        cbbBlockNumToOperation.SelectedIndex = 0
        cbbBeginBlok.SelectedIndex = 0
        cbbEndBlockNum.SelectedIndex = 0
    End Sub

    Private Sub btnReadSingleBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadSingleBlock.Click
        Dim state As Byte = 0
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30
        Dim blockNum As Byte = 0
        Dim blockSecStatus As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}

        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        tbDataReaded.Text = ""
        blockNum = CByte(cbbBlockNumToOperation.SelectedIndex)
        state = GetState(CByte(cbbBlockSize.SelectedIndex * 4 + 4), "", False)

        Dim data(cbbBlockSize.SelectedIndex * 4 + 3) As Byte

        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        fCmdRet = StaticClassReaderA.ReadSingleBlock(readerAddr, state, UID, blockNum, blockSecStatus, data, errorCode, portIndex)
        If fCmdRet = 0 Then
            tbDataReaded.Text = blockSecStatus.ToString("x2") + " " + ByteArrayToHexString(data).Replace(" ", "")
        End If
        AddCmdLog("ReadSingleBlock", fCmdRet, errorCode)
    End Sub

    Private Sub btnLcokBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLcokBlock.Click
        Dim state As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim errorCode As Byte = 0
        Dim blockNum As Byte = 0
        Dim fCmdRet As Integer = &H30

        If MessageBox.Show(Me, "Lock Block ?", "Lock", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        state = GetState(cbbWriteType.SelectedText)
        blockNum = CByte(cbbBlockNumToOperation.SelectedIndex)
        fCmdRet = StaticClassReaderA.LockBlock(readerAddr, state, UID, blockNum, errorCode, portIndex)
        AddCmdLog("Lock Block", fCmdRet, errorCode)
    End Sub

    Private Sub btnWriteSingleBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteSingleBlock.Click
        Dim state As Byte = 0
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30
        Dim blockNum As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}

        If tbDataToWrite.Text.Length <> (cbbBlockSize.SelectedIndex * 4 + 4) * 2 Then
            MessageBox.Show("Input correct data", "Information")
            Return
        End If
        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If
        Dim data(cbbBlockSize.SelectedIndex * 4 + 3) As Byte
        data = HexStringToByteArray(tbDataToWrite.Text)
        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        blockNum = CByte(cbbBlockNumToOperation.SelectedIndex)
        state = GetState(CByte(cbbBlockSize.SelectedIndex * 4 + 4), cbbWriteType.SelectedText, True)

        fCmdRet = StaticClassReaderA.WriteSingleBlock(readerAddr, state, UID, blockNum, data, errorCode, portIndex)
        AddCmdLog("Write Single Block", fCmdRet, errorCode)
    End Sub

    Private Sub cbbBlockSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbBlockSize.SelectedIndexChanged
        tbDataToWrite.MaxLength = (cbbBlockSize.SelectedIndex * 4 + 4) * 2
    End Sub

    Private Sub btnReadMultiBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadMultiBlock.Click
        Dim state As Byte = 0
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30
        Dim startBlockNum As Byte = 0
        Dim blockCount As Byte = 0
        Dim blockSize As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim i As Integer

        If rdbAddressMode.Checked And (cbbUIDListforInfo.Items.Count = 0 Or cbbUIDListforInfo.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If

        startBlockNum = CByte(cbbBeginBlok.SelectedIndex)
        If cbbEndBlockNum.SelectedIndex < startBlockNum Then
            MessageBox.Show("Block number error", "Information")
            Return
        End If

        blockCount = CByte(cbbEndBlockNum.SelectedIndex - startBlockNum + 1)
        If cbbBlockSize.SelectedIndex = 0 Then  'BlockSize为4时,一次最大能读取28个块
            If blockCount > 28 Then
                MessageBox.Show("Block count can't over 28", "Information")
                Return
            End If
        Else                                    'BlockSize为8时,一次最大能读取15个块
            If blockCount > 15 Then
                MessageBox.Show("Block count can't over 15", "Information")
                Return
            End If
        End If
        blockSize = CByte(cbbBlockSize.SelectedIndex * 4 + 4)

        Dim data(blockSize * blockCount - 1) As Byte
        Dim blockSecStatus(blockCount - 1) As Byte
        state = GetState(blockSize, "", False)
        If rdbAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUIDListforInfo.SelectedItem.ToString())
        End If
        fCmdRet = StaticClassReaderA.ReadMultipleBlock(readerAddr, state, UID, startBlockNum, blockCount, blockSecStatus, data, errorCode, portIndex)
        If fCmdRet = 0 Then
            Dim frmdata As New frmMultipleBlockDataList()
            frmdata.Text = cbbUIDListforInfo.SelectedItem.ToString()
            Dim temp As String = ByteArrayToHexString(data).Replace(" ", "")
            For i = startBlockNum To (cbbEndBlockNum.SelectedIndex + 1) - 1
                frmdata.ListView1.Items.Add(i.ToString())
                frmdata.ListView1.Items((i - startBlockNum)).SubItems.Add((Convert.ToString(blockSecStatus((i - startBlockNum)), 16).PadLeft(2, "0"c) + " " + temp.Substring((i - startBlockNum) * blockSize * 2, blockSize * 2)))
            Next i
            frmdata.Show()
        End If
        AddCmdLog("ReadMultipleBlocks", fCmdRet, errorCode)
    End Sub

    Private Sub btnStartTestMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartTestMode.Click
        btnStartTestMode.Enabled = False
        btnStopTestMode.Enabled = True
        fIsTestMode = True
        timerTestMode.Enabled = True
    End Sub

    Private Sub timerTestMode_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerTestMode.Tick
        timerTestMode.Enabled = False
        DSFIDAndUIDList = ""
        totalCardNumber = 0
        btnNewInventoryScanNoAFI_Click(btnNewInventoryScanNoAFI, Nothing)
        If (fIsTestMode = True) And (Not fIsAppClose) Then
            timerTestMode.Enabled = True
        End If
    End Sub

    Private Sub btnStopTestMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopTestMode.Click
        timerTestMode.Enabled = False
        fIsTestMode = False
        btnStartTestMode.Enabled = True
        btnStopTestMode.Enabled = False
    End Sub

    Private Sub btnSetUserBlockSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetUserBlockSize.Click
        Dim fCmdRet As Integer = &H30
        Dim userBlockSize As Byte = 0

        userBlockSize = CByte(cbUserBlockSizeSet.SelectedIndex + 1)
        fCmdRet = StaticClassReaderA.SetUserDefinedBlockLength(readerAddr, userBlockSize, portIndex)
        AddCmdLog("Set Defined Block Length", fCmdRet)
    End Sub

    Private Sub btnGetUserBlockSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetUserBlockSize.Click
        Dim fCmdRet As Integer = &H30
        Dim userBlockSize As Byte = 0

        tbUserBlockSizeGet.Text = ""
        fCmdRet = StaticClassReaderA.GetUserDefinedBlocklength(readerAddr, userBlockSize, portIndex)
        If fCmdRet = 0 Then
            tbUserBlockSizeGet.Text = " " + Convert.ToString(userBlockSize, 10).PadLeft(2, "0"c)
            UserDefineBlockSize = userBlockSize
            tbUserDataToWrite.MaxLength = UserDefineBlockSize * 2
        End If
        AddCmdLog("Get Defined Block Length", fCmdRet)
    End Sub

    Private Sub btnUserReadSingleBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUserReadSingleBlock.Click
        Dim state As Byte = 0
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30
        Dim blockNum As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim data(7) As Byte

        Try
            tbUserDataGetted.Text = ""
            If rdbUserAddressMode.Checked And (cbbUserUidList.Items.Count = 0 Or cbbUserUidList.SelectedItem Is Nothing) Then
                MessageBox.Show("Select a UID", "Information")
                Return
            End If
            blockNum = CByte(cbbUserBlockNumber.SelectedIndex)
            state = &HA0
            If Not rdbUserAddressMode.Checked Then
                state = &HA1
            End If
            If rdbUserAddressMode.Checked Then
                UID = HexStringToByteArray(cbbUserUidList.SelectedItem.ToString())
            End If
            fCmdRet = StaticClassReaderA.CustomizedReadSingleBlock(readerAddr, state, UID, blockNum, data, errorCode, portIndex)
            If fCmdRet = 0 Then
                Array.Resize(data, UserDefineBlockSize + 1)     '1个字节安全状态字
                tbUserDataGetted.Text = ByteArrayToHexString(data).Replace(" ", "").Insert(2, " ")
            End If
        Catch

        End Try
        AddCmdLog("Read Single Block", fCmdRet, errorCode)
    End Sub

    Private Sub btnUserWriteSingleBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUserWriteSingleBlock.Click
        Dim state As Byte = 0
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30
        Dim blockNum As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}

        Try
            If tbUserDataToWrite.Text.Length <> UserDefineBlockSize * 2 Then
                MessageBox.Show("Input correct data", "Information")
                Return
            End If
            If rdbUserAddressMode.Checked And (cbbUserUidList.Items.Count = 0 Or cbbUserUidList.SelectedItem Is Nothing) Then
                MessageBox.Show("Select a UID", "Information")
                Return
            End If

            Dim data(UserDefineBlockSize) As Byte
            data = HexStringToByteArray(tbUserDataToWrite.Text)

            If rdbUserAddressMode.Checked Then
                UID = HexStringToByteArray(cbbUserUidList.SelectedItem.ToString())
            End If
            blockNum = CByte(cbbUserBlockNumber.SelectedIndex)
            If cbbUserWriteType.SelectedIndex = 0 Then
                state = &HA0
                If Not rdbUserAddressMode.Checked Then
                    state = &HA1
                End If
            Else
                state = &HA8
                If Not rdbUserAddressMode.Checked Then
                    state = &HA9
                End If
            End If
            fCmdRet = StaticClassReaderA.CustomizedWriteSingleBlock(readerAddr, state, UID, blockNum, data, UserDefineBlockSize, errorCode, portIndex)
        Catch

        End Try
        AddCmdLog("Write Single Block", fCmdRet, errorCode)
    End Sub

    Private Sub btnUserReadMultiBlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUserReadMultiBlock.Click
        Dim state As Byte = 0
        Dim errorCode As Byte = 0
        Dim fCmdRet As Integer = &H30
        Dim startBlockNum As Byte = 0
        Dim blockCount As Byte = 0
        Dim blockSize As Byte = 0
        Dim UID As Byte() = {0, 0, 0, 0, 0, 0, 0, 0}
        Dim i As Integer

        If rdbUserAddressMode.Checked And (cbbUserUidList.Items.Count = 0 Or cbbUserUidList.SelectedItem Is Nothing) Then
            MessageBox.Show("Select a UID", "Information")
            Return
        End If

        startBlockNum = CByte(cbbUserStartBlockNumber.SelectedIndex)
        If cbbUserEndBlockNumber.SelectedIndex < startBlockNum Then
            MessageBox.Show("Block number error", "Information")
            Return
        End If
        blockCount = CByte(cbbUserEndBlockNumber.SelectedIndex - startBlockNum + 1)
        blockSize = UserDefineBlockSize

        Dim data((blockSize + 1) * blockCount) As Byte
        Dim blockSecStatus(blockCount) As Byte

        state = &HA0
        If Not rdbUserAddressMode.Checked Then
            state = &HA1
        End If
        If rdbUserAddressMode.Checked Then
            UID = HexStringToByteArray(cbbUserUidList.SelectedItem.ToString())
        End If
        fCmdRet = StaticClassReaderA.CustomizedReadMultipleBlock(readerAddr, state, UID, startBlockNum, blockCount, data, errorCode, portIndex)
        If fCmdRet = 0 Then
            Dim frmdata As New frmMultipleBlockDataList()
            Dim temp As String = ByteArrayToHexString(data).Replace(" ", "")
            Dim s As String
            For i = startBlockNum To (cbbUserEndBlockNumber.SelectedIndex + 1) - 1
                s = temp.Substring((i - startBlockNum) * (blockSize + 1) * 2, (blockSize + 1) * 2)
                frmdata.ListView1.Items.Add(i.ToString())
                frmdata.ListView1.Items((i - startBlockNum)).SubItems.Add(s.Insert(2, " "))
            Next i
            frmdata.Show()
        End If
        AddCmdLog("ReadMultipleBlocks", fCmdRet, errorCode)
    End Sub

    Private Sub cbbUserMaxBlockNum_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbUserMaxBlockNum.SelectedIndexChanged
        Dim i As Byte
        Try
            For i = 0 To cbbUserMaxBlockNum.SelectedIndex
                cbbUserBlockNumber.Items.Add(i)
                cbbUserStartBlockNumber.Items.Add(i)
                cbbUserEndBlockNumber.Items.Add(i.ToString())
            Next
            cbbUserBlockNumber.SelectedIndex = 0
            cbbUserStartBlockNumber.SelectedIndex = 0
            cbbUserEndBlockNumber.SelectedIndex = 0
        Catch

        End Try
    End Sub

    Private Sub btnTransparentRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransparentRead.Click
        Dim cmdData() As Byte
        Dim respData(255) As Byte
        Dim fCmdRet As Integer = &H30
        Dim temp As String
        Dim errorCode As Byte = 0
        Dim respLength As Byte = 0
        Dim feedBackDataLength As Byte = 0

        tbResponeTransparentRead.Text = ""
        If tbCmdTransparentRead.Text = "" Then
            MessageBox.Show("Input Command", "Information")
            Return
        End If
        temp = tbCmdTransparentRead.Text.Replace(" ", "")
        cmdData = New Byte(temp.Length / 2 - 1) {}

        respLength = Convert.ToByte(temp.Substring(0, 2), 16)
        temp = temp.Remove(0, 2)
        cmdData = HexStringToByteArray(temp)

        fCmdRet = StaticClassReaderA.TransparentRead(readerAddr, respLength, CByte(cmdData.Length), cmdData, feedBackDataLength, respData, _
                                                     errorCode, portIndex)
        Array.Resize(respData, feedBackDataLength)
        If fCmdRet = 0 Then
            tbResponeTransparentRead.Text = ByteArrayToHexString(respData)
        End If
        AddCmdLog("TransparentRead", fCmdRet, errorCode)
    End Sub

    Private Sub btnTransparentSpecifyResponeTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransparentSpecifyResponeTime.Click
        Dim cmdData() As Byte
        Dim respData(256) As Byte
        Dim repTime(2) As Byte
        Dim fCmdRet As Integer = &H30
        Dim temp As String
        Dim errorCode As Byte = 0
        Dim respLength As Byte = 0
        Dim feedBackDataLength As Byte = 0

        tbResponeTransparentSpecifyResponeTime.Text = ""
        If tbCmdTransparentSpecifyResponeTime.Text = "" Then
            MessageBox.Show("Input Command", "Information")
            Return
        End If
        temp = tbCmdTransparentSpecifyResponeTime.Text.Replace(" ", "")

        If temp.Length < 6 Then
            MessageBox.Show("Command Too Short", "Information")
            Return
        End If

        repTime = HexStringToByteArray(temp.Substring(0, 4))
        respLength = Convert.ToByte(temp.Substring(4, 2), 16)

        cmdData = HexStringToByteArray(temp.Substring(6, temp.Length - 6))

        fCmdRet = StaticClassReaderA.TransparentCustomizedCmd(readerAddr, repTime, respLength, CByte(cmdData.Length), cmdData, feedBackDataLength, respData, errorCode, portIndex)

        Array.Resize(respData, feedBackDataLength)
        If fCmdRet = 0 Then
            tbResponeTransparentSpecifyResponeTime.Text = ByteArrayToHexString(respData)
        End If
        AddCmdLog("TransparentCustomizedCmd", fCmdRet, errorCode)
    End Sub

    Private Sub btnTransparentWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransparentWrite.Click
        Dim cmdData() As Byte
        Dim respData(256) As Byte
        Dim [option](4) As Byte
        Dim fCmdRet As Integer = &H30
        Dim temp As String
        Dim errorCode As Byte = 0
        Dim respLength As Byte = 0
        Dim feedBackDataLength As Byte = 0

        tbResponeTransparentWrite.Text = ""
        If tbCmdTransparentWrite.Text = "" Then
            MessageBox.Show("Input Command", "Information")
            Return
        End If
        temp = tbCmdTransparentWrite.Text.Replace(" ", "")

        If temp.Length < 10 Then
            MessageBox.Show("Command Too Short", "Information")
            Return
        End If

        [option] = HexStringToByteArray(temp.Substring(0, 8))
        respLength = Convert.ToByte(temp.Substring(8, 2), 16)

        cmdData = HexStringToByteArray(temp.Substring(10, temp.Length - 10))

        fCmdRet = StaticClassReaderA.TransparentWrite(readerAddr, [option], respLength, CByte(cmdData.Length), cmdData, feedBackDataLength, respData, errorCode, portIndex)

        Array.Resize(respData, feedBackDataLength)
        If fCmdRet = 0 Then
            tbResponeTransparentWrite.Text = ByteArrayToHexString(respData)
        End If
        AddCmdLog("TransparentWrite", fCmdRet, errorCode)
    End Sub

    Private Sub FrmDL810_00Demo_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        fIsTestMode = False
        fIsScanMode = False
        fIsAppClose = True
    End Sub

    Private Sub btnStartScanMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartScanMode.Click
        Dim scanModeData(10) As Byte
        Dim fCmdRet As Integer = &H30

        scanModeData(0) = 1

        If rdbScanModeWithComAddr.Checked Then  '1:发送comAddr;0:不发送
            scanModeData(1) = 1
        Else
            scanModeData(1) = 0
        End If
        If rdbScanModeWithUID.Checked Then
            scanModeData(1) = scanModeData(1) Or &H2
        Else
            scanModeData(1) = scanModeData(1) And &HFD
        End If

        If rdbScanModeIncludeSpecifyBlock.Checked Then
            scanModeData(1) = scanModeData(1) Or &H4
        Else
            scanModeData(1) = scanModeData(1) And &HFB
        End If

        If rdbScanModeWithSecWord.Checked Then
            scanModeData(1) = scanModeData(1) Or &H8
        Else
            scanModeData(1) = scanModeData(1) And &HF7
        End If

        If rdbScanModeHex.Checked Then
            scanModeData(1) = scanModeData(1) Or &H10
        Else
            scanModeData(1) = scanModeData(1) And &HEF
        End If

        If rdbScanModeSwitchRF.Checked Then
            scanModeData(1) = scanModeData(1) Or &H20
        Else
            scanModeData(1) = scanModeData(1) And &HDF
        End If

        If rdbScanModeBuzzerOn.Checked Then
            scanModeData(1) = scanModeData(1) Or &H40
        Else
            scanModeData(1) = scanModeData(1) And &HBF
        End If
        If rdbScanModeLedFlicker.Checked Then
            scanModeData(1) = scanModeData(1) Or &H80
        Else
            scanModeData(1) = scanModeData(1) And &H7F
        End If
        scanModeData(2) = CByte(cbbScanModeStartBlock.SelectedIndex)
        scanModeData(3) = CByte(cbbScanModeBlockCount.SelectedIndex)

        scanModeData(4) = CByte(cbbScanModeStartByte.SelectedIndex)
        scanModeData(5) = CByte(cbbScanModeByteCount.SelectedIndex)

        If Not ckbScanModeCoustomSpaceMark.Checked Then
            scanModeData(6) = CByte(1 << cbbScanModeSpaceMark.SelectedIndex)
        Else
            scanModeData(6) = &H80
            scanModeData(7) = ASCIIEncoding.ASCII.GetBytes(tbScanModeCoustomSpaceMark.Text)(0)  '取第一个字符为分隔符
        End If

        If Not ckbScanModeCoustomEndMark.Checked Then
            scanModeData(8) = CByte(1 << cbbScanModeEndMark.SelectedIndex)
        Else
            scanModeData(8) = &H80
            scanModeData(9) = ASCIIEncoding.ASCII.GetBytes(tbScanModeCoustomEndMark.Text)(0)    '取第一个字符为结束符
        End If
        scanModeData(10) = &H0

        fCmdRet = StaticClassReaderA.SetScanMode(readerAddr, scanModeData, portIndex)

        If fCmdRet = 0 Then
            timerScanMode.Enabled = True
            btnStopScanMode.Enabled = True
            btnStartScanMode.Enabled = False
            btnDisplayOn.Enabled = False
            btnDisplayOff.Enabled = True
            gbpScanModeSetting.Enabled = False
            fIsScanMode = True
        End If
        AddCmdLog("SetScanMode", fCmdRet)
    End Sub

    Private Sub DisplayScanModeData()
        Dim ScanModeData(40960) As Byte
        Dim ScanModeDataLength As Integer = 0
        Dim fCmdRet As Integer = &H30
        Dim s As String

        fCmdRet = StaticClassReaderA.ReadScanModeData(ScanModeData, ScanModeDataLength, portIndex)

        If fCmdRet = 0 Then
            Array.Resize(ScanModeData, ScanModeDataLength)
            If rdbScanModeHex.Checked Then
                s = ByteArrayToHexString(ScanModeData)
            Else
                s = New String(System.Text.Encoding.ASCII.GetChars(ScanModeData))
            End If
            tbScanModeData.AppendText(s)
        End If

        If fCmdRet = 1 Then
            tbScanModeData.AppendText(DateTime.Now.ToLongTimeString() + "  " + "No New Data .")
        End If
        tbScanModeData.AppendText(Environment.NewLine)
    End Sub

    Private Sub timerScanMode_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerScanMode.Tick
        timerScanMode.Enabled = False
        If (fIsScanMode) And (Not fIsAppClose) Then
            DisplayScanModeData()
            timerScanMode.Enabled = True
        End If

    End Sub

    Private Sub btnDisplayOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayOn.Click
        timerScanMode.Enabled = True
        btnDisplayOn.Enabled = False
        btnDisplayOff.Enabled = True
    End Sub

    Private Sub btnDisplayOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayOff.Click
        timerScanMode.Enabled = False
        btnDisplayOn.Enabled = True
        btnDisplayOff.Enabled = False
    End Sub

    Private Sub btnCleanScanModeData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCleanScanModeData.Click
        tbScanModeData.Text = ""
    End Sub

    Private Sub TabControl1_Selecting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        fIsTestMode = False
        fIsScanMode = False
        StatusBar1.Panels(0).Text = ""
        StatusBar1.Panels(2).Text = ""
        If cbbAlreadyOpenedPortList.Items.Count <> 0 Then
            If TabControl1.SelectedTab Is tpTestMode Then   '切换到"测试模式"页        
                lvTestMode.Items.Clear()
                btnStartTestMode.Enabled = True
                btnStopTestMode.Enabled = False
            ElseIf TabControl1.SelectedTab Is tpScanMode Then
                btnDisplayOff.Enabled = False
                btnDisplayOn.Enabled = False
                btnStartScanMode.Enabled = True
                btnStopScanMode.Enabled = False
                GetScanModeSetting()
            ElseIf TabControl1.SelectedTab Is tpCustomizeBlockLength Then
                btnUserReadMultiBlock.Enabled = False
                btnUserReadSingleBlock.Enabled = False
                btnUserWriteSingleBlock.Enabled = False
                btnGetUserBlockSize_Click(Nothing, Nothing)
            End If
        End If
    End Sub

    Private Sub GetScanModeSetting()
        Dim scanModeSetting(10) As Byte
        Dim fCmdRet As Integer = &H30

        fIsScanMode = False
        timerScanMode.Enabled = False

        fCmdRet = StaticClassReaderA.GetScanModeStatus(readerAddr, scanModeSetting, portIndex)

        If fCmdRet = 0 Then
            If (scanModeSetting(1) And &H1) = &H1 Then '1:发送comAddr;0:不发送
                rdbScanModeWithComAddr.Checked = True
            Else
                rdbScanModeNoComAddr.Checked = True
            End If
            If (scanModeSetting(1) And &H2) = &H2 Then
                rdbScanModeWithUID.Checked = True
            Else
                rdbScanModeNoUID.Checked = True
            End If
            If (scanModeSetting(1) And &H3) = &H3 Then
                rdbScanModeIncludeSpecifyBlock.Checked = True
            Else
                rdbScanModeExcludeSpecifyBlock.Checked = True
            End If
            If (scanModeSetting(1) And &H4) = &H4 Then
                rdbScanModeWithSecWord.Checked = True
            Else
                rdbScanModeNoSecWord.Checked = True
            End If

            If (scanModeSetting(1) And &H10) = &H10 Then
                rdbScanModeHex.Checked = True
            Else
                rdbScanModeAscii.Checked = True
            End If
            If (scanModeSetting(1) And &H20) = &H20 Then
                rdbScanModeSwitchRF.Checked = True
            Else
                rdbScanModeNotSwitchRF.Checked = True
            End If
            If (scanModeSetting(1) And &H40) = &H40 Then
                rdbScanModeBuzzerOn.Checked = True
            Else
                rdbScanModeBuzzerOff.Checked = True
            End If

            If (scanModeSetting(1) And &H80) = &H80 Then
                rdbScanModeLedFlicker.Checked = True
            Else
                rdbScanModeLedNoFlicker.Checked = True
            End If

            cbbScanModeStartBlock.SelectedIndex = scanModeSetting(2)
            cbbScanModeBlockCount.SelectedIndex = scanModeSetting(3)

            cbbScanModeStartByte.SelectedIndex = scanModeSetting(4)
            cbbScanModeByteCount.SelectedIndex = scanModeSetting(5)

            If CByte(scanModeSetting(6) And &H80) = &H80 Then
                ckbScanModeCoustomSpaceMark.Checked = True
                tbScanModeCoustomSpaceMark.Text = Convert.ToChar(scanModeSetting(7))
            Else
                If scanModeSetting(6) < &H10 Then
                    cbbScanModeSpaceMark.SelectedIndex = scanModeSetting(6) - 1
                Else
                    cbbScanModeSpaceMark.SelectedIndex = (scanModeSetting(6) >> 4) + 3
                End If
            End If
            If CByte(scanModeSetting(8) And &H80) = &H80 Then
                ckbScanModeCoustomEndMark.Checked = True
                tbScanModeCoustomEndMark.Text = Convert.ToChar(scanModeSetting(9))
            Else
                If scanModeSetting(8) < &H10 Then
                    cbbScanModeEndMark.SelectedIndex = scanModeSetting(8) - 1
                Else
                    cbbScanModeEndMark.SelectedIndex = (scanModeSetting(8) >> 4) + 3
                End If
            End If
            If scanModeSetting(0) = &H1 Then
                fIsScanMode = True
                timerScanMode.Enabled = True
                btnStartScanMode.Enabled = False
                btnDisplayOff.Enabled = True
                btnDisplayOn.Enabled = False
                btnStopScanMode.Enabled = True
            Else
                fIsScanMode = False
                timerScanMode.Enabled = False
                btnStartScanMode.Enabled = True
                btnDisplayOff.Enabled = False
                btnDisplayOn.Enabled = False
                btnStopScanMode.Enabled = False
            End If
        End If
        AddCmdLog("GetScanModeStatus", fCmdRet)
    End Sub

    Private Sub btnStopScanMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopScanMode.Click
        Dim scanModeData(10) As Byte
        Dim fCmdRet As Integer = &H30

        timerScanMode.Enabled = False
        scanModeData(0) = 0
        If rdbScanModeWithComAddr.Checked Then  '1:发送comAddr;0:不发送
            scanModeData(1) = 1
        Else
            scanModeData(1) = 0
        End If
        If rdbScanModeWithUID.Checked Then
            scanModeData(1) = scanModeData(1) Or &H2
        Else
            scanModeData(1) = scanModeData(1) And &HFD
        End If

        If rdbScanModeIncludeSpecifyBlock.Checked Then
            scanModeData(1) = scanModeData(1) Or &H4
        Else
            scanModeData(1) = scanModeData(1) And &HFB
        End If

        If rdbScanModeWithSecWord.Checked Then
            scanModeData(1) = scanModeData(1) Or &H8
        Else
            scanModeData(1) = scanModeData(1) And &HF7
        End If

        If rdbScanModeHex.Checked Then
            scanModeData(1) = scanModeData(1) Or &H10
        Else
            scanModeData(1) = scanModeData(1) And &HEF
        End If

        If rdbScanModeSwitchRF.Checked Then
            scanModeData(1) = scanModeData(1) Or &H20
        Else
            scanModeData(1) = scanModeData(1) And &HDF
        End If

        If rdbScanModeBuzzerOn.Checked Then
            scanModeData(1) = scanModeData(1) Or &H40
        Else
            scanModeData(1) = scanModeData(1) And &HBF
        End If
        If rdbScanModeLedFlicker.Checked Then
            scanModeData(1) = scanModeData(1) Or &H80
        Else
            scanModeData(1) = scanModeData(1) And &H7F
        End If
        scanModeData(2) = CByte(cbbScanModeStartBlock.SelectedIndex)
        scanModeData(3) = CByte(cbbScanModeBlockCount.SelectedIndex)

        scanModeData(4) = CByte(cbbScanModeStartByte.SelectedIndex)
        scanModeData(5) = CByte(cbbScanModeByteCount.SelectedIndex)

        If Not ckbScanModeCoustomSpaceMark.Checked Then
            scanModeData(6) = CByte(1 << cbbScanModeSpaceMark.SelectedIndex)
        Else
            scanModeData(6) = &H80
            scanModeData(7) = ASCIIEncoding.ASCII.GetBytes(tbScanModeCoustomSpaceMark.Text)(0)  '取第一个字符为分隔符
        End If

        If Not ckbScanModeCoustomEndMark.Checked Then
            scanModeData(8) = CByte(1 << cbbScanModeEndMark.SelectedIndex)
        Else
            scanModeData(8) = &H80
            scanModeData(9) = ASCIIEncoding.ASCII.GetBytes(tbScanModeCoustomEndMark.Text)(0)    '取第一个字符为结束符
        End If
        scanModeData(10) = &H0

        fCmdRet = StaticClassReaderA.SetScanMode(readerAddr, scanModeData, portIndex)
        If fCmdRet = 0 Then
            fIsScanMode = False
            timerScanMode.Enabled = False
            btnStopScanMode.Enabled = False
            btnStartScanMode.Enabled = True
            btnDisplayOn.Enabled = False
            btnDisplayOff.Enabled = False
            gbpScanModeSetting.Enabled = True
        Else
            timerScanMode.Enabled = True
            fIsScanMode = False
        End If
        AddCmdLog("ExitScanMode", fCmdRet)
    End Sub

    Private Sub cbbUserBlockNumber_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbUserBlockNumber.SelectedIndexChanged
        btnUserReadSingleBlock.Enabled = True
        btnUserWriteSingleBlock.Enabled = True
        btnUserReadMultiBlock.Enabled = True
    End Sub

    Private Sub cbbBlockNumToOperation_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbBlockNumToOperation.SelectedIndexChanged
        btnReadSingleBlock.Enabled = True
        btnWriteSingleBlock.Enabled = True
        btnReadMultiBlock.Enabled = True
        btnLcokBlock.Enabled = True
    End Sub

    Private Sub tbReaderAddr_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbReaderAddr.KeyPress, tbUserAFI.KeyPress, tbUserDataToWrite.KeyPress, tbDSFID.KeyPress, tbDataToWrite.KeyPress, tbAFI.KeyPress, tbAddressToWrite.KeyPress
        e.Handled = ("0123456789ABCDEF".IndexOf(Char.ToUpper(e.KeyChar)) < 0)  '  ""退格键      
    End Sub

    Private Sub tbCmdTransparentRead_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbCmdTransparentRead.KeyPress, tbCmdTransparentWrite.KeyPress, tbCmdTransparentSpecifyResponeTime.KeyPress
        e.Handled = "0123456789ABCDEF ".IndexOf(Char.ToUpper(e.KeyChar)) < 0 '""退格键
    End Sub

    Private Sub rdbModulation100_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbModulation100.Click, rdbParseModeWPPM.Click, rdbParseModeDPPM.Click, rdbModulation10.Click
        Dim ParseMode As Byte
        Dim fCmdRet As Integer

        If ((rdbParseModeDPPM.Checked = True) And (rdbModulation10.Checked = True)) Then
            ParseMode = &H1
        ElseIf ((rdbParseModeDPPM.Checked = True) And (rdbModulation100.Checked = True)) Then
            ParseMode = &H81
        ElseIf ((rdbParseModeWPPM.Checked = True) And (rdbModulation10.Checked = True)) Then
            ParseMode = &H0
        ElseIf ((rdbParseModeWPPM.Checked = True) And (rdbModulation100.Checked = True)) Then
            ParseMode = &H80
        End If
        fCmdRet = StaticClassReaderA.SetParseMode(readerAddr, ParseMode, portIndex)
        If fCmdRet = 0 Then
            If sender Is rdbParseModeDPPM Then
                rdbParseModeDPPM.Enabled = False
                rdbParseModeWPPM.Enabled = True
            ElseIf sender Is rdbParseModeWPPM Then
                rdbParseModeDPPM.Enabled = True
                rdbParseModeWPPM.Enabled = False
            ElseIf sender Is rdbModulation10 Then
                rdbModulation10.Enabled = False
                rdbModulation100.Enabled = True
            ElseIf sender Is rdbModulation100 Then
                rdbModulation10.Enabled = True
                rdbModulation100.Enabled = False
            End If
        End If
        AddCmdLog("SetParseMode", fCmdRet)
    End Sub

    Private Sub cbbUIDListforInfo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbUIDListforInfo.SelectedIndexChanged
        If tbReaderInfoType.Text <> "DL810_01Lite" And tbReaderInfoType.Text <> "DL810_01Lite" Then
            btnGetSystemInfo.Enabled = True
        End If
        gbpOtherCmd.Enabled = True
    End Sub

    Private Sub cbbWriteType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbWriteType.SelectedIndexChanged
        If cbbWriteType.Items.Count = 0 Then
            gbpAFI.Enabled = False
            gbpDSFID.Enabled = False
            btnGetSystemInfo.Enabled = False
        Else
            gbpAFI.Enabled = True
            gbpDSFID.Enabled = True
            btnGetSystemInfo.Enabled = True
        End If
    End Sub

    Private Sub rdbSelectMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbSelectMode.Click
        cbbUIDListforInfo.Enabled = False
    End Sub

    Private Sub rdbAddressMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbAddressMode.Click
        cbbUIDListforInfo.Enabled = True
    End Sub

    Private Sub rdbNonAddressMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbNonAddressMode.Click
        cbbUIDListforInfo.Enabled = True
    End Sub
End Class
