using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using ReaderA;

namespace DL810Demo
{
    public partial class frmDL810Demo : Form
    {
        private int portIndex = -1;
        private byte readerAddr = 0xff;
        private bool fIsTestMode = false;          //是否正在进行测试模式
        private byte UserDefineBlockSize = 0; 
        private bool fIsScanMode = false;          //是否正在进行扫描模式
        private ArrayList AlreadyOpenPortList = new ArrayList();
        private string DSFIDAndUIDList;           //存储从开始询查到接收到0E之间的所有DSFID,UID 
        private byte totalCardNumber = 0;
        private const byte OK = 0x00;
        private bool fIsAppClose = false;
        private const byte lengthError = 0x01;
        private const byte operationNotSupport = 0x02;
        private const byte dataRangError = 0x03;
        private const byte cmdNotOperation = 0x04;
        private const byte rfClosed = 0x05;
        private const byte EEPROM = 0x06;
        private const byte timeOut = 0x0a;
        private const byte moreUID = 0x0b;
        private const byte ISOError = 0x0c;
        private const byte noElectronicTag = 0x0e;
        private const byte operationError = 0x0f;
        private const byte cmdNotSupport = 0x01;
        private const byte cmdNotIdentify = 0x02;
        private const byte errOperationNotSupport = 0x03;
        private const byte unknownError = 0x0f;
        private const byte blockError = 0x10;
        private const byte blockLockedCntLock = 0x11;
        private const byte blockLockedCntWrite = 0x12;
        private const byte blockCntOperate = 0x13;
        private const byte blockCntLock = 0x14;
        private const byte communicationErr = 0x30;
        private const byte retCRCErr = 0x31;
        private const byte retDataErr = 0x32;
        private const byte communicationBusy = 0x33;
        private const byte executeCmdBusy = 0x34;
        private const byte comPortOpened = 0x35;
        private const byte comPortClose = 0x36;
        private const byte invalidHandle = 0x37;
        private const byte invalidPort = 0x38;
        public frmDL810Demo()
        {
            InitializeComponent();
            InitializeComboBox();
            DSFIDAndUIDList = "";
            timerTestMode.Enabled = false;
            this.SetStyle(ControlStyles.DoubleBuffer |
                          ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.UserPaint, true);
            UpdateStyles();
            InitializeBtnEnable();
        }

        private void InitializeComboBox()
        {
            cbComPortList.SelectedIndex = 0;
            cbRelayControl.SelectedIndex = 0;
            cbOutput1Status.SelectedIndex = 0;
            cbOutput2Status.SelectedIndex = 0;
            cbScanModeStartBlock.SelectedIndex = 1;
            cbScanModeBlockCount.SelectedIndex = 1;
            cbScanModeStartByte.SelectedIndex = 1;
            cbScanModeByteCount.SelectedIndex = 1;
            cbScanModeEndMark.SelectedIndex = 0;
            cbScanModeSpaceMark.SelectedIndex = 0;
            cbInventoryScanTimeToWrite.SelectedIndex = 27;
            cbAccessTimeToSet.SelectedIndex = 0;
            cbUserBlockSizeSet.SelectedIndex = 0;
            cbUserWriteType.SelectedIndex = 1;
            cbUserMaxBlockNum.SelectedIndex = 1;
        }

        private void 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;        
        }

        private void 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)
            {
                gbpSpecifyRsptimeTransparentCmd.Enabled = true;
                gbpTransparentRead.Enabled = true;
                gbpTransparentWrite.Enabled = true;
            }
            else
            if (tabControl1.TabPages.IndexOf(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);

            if (tabControl1.TabPages.IndexOf(tpTestMode) >= 0)
                tabControl1.TabPages.Remove(tpTestMode);
        }

        private void 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(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
            if (tabControl1.TabPages.IndexOf(tpTestMode) >= 0)
                tabControl1.TabPages.Remove(tpTestMode);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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(null, null);
            if (tbReceiveChannelStatus.Text.IndexOf("TX/RX") >= 0)
            {
                gbpSpecifyRsptimeTransparentCmd.Enabled = true;
                gbpTransparentRead.Enabled = true;
                gbpTransparentWrite.Enabled = true;
            }
            else
            {
                if (tabControl1.TabPages.IndexOf(tpTransparent) >= 0)
                    tabControl1.TabPages.Remove(tpTransparent);
            }
        }

        private void 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;   
        }

        private void 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;
        }

        private void 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;   
        }

        private void 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(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
        }

        private void 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(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
        }

        private void 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(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);

        }

        private void 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)
            {
                gbpSpecifyRsptimeTransparentCmd.Enabled = true;
                gbpTransparentRead.Enabled = true;
                gbpTransparentWrite.Enabled = true;
            }
            else
            if (tabControl1.TabPages.IndexOf(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
        }

        private void 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(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
            if (tabControl1.TabPages.IndexOf(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
            if (tabControl1.TabPages.IndexOf(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);
            if (tabControl1.TabPages.IndexOf(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);
            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }

        private void 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)
            {
                gbpSpecifyRsptimeTransparentCmd.Enabled = true;
                gbpTransparentRead.Enabled = true;
                gbpTransparentWrite.Enabled = true;
            }
            else
            if (tabControl1.TabPages.IndexOf(tpTransparent) >= 0)
                tabControl1.TabPages.Remove(tpTransparent);

            if (tabControl1.TabPages.IndexOf(tpCoustomDataLen) >= 0)
                tabControl1.TabPages.Remove(tpCoustomDataLen);

            if (tabControl1.TabPages.IndexOf(tpScanMode) >= 0)
                tabControl1.TabPages.Remove(tpScanMode);
        }      
       
        private string DL810_00GetReturnCodeDesc(int cmdRet)
        {
            switch (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 "Inventory-Scan-Time overflow";
                case moreUID:
                    return "Not all tag's UID are collected before the Inventory-Scan-Time overflow";
                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 ComPort ";
                case OK:
                    return "successfully";
                default:
                    return "";
            }
        }

        private string DL810_00GetErrorCodeDesc(byte errorCode)
        {
            switch (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 "Appointed  block can't be used or does not exist ";
                case blockLockedCntLock:
                case blockLockedCntWrite:
                    return "Appointed  block is locked";
                case blockCntOperate:
                    return "Appointed  block can't be operated normally";
                case blockCntLock:
                    return "Appointed  block can't be locked normally";

                default:
                    return "";
            }
        }

         private void btnGetReaderInfo_Click(object sender, EventArgs e)
        {
            byte[] verInfo = new byte[2];
            byte[] trType = new byte[2];
            byte readerType = 0;
            byte inventoryScanTime = 0;
            int fCmdRet = 0x30;

            ClearReaderInformation();
            if(cbAlreadyOpenedPortList.Items.Count == 0)
            InitializeBtnEnable();
            if (sender == btnGetReaderInfo)     //区分是通过"GetReaderInformation"按钮还是下拉列表激活了该事件。
            {
                if (tbReaderAddr.Text != "")
                {
                    readerAddr = Convert.ToByte(tbReaderAddr.Text, 16);
                }
                else
                {
                    MessageBox.Show("请输入读写器地址");
                    return;
                }
            }
            fCmdRet = StaticClassReaderA.GetReaderInformation(ref readerAddr, verInfo, 
                                                          ref readerType, trType, 
                                                          ref inventoryScanTime,
                                                          portIndex);
            if (fCmdRet == 0)
            {
                tbReadInfoAddr.Text = Convert.ToString(readerAddr, 16).PadLeft(2, '0').ToUpper();
                tbReaderInfoVersion.Text = Convert.ToString(verInfo[0], 10).PadLeft(2, '0') + "." +
                                           Convert.ToString(verInfo[1], 10).PadRight(2, '0');
                tbReaderInfoType.Text = GetReaderType(readerType);
                if ((trType[1] & 0x08) == 0x08)
                { tbReaderInfoProtocol.Text = "ISO/IEC 15693"; }
                tbReaderInfoInventoryScanTime.Text = inventoryScanTime.ToString().ToUpper();

                if (tabControl1.TabPages.IndexOf(tpTestMode) < 0)
                    tabControl1.TabPages.Insert(2, tpTestMode);

                if (tabControl1.TabPages.IndexOf(tpScanMode) < 0)
                    tabControl1.TabPages.Insert(3, tpScanMode);

                if (tabControl1.TabPages.IndexOf(tpCoustomDataLen) < 0)
                    tabControl1.TabPages.Insert(4, tpCoustomDataLen);

                if (tabControl1.TabPages.IndexOf(tpTransparent) < 0)
                    tabControl1.TabPages.Insert(5, tpTransparent);


                switch (tbReaderInfoType.Text)
                {
                    case "DL810_37":
                        DL810_37SREnable();
                        break;
                    case "DL810_36":
                    case "DL810_36SC":
                    case "DL810_36CF":
                        DL810_36SREnable();
                        break;
                    case "DL810_96A":
                    case "DL810_96":
                        DL810_96AEnable();
                        break;
                    case "DL810_93T":
                        //                    case "DL810_93T":
                        DL810_93TEnanle();
                        break;
                    case "DL810_92T":
                        //                    case "DL810_92T":
                        DL810_92TEnanle();
                        break;
                    case "DL810_91T":
                        //                    case "DL810_91T":
                        DL810_91TEnanle();
                        break;
                    case "DL810_93A":
                        //                    case "DL810_93A":
                        DL810_93AEnable();
                        break;
                    case "DL810_92A":
                        //                   case "DL810_92A":
                        DL810_92AEnable();
                        break;
                    case "DL810_91F":
                        //                    case "DL810_91F":
                        DL810_91FEnable();
                        break;
                    case "DL810_91":
                        //                    case "DL810_91":
                        DL810_91Enable();
                        break;
                    case "DL810_03T":
                        //                    case "DL810_03T":
                        DL810_03TEnable();
                        break;
                    case "DL810_02T":
                        //                    case "DL810_02T":
                        DL810_02TEnable();
                        break;
                    case "DL810_01T":
                        //                    case "DL810_01T":
                        DL810_01TEnable();
                        break;
                    case "DL810_03A":
                        //                    case "DL810_03A":
                        DL810_03AEnable();
                        break;
                    case "DL810_02A":
                        //                    case "DL810_02A":
                        DL810_02AEnable();
                        break;
                    case "DL810_01Lite":
                        //                    case "DL810_01Lite":
                        DL810_01LiteEnable();
                        break;
                    case "DL810_01":
                        //                    case "DL810_01":
                        DL810_01Enable();
                        break;
                }


                if ((string.Compare(tbReaderInfoVersion.Text, "06.00") > 0) ||
                   (tbReaderInfoType.Text == "DL810_01T") ||
                   (tbReaderInfoType.Text == "DL810_02T") ||
                   (tbReaderInfoType.Text == "DL810_03T") ||
                   (tbReaderInfoType.Text == "DL810_91T") ||
                   (tbReaderInfoType.Text == "DL810_93T") ||
                   (tbReaderInfoType.Text == "DL810_93T") ||
                   (tbReaderInfoType.Text == "DL810_92T") ||
                   (tbReaderInfoType.Text == "DL810_01T") ||
                   (tbReaderInfoType.Text == "DL810_02T") ||
                   (tbReaderInfoType.Text == "DL810_03T") ||
                   (tbReaderInfoType.Text == "DL810_91T") ||
                   (tbReaderInfoType.Text == "DL810_92T") ||
                   (tbReaderInfoType.Text == "DL810_93T") ||
                   (tbReaderInfoType.Text == "DL810_96") ||
                   (tbReaderInfoType.Text == "DL810_96A") ||
                   (tbReaderInfoType.Text == "DL810_01TSC") ||
                   (tbReaderInfoType.Text == "DL810_91TSC"))
                {
                    GetParseMode();
                }

                if (tbReaderInfoType.Text == "DL810_96A")
                {
                    btnGetReceiveChannelStatus_Click(null, null);
                    if (tbReceiveChannelStatus.Text == "RXOnly")
                        if (tabControl1.TabPages.IndexOf(tpTransparent) >= 0)
                        { tabControl1.TabPages.Remove(tpTransparent); }
                }


                if ((tbReaderInfoType.Text == "DL810_37") || (tbReaderInfoType.Text == "DL810_37SC") ||
                   (tbReaderInfoType.Text == "DL810_36") || (tbReaderInfoType.Text == "DL810_36SR") ||
                   (tbReaderInfoType.Text == "DL810_36CF"))
                {
                    label16.Text = "LED";
                    label15.Text = "Buzzer";
                    cbOutput1Status.Items.Clear();
                    cbOutput1Status.Items.Add("Active");
                    cbOutput1Status.Items.Add("Mute");
                    cbOutput1Status.SelectedIndex = 0;

                    cbOutput2Status.Items.Clear();
                    cbOutput2Status.Items.Add("Green");
                    cbOutput2Status.Items.Add("Red");
                    cbOutput2Status.SelectedIndex = 0;
                }
                else
                {
                    label16.Text = "Output2";
                    label15.Text = "Output1";
                    cbOutput1Status.Items.Clear();
                    cbOutput1Status.Items.Add("Low");
                    cbOutput1Status.Items.Add("Hight");
                    cbOutput1Status.SelectedIndex = 0;
                    cbOutput2Status.Items.Clear();
                    cbOutput2Status.Items.Add("Low");
                    cbOutput2Status.Items.Add("Hight");
                    cbOutput2Status.SelectedIndex = 0;
                }
                    StatusBar1.Panels[1].Text = cbAlreadyOpenedPortList.SelectedItem.ToString();
            }
            AddCmdLog(btnGetReaderInfo.Text, fCmdRet);
        }

        private void GetParseMode()
        {
            int fCmdRet;
            byte ParseMode = 0; ;
            fCmdRet = StaticClassReaderA.GetParseMode(ref readerAddr, ref ParseMode, portIndex);
            if (fCmdRet == 0)
            {
                if (ParseMode == 0x01)
                {
                    rbParseModeDPPM.Checked = true;
                    rbParseModeDPPM.Enabled = false;
                    rbModulation10.Checked = true;
                    rbModulation10.Enabled = false;
                }
                if (ParseMode == 0x81)
                {
                    rbParseModeDPPM.Checked = true;
                    rbParseModeDPPM.Enabled = false;
                    rbModulation100.Checked = true;
                    rbModulation100.Enabled = false;
                }
                if (ParseMode == 0x00)
                {
                    rbParseModeWPPM.Checked = true;
                    rbParseModeWPPM.Enabled = false;
                    rbModulation10.Checked = true;
                    rbModulation10.Enabled = false;
                }
                if (ParseMode == 0x80)
                {
                    rbParseModeWPPM.Checked = true;
                    rbParseModeWPPM.Enabled = false;
                    rbModulation100.Checked = true;
                    rbModulation100.Enabled = false;
                }                 
            }
            AddCmdLog("Get Parse Mode", fCmdRet);
        }

        private void SetParseMode()
        {
            int fCmdRet;
            byte ParseMode = 0; 
            
                if ((rbParseModeDPPM.Checked == true) &&
                    (rbModulation10.Checked == true))
                {
                    ParseMode = 0x01;
                }
                if ((rbParseModeDPPM.Checked == true) &&
                    (rbModulation100.Checked == true))
                {
                    ParseMode = 0x81;
                 }
                if ((rbParseModeWPPM.Checked == true) &&
                    (rbModulation10.Checked == true))
                {
                   ParseMode = 0x00;
                 }
                if ((rbParseModeWPPM.Checked == true) &&
                    (rbModulation100.Checked == true))
                {
                    ParseMode = 0x80;
                }

            fCmdRet = StaticClassReaderA.SetParseMode(ref readerAddr, ref ParseMode, portIndex);
            AddCmdLog("Set Parse Mode", fCmdRet);        
        }

        #region ClearReaderInfo                     
        private void ClearReaderInformation()
        {
            tbReadInfoAddr.Text = "";
            tbReaderInfoVersion.Text = "";
            tbReaderInfoType.Text = "";
            tbReaderInfoInventoryScanTime.Text = "";
            tbReaderInfoProtocol.Text = "";
        }
        #endregion

        #region  GetReaderTypeString
        private string GetReaderType(byte version)
        {
            switch (version)
            {
                case 0x45:
                    return "DL810_01";                    
                case 0x55:                    
                    return "DL810_36";
                case 0x58:
                    return "DL810_38";
                case 0x5C:
                    return "DL810_36SC";
                case 0x46:
                    return "DL810_01Lite";
                case 0x47:
                    return "DL810_03A";
                case 0x71:
                    return "DL810_03AD";
                case 0x48:
                    return "DL810_36CF";
                case 0xA1:
                    return "DL810_01";
                case 0xA2:
                    return "DL810_03A";
                case 0xA6:
                    return "DL810_01Lite";
                case 0x80:
                    return "DL810_91D";
                case 0x5B:
                    return "DL810_37";
                case 0x5D:
                    return "DL810_37SC";
                case 0x90:
                    return "DL810_91";
                case 0x30:
                    return "DL810_91F";
                case 0x3A:
                    return "DL810_96";
                case 0x3B:
                    return "DL810_96A";
                case 0xA7:
                    return "DL810_01D";
                case 0x4B:
                    return "DL810_02AD";
                case 0xA3:
                    return "DL810_02AD";
                case 0x81:
                    return "DL810_92A";
                case 0x82:
                    return "DL810_93A";
                case 0x93:
                    return "DL810_91F";
                case 0x91:
                    return "DL810_92A";
                case 0x92:
                    return "DL810_93A";
                case 0x70:                  //version 06.00
                    return "DL810_01D";
                case 0x8B:
                    return "DL810_03AGD";
                case 0x72:
                    return "DL810_03AD";
                case 0x97:
                    return "DL810_91D";
                case 0x7E:
                    return "DL810_01T";
                case 0x7F:
                    return "DL810_01T";
                case 0x8E:
                    return "DL810_91T";
                case 0x8F:
                    return "DL810_91T";
                case 0x83:
                    return "DL810_92T";
                case 0x84:                   
                    return "DL810_93T";              
                case 0x74:
                    return "DL810_02T";
                case 0x73:
                    return "DL810_03T";
                case 0x98:
                    return "DL810_02T";
                case 0x99:
                    return "DL810_03T";
                case 0x9A:
                    return "DL810_92T";
                case 0x9B:
                    return "DL810_93T";
                case 0x8A:
                    return "DL810_03AGD";
                case 0x50:
                    return "DL810_01TSC";
                case 0x51:
                    return "DL810_91T";
                default:
                    return "";
            }
        }
        #endregion

        private void btnOpenComPort_Click(object sender, EventArgs e)
        {
            int portNum = -1;
            int fCmdRet = 0x30;

            try
            {
                this.Cursor = Cursors.WaitCursor;
                btnCloseComPort.Enabled = false;
                if (tbReaderAddr.Text == "")
                {
                    MessageBox.Show("Input Reader Address");
                    return;
                }
                readerAddr = Convert.ToByte(tbReaderAddr.Text, 16);
                ClearReaderInformation();
                if (cbComPortList.SelectedItem.ToString() == "Auto")
                {
                    fCmdRet = StaticClassReaderA.AutoOpenComPort(ref portNum, ref readerAddr, ref portIndex);
                    AlreadyOpenPortList.Add(portNum);
                }
                else
                {
                    portNum = cbComPortList.SelectedIndex;
                    if (cbAlreadyOpenedPortList.Items.Count != 0)
                        foreach (int i in AlreadyOpenPortList)
                            if (portNum == i)
                            {
                                MessageBox.Show("Port Opened !");
                                return;
                            }
                    fCmdRet = StaticClassReaderA.OpenComPort(portNum, ref readerAddr, ref portIndex);
                }
                AddCmdLog(btnOpenComPort.Text, fCmdRet);
                if (fCmdRet == 0)
                {
                    cbAlreadyOpenedPortList.Items.Add("COM" + portNum.ToString());
                    cbAlreadyOpenedPortList.SelectedIndex = cbAlreadyOpenedPortList.SelectedIndex + 1;
                    StatusBar1.Panels[1].Text = "COM" + portNum.ToString();
                }
                else
                {
                    MessageBox.Show("Communication error","Communication");
                }
                
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
                btnCloseComPort.Enabled = true;   
            }
        }

        #region AddCmdLog    //更新状态条内容,重载,有errorCode和无errorCode
        private void AddCmdLog(string cmdStr, int cmdRet, byte errorCode)
        {
            try
            {
                if (!fIsAppClose)
                {
                    StatusBar1.Panels[0].Text = "";
                    StatusBar1.Panels[0].Text = DateTime.Now.ToLongTimeString() + " " +
                                                cmdStr + ": " +
                                                DL810_00GetReturnCodeDesc(cmdRet) + " " +
                                                DL810_00GetErrorCodeDesc(errorCode);
                }
            }
            finally
            {
                ;
            }
        }
        private void AddCmdLog(string cmdStr, int cmdRet)
        {
            try
            {
                if (!fIsAppClose)
                {
                    StatusBar1.Panels[0].Text = "";
                    StatusBar1.Panels[0].Text = DateTime.Now.ToLongTimeString() + " " +
                                                cmdStr + ": " +
                                                DL810_00GetReturnCodeDesc(cmdRet);
                }
            }
            finally
            {
                ;
            }
        }
        #endregion

        private void btnCloseComPort_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            string s;
            if (cbAlreadyOpenedPortList.Items.Count == 0 ||
                cbAlreadyOpenedPortList.SelectedItem == null)
            {
                MessageBox.Show("Select Port");
                return;
            }
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Port Closed");
                return;
            }
            fCmdRet = StaticClassReaderA.CloseSpecComPort(portIndex);

            AddCmdLog(btnCloseComPort.Text, fCmdRet);

            if (fCmdRet == 0)
            {              
                cbAlreadyOpenedPortList.Items.Remove("COM" + portIndex.ToString());
                if (cbAlreadyOpenedPortList.Items.Count != 0)
                {
                    cbAlreadyOpenedPortList.SelectedIndex = 0;
                    cbAlreadyOpenedPortList.Refresh();
                    s = cbAlreadyOpenedPortList.SelectedItem.ToString();
                    portIndex = Convert.ToInt16(s.Substring(3, (s.Length - 3)));
                    AlreadyOpenPortList.Remove(portIndex);
                }
                else
                {
                    InitializeBtnEnable();
                    foreach (Control ctl in this.Controls[1].Controls)      //先找到tabControl控件,即Controls[1]
                        if (ctl is TabPage)                                 //tabControl控件中的tabPage
                    foreach(Control ctl1 in ctl.Controls )
                        if (ctl1 is GroupBox)                               //tabPage中的GroupBox
                            foreach (System.Windows.Forms.Control ctl2 in ctl1.Controls)
                        {
                            if ((ctl2 is TextBox) && (ctl2.Name != "tbReaderAddr"))   //GroupBox中的TextBox
                                (ctl2 as TextBox).Text = "";
                        } 

                }
                lbUIDList.Items.Clear();
                cbUIDListforInfo.Items.Clear();
                cbUserUidList.Items.Clear();
            }
        }

        #region 获取当前使用的串口
        private bool GetCurrentUsePort()
        {
            string temp;
            if (cbAlreadyOpenedPortList.Items.Count == 0 ||
                cbAlreadyOpenedPortList.SelectedItem == null)
                return (false);
            temp = cbAlreadyOpenedPortList.SelectedItem.ToString();
            portIndex = Convert.ToInt32(temp.Substring(3, temp.Length - 3), 10);
            return (true);
        }
        #endregion

        private void cbAlreadyOpenedPortList_SelectedValueChanged(object sender, EventArgs e)
        {
            GetCurrentUsePort();
            readerAddr = 0xFF;
            btnGetReaderInfo_Click(null, null);            
        }

        private void btnSetRelay_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte relaySet = (byte)cbRelayControl.SelectedIndex;
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.SetRelay(ref readerAddr, ref relaySet, portIndex);

            AddCmdLog("Set Realy", fCmdRet);

        }

        private void btnSetOutputStatus_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte outputSet = (byte)(cbOutput1Status.SelectedIndex + cbOutput2Status.SelectedIndex * 2);
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.SetGeneralOutput(ref readerAddr, ref outputSet, portIndex);
            AddCmdLog("Set General Output", fCmdRet);
        }

        private void btnGetInoutStatus_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte inputStatus = 0xff;

            tbInputStatus.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.GetGeneralInput(ref readerAddr, ref inputStatus, portIndex);
            if (fCmdRet == 0)
            {
                if(inputStatus == 0)
                {
                    tbInputStatus.Text = "Low";
                }
                else
                {
                    tbInputStatus.Text = "Hight";
                }
            }

            AddCmdLog("Get General Input Status", fCmdRet);
        }

        private void btnWriteAddress_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte newReaderAddr = 0;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if (tbAddressToWrite.Text == "")
            {
                MessageBox.Show("Input Reader Address");
                return;
            }
            newReaderAddr = Convert.ToByte(tbAddressToWrite.Text.Substring(0,2),16);
            fCmdRet = StaticClassReaderA.WriteComAdr(ref readerAddr,ref newReaderAddr,portIndex);
            if (fCmdRet == 0)
            {
                readerAddr = newReaderAddr;
                btnGetReaderInfo_Click(null, null);
            }
            AddCmdLog("Write Reader Address", fCmdRet);
        }

        private void btnGetCurrentANT_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte ANTcurrentUsed = 0;

            tbANTCurrentUsed.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.GetANTStatus(ref readerAddr, ref ANTcurrentUsed, portIndex);
            if (fCmdRet == 0)
            {
                if (ANTcurrentUsed == 1)
                { tbANTCurrentUsed.Text = "ANT1"; }
                else if (ANTcurrentUsed == 2)
                { tbANTCurrentUsed.Text = "ANT2"; }
                else if (ANTcurrentUsed == 4)
                { tbANTCurrentUsed.Text = "ANT3"; }
                else if (ANTcurrentUsed == 8)
                { tbANTCurrentUsed.Text = "ANT4"; }
            }
            AddCmdLog("Get Active Antenna", fCmdRet);  

        }

        private void bntSetActiveANT_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte ANTSet = 0;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if (rbANT1.Checked)
            { ANTSet = 1; }
            else if (rbANT2.Checked)
            { ANTSet = 2; }
            else if (rbANT3.Checked)
            { ANTSet = 4; }
            else if (rbANT4.Checked)
            { ANTSet = 8; }
            fCmdRet = StaticClassReaderA.SetActiveANT(ref readerAddr, ref ANTSet, portIndex);
            AddCmdLog("Set Active Antenna", fCmdRet);
        }

        private void btnWriteInventoryScanTime_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte inventoryScanTime = 30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            inventoryScanTime = (byte)(cbInventoryScanTimeToWrite.SelectedIndex + 3);
            fCmdRet = StaticClassReaderA.WriteInventoryScanTime(ref readerAddr, ref inventoryScanTime, portIndex);
            if (fCmdRet == 0)
            {
                btnGetReaderInfo_Click(null, null);        
            }
            AddCmdLog("Write InventoryScanTime ", fCmdRet);
        }

        private void btnSetAccessTime_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte accessTimeToWrite = 0;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            accessTimeToWrite = (byte)(cbAccessTimeToSet.SelectedIndex);
            fCmdRet = StaticClassReaderA.SetAccessTime(ref readerAddr, ref accessTimeToWrite, portIndex);
            AddCmdLog("Set Access Time", fCmdRet);
        }

        private void btnGetAccessTime_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte AccessTime = 0;

            tbAccessTimeGetted.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.GetAccessTime(ref readerAddr, ref AccessTime, portIndex);
            if (fCmdRet == 0)
            { tbAccessTimeGetted.Text = AccessTime.ToString(); }
            AddCmdLog("Get Access Time", fCmdRet);
        }

        private void btnSetReceiveChannel_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte receiveChannelToSet = 0;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            receiveChannelToSet = (byte)((checkBSetRTXChannel.Checked ? 1 : 0) * 2 +
                                         (checkBSetRXChannel.Checked ? 1 : 0));
            fCmdRet = StaticClassReaderA.SetReceiveChannel(ref readerAddr, ref receiveChannelToSet, portIndex);
            AddCmdLog("Set Receive Channel", fCmdRet);
        }

        private void btnGetReceiveChannelStatus_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte receiveChannelGetted = 0;

            tbAccessTimeGetted.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open COMPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.GetReceiveChannelStatus(ref readerAddr, ref receiveChannelGetted, portIndex);
            if (fCmdRet == 0)
            {
                if (receiveChannelGetted == 1)
                { tbReceiveChannelStatus.Text = "RXOnly"; }
                else if (receiveChannelGetted == 2)
                { tbReceiveChannelStatus.Text = "TX/RX + RXOnly"; }
                else if (receiveChannelGetted == 3)
                { tbReceiveChannelStatus.Text = "TX/RX"; }
            }
            AddCmdLog("Current Receive Channel", fCmdRet);
        }

        private void btnOpenRF_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.OpenRf(ref readerAddr, portIndex);
            AddCmdLog(btnOpenRF.Text, fCmdRet);
        }

        private void btnCloseRF_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            fCmdRet = StaticClassReaderA.CloseRf(ref readerAddr, portIndex);
            AddCmdLog(btnCloseRF.Text, fCmdRet);
        }

        #region  16进制字符串到数组之间的相互转换
        private byte[] HexStringToByteArray(string s)
        {
            s = s.Replace(" ", "");
            byte[] buffer = new byte[s.Length / 2];
            for (int i = 0; i < s.Length; i += 2)
                buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
            return buffer;
        }
        private string ByteArrayToHexString(byte[] data)
        {
            StringBuilder sb = new StringBuilder(data.Length * 3);
            foreach (byte b in data)
                sb.Append(Convert.ToString(b, 16).PadLeft(2, '0').PadRight(3, ' '));
            return sb.ToString().ToUpper();
        }
        #endregion

        private void btnStayQuite_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte errorCode = 0;
            byte[] uid = new byte[8];

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            uid = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString()); 
            fCmdRet = StaticClassReaderA.StayQuiet(ref readerAddr,uid, ref errorCode, portIndex); 
            AddCmdLog(btnStayQuite.Text, fCmdRet, errorCode);
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte errorCode = 0;
            byte[] uid = new byte[8];

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;                    
            }
            uid = HexStringToByteArray( cbUIDListforInfo.SelectedItem.ToString());
            
            fCmdRet = StaticClassReaderA.Select(ref readerAddr,uid, ref errorCode, portIndex);
            AddCmdLog(btnSelect.Text, fCmdRet, errorCode);
        }

        #region   获取某些命令的state值
        private byte GetState()
        {
            return (byte)(rbAddressMode.Checked ? 0 : 1);
        }
        private byte GetState(string writeType)
        {
            if (writeType.IndexOf("A") >= 0)
            {
                return (byte)((rbAddressMode.Checked) ? 0 : 1);
            }
            else
            {
                return (byte)((rbAddressMode.Checked) ? 8 : 9);
            }
        }
        private byte GetState(byte blocSize, string writeType, bool isCheckWriteType)
        {
            if (!isCheckWriteType)
            {
                if (blocSize == 4)
                { return (byte)(rbAddressMode.Checked ? 0 : 1); }
                else
                { return (byte)(rbAddressMode.Checked ? 4 : 5); }
            }
            else
            {
                if (blocSize == 4)
                {
                    if (writeType.IndexOf("A") >= 0)            //A类标签,每个块4字节
                    {
                        return (byte)((rbAddressMode.Checked) ? 0 : 1);
                    }
                    else                                        //B类标签,每个块4字节
                    {
                        return (byte)((rbAddressMode.Checked) ? 8 : 9);
                    }
                }
                else
                {
                    if (writeType.IndexOf("A") >= 0)            //A类标签,每个块8字节
                    {
                        return (byte)((rbAddressMode.Checked) ? 4 : 5);
                    }
                    else                                        //B类标签,每个块8字节
                    {
                        return (byte)((rbAddressMode.Checked) ? 0x0C : 0x0D);
                    }
                }
            
            }
        }
        #endregion

        private void btnResetToReady_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte state;
            byte errorCode = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 }; 

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            else
                UID = null;
            state = GetState();
            fCmdRet = StaticClassReaderA.ResetToReady(ref readerAddr, ref state, UID, ref errorCode, portIndex);

            AddCmdLog(btnResetToReady.Text, fCmdRet, errorCode);
        }

        private void rbAddressMode_Click(object sender, EventArgs e)
        {
            cbUIDListforInfo.Enabled = rbAddressMode.Checked;
            btnSelect.Enabled = true;
            btnStayQuite.Enabled = true;
        }

        private void btnInventoryNoAFI_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte state = 0;
            byte AFI = 0;
            byte[] DSFIDAndUID = new byte[9];
            byte cardNumber = 0;
            string strDSFIDAndUID = "";

            cbUIDListforInfo.Items.Clear();
            cbUserUidList.Items.Clear();
            lbUIDList.Items.Clear();
            labelCardNum.Text = "0";
            tbSystemInfoData.Text = "";
            tbSystemInfo.Text = "";
            cbWriteType.Items.Clear();
            cbEndBlockNum.Items.Clear();
            cbBeginBlok.Items.Clear();
            cbBlockNumToOperation.Items.Clear();

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if (sender == btnInventoryWithAFI)
            {
                if (tbAFI.Text == "")
                {
                    MessageBox.Show("Input AFI");
                    return;
                }
                AFI = Convert.ToByte(tbAFI.Text, 16);
                state = 1;
            }
            if (sender == btnUserInventoryWithAFI)
            {
                if (tbUserAFI.Text == "")
                {
                    MessageBox.Show("Input AFI");
                    return;
                }
                AFI = Convert.ToByte(tbUserAFI.Text, 16);
                state = 1;
            }

            fCmdRet = StaticClassReaderA.Inventory(ref readerAddr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
            if (fCmdRet == 0)
            {
                strDSFIDAndUID = ByteArrayToHexString(DSFIDAndUID).Replace(" ","");
                cbUIDListforInfo.Items.Add(strDSFIDAndUID.Substring(2, 16));          
                cbUIDListforInfo.SelectedIndex = 0;
                cbUserUidList.Items.Add(strDSFIDAndUID.Substring(2, 16));
                cbUserUidList.SelectedIndex = 0;
                lbUIDList.Items.Add(strDSFIDAndUID);
                labelCardNum.Text = cardNumber.ToString();
            }
            AddCmdLog(((Button)sender).Text, fCmdRet);
        }

        private void btnGetSystemInfo_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte errorCode = 0;
            byte state = 0;
            byte informationFlag = 0;
            byte DSFID = 0;
            byte AFI = 0;
            byte ICReference = 0;
            byte[] UIDI = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte[] UIDO = new byte[8];
            byte[] menorySize = new byte[2];
            byte blockSize= 0,blockNum = 0;
            string tagWriteType = "";
            string FirmName = "";
            int i;

            btnReadSingleBlock.Enabled = false;
            btnReadMultiBlock.Enabled = false;
            btnWriteSingleBlock.Enabled = false;
            btnLcokBlock.Enabled = false;
            tbSystemInfoData.Text = "";
            tbSystemInfo.Text = "";
            cbWriteType.Items.Clear();
            cbEndBlockNum.Items.Clear();
            cbBeginBlok.Items.Clear();
            cbBlockNumToOperation.Items.Clear();
            cbMaxBlockNum.Items.Clear();
            cbBlockSize.Items.Clear();

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            state = GetState();
           
            if (rbAddressMode.Checked)
                UIDI = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            fCmdRet = StaticClassReaderA.GetSystemInformation(ref readerAddr, ref state, UIDI, ref informationFlag, UIDO, 
                                                          ref DSFID, ref AFI, menorySize,
                                                          ref ICReference, ref errorCode, portIndex);
            if (fCmdRet == 0)
            {
                tbSystemInfoData.Text = ByteArrayToHexString(UIDO).Replace(" ","");
                tbSystemInfo.Text = "UID0: " + ByteArrayToHexString(UIDO).Replace(" ", "");
                if ((informationFlag & 0x01) == 0x01)
                {
                    tbSystemInfoData.Text = tbSystemInfoData.Text + " " + Convert.ToString(DSFID, 16).PadLeft(2, '0').ToUpper();
                    tbSystemInfo.Text = tbSystemInfo.Text + " " + "DSFID: " + Convert.ToString(DSFID, 16).PadLeft(2, '0').ToUpper();
                }
                if ((informationFlag & 0x02) == 0x02)
                {
                    tbSystemInfoData.Text = tbSystemInfoData.Text + " " + Convert.ToString(AFI, 16).PadLeft(2, '0').ToUpper();
                    tbSystemInfo.Text = tbSystemInfo.Text + " " + "AFI: " + Convert.ToString(AFI, 16).PadLeft(2, '0').ToUpper();          
                }
                if ((informationFlag & 0x04) == 0x04)
                {
                    tbSystemInfoData.Text = tbSystemInfoData.Text + " " + ByteArrayToHexString(menorySize).Replace(" ", "");
                    tbSystemInfo.Text = tbSystemInfo.Text + " " + "MemorySize: " + ByteArrayToHexString(menorySize).Replace(" ", "");
                }
                if ((informationFlag & 0x08) == 0x08)
                {
                    tbSystemInfoData.Text = tbSystemInfoData.Text + " " + Convert.ToString(ICReference, 16).PadLeft(2, '0').ToUpper();
                    tbSystemInfo.Text = tbSystemInfo.Text + " " + "ICReference: " + Convert.ToString(ICReference, 16).PadLeft(2, '0').ToUpper();
                }

                GetTagInfo(UIDO[6], UIDO[7],ref FirmName, ref blockSize, ref blockNum, ref tagWriteType);

                cbWriteType.Items.Add("A ");
                cbWriteType.Items.Add("B ");                
                if (tagWriteType.IndexOf("B") != -1)
                { cbWriteType.SelectedIndex = 1; }
                else
                { cbWriteType.SelectedIndex = 0; }

                cbBlockSize.Items.Add("4");
                cbBlockSize.Items.Add("8");                
                if (blockSize == 8)
                { cbBlockSize.SelectedIndex = 1; }
                else
                { cbBlockSize.SelectedIndex = 0; }                
                
                for (i = 0; i < 256; i++)
                {
                    cbMaxBlockNum.Items.Add(i.ToString());
                }
                cbMaxBlockNum.SelectedIndex = blockNum - 1;

                StatusBar1.Panels[2].Text = FirmName + "," + "Type "+tagWriteType + "," + blockSize.ToString() +
                                            "Bytes/Block," + blockNum.ToString() + "Blocks";
            }
            AddCmdLog(btnGetSystemInfo.Text, fCmdRet, errorCode);
        }

        private void GetTagInfo(byte FirmCode, byte OtherCode,ref string FirmName,  ref byte BlockSize, ref byte BlockNum, ref string TagType)
        {
            switch (FirmCode)
            {
                case 0x02:
                    BlockSize = 4;
                    BlockNum = 16;
                    TagType = "B";
                    FirmName = "STMicroelectronics"; 
                    break;
                case 0x04:
                    BlockSize = 4;
                    BlockNum = 28;
                    TagType = "B";
                    FirmName = "Philips Semiconductors";
                    break;
                case 0x05:
                    BlockSize = 4;
                    BlockNum = 58;
                    if (OtherCode == 0xE0)
                        BlockNum = 250;
                    else if (OtherCode == 0x60)
                        BlockNum = 58; 
                    TagType = "B";
                    FirmName = "Infineon";
                    break;
                case 0x07:
                    BlockSize = 4;
                    BlockNum = 64;
                    TagType = "A";
                    FirmName = "Texas Instruments";
                    break;
                case 0x08:
                    BlockSize = 8;
                    BlockNum = 250;
                    TagType = "A/B";
                    FirmName = "Fujitsu";
                    break;
                case 0x16:                                  
                    BlockSize= 4;                      
                    BlockNum = 14;
                    TagType = "A"; 
                    FirmName = "EM Microelectronic" ;
                    break;
                default:
                    FirmName = "";
                    break;
             }
        }

        private void btnNewInventoryScanNoAFI_Click(object sender, EventArgs e)
        {
            int i,fCmdRet = 0x30;
            byte state = 6;             //默认不带AFI的InventoryScan
            byte AFI = 0;
            byte[] DSFIDAndUID = new byte[2300];
            byte cardNumber = 0;
            ListViewItem aListItem = new ListViewItem();
            string s ="",FirmName = "",strDSFIDAndUID = "";
            byte BlockSize  = 0;
            byte BlockNum = 0;
            string TagType ="";

            cbUIDListforInfo.Items.Clear(); 
            lbUIDList.Items.Clear(); 
            labelCardNum.Text = "0";
            tbSystemInfoData.Text = "";
            tbSystemInfo.Text = "";            
            cbWriteType.Items.Clear();
            cbEndBlockNum.Items.Clear();
            cbBeginBlok.Items.Clear();
            cbBlockNumToOperation.Items.Clear();
            cbMaxBlockNum.Items.Clear();
            cbBlockSize.Items.Clear();

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }

            if (sender == btnContinueInventoryScanNoAFI)
            {
                state = 2;
            }
            else if (sender == btnNewInventoryScanWithAFI)
            {
                if (tabControl1.SelectedIndex == 4)
                {
                    if (tbUserAFI.Text == "")
                    {
                        MessageBox.Show("Input AFI");
                        return;
                    }
                    AFI = Convert.ToByte(tbUserAFI.Text, 16);
                }
                else
                {
                    if (tbAFI.Text == "")
                    {
                        MessageBox.Show("Input AFI");
                        return;
                    }
                    AFI = Convert.ToByte(tbAFI.Text, 16);
                }
                state = 7;
            }
            else if (sender == btnContinueInventoryScanWithAFI)
            {
                if (tabControl1.SelectedIndex == 4)
                {
                    if (tbUserAFI.Text == "")
                    {
                        MessageBox.Show("Input AFI");
                        return;
                    }
                    AFI = Convert.ToByte(tbUserAFI.Text, 16);
                }
                else
                {
                    if (tbAFI.Text == "")
                    {
                        MessageBox.Show("Input AFI");
                        return;
                    }
                    AFI = Convert.ToByte(tbAFI.Text, 16);
                }

                state = 3;
            }
            fCmdRet = StaticClassReaderA.Inventory(ref readerAddr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);

            if ((fCmdRet == 0x0A) || (fCmdRet == 0x0B) || (fCmdRet == 0x0E))                                                    
            {
                Array.Resize(ref DSFIDAndUID, cardNumber * 9);
                strDSFIDAndUID = ByteArrayToHexString(DSFIDAndUID).Replace(" ", "");
                if (fIsTestMode)
                {
                    DeleteRepeatUID(strDSFIDAndUID,ref DSFIDAndUIDList);
                    totalCardNumber = (byte)(DSFIDAndUIDList.Length / 18);
                    if (fCmdRet == 0x0E)
                    {
                        while (lvTestMode.Items.Count < totalCardNumber)     //以下是为了不闪烁
                        {
                            aListItem = lvTestMode.Items.Add((lvTestMode.Items.Count + 1).ToString());
                            aListItem.SubItems.Add("");
                            aListItem.SubItems.Add("");
                            aListItem.SubItems.Add("");
                        }
                        while (lvTestMode.Items.Count > totalCardNumber)
                        { lvTestMode.Items.Remove(lvTestMode.Items[lvTestMode.Items.Count - 1]); }
                        for (i = 0; i < totalCardNumber; i++)
                        {

                            aListItem = lvTestMode.Items[i];
                            GetTagInfo(Convert.ToByte(DSFIDAndUIDList.Substring(18 * i + 14, 2), 16),
                                       Convert.ToByte(DSFIDAndUIDList.Substring(18 * i + 16, 2), 16),
                                       ref FirmName, ref BlockSize, ref BlockNum, ref 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);
                        }
                    }
                    if (fCmdRet == 0x0B)
                    {
                        btnNewInventoryScanNoAFI_Click(btnContinueInventoryScanNoAFI, null);  
                    }
                }
                else
                {
                    if ((fCmdRet == 0x0E) || (fCmdRet == 0x0B))
                    {
                        for (i = 0; i < cardNumber; i++)
                        {
                            s = strDSFIDAndUID.Substring(18 * i , 18);
                            cbUIDListforInfo.Items.Add(s.Substring(2,16));
                            cbUserUidList.Items.Add(s.Substring(2,16));
                            lbUIDList.Items.Add(s);
                            labelCardNum.Text = cardNumber.ToString();
                        }
                        if (cardNumber > 0)
                        {
                            cbUIDListforInfo.SelectedIndex = 0;
                            cbUserUidList.SelectedIndex = 0;
                        }
                    }                 
                }
            }
            if ((fIsTestMode) && (totalCardNumber != 0))
                AddCmdLog(((Button)sender).Text, 0);
            else
                AddCmdLog(((Button)sender).Text, fCmdRet);
        }

        private void ChangeSubItem(ListViewItem ListItem, int subItemIndex, string ItemText)
        {
            if (ListItem.SubItems[subItemIndex].Text != ItemText)
            {
                ListItem.SubItems[subItemIndex].Text = ItemText;    
            }
        }

        private void DeleteRepeatUID(string tempUIDString, ref string unipueUIDString)
        { 
            int i ; 
            string  s;
            for (i = 0; i < tempUIDString.Length/18; i++)
            {
                s = tempUIDString.Substring(18*i,18);
                if (unipueUIDString.IndexOf(s) < 0)
                    unipueUIDString = unipueUIDString + s;
            } 
        }
    
        private void btnWriteAFI_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte errorCode = 0;
            byte AFI = 0;
            int fCmdRet = 0x30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            if (tbAFI.Text == "")
            {
                MessageBox.Show("Input AFI");
                return;
            }
            AFI = Convert.ToByte(tbAFI.Text, 16);
            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            state = GetState(cbWriteType.SelectedItem.ToString());
            fCmdRet = StaticClassReaderA.WriteAFI(ref readerAddr, ref state, UID, AFI, ref errorCode, portIndex);

            AddCmdLog(btnWriteAFI.Text, fCmdRet, errorCode);
        }

        private void cbMaxBlockNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i;
            cbBlockNumToOperation.Items.Clear();
            cbBeginBlok.Items.Clear();
            cbEndBlockNum.Items.Clear();
            for (i = 0; i < cbMaxBlockNum.SelectedIndex + 1; i++)
            {
                cbBlockNumToOperation.Items.Add(i.ToString());
                cbBeginBlok.Items.Add(i.ToString());
                cbEndBlockNum.Items.Add(i.ToString());
            }
            cbBlockNumToOperation.SelectedIndex = 0;
            cbBeginBlok.SelectedIndex = 0;
            cbEndBlockNum.SelectedIndex = 0;
        }

        private void btnWriteDSFID_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte errorCode = 0;
            byte DSFID = 0;
            int fCmdRet = 0x30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            if (tbDSFID.Text == "")
            {
                MessageBox.Show("Input DSFID");
                return;
            }
            DSFID = Convert.ToByte(tbDSFID.Text, 16);

            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            state = GetState(cbWriteType.SelectedItem.ToString());
            fCmdRet = StaticClassReaderA.WriteDSFID(ref readerAddr, ref state, UID, DSFID, ref errorCode, portIndex);

            AddCmdLog(btnWriteDSFID.Text, fCmdRet, errorCode);
        }

        private void btnLockAFI_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte errorCode = 0;
            int fCmdRet = 0x30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            if (MessageBox.Show(this, "Lock AFI ?", "Lock", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                return;

            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            state = GetState(cbWriteType.SelectedItem.ToString());
            fCmdRet = StaticClassReaderA.LockAFI(ref readerAddr, ref state, UID, ref errorCode, portIndex);

            AddCmdLog(btnLockAFI.Text, fCmdRet, errorCode);            
        }

        private void btnLockDSFID_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte errorCode = 0;
            int fCmdRet = 0x30;


            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }
            if (MessageBox.Show(this, "Lock DSFID ?", "Lock", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                return;
            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            state = GetState(cbWriteType.SelectedItem.ToString());
            fCmdRet = StaticClassReaderA.LockDSFID(ref readerAddr, ref state, UID, ref errorCode, portIndex);

            AddCmdLog(btnLockDSFID.Text, fCmdRet, errorCode);
        }

        private void btnReadSingleBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;            
            byte errorCode = 0;
            int fCmdRet = 0x30;
            byte blockNum = 0;
            byte blockSecStatus = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            tbDataReaded.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }
            
            blockNum = (byte)cbBlockNumToOperation.SelectedIndex;
            state = GetState((byte)(cbBlockSize.SelectedIndex * 4 + 4), cbBlockSize.SelectedItem.ToString(), false);
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))
            {
                MessageBox.Show("Select UID");
                return;
            }


            byte[] data = new byte[cbBlockSize.SelectedIndex * 4 + 4];

            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());                

            fCmdRet = StaticClassReaderA.ReadSingleBlock(ref readerAddr, ref state, UID, blockNum, ref blockSecStatus, data, ref errorCode, portIndex);
            if (fCmdRet == 0)
                tbDataReaded.Text = blockSecStatus.ToString("x2") + " " + ByteArrayToHexString(data).Replace(" ", "");
            AddCmdLog(btnReadSingleBlock.Text, fCmdRet, errorCode);
        }

        private void cbBlockSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            tbDataToWrite.MaxLength = (cbBlockSize.SelectedIndex  * 4 + 4) * 2;
        }

        private void btnWriteSingleBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;            
            byte errorCode = 0;
            int fCmdRet = 0x30;
            byte blockNum = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }


            if (tbDataToWrite.Text.Length != (cbBlockSize.SelectedIndex  * 4 + 4) * 2)
            {
                MessageBox.Show("Input Correct Data"); 
                return;
            }
            if ((rbAddressMode.Checked) &&
               ((cbUIDListforInfo.Items.Count == 0) ||
                (cbUIDListforInfo.SelectedItem == null)))
            {
                MessageBox.Show("Select UID");
                return;
            }
            byte[] data = new byte[cbBlockSize.SelectedIndex * 4 + 4];
            data = HexStringToByteArray(tbDataToWrite.Text);
            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            blockNum = (byte)cbBlockNumToOperation.SelectedIndex;
            state = GetState((byte)(cbBlockSize.SelectedIndex * 4 + 4), cbWriteType.SelectedItem.ToString(), true);

            fCmdRet = StaticClassReaderA.WriteSingleBlock(ref readerAddr, ref state, UID, blockNum, data, ref errorCode, portIndex);

            AddCmdLog(btnWriteSingleBlock.Text, fCmdRet, errorCode);
        }

        private void btnLcokBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte errorCode = 0;
            byte blockNum = 0;
            int fCmdRet = 0x30;


            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }

            if (MessageBox.Show(this, "Lock Appointed Block ?", "Lock", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                return;

            UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());
            state = GetState(cbWriteType.SelectedItem.ToString());
            blockNum = (byte)cbBlockNumToOperation.SelectedIndex;
            fCmdRet = StaticClassReaderA.LockBlock(ref readerAddr, ref state, UID, blockNum, ref errorCode, portIndex);

            AddCmdLog(btnLcokBlock.Text, fCmdRet, errorCode);  
        }

        private void btnReadMultiBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte errorCode = 0;
            int fCmdRet = 0x30;
            byte startBlockNum = 0;
            byte blockCount = 0;
            byte blockSize = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            int i;


            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))

            {
                MessageBox.Show("Select UID");
                return;
            }


            startBlockNum = (byte)cbBeginBlok.SelectedIndex;
            if (cbEndBlockNum.SelectedIndex < startBlockNum)
            {
                MessageBox.Show("Block Number Error");
                return;
            }
            blockCount = (byte)(cbEndBlockNum.SelectedIndex - startBlockNum + 1);
            blockSize = (byte)(cbBlockSize.SelectedIndex * 4 + 4);
            if (cbBlockSize.SelectedIndex == 0)            //BlockSize为4时,一次最大能读取28个块
            {
               if (blockCount > 28)            
               {
                   MessageBox.Show("Block Count Can't Over 28");
                   return;
               }
            }
            else                                            //BlockSize为8时,一次最大能读取15个块
            {
                if (blockCount > 15)   
                {
                    MessageBox.Show("Block Count Can't Over 15");
                    return;
                }
            }

            byte[] data = new byte[ blockSize * blockCount];
            byte[] blockSecStatus = new byte[blockCount];
            state = GetState(blockSize, cbWriteType.SelectedItem.ToString(), false);
            if (rbAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());

            fCmdRet = StaticClassReaderA.ReadMultipleBlock(ref readerAddr, ref state, UID, startBlockNum, blockCount, 
                                                       blockSecStatus, data, ref errorCode, portIndex);
            if (fCmdRet == 0)
            {
                frmMultipleBlockDataList frmdata = new frmMultipleBlockDataList();
                frmdata.Text = cbUIDListforInfo.SelectedItem.ToString() 
                               + "  Block" + startBlockNum.ToString() 
                               + " - Block" + cbEndBlockNum.SelectedIndex.ToString();
                string temp = ByteArrayToHexString(data).Replace(" ","");
                for (i = startBlockNum; i < cbEndBlockNum.SelectedIndex + 1; i++)
                {
                    frmdata.ListView1.Items.Add(i.ToString());
                    frmdata.ListView1.Items[i - startBlockNum].SubItems.Add(Convert.ToString(blockSecStatus[i - startBlockNum], 16).PadLeft(2, '0') 
                                                                            + " " 
                                                                            + temp.Substring((i - startBlockNum) * blockSize * 2, blockSize * 2));
                }
                frmdata.Show();
            }                
            AddCmdLog(btnReadMultiBlock.Text, fCmdRet, errorCode);
        }

        private void tbReaderAddr_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = "0123456789ABCDEF\b".IndexOf(char.ToUpper(e.KeyChar)) < 0;  //  "\b"退格键             
        }

        private void tbCmdTramsparentRead_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = "0123456789ABCDEF\b ".IndexOf(char.ToUpper(e.KeyChar)) < 0;  //  "\b"退格键
        }

        private void btnStartTestMode_Click(object sender, EventArgs e)
        {
            btnStartTestMode.Enabled = false;
            btnStopTestMode.Enabled = true;
            fIsTestMode = true;
            timerTestMode.Enabled = true;
        }

        private void btnStopTestMode_Click(object sender, EventArgs e)
        {
            timerTestMode.Enabled = false;
            fIsTestMode = false;
            btnStartTestMode.Enabled = true;
            btnStopTestMode.Enabled = false;            
        }

        private void timer1_Tick(object sender, EventArgs e)
        {            
            timerTestMode.Enabled = false;
            DSFIDAndUIDList = "";
            totalCardNumber = 0;            
            btnNewInventoryScanNoAFI_Click(btnNewInventoryScanNoAFI, null);
            if (( fIsTestMode == true) && (!fIsAppClose))
            timerTestMode.Enabled = true;
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)      
        {
            fIsTestMode = false;
            fIsScanMode = false;
            if (GetCurrentUsePort())
            {
                if (tabControl1.SelectedTab == tpGeneralOperation)
                {
                    btnReadSingleBlock.Enabled = false;
                    btnReadMultiBlock.Enabled = false;
                    btnWriteSingleBlock.Enabled = false;
                    btnLcokBlock.Enabled = false;
                }
                if (tabControl1.SelectedTab == tpTestMode)             //切换到"测试模式"页        
                {
                    lvTestMode.Items.Clear();
                    btnStartTestMode.Enabled = true;
                    btnStopTestMode.Enabled = false;
                }
                if (tabControl1.SelectedTab == tpScanMode)
                {
                    btnDisplayOff.Enabled = false;
                    btnDisplayOn.Enabled = false;
                    btnStartScanMode.Enabled = true;
                    btnStopScanMode.Enabled = false;
                    GetScanModeSetting();                    
                }
                if (tabControl1.SelectedTab == tpCoustomDataLen)
                {
                    btnUserReadMultiBlock.Enabled = false;
                    btnUserReadSingleBlock.Enabled = false;
                    btnUserWriteSingleBlock.Enabled = false;
                    btnGetUserBlockSize_Click(null, null);
                }
            }
        }

        private void btnStartScanMode_Click(object sender, EventArgs e)
        {
            byte[] scanModeData = new byte[11];
            int fCmdRet = 0x30;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            scanModeData[0] = (byte)((sender == btnStartScanMode) ?  1 : 0);           //1:打开扫描模式;0关闭扫描模式.
            if (scanModeData[0] == 0)
            {
                fIsScanMode = false;
            }
            else
            {
                fIsScanMode = true;                           
            }

            scanModeData[1] = (byte)((rbScanModeWithComAddr.Checked) ? 1 : 0);         //1:发送comAddr;0:不发送

            scanModeData[1] = (byte)((rbScanModeWithUID.Checked) ? (scanModeData[1] |= 0x02) : (scanModeData[1] &= 0xFD));//1:包含UID

            scanModeData[1] = (byte)((rbScanModeIncludeSpecifyBlock.Checked) ? (scanModeData[1] |= 0x04) : (scanModeData[1] &= 0xFB));

            scanModeData[1] = (byte)((rbScanModeWithSecWord.Checked) ? (scanModeData[1] |= 0x08) : (scanModeData[1] &= 0xF7));

            scanModeData[1] = (byte)((rbScanModeHex.Checked) ? (scanModeData[1] |= 0x10) : (scanModeData[1] &= 0xEF));

            scanModeData[1] = (byte)((rbScanModeSwitchRF.Checked) ? (scanModeData[1] |= 0x20) : (scanModeData[1] &= 0xDF));

            scanModeData[1] = (byte)((rbScanModeBuzzerOn.Checked) ? (scanModeData[1] |= 0x40) : (scanModeData[1] &= 0xBF));

            scanModeData[1] = (byte)((rbScanModeLedFlicker.Checked) ? (scanModeData[1] |= 0x80) : (scanModeData[1] &= 0x7F));

            scanModeData[2] = (byte)cbScanModeStartBlock.SelectedIndex;
            scanModeData[3] = (byte)cbScanModeBlockCount.SelectedIndex;

            scanModeData[4] = (byte)cbScanModeStartByte.SelectedIndex;
            scanModeData[5] = (byte)cbScanModeByteCount.SelectedIndex;

            if (!checkBScanModeCoustomSpaceMark.Checked)
            {
                scanModeData[6] = (byte)(1 << cbScanModeSpaceMark.SelectedIndex);
            }
            else
            {
                scanModeData[6] = 0x80;
                scanModeData[7] = Convert.ToByte(tbScanModeCoustomSpaceMark.Text);
            }

            if (!checkBScanModeCoustomEndMark.Checked)
            {
                scanModeData[8] = (byte)(1 << cbScanModeEndMark.SelectedIndex);
            }
            else
            {
                scanModeData[8] = 0x80;
                scanModeData[9] = Convert.ToByte(tbScanModeCoustomEndMark.Text);
            }
            scanModeData[10] = 0x00;

            fCmdRet = StaticClassReaderA.SetScanMode(ref readerAddr, scanModeData, portIndex);
            AddCmdLog(((Button)sender).Text, fCmdRet);

            if (fCmdRet == 0)
            {
                if (sender == btnStartScanMode)
                {
                    timerScanMode.Enabled = true;
                    btnStopScanMode.Enabled = true;
                    btnStartScanMode.Enabled = false;
                    btnDisplayOn.Enabled = false;
                    btnDisplayOff.Enabled = true;
                }
                else
                {               
                    timerScanMode.Enabled = false;
                    btnStopScanMode.Enabled = false;
                    btnStartScanMode.Enabled = true;
                    btnDisplayOn.Enabled = false;
                    btnDisplayOff.Enabled = false;
                }
            }            
        }

        private void DisplayScanModeData()
        {
            byte[] ScanModeData = new byte[40960];
            int ScanModeDataLength = 0;
            int fCmdRet = 0x30;
            string s;

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

            if (fCmdRet == 0)
            {
                if (rbScanModeHex.Checked)
                {
                    Array.Resize(ref ScanModeData, ScanModeDataLength);
                    s = ByteArrayToHexString(ScanModeData);
                }
                else
                {
                    s = new string(System.Text.Encoding.ASCII.GetChars(ScanModeData));
                }
                tbScanModeData.AppendText(s + "\r\n");
                tbScanModeData.AppendText(Environment.NewLine);
            }

            if (fCmdRet == 1)
            {
                tbScanModeData.AppendText(DateTime.Now.ToLongTimeString() + "  " + "No New Data .\r\n");
            }   
        }

        private void GetScanModeSetting()
        {
            byte[] scanModeSetting = new byte[11];
            int fCmdRet = 0x30;
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }

            fIsScanMode = false;
            timerScanMode.Enabled = false;

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

            if (fCmdRet == 0)
            {
                rbScanModeWithComAddr.Checked = ((byte)(scanModeSetting[1] & 0x01) == 0x01) ? true : false; //1:发送comAddr;0:不发送
                rbScanModeWithUID.Checked =  ((byte)(scanModeSetting[1] & 0x02) == 0x02) ? true : false;
                rbScanModeIncludeSpecifyBlock.Checked = ((byte)(scanModeSetting[1] & 0x03) == 0x03) ? true : false;
                rbScanModeWithSecWord.Checked = ((byte)(scanModeSetting[1] & 0x04) == 0x04) ? true : false;
                rbScanModeHex.Checked = ((byte)(scanModeSetting[1] & 0x10) == 0x10) ? true : false;
                rbScanModeSwitchRF.Checked = ((byte)(scanModeSetting[1] & 0x20) == 0x20) ? true : false;
                rbScanModeBuzzerOn.Checked = ((byte)(scanModeSetting[1] & 0x40) == 0x40) ? true : false;
                rbScanModeLedFlicker.Checked = ((byte)(scanModeSetting[1] & 0x80) == 0x80) ? true : false;

                cbScanModeStartBlock.SelectedIndex = scanModeSetting[2];
                cbScanModeBlockCount.SelectedIndex = scanModeSetting[3];

                cbScanModeStartByte.SelectedIndex = scanModeSetting[4];
                cbScanModeByteCount.SelectedIndex = scanModeSetting[5];

                if ((byte)(scanModeSetting[6] & 0x80) == 0x80)
                {
                    checkBScanModeCoustomSpaceMark.Checked = true;
                    tbScanModeCoustomSpaceMark.Text = Convert.ToString(scanModeSetting[7]);
                }
                else
                {
                    if (scanModeSetting[6]< 0x10)
                        cbScanModeSpaceMark.SelectedIndex = scanModeSetting[6] - 1;
                    else
                        cbScanModeSpaceMark.SelectedIndex = (scanModeSetting[6] >> 4) + 3;
                }

                if ((byte)(scanModeSetting[8] & 0x80) == 0x80)
                {
                    checkBScanModeCoustomEndMark.Checked = true;
                    tbScanModeCoustomEndMark.Text = Convert.ToString(scanModeSetting[9]);
                }
                else
                {
                    if (scanModeSetting[8] < 0x10)
                        cbScanModeEndMark.SelectedIndex = scanModeSetting[8] - 1;
                    else
                        cbScanModeEndMark.SelectedIndex = (scanModeSetting[8] >> 4) + 3;
                }
                if (scanModeSetting[0] == 0x01)
                {
                    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;   
                }
            }
                      
        }

        private void timerScanMode_Tick(object sender, EventArgs e)
        {
            timerScanMode.Enabled = false;
            DisplayScanModeData();
            if ((fIsScanMode) && (!fIsAppClose))
                timerScanMode.Enabled = true;
        }

        private void btnCleanScanModeData_Click(object sender, EventArgs e)
        {
            tbScanModeData.Text = "";
        }

        private void btnDisplayOn_Click(object sender, EventArgs e)
        {
            timerScanMode.Enabled = true;
            btnDisplayOn.Enabled = false;
            btnDisplayOff.Enabled = true;
        }

        private void btnDisplayOff_Click(object sender, EventArgs e)
        {
            timerScanMode.Enabled = false;
            btnDisplayOn.Enabled = true;
            btnDisplayOff.Enabled = false;
        }
        
        private void btnTransparentRead_Click(object sender, EventArgs e)
        {
            byte[] cmdData;
            byte[] respData = new byte[256];
            int fCmdRet = 0x30;
            string temp;
            byte errorCode = 0;
            byte respLength = 0;            
            byte feedBackDataLength = 0;   

            tbResponeTramsparentRead.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if (tbCmdTramsparentRead.Text == "")
            {
                MessageBox.Show("Input Command Data");
                return;
            }
            temp = tbCmdTramsparentRead.Text.Replace(" ", "");
            cmdData = new byte[temp.Length / 2];

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

            fCmdRet = StaticClassReaderA.TransparentRead(ref readerAddr, respLength, (byte)cmdData.Length, cmdData, ref feedBackDataLength,
                                                     respData, ref errorCode, portIndex);
            Array.Resize(ref respData, feedBackDataLength);

            if (fCmdRet == 0)
            {
                tbResponeTramsparentRead.Text = (ByteArrayToHexString(respData));
            }
            AddCmdLog(btnTransparentRead.Text, fCmdRet, errorCode);
            
        }

        private void btnTransparentWrite_Click(object sender, EventArgs e)
        {
            byte[] cmdData;
            byte[] respData = new byte[256];
            byte[] option = new byte[4];
            int fCmdRet = 0x30;
            string temp;
            byte errorCode = 0;
            byte respLength = 0, feedBackDataLength = 0;

            tbResponeTramsparentWrite.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if (tbCmdTramsparentWrite.Text == "")
            {
                MessageBox.Show("Input Command Data");
                return;
            }
            temp = tbCmdTramsparentWrite.Text.Replace(" ", "");

            if (temp.Length < 10)
            {
                MessageBox.Show("Command Too Short");
                return;
            }

            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(ref readerAddr, option, respLength, (byte)cmdData.Length, cmdData,
                                                      ref feedBackDataLength, respData, ref errorCode, portIndex);

            Array.Resize(ref respData, feedBackDataLength);
            if (fCmdRet == 0)
            {
                tbResponeTramsparentWrite.Text = (ByteArrayToHexString(respData));
            }

            AddCmdLog(btnTransparentWrite.Text, fCmdRet, errorCode);
        }

        private void btnTransparentSpecifyResponeTime_Click(object sender, EventArgs e)
        {
            byte[] cmdData;
            byte[] respData = new byte[256];
            byte[] repTime = new byte[2];
            int fCmdRet = 0x30;
            string temp;
            byte errorCode = 0;
            byte respLength = 0, feedBackDataLength = 0;

            tbResponeTransparentSpecifyResponeTime.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
                return;
            }
            if (btnCmdTransparentSpecifyResponeTime.Text == "")
            {
                MessageBox.Show("Input Command Data");
                return;
            }
            temp = btnCmdTransparentSpecifyResponeTime.Text.Replace(" ", "");

            if (temp.Length < 6)
            {
                MessageBox.Show("Command Too Short");
                return;
            }

            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(ref readerAddr, repTime, respLength, (byte)cmdData.Length, cmdData,
                                                              ref feedBackDataLength, respData, ref errorCode, portIndex);

            Array.Resize(ref respData, feedBackDataLength);
            if (fCmdRet == 0)
            {
                tbResponeTransparentSpecifyResponeTime.Text = (ByteArrayToHexString(respData));
            }
            AddCmdLog("TransparentCustomizedCmd", fCmdRet, errorCode);
 
        }

        private void btnSetUserBlockSize_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte userBlockSize = 0;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }

            userBlockSize = (byte)(cbUserBlockSizeSet.SelectedIndex + 1);
            fCmdRet = StaticClassReaderA.SetUserDefinedBlockLength(ref readerAddr,
                                                               ref userBlockSize, 
                                                               portIndex);
            AddCmdLog("User defined block length", fCmdRet);
        }

        private void btnGetUserBlockSize_Click(object sender, EventArgs e)
        {
            int fCmdRet = 0x30;
            byte userBlockSize = 0;

            tbUserBlockSizeGet.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }

            fCmdRet = StaticClassReaderA.GetUserDefinedBlocklength(ref readerAddr,
                                                               ref userBlockSize,
                                                               portIndex);
            if (fCmdRet == 0)
            {
                tbUserBlockSizeGet.Text = " " + Convert.ToString(userBlockSize, 10).PadLeft(2,'0');
                UserDefineBlockSize = userBlockSize;
                tbUserDataToWrite.MaxLength = UserDefineBlockSize * 2;
            }
            AddCmdLog("Get user defined block length", fCmdRet);

        }

        private void btnUserNewInventoryScanNoAFI_Click(object sender, EventArgs e)
        {
            sender = btnNewInventoryScanNoAFI;

            if (sender == btnUserContinueInventoryScanNoAFI)
                sender = btnContinueInventoryScanNoAFI;

            else if (sender == btnUserNewInventoryScanWithAFI)
                sender = btnNewInventoryScanWithAFI;

            else if (sender == btnUserContinueInventoryScanWithAFI)
                sender = btnContinueInventoryScanWithAFI;

            btnNewInventoryScanNoAFI_Click(sender,e);
        }

        private void btnUserReadSingleBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte errorCode = 0;
            int fCmdRet = 0x30;
            byte blockNum = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            byte[] data = new byte[8];

            tbUserDataGetted.Text = "";
            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }

            blockNum = (byte)cbUserBlockNumber.SelectedIndex;

            state = 0xA0;
            if (!rbtnUserAddressMode.Checked)
            { state = 0xA1; }
            

            if ((rbtnUserAddressMode.Checked) &&
                ((cbUserUidList.Items.Count == 0) ||
                 (cbUserUidList.SelectedItem == null)))
            {
                MessageBox.Show("Select UID");
                return;
            }

            if (rbtnUserAddressMode.Checked)
            UID = HexStringToByteArray(cbUserUidList.SelectedItem.ToString());

            fCmdRet = StaticClassReaderA.CustomizedReadSingleBlock(ref readerAddr, ref state, UID, blockNum, data, ref errorCode, portIndex);
            if (fCmdRet == 0)
            {
                Array.Resize(ref data, UserDefineBlockSize + 1);
                tbUserDataGetted.Text = ByteArrayToHexString(data).Replace(" ", "").Insert(2," ");
            }
            AddCmdLog(btnUserReadSingleBlock.Text, fCmdRet, errorCode);
        }

        private void btnUserReadMultiBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte errorCode = 0;
            int fCmdRet = 0x30;
            byte startBlockNum = 0;
            byte blockCount = 0;
            byte blockSize = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };
            int i;

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }
            if ((rbAddressMode.Checked) &&
                ((cbUIDListforInfo.Items.Count == 0) ||
                 (cbUIDListforInfo.SelectedItem == null)))
            {
                MessageBox.Show("Select UID");
                return;
            }

            startBlockNum = (byte)cbUserStartBlockNumber.SelectedIndex;
            if (cbUserEndBlockNumber.SelectedIndex < startBlockNum)
            {
                MessageBox.Show("Block Number Error");
                return;
            }
            blockCount = (byte)(cbUserEndBlockNumber.SelectedIndex - startBlockNum + 1);
            blockSize = UserDefineBlockSize;

            byte[] data = new byte[(blockSize + 1) * blockCount];
            byte[] blockSecStatus = new byte[blockCount];

            state = 0xA0;
            if (!rbAddressMode.Checked)
                state = 0xA1;
            if (rbtnUserAddressMode.Checked)
                UID = HexStringToByteArray(cbUIDListforInfo.SelectedItem.ToString());

            fCmdRet = StaticClassReaderA.CustomizedReadMultipleBlock(ref readerAddr, ref state, UID, startBlockNum, blockCount,
                                                                 data, ref errorCode, portIndex);
            if (fCmdRet == 0)
            {
                frmMultipleBlockDataList frmdata = new frmMultipleBlockDataList();
                string temp = ByteArrayToHexString(data).Replace(" ", "");
                string s;

                for (i = startBlockNum; i < cbUserEndBlockNumber.SelectedIndex + 1; i++)
                {
                    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," "));

                }
                frmdata.Show();
            }
            AddCmdLog(btnReadMultiBlock.Text, fCmdRet, errorCode);
        }

        private void btnUserWriteSingleBlock_Click(object sender, EventArgs e)
        {
            byte state = 0;
            byte errorCode = 0;
            int fCmdRet = 0x30;
            byte blockNum = 0;
            byte[] UID = { 0, 0, 0, 0, 0, 0, 0, 0 };

            if (!GetCurrentUsePort())
            {
                MessageBox.Show("Open ComPort, Please");
            }

            if (tbUserDataToWrite.Text.Length != (UserDefineBlockSize * 2))
            {
                MessageBox.Show("Input Correct data");
                return;
            }

            if ((rbAddressMode.Checked) &&
               ((cbUIDListforInfo.Items.Count == 0) ||
                (cbUIDListforInfo.SelectedItem == null)))
            {
                MessageBox.Show("Select UID");
                return;
            }

            byte[] data = new byte[UserDefineBlockSize];
            data = HexStringToByteArray(tbUserDataToWrite.Text);

            if (rbtnUserAddressMode.Checked)
            UID = HexStringToByteArray(cbUserUidList.SelectedItem.ToString());
            blockNum = (byte)cbUserBlockNumber.SelectedIndex;
            if (cbUserWriteType.SelectedIndex == 0)
            {
                state = 0xA0;
                if (!rbtnUserAddressMode.Checked)
                    state = 0xA1;
            }
            else 
            {
                state = 0xA8;
                if (!rbtnUserAddressMode.Checked)
                    state = 0xA9;
            }

            fCmdRet = StaticClassReaderA.CustomizedWriteSingleBlock(ref readerAddr, ref state, UID, blockNum, data,UserDefineBlockSize, ref errorCode, portIndex);

            AddCmdLog(btnWriteSingleBlock.Text, fCmdRet, errorCode);
        }

        private void cbUserMaxBlock_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i;
            cbUserBlockNumber.Items.Clear();
            cbUserStartBlockNumber.Items.Clear();
            cbUserEndBlockNumber.Items.Clear();
            for (i = 0; i < cbUserMaxBlockNum.SelectedIndex + 1; i++)
            {
                cbUserBlockNumber.Items.Add(i.ToString());
                cbUserStartBlockNumber.Items.Add(i.ToString());
                cbUserEndBlockNumber.Items.Add(i.ToString());
            }
            cbUserBlockNumber.SelectedIndex = 0;
            cbUserStartBlockNumber.SelectedIndex = 0;
            cbUserEndBlockNumber.SelectedIndex = 0;
        }


        private void rbParseModeWPPM_Click(object sender, EventArgs e)
        {
            rbParseModeDPPM.Enabled = true;
            rbParseModeWPPM.Enabled = false;
            SetParseMode();
        }

        private void cbBlockNumToOperation_SelectionChangeCommitted(object sender, EventArgs e)
        {

        }

        private void rbParseModeDPPM_Click(object sender, EventArgs e)
        {
            rbParseModeDPPM.Enabled = false;
            rbParseModeWPPM.Enabled = true;
            SetParseMode();
        }

        private void rbModulation100_Click(object sender, EventArgs e)
        {
            rbModulation10.Enabled = true;
            rbModulation100.Enabled = false;
            SetParseMode();
        }

        private void rbModulation10_Click(object sender, EventArgs e)
        {
            rbModulation100.Enabled = true;
            rbModulation10.Enabled = false;
            SetParseMode();
        }

        private void cbUIDListforInfo_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((tbReaderInfoType.Text != "DL810_01Lite") &&
                (tbReaderInfoType.Text != "DL810_01Lite"))
            {
                gbpAFI.Enabled = true;
                gbpDSFID.Enabled = true;
                btnGetSystemInfo.Enabled = true;
            }
            gbpOtherCmd.Enabled = true;
        }

        private void rbSelectMode_Click(object sender, EventArgs e)
        {
            btnSelect.Enabled = false;
            btnStayQuite.Enabled = false;
            cbUIDListforInfo.Enabled = rbAddressMode.Checked;
        }

        private void cbBeginBlok_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnReadMultiBlock.Enabled = true;
        }

        private void cbBlockNumToOperation_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnReadSingleBlock.Enabled = true;
            btnReadMultiBlock.Enabled = true;
            btnWriteSingleBlock.Enabled = true;
            btnLcokBlock.Enabled = true;
        }

        private void cbUserBlockNumber_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnUserReadMultiBlock.Enabled = true;
            btnUserReadSingleBlock.Enabled = true;
            btnUserWriteSingleBlock.Enabled = true;
        }

        private void frmDL810_00Demo_FormClosing(object sender, FormClosingEventArgs e)
        {
            fIsAppClose = true;
            fIsScanMode = true;
            fIsTestMode = true;
        }
    }

}