Пример #1
0
 public void Read()
 {
     while (_keepreading)
     {
         try
         {
             ulong icCardNo = 0;
             int   st       = dc_reset(Icdev, 0);
             dc_config_card(Icdev, 65);
             dc_card(Icdev, '0', ref icCardNo);
             if (icCardNo != 0)
             {
                 dc_beep(Icdev, 10);
                 HandDataBack?.Invoke(this, new DataEventArgs(icCardNo.ToString()));
                 IsRead = false;
             }
             TimeSpan waitTime = new TimeSpan(0, 0, 0, 2, 50);
             Thread.Sleep(waitTime);
         }
         catch (Exception ex)
         {
             LogUtil.WriteLog(ex);
         }
     }
 }
Пример #2
0
        public void Read()
        {
            while (_keepreading)
            {
                try
                {
                    string strData;
                    byte[] r_byte = new byte[20];
                    if (port.IsOpen)
                    {
                        port.Read(r_byte, 0, 8);

                        if (r_byte[0] != 0xBB)
                        {
                            strData = "";
                            for (int i = 2; i < 6; i++)
                            {
                                strData = strData + funBtoHex(r_byte[i]);
                            }
                            HandDataBack?.Invoke(this, new DataEventArgs(strData));
                            IsRead = false;
                        }
                    }
                    else
                    {
                        Thread.Sleep(50);
                    }
                }
                catch (Exception ex) { LogUtil.WriteLog(ex); }
            }
        }
Пример #3
0
        private void _SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int dataLength = _SerialPort.BytesToRead;

            byte[] buffer = new byte[dataLength];
            _SerialPort.Read(buffer, 0, dataLength);
            //LogUtil.WriteLog(FrameHelper.bytetostr(buffer));
            string strData = Encoding.ASCII.GetString(buffer);

            HandDataBack?.Invoke(this, new DataEventArgs(strData));
        }
Пример #4
0
 public void Read()
 {
     byte[] ReceiveBytes = new byte[4096];
     while (true)
     {
         try
         {
             if (_keepreading)
             {
                 byte   fComAdr = 0;
                 byte   AdrTID = 0;
                 byte   LenTID = 0;
                 byte   TIDFlag = 0;
                 int    Totallen = 0;
                 int    CardNum = 0;
                 int    EPClen = 0;
                 int    m = 0;
                 string temps, sEPC;
                 byte[] EPC = new byte[5000];
                 fCmdRet = StaticClassReaderB.Inventory_G2(ref fComAdr, AdrTID, LenTID, TIDFlag, EPC, ref Totallen, ref CardNum, rfidcomindex);
                 if ((fCmdRet == 1) | (fCmdRet == 2) | (fCmdRet == 3) | (fCmdRet == 4) | (fCmdRet == 0xFB))//代表已查找结束,
                 {
                     if (CardNum != 0)
                     {
                         byte[] daw = new byte[Totallen];
                         Array.Copy(EPC, daw, Totallen);
                         temps  = ByteArrayToHexString(daw);
                         EPClen = daw[m];
                         sEPC   = temps.Substring(m * 2 + 2, EPClen * 2);
                         HandDataBack?.Invoke(this, new DataEventArgs(sEPC));
                     }
                 }
             }
             Thread.Sleep(2000);
         }
         catch (Exception ex)
         {
             LogUtil.WriteLog(ex);
         }
     }
 }
Пример #5
0
        public void Read()
        {
            byte[] ReceiveBytes = new byte[4096];

            while (_keepreading)
            {
                if (port.IsOpen)
                {
                    byte[] buffer = new byte[port.ReadBufferSize + 1];
                    try
                    {
                        int    count = port.Read(buffer, 0, port.ReadBufferSize);
                        string restr = System.Text.Encoding.ASCII.GetString(buffer, 0, count);

                        if (restr.IndexOf('\r') != -1)
                        {
                            sb.Append(restr);
                            //  SetText(sb.ToString());
                            HandDataBack?.Invoke(this, new CardEventArgs(sb.ToString()));
                            sb.Clear();
                            isread = false;
                        }
                        else
                        {
                            sb.Append(restr);
                        }
                    }


                    catch (TimeoutException) { }
                }
                else
                {
                    TimeSpan waitTime = new TimeSpan(0, 0, 0, 1, 50);
                    Thread.Sleep(waitTime);
                }
            }
        }
Пример #6
0
        public void Read()
        {
            try
            {
                while (_keepreading)
                {
                    string strData;
                    byte[] r_byte = new byte[20];
                    if (port.IsOpen)
                    {
                        try
                        {
                            port.Read(r_byte, 0, 8);

                            if (r_byte[0] != 0xBB)
                            {
                                strData = "";
                                for (int i = 2; i < 6; i++)
                                {
                                    strData = strData + funBtoHex(r_byte[i]);
                                }
                                HandDataBack?.Invoke(this, new CardEventArgs(strData));
                                isread = false;
                            }
                        }
                        catch (TimeoutException) { }
                    }
                    else
                    {
                        TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 50);
                        Thread.Sleep(waitTime);
                    }
                }
            }
            catch { }
        }