public bool CloseConnection()
        {
            var result = false;

            try
            {
                if (_readerProfile.ConnectionType == ConnectionType.Serial)
                {
                    fCmdRet = RWDev.CloseSpecComPort(frmcomportindex);
                    result  = true;
                }
                else
                {
                    fCmdRet = RWDev.CloseNetPort(FrmPortIndex);
                    result  = true;
                }

                _readerConnected = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(result);
        }
        private void flash_G2()
        {
            Session = Convert.ToByte((int)_readerProfile.InventorySearchMode);
            Qvalue  = Convert.ToByte(4);
            byte Ant = 0x80;
            int  CardNum = 0;
            int  Totallen = 0;
            int  EPClen, m;

            byte[] EPC = new byte[50000];
            int    CardIndex;
            string temps, temp;

            temp = "";
            string sEPC;
            byte   MaskMem = 0;

            byte[] MaskAdr = new byte[2];
            byte   MaskLen = 0;

            byte[] MaskData = new byte[100];
            byte   MaskFlag = 0;
            byte   AdrTID   = 0;
            byte   LenTID   = 0;

            AdrTID   = 0;
            LenTID   = 6;
            MaskFlag = 0;
            int cbtime = System.Environment.TickCount;

            CardNum = 0;
            fCmdRet = RWDev.Inventory_G2(ref fComAdr, Qvalue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, InAnt, Scantime, FastFlag, EPC, ref Ant, ref Totallen, ref CardNum, frmcomportindex);
            int cmdTime = System.Environment.TickCount - cbtime;//命令时间

            if ((fCmdRet == 0x30) || (fCmdRet == 0x37))
            {
                if (_readerProfile.ConnectionType == ConnectionType.Ethernet)
                {
                    if (frmcomportindex > 1023)
                    {
                        fCmdRet = RWDev.CloseNetPort(frmcomportindex);
                        if (fCmdRet == 0)
                        {
                            frmcomportindex = -1;
                        }
                        Thread.Sleep(1000);
                    }
                    fComAdr = 255;
                    string ipAddress = _readerProfile.IpAddress;
                    int    nPort     = Convert.ToInt32("27011");
                    fCmdRet = RWDev.OpenNetPort(nPort, ipAddress, ref fComAdr, ref frmcomportindex);
                }
            }
            if (CardNum == 0)
            {
                if (Session > 1)
                {
                    AA_times = AA_times + 1;//没有得到标签只更新状态栏
                }
                IntPtr ptrWnd = IntPtr.Zero;
                // ptrWnd = FindWindow(null, "UHFReader288 Demo V1.16");
                if (ptrWnd != IntPtr.Zero)         // 检查当前统计窗口是否打开
                {
                    string para = fCmdRet.ToString();
                    //  SendMessage(ptrWnd, WM_SENDSTATU, IntPtr.Zero, para);
                }
                return;
            }
            AA_times = 0;

            if ((fCmdRet == 1) || (fCmdRet == 2) || (fCmdRet == 0x26)) //代表已查找结束,
            {
                byte[] daw = new byte[Totallen];
                Array.Copy(EPC, daw, Totallen);
                temps = ByteArrayToHexString(daw);
                if (fCmdRet == 0x26)
                {
                    string SDCMD = temps.Substring(0, 12);
                    temps = temps.Substring(12);
                    daw   = HexStringToByteArray(temps);
                    byte[] datas = new byte[6];
                    datas = HexStringToByteArray(SDCMD);
                    int tagrate = datas[0] * 256 + datas[1];
                    int tagnum  = datas[2] * 256 * 256 * 256 + datas[3] * 256 * 256 + datas[4] * 256 + datas[5];
                    total_tagnum = total_tagnum + tagnum;
                    IntPtr ptrWnd = IntPtr.Zero;
                    // ptrWnd = FindWindow(null, "UHFReader288 Demo V1.16");
                    if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开
                    {
                        string para = tagrate.ToString() + "," + total_tagnum.ToString() + "," + cmdTime.ToString();
                        //   SendMessage(ptrWnd, WM_SENDTAGSTAT, IntPtr.Zero, para);
                    }
                }
                m = 0;


                List <string> epsList = new List <string>();
                for (CardIndex = 0; CardIndex < CardNum; CardIndex++)
                {
                    EPClen = daw[m] + 1;
                    temp   = temps.Substring(m * 2 + 2, EPClen * 2);
                    sEPC   = temp.Substring(0, temp.Length - 2);
                    int RSSI = Convert.ToInt32(temp.Substring(temp.Length - 2, 2), 16);
                    m = m + EPClen + 1;
                    if (sEPC.Length != (EPClen - 1) * 2)
                    {
                        return;
                    }


                    if (epsList.Contains(sEPC))
                    {
                        continue;
                    }
                    epsList.Add(sEPC);

                    IntPtr ptrWnd = IntPtr.Zero;
                    //  ptrWnd = FindWindow(null, "UHFReader288 Demo V1.16");
                    if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开
                    {
                        string para = sEPC + "," + RSSI.ToString() + " ";
                        //   SendMessage(ptrWnd, WM_SENDTAG, IntPtr.Zero, para);
                    }
                    var readTime = DateTime.Now;

                    var tag = new Split
                    {
                        DateTimeOfDay       = readTime,
                        TimeOfDay           = readTime.ToString("hh.mm.ss.ff"),
                        Epc                 = sEPC,
                        Rssi                = RSSI,
                        SplitName           = _readerProfile.Name,
                        SplitDeviceId       = _readerProfile.Id,
                        InventorySearchMode = _readerProfile.InventorySearchMode,
                        Antenna             = Ant.ToString()
                    };

                    recordTag(tag);
                }
            }
        }