Exemple #1
0
        public RicTextInfo Scan(int channel, int timeout = 30)
        {
            RicTextInfo temp          = null;
            int         tmpRemainTime = timeout * 2;

            try
            {
                do
                {
                    try
                    {
                        Init(channel);
                        if (Authenticate())//fixed time 500 ms
                        {
                            temp = DecodeObject();
                            break;
                        }
                        Realase();
                        tmpRemainTime -= 1;
                    }
                    catch { }
                } while (tmpRemainTime > 0);
                isOpen = false;
            }
            catch (Exception exception) { throw exception; }

            return(temp);
        }
Exemple #2
0
        private RicTextInfo DecodeObject()
        {
            int         itemCount   = GetContentItem();
            RicTextInfo ricTextInfo = null;
            string      filePath    = Path.Combine(ProtoController.Dir, ContentFilePath);

            if (File.Exists(filePath))
            {
                ricTextInfo = new RicTextInfo();
                try
                {
                    FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    byte[]     bytes      = new byte[fileStream.Length];
                    fileStream.Read(bytes, 0, (int)fileStream.Length);
                    fileStream.Close();
                    ricTextInfo = StringConvertObject(bytes);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            filePath = Path.Combine(ProtoController.Dir, PhotoFilePath);
            if (File.Exists(filePath) && ricTextInfo != null)
            {
                try
                {
                    byte[] tmpPhotoBytes = null;
                    using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        tmpPhotoBytes = new byte[fileStream.Length];
                        fileStream.Read(tmpPhotoBytes, 0, (int)fileStream.Length);
                    }
                    ricTextInfo.Photo = tmpPhotoBytes;
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }

            byte[] fingerBuffer = DecodeFingerPrint();
            ricTextInfo.FingerBuffer  = fingerBuffer;
            ricTextInfo.IncludeFinger = (fingerBuffer != null && fingerBuffer.Length > 0);

            DeleteCardFile();
            return(ricTextInfo);
        }
Exemple #3
0
        private RicTextInfo StringConvertObject(byte[] bytes)
        {
            var idCardInfo = new RicTextInfo();

            if (bytes != null && bytes.Length == 256)
            {
                int    i       = 30;
                string name    = EncodingConvert(bytes, 0, 30).Trim();
                int    sexCode = TypeHelper.ParseInt(EncodingConvert(bytes, i, 2));
                i += 2;
                int    nationCode = TypeHelper.ParseInt(EncodingConvert(bytes, i, 4));
                string nation     = new VolkCollection()[nationCode];
                i += 4;
                int birthDate = TypeHelper.ParseInt(EncodingConvert(bytes, i, 16));
                i += 16;
                string address = EncodingConvert(bytes, i, 70).Trim();
                i += 70;
                string idNumber = EncodingConvert(bytes, i, 36).Trim();
                i += 36;
                string issuingAuthority = EncodingConvert(bytes, i, 30).Trim();
                i += 30;
                string issuingDate = EncodingConvert(bytes, i, 16).Trim();
                i += 16;
                string expiratinDate = EncodingConvert(bytes, i, 16).Trim();


                idCardInfo.DwellingPlace   = address;
                idCardInfo.Birth           = TypeHelper.ParseString(birthDate);
                idCardInfo.ExpireDate      = expiratinDate;
                idCardInfo.CitizenIDNumber = idNumber;
                idCardInfo.Authority       = issuingAuthority;
                idCardInfo.AuthortityDate  = issuingDate;
                idCardInfo.Name            = name;
                idCardInfo.Volk            = nation;
                idCardInfo.VolkCode        = TypeHelper.ParseString(nationCode);
                idCardInfo.Sex             = DecodeSex(sexCode);
                idCardInfo.SexCode         = TypeHelper.ParseString(sexCode);
            }
            return(idCardInfo);
        }
Exemple #4
0
        public int Scan(IDReadCompletedHandler completedHandler, int channel = 1001, int timeout = 30)
        {
            if (isOpen)
            {
                return(1);
            }
            idrReadThrad = new Thread((object arg) =>
            {
                int tmpRemainTime = (int)arg * 2;
                try
                {
                    RicTextInfo temp = null;
                    do
                    {
                        try
                        {
                            Init(channel);
                            if (Authenticate())//fixed time 500 ms
                            {
                                temp = DecodeObject();
                                Realase();
                                break;
                            }
                            Realase();
                            tmpRemainTime -= 1;
                        }
                        catch { }
                    } while (tmpRemainTime > 0);
                    isOpen = false; completedHandler.Invoke(temp);
                }
                catch (Exception exception) { throw exception; }
            });
            idrReadThrad.Start(timeout); isOpen = true;

            return(1);
        }