Esempio n. 1
0
        private void btnCaptureSingle_Click(object sender, EventArgs e)
        {
            UFScanner  Scanner;
            UFS_STATUS ufs_res;

            if (!GetGetCurrentScanner(out Scanner))
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = Scanner.CaptureSingleImage();
            Cursor.Current = this.Cursor;

            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner CaptureSingleImage: OK\r\n");
                DrawCapturedImage(Scanner);
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner CaptureSingleImage: " + m_strError + "\r\n");
            }
        }
Esempio n. 2
0
        private void btnUninit_Click(object sender, EventArgs e)
        {
            //=========================================================================//
            // Uninit Scanners
            //=========================================================================//
            UFS_STATUS ufs_res;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Uninit();
            Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner Uninit: OK\r\n");
                m_ScannerManager.ScannerEvent -= ScannerEvent;
                lbScannerList.Items.Clear();
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner Uninit: " + m_strError + "\r\n");
            }

            pbImageFrame.Image = null;
            //=========================================================================//
        }
Esempio n. 3
0
        public void InicializaBiometria()
        {
            groupBox2.Enabled = true;

            //=========================================================================//
            // Inicializa algoritmo
            //=========================================================================//
            UFS_STATUS ufs_res;
            int        nScannerNumber;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Init();
            Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                toolStripStatusLabel1.Text = "Inicialização de algoritmo: OK";
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                toolStripStatusLabel1.Text = m_strError;
                return;
            }

            m_ScannerManager.ScannerEvent += new UFS_SCANNER_PROC(ScannerEvent);

            nScannerNumber             = m_ScannerManager.Scanners.Count;
            toolStripStatusLabel1.Text = "Algoritmo inicializado";

            groupBox2.Enabled = true;

            m_template1 = null;
            m_template2 = null;
            m_template3 = null;
        }
Esempio n. 4
0
        private void btnExtract_Click(object sender, EventArgs e)
        {
            UFScanner  Scanner;
            UFS_STATUS ufs_res;

            if (!GetGetCurrentScanner(out Scanner))
            {
                return;
            }

            Scanner.TemplateSize = MAX_TEMPLATE_SIZE;
            Scanner.DetectCore   = cbDetectCore.Checked;

            byte[] Template = new byte[MAX_TEMPLATE_SIZE];
            int    TemplateSize;
            int    EnrollQuality;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = Scanner.Extract(Template, out TemplateSize, out EnrollQuality);
            Cursor.Current = this.Cursor;

            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner Extract: OK\r\n");
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner Extract: " + m_strError + "\r\n");
            }
        }
 UFScanner GetSelectedScanner()
 {
     try
     {
         if (lstScanners.SelectedIndex >= 0)
         {
             UFScanner scanner = _scannerManager.Scanners[lstScanners.SelectedIndex];
             if (scanner == null)
             {
                 WriteLog("Please check that selected scanner is connected", true);
             }
             else
             {
                 return(scanner);
             }
         }
         else
         {
             WriteLog("Select scanner and try again");
         }
     }
     catch (Exception ex)
     {
         WriteLog(ex.Message, true);
     }
     return(null);
 }
        private void CaptureTemplate(object sender, RoutedEventArgs e)
        {
            try
            {
                UFScanner scanner = GetSelectedScanner();
                if (scanner == null)
                {
                    return;
                }

                this.Cursor = Cursors.Wait;
                scanner.ClearCaptureImageBuffer();

                UFS_STATUS ufsRes = scanner.CaptureSingleImage();


                if (ufsRes == UFS_STATUS.OK)
                {
                    UFS_STATUS capturingStatus = ExtractTemplate(scanner);
                }
                else
                {
                    string error = string.Empty;
                    UFScanner.GetErrorString(ufsRes, out error);
                    WriteLog(error, false);
                }
            }
            catch (Exception exc)
            {
                WriteLog(exc.Message, true);
            }
            this.Cursor = Cursors.Arrow;
        }
        private void InitializeScanners()
        {
            try
            {
                WriteLog("Initializing scanners");

                UFS_STATUS ufsRes = _scannerManager.Init();

                if (ufsRes == UFS_STATUS.OK)
                {
                }
                else
                {
                    string error = string.Empty;
                    UFScanner.GetErrorString(ufsRes, out error);
                    WriteLog(error, false);
                    //init failed probably problem with license
                    btnCapture.IsEnabled = false;
                    return;
                }

                btnCapture.IsEnabled = UpdateScannersList() > 0;
            }
            catch (Exception ex)
            {
                WriteLog(ex.Message, true);
            }
        }
Esempio n. 8
0
        private void Init()
        {
            //=========================================================================//
            // Inicializa algoritmo
            //=========================================================================//
            UFS_STATUS ufs_res;
            int        nScannerNumber;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Init();
            Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                lbMensagem.Text = "Inicialização de algoritmo: OK";
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                lbMensagem.Text = m_strError;
                return;
            }

            //m_ScannerManager.ScannerEvent += new UFS_SCANNER_PROC(ScannerEvent);

            nScannerNumber = m_ScannerManager.Scanners.Count;

            m_template1 = null;
            m_template2 = null;
            m_template3 = null;
        }
        private bool ExtractTemplate(byte[] Template, out int TemplateSize)
        {
            UFS_STATUS ufs_res;
            int        EnrollQuality;

            m_Scanner.ClearCaptureImageBuffer();

            //tbxMessage.AppendText("Place Finger\r\n");

            TemplateSize = 0;
            while (true)
            {
                ufs_res = m_Scanner.CaptureSingleImage();
                if (ufs_res != UFS_STATUS.OK)
                {
                    UFScanner.GetErrorString(ufs_res, out m_strError);
                    //tbxMessage.AppendText("UFScanner CaptureSingleImage: " + m_strError + "\r\n");
                    return(false);
                }

                ufs_res = m_Scanner.Extract(Template, out TemplateSize, out EnrollQuality);
                if (ufs_res == UFS_STATUS.OK)
                {
                    //tbxMessage="UFScanner Extract: OK\r\n");
                    break;
                }
                else
                {
                    UFScanner.GetErrorString(ufs_res, out m_strError);
                    // tbxMessage="UFScanner Extract: " + m_strError + "\r\n");
                }
            }

            return(true);
        }
        int UpdateScannersList()
        {
            int nScannerNumber = _scannerManager.Scanners.Count;

            lstScanners.Items.Clear();
            if (nScannerNumber > 0)
            {
                WriteLog(false, "Scanners found {0}", nScannerNumber.ToString());


                for (int i = 0; i < nScannerNumber; i++)
                {
                    UFScanner scanner = _scannerManager.Scanners[i];
                    scanner.DetectCore   = true;
                    scanner.UseSIF       = false;
                    scanner.TemplateSize = 384;



                    lstScanners.Items.Add(string.Format("{0} : {1}", i + 1, GetScannerTypeString(scanner.ScannerType)));
                }
            }
            else
            {
                WriteLog(false, "No available scanners");
            }
            return(nScannerNumber);
        }
Esempio n. 11
0
        public void InitializeReader(string connectionString)
        {
            m_ScannerManager = new UFScannerManager(new ScannerManager());

            m_Scanner            = null;
            m_Database           = null;
            m_Matcher            = null;
            m_bTemplate1         = new byte[nMAX_TEMPLATE_SIZE];
            m_szConnectionString = connectionString;
        }
        private void btnInit_Click(object sender, EventArgs e)
        {
            //=========================================================================//
            // Initilize scanners
            //=========================================================================//
            UFS_STATUS ufs_res;
            int        nScannerNumber;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Init();
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner Init: OK\r\n");
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner Init: " + m_strError + "\r\n");
                Cursor.Current = this.Cursor;
                return;
            }

            m_ScannerManager.ScannerEvent += new UFS_SCANNER_PROC(ScannerEvent);

            nScannerNumber = m_ScannerManager.Scanners.Count;
            tbxMessage.AppendText("UFScanner GetScannerNumber: " + nScannerNumber + "\r\n");

            UpdateScannerList();

            if (cbScanTemplateType.SelectedIndex == -1)
            {
                cbScanTemplateType.SelectedIndex = 1;
                m_nType = 1;
            }
            //=========================================================================//

            //=========================================================================//
            // Create matcher
            //=========================================================================//
            m_Matcher = new UFMatcher();

            if (m_Matcher.InitResult == UFM_STATUS.OK)
            {
                tbxMessage.AppendText("UFMatcher Init: OK\r\n");
            }
            else
            {
                UFMatcher.GetErrorString(m_Matcher.InitResult, out m_strError);
                tbxMessage.AppendText("UFMatcher Init: " + m_strError + "\r\n");
            }

            GetMatcherSettings(m_Matcher);
            //=========================================================================//
            Cursor.Current = this.Cursor;
        }
Esempio n. 13
0
 private bool GetGetCurrentScanner(out UFScanner Scanner)
 {
     Scanner = m_ScannerManager.Scanners[lbScannerList.SelectedIndex];
     if (Scanner != null)
     {
         return(true);
     }
     else
     {
         tbxMessage.AppendText("Selected Scanner is not connected\r\n");
         return(false);
     }
 }
Esempio n. 14
0
 private bool GetCurrentScanner(out UFScanner Scanner)
 {
     Scanner = m_ScannerManager.Scanners[indexScannerSelecionado];
     if (Scanner != null)
     {
         return(true);
     }
     else
     {
         toolStripStatusLabel1.Text = "Scanner não está conectado";
         return(false);
     }
 }
Esempio n. 15
0
 private bool GetCurrentScanner(out UFScanner Scanner)
 {
     Scanner = m_ScannerManager.Scanners[0];
     if (Scanner != null)
     {
         return(true);
     }
     else
     {
         lbMensagem.Text = "Scanner não está conectado";
         return(false);
     }
 }
        public string   Initializescanner()
        {
            //=========================================================================//
            // Initilize scanners
            //=========================================================================//
            UFS_STATUS ufs_res;
            int        nScannerNumber;
            string     tbxMessage = "";

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Init();


            //  Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage = "UFScanner Init: OK\r\n";
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage = "UFScanner Init: " + m_strError + "\r\n";
                return(tbxMessage);
            }

            nScannerNumber = m_ScannerManager.Scanners.Count;
            tbxMessage     = "UFScanner GetScannerNumber: " + nScannerNumber + "\r\n";

            if (nScannerNumber == 0)
            {
                tbxMessage = "There's no available scanner\r\n";
                return(tbxMessage);
            }
            else
            {
                tbxMessage = "First scanner will be used\r\n";
            }

            m_Scanner         = m_ScannerManager.Scanners[0];
            m_Scanner.Timeout = 5000;
            //=========================================================================//
            // UpdateDatabaseList();
            //=========================================================================//

            //=========================================================================//
            // Create matcher
            //=========================================================================//
            m_Matcher = new UFMatcher();
            return("");
            //=========================================================================//
        }
        public SupremaFingerPrint()
        {
            m_ScannerManager = new UFScannerManager(new ScannerManager());
            // Set timeout for capturing images to 5 seconds



            m_Scanner = null;

            m_Database = null;
            m_Matcher  = null;

            m_Template1 = new byte[MAX_TEMPLATE_SIZE];
            m_Template2 = new byte[MAX_TEMPLATE_SIZE];
        }
Esempio n. 18
0
        public bool iniciarScanner()
        {
            this.ScannerManager = new UFScannerManager(this);

            this.ufs_res = this.ScannerManager.Init();
            //get firts scanner
            this.scanner = this.ScannerManager.Scanners[0];
            if (this.scanner == null)
            {
                MessageBox.Show("Escanner no encontrado", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            setParametros();
            return(true);
        }
Esempio n. 19
0
        private void UFE30_DatabaseDemo_Load(object sender, EventArgs e)
        {
            m_ScannerManager = new UFScannerManager(this);
            m_Scanner        = null;
            m_Database       = null;
            m_Matcher        = null;

            m_Template1 = new byte[MAX_TEMPLATE_SIZE];
            m_Template2 = new byte[MAX_TEMPLATE_SIZE];

            lvDatabaseList.Columns.Add("Serial", 50, HorizontalAlignment.Left);
            lvDatabaseList.Columns.Add("UserID", 60, HorizontalAlignment.Left);
            lvDatabaseList.Columns.Add("FingerIndex", 80, HorizontalAlignment.Left);
            lvDatabaseList.Columns.Add("Template1", 80, HorizontalAlignment.Left);
            lvDatabaseList.Columns.Add("Template2", 80, HorizontalAlignment.Left);
            lvDatabaseList.Columns.Add("Memo", 60, HorizontalAlignment.Left);
        }
        //public bool IsInitializescanner()
        //{
        //    UFS_STATUS ufs_res;
        //    int nScannerNumber;
        //    string tbxMessage = "";
        //    Cursor.Current = Cursors.WaitCursor;
        //    //   ufs_res = m_ScannerManager.Init();

        //    if (ufs_res.in == UFS_STATUS.OK)
        //    {
        //        return true;
        //    }
        //}
        public string  Uninit()
        {
            //=========================================================================//
            // Uninit scanner module
            //=========================================================================//
            UFS_STATUS ufs_res;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Uninit();
            // Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage = "UFScanner Uninit: OK\r\n";
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage = "UFScanner Uninit: " + m_strError + "\r\n";
            }
            //=========================================================================//

            //=========================================================================//
            // Close database
            //=========================================================================//
            //UFD_STATUS ufd_res;

            //if (m_Database != null)
            //{
            //    ufd_res = m_Database.Close();
            //    if (ufd_res == UFD_STATUS.OK)
            //    {
            //       tbxMessage="UFDatabase Close: OK\r\n";
            //    }
            //    else
            //    {
            //        UFDatabase.GetErrorString(ufd_res, out m_strError);
            //       tbxMessage="UFDatabase Close: " + m_strError + "\r\n";
            //    }
            //}

            //  lvDatabaseList.Items.Clear();

            return(tbxMessage);
            //=========================================================================//
        }
Esempio n. 21
0
        private void UFE30_Enroll_Load(object sender, EventArgs e)
        {
            UFS_STATUS ufs_res;
            string     strError;

            m_extract_num  = 0;
            m_try_extract  = true;
            m_bFingerCheck = false;

            int i;

            m_EnrollTemplate_input     = new byte[MAX_TEMPLATE_INPUT_NUM][];
            m_EnrollTemplateSize_input = new int[MAX_TEMPLATE_INPUT_NUM];
            for (i = 0; i < MAX_TEMPLATE_INPUT_NUM; i++)
            {
                m_EnrollTemplate_input[i]     = new byte[MAX_TEMPLATE_SIZE];
                m_EnrollTemplateSize_input[i] = 0;
            }

            m_EnrollTemplate_output     = new byte[m_output_num][];
            m_EnrollTemplateSize_output = new int[m_output_num];
            for (i = 0; i < m_output_num; i++)
            {
                m_EnrollTemplate_output[i]     = new byte[MAX_TEMPLATE_SIZE];
                m_EnrollTemplateSize_output[i] = 0;
            }

            tbxMessage.AppendText("Advanced Enroll is started. Place your finger\r\n");

            m_Scanner.ClearCaptureImageBuffer();

            m_Scanner.Timeout = 0;

            m_Scanner.CaptureEvent += new UFS_CAPTURE_PROC(EnrollEvent);
            ufs_res = m_Scanner.StartCapturing();
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner StartCapturing: OK\r\n");
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out strError);
                tbxMessage.AppendText("UFScanner StartCapturing: " + strError + "\r\n");
            }
        }
Esempio n. 22
0
        public void FinalizaBiometria()
        {
            //=========================================================================//
            // Finaliza algoritmo
            //=========================================================================//
            UFS_STATUS ufs_res;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Uninit();
            Cursor.Current = this.Cursor;
            if (ufs_res != UFS_STATUS.OK)
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                lbMensagem.Text = m_strError;
            }

            pictureBox1.Image = null;
        }
Esempio n. 23
0
        private void DrawCapturedImage(UFScanner Scanner)
        {
            Graphics  g    = pbImageFrame.CreateGraphics();
            Rectangle rect = new Rectangle(0, 0, pbImageFrame.Width, pbImageFrame.Height);

            try {
                //
                //Scanner.DrawCaptureImageBuffer(g, rect, cbDetectCore.Checked);
                //
                Bitmap bitmap;
                int    Resolution;
                Scanner.GetCaptureImageBuffer(out bitmap, out Resolution);
                pbImageFrame.Image = bitmap;
            }
            finally {
                g.Dispose();
            }
        }
Esempio n. 24
0
        private void btnUninit_Click(object sender, EventArgs e)
        {
            //=========================================================================//
            // Uninit scanner module
            //=========================================================================//
            UFS_STATUS ufs_res;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Uninit();
            Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner Uninit: OK\r\n");
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner Uninit: " + m_strError + "\r\n");
            }
            //=========================================================================//

            //=========================================================================//
            // Close database
            //=========================================================================//
            UFD_STATUS ufd_res;

            if (m_Database != null)
            {
                ufd_res = m_Database.Close();
                if (ufd_res == UFD_STATUS.OK)
                {
                    tbxMessage.AppendText("UFDatabase Close: OK\r\n");
                }
                else
                {
                    UFDatabase.GetErrorString(ufd_res, out m_strError);
                    tbxMessage.AppendText("UFDatabase Close: " + m_strError + "\r\n");
                }
            }

            lvDatabaseList.Items.Clear();
            //=========================================================================//
        }
Esempio n. 25
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            UFS_STATUS ufs_res;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Update();
            Cursor.Current = this.Cursor;

            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner Update: OK\r\n");
                UpdateScannerList();
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner Update: " + m_strError + "\r\n");
            }
        }
Esempio n. 26
0
        private void btnAbortCapturing_Click(object sender, EventArgs e)
        {
            UFScanner  Scanner;
            UFS_STATUS ufs_res;

            if (!GetGetCurrentScanner(out Scanner))
            {
                return;
            }

            ufs_res = Scanner.AbortCapturing();
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner AbortCapturing: OK\r\n");
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner AbortCapturing: " + m_strError + "\r\n");
            }
        }
        private void btnAutoCapture_Click(object sender, EventArgs e)
        {
            UFScanner  Scanner;
            UFS_STATUS ufs_res;

            if (!GetGetCurrentScanner(out Scanner))
            {
                return;
            }

            Scanner.CaptureEvent += new UFS_CAPTURE_PROC(CaptureEvent);
            ufs_res = Scanner.StartAutoCapture();
            if (ufs_res == UFS_STATUS.OK)
            {
                tbxMessage.AppendText("UFScanner StartAutoCapture: OK\r\n");
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                tbxMessage.AppendText("UFScanner StartAutoCapture: " + m_strError + "\r\n");
            }
        }
Esempio n. 28
0
        public void FinalizaBiometria()
        {
            groupBox2.Enabled = false;
            //=========================================================================//
            // Finaliza algoritmo
            //=========================================================================//
            UFS_STATUS ufs_res;

            Cursor.Current = Cursors.WaitCursor;
            ufs_res        = m_ScannerManager.Uninit();
            Cursor.Current = this.Cursor;
            if (ufs_res == UFS_STATUS.OK)
            {
                toolStripStatusLabel1.Text     = "Algoritmo finalizado";
                m_ScannerManager.ScannerEvent -= ScannerEvent;
            }
            else
            {
                UFScanner.GetErrorString(ufs_res, out m_strError);
                toolStripStatusLabel1.Text = m_strError;
            }

            pictureBox1.Image = null;
        }
        private UFS_STATUS ExtractTemplate(UFScanner scanner)
        {
            try
            {
                byte[] template      = new byte[TemplateBufferSize];
                int    enrollQuality = 0;


                UFS_STATUS ufsRes = scanner.Extract(template, out _templateSize, out enrollQuality);

                if (ufsRes == UFS_STATUS.OK)
                {
                    if (template.Length != TemplateBufferSize)
                    {
                        //WriteLog(true, "Invalid template size, try again");
                        //return UFS_STATUS.ERR_NOT_GOOD_IMAGE;
                        byte[] tmp = new byte[TemplateBufferSize];
                        for (int i = template.Length - 1; i < tmp.Length; i++)
                        {
                            tmp[i] = 0;
                        }
                        template = tmp;
                    }


                    WriteLog("Template capturing completed");
                    WriteLog(string.Format("Template quality is {0}", enrollQuality));

                    if (enrollQuality < Settings.MinimalTemplateQualityPercent)
                    {
                        MessageBoxResult result = MessageBox.Show("The quality of captured template is too low for using it, Would you like to retry template capturing?",
                                                                  "Poor template quality", MessageBoxButton.YesNo, MessageBoxImage.Information);
                        if (result == MessageBoxResult.Yes)
                        {
                            CaptureTemplate(this, null);
                        }
                    }
                    else
                    {
                        _template = Encoding.ASCII.GetString(TemplateConverter.ConvertToSynelTemplateFormat(template));

                        System.Drawing.Bitmap bitm = null;
                        int resolution             = 0;
                        scanner.GetCaptureImageBuffer(out bitm, out resolution);
                        fingerImage.Source = loadBitmap(bitm);
                    }
                }
                else
                {
                    string error = string.Empty;
                    UFScanner.GetErrorString(ufsRes, out error);
                    WriteLog(error, false);
                }

                return(ufsRes);
            }
            catch (Exception exc)
            {
                WriteLog(exc.Message, true);
            }
            return(UFS_STATUS.ERROR);
        }
Esempio n. 30
0
        public void run()
        {
            const int MAX_TEMPLATE_SIZE = 384;

            UFS_STATUS       ufs_res;
            UFScannerManager ScannerManager;
            int nScannerNumber;

            ScannerManager = new UFScannerManager(null);

            ufs_res        = ScannerManager.Init();
            nScannerNumber = ScannerManager.Scanners.Count;

            UFScanner Scanner = null;

            Scanner = ScannerManager.Scanners[0];


            //Scanner.Timeout = 7000;
            //Scanner.TemplateSize = MAX_TEMPLATE_SIZE;
            //Scanner.DetectCore = false;

            //byte[] Template = new byte[MAX_TEMPLATE_SIZE];
            byte[] Template0 = new byte[MAX_TEMPLATE_SIZE];
            byte[] Template1 = new byte[MAX_TEMPLATE_SIZE];

            int TemplateSize;
            int EnrollQuality;



            IntPtr versionPtr = API.BS2_Version();

            Console.WriteLine("SDK version : {0}", Marshal.PtrToStringAnsi(versionPtr));
            IntPtr sdkContext = IntPtr.Zero;

            sdkContext = API.BS2_AllocateContext();
            if (sdkContext == IntPtr.Zero)
            {
                Console.WriteLine("BS2_AllocateContext Failed.");
                return;
            }

            BS2ErrorCode result = (BS2ErrorCode)API.BS2_Initialize(sdkContext);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("BS2_Initialize failed. Error : {0}", result);
                API.BS2_ReleaseContext(sdkContext);
                return;
            }

            // Connect to via Device IP address
            string ipAddress = "192.168.16.224";
            ushort port      = 51211;
            uint   deviceId  = 0;

            //ADD------ BS_SDK_ERROR_CANNOT_CONNECT_SOCKET error test
            IntPtr ptrIPAddr = Marshal.StringToHGlobalAnsi(ipAddress);


            //result = (BS2ErrorCode)API.BS2_ConnectDeviceViaIP(context, ipAddress, port, out deviceId);
            result = (BS2ErrorCode)API.BS2_ConnectDeviceViaIP(sdkContext, ptrIPAddr, port, out deviceId);


            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Connecting to device failed : {0}", result);
                return;
            }

            Marshal.FreeHGlobal(ptrIPAddr);
            Console.WriteLine("Connected");

            BS2SimpleDeviceInfo deviceInfo;

            result = (BS2ErrorCode)API.BS2_GetDeviceInfo(sdkContext, deviceId, out deviceInfo);
            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("BS2_GetDeviceInfo failed. Error : {0}", result);
                return;
            }



            BS2FingerprintTemplateFormatEnum  templateFormat        = BS2FingerprintTemplateFormatEnum.FORMAT_SUPREMA;
            SortedSet <BS2CardAuthModeEnum>   privateCardAuthMode   = new SortedSet <BS2CardAuthModeEnum>();
            SortedSet <BS2FingerAuthModeEnum> privateFingerAuthMode = new SortedSet <BS2FingerAuthModeEnum>();
            SortedSet <BS2IDAuthModeEnum>     privateIDAuthMode     = new SortedSet <BS2IDAuthModeEnum>();

            bool cardSupported   = Convert.ToBoolean(deviceInfo.cardSupported);
            bool fingerSupported = Convert.ToBoolean(deviceInfo.fingerSupported);
            bool pinSupported    = Convert.ToBoolean(deviceInfo.pinSupported);

            privateIDAuthMode.Add(BS2IDAuthModeEnum.PROHIBITED);

            if (cardSupported)
            {
                privateCardAuthMode.Add(BS2CardAuthModeEnum.PROHIBITED);
                privateCardAuthMode.Add(BS2CardAuthModeEnum.CARD_ONLY);

                if (pinSupported)
                {
                    privateCardAuthMode.Add(BS2CardAuthModeEnum.CARD_PIN);

                    privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_PIN);

                    if (fingerSupported)
                    {
                        privateCardAuthMode.Add(BS2CardAuthModeEnum.CARD_BIOMETRIC_OR_PIN);
                        privateCardAuthMode.Add(BS2CardAuthModeEnum.CARD_BIOMETRIC_PIN);

                        privateFingerAuthMode.Add(BS2FingerAuthModeEnum.BIOMETRIC_PIN);

                        privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_BIOMETRIC_OR_PIN);
                        privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_BIOMETRIC_PIN);
                    }
                }

                if (fingerSupported)
                {
                    privateCardAuthMode.Add(BS2CardAuthModeEnum.CARD_BIOMETRIC);

                    privateFingerAuthMode.Add(BS2FingerAuthModeEnum.BIOMETRIC_ONLY);

                    privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_BIOMETRIC);
                }
            }
            else if (fingerSupported)
            {
                if (pinSupported)
                {
                    privateFingerAuthMode.Add(BS2FingerAuthModeEnum.BIOMETRIC_PIN);

                    privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_BIOMETRIC_OR_PIN);
                    privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_BIOMETRIC_PIN);
                }

                privateFingerAuthMode.Add(BS2FingerAuthModeEnum.BIOMETRIC_ONLY);

                privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_BIOMETRIC);
            }
            else if (pinSupported)
            {
                privateIDAuthMode.Add(BS2IDAuthModeEnum.ID_PIN);
            }

            BS2UserBlob[] userBlob = Util.AllocateStructureArray <BS2UserBlob>(1);
            userBlob[0].user.version        = 0;
            userBlob[0].user.formatVersion  = 0;
            userBlob[0].user.faceChecksum   = 0;
            userBlob[0].user.fingerChecksum = 0;
            userBlob[0].user.numCards       = 0;
            userBlob[0].user.numFingers     = 0;
            userBlob[0].user.numFaces       = 0;

            userBlob[0].cardObjs   = IntPtr.Zero;
            userBlob[0].fingerObjs = IntPtr.Zero;
            userBlob[0].faceObjs   = IntPtr.Zero;

            Console.WriteLine("Enter the ID for the User which you want to enroll");
            Console.Write(">>>> ");
            string userID = Console.ReadLine();

            if (userID.Length == 0)
            {
                Console.WriteLine("The user id can not be empty.");
                return;
            }
            else if (userID.Length > BS2Environment.BS2_USER_ID_SIZE)
            {
                Console.WriteLine("The user id should less than {0} words.", BS2Environment.BS2_USER_ID_SIZE);
                return;
            }
            else
            {
                //TODO Alphabet user id is not implemented yet.
                UInt32 uid;
                if (!UInt32.TryParse(userID, out uid))
                {
                    Console.WriteLine("The user id should be a numeric.");
                    return;
                }

                byte[] userIDArray = Encoding.UTF8.GetBytes(userID);
                Array.Clear(userBlob[0].user.userID, 0, BS2Environment.BS2_USER_ID_SIZE);
                Array.Copy(userIDArray, userBlob[0].user.userID, userIDArray.Length);
            }

            Console.WriteLine("When is this user valid from? [default(Today), yyyy-MM-dd HH:mm:ss]");
            Console.Write(">>>> ");
            //if (!Util.GetTimestamp("yyyy-MM-dd HH:mm:ss", 0, out userBlob[0].setting.startTime))
            //{
            //    return;
            //}
            userBlob[0].setting.startTime = 1262307661; //2010-01-01 01:01:01

            Console.WriteLine("When is this user valid to? [default(Today), yyyy-MM-dd HH:mm:ss]");
            Console.Write(">>>> ");
            //if (!Util.GetTimestamp("yyyy-MM-dd HH:mm:ss", 0, out userBlob[0].setting.endTime))
            //{
            //    return;
            //}
            userBlob[0].setting.endTime = 1893459661; //2030-01-01 01:01:01

            if (fingerSupported)
            {
                Console.WriteLine("Enter the security level for this user: [{0}: {1}, {2}: {3}, {4}: {5}(default), {6}: {7}, {8}: {9}]",
                                  (byte)BS2UserSecurityLevelEnum.LOWER,
                                  BS2UserSecurityLevelEnum.LOWER,
                                  (byte)BS2UserSecurityLevelEnum.LOW,
                                  BS2UserSecurityLevelEnum.LOW,
                                  (byte)BS2UserSecurityLevelEnum.NORMAL,
                                  BS2UserSecurityLevelEnum.NORMAL,
                                  (byte)BS2UserSecurityLevelEnum.HIGH,
                                  BS2UserSecurityLevelEnum.HIGH,
                                  (byte)BS2UserSecurityLevelEnum.HIGHER,
                                  BS2UserSecurityLevelEnum.HIGHER);
                Console.Write(">>>> ");
                userBlob[0].setting.securityLevel = Util.GetInput((byte)BS2UserSecurityLevelEnum.NORMAL);

                userBlob[0].setting.fingerAuthMode = (byte)BS2FingerAuthModeEnum.NONE;



                Array.Clear(userBlob[0].name, 0, BS2Environment.BS2_USER_NAME_LEN);

                userBlob[0].photo.size = 0;
                Array.Clear(userBlob[0].photo.data, 0, BS2Environment.BS2_USER_PHOTO_SIZE);
                Array.Clear(userBlob[0].pin, 0, BS2Environment.BS2_PIN_HASH_SIZE);



                if (fingerSupported)
                {
                    Console.WriteLine("How many fingerprints do you want to register? [1(default) - {0}]", BS2Environment.BS2_MAX_NUM_OF_FINGER_PER_USER);
                    Console.Write(">>>> ");
                    userBlob[0].user.numFingers = Util.GetInput((byte)1);

                    if (userBlob[0].user.numFingers > 0)
                    {
                        BS2FingerprintConfig fingerprintConfig;
                        Console.WriteLine("Trying to get fingerprint config");
                        result = (BS2ErrorCode)API.BS2_GetFingerprintConfig(sdkContext, deviceId, out fingerprintConfig);
                        if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                        {
                            Console.WriteLine("Got error({0}).", result);
                            return;
                        }
                        else
                        {
                            templateFormat = (BS2FingerprintTemplateFormatEnum)fingerprintConfig.templateFormat;
                        }

                        int            structSize  = Marshal.SizeOf(typeof(BS2Fingerprint));
                        BS2Fingerprint fingerprint = Util.AllocateStructure <BS2Fingerprint>();
                        userBlob[0].fingerObjs = Marshal.AllocHGlobal(structSize * userBlob[0].user.numFingers);
                        IntPtr curFingerObjs = userBlob[0].fingerObjs;

                        /*
                         * Console.WriteLine("Place your finger");
                         * ufs_res = Scanner.ClearCaptureImageBuffer();
                         * ufs_res = Scanner.CaptureSingleImage();
                         * ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, Template, out TemplateSize, out EnrollQuality);
                         * byte[] template0 = Template;
                         *
                         * Console.WriteLine("Place your finger once more");
                         * ufs_res = Scanner.ClearCaptureImageBuffer();
                         * ufs_res = Scanner.CaptureSingleImage();
                         * ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, Template, out TemplateSize, out EnrollQuality);
                         * byte[] template1 = Template;
                         *
                         * System.Buffer.BlockCopy(template0, 0, fingerprint.data, 0, template0.Length);
                         * System.Buffer.BlockCopy(template1, 0, fingerprint.data, template0.Length, template1.Length);
                         */


                        Console.WriteLine("Place your finger");
                        ufs_res = Scanner.ClearCaptureImageBuffer();
                        ufs_res = Scanner.CaptureSingleImage();

                        if (ufs_res == UFS_STATUS.OK)
                        {
                            Console.WriteLine("1st capturing succeeded");
                        }
                        else
                        {
                            Console.WriteLine("1st capturing failed");
                            return;
                        }

                        ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, Template0, out TemplateSize, out EnrollQuality);

                        if (ufs_res == UFS_STATUS.OK)
                        {
                            Console.WriteLine("1st extraction succeeded");
                        }
                        else
                        {
                            Console.WriteLine("1st extraction failed");
                            return;
                        }
                        Console.WriteLine("Place your finger once more");



                        ufs_res = Scanner.ClearCaptureImageBuffer();
                        ufs_res = Scanner.CaptureSingleImage();
                        if (ufs_res == UFS_STATUS.OK)
                        {
                            Console.WriteLine("2nd capturing succeeded");
                        }
                        else
                        {
                            Console.WriteLine("2nd capturing failed");
                            return;
                        }


                        ufs_res = Scanner.ExtractEx(MAX_TEMPLATE_SIZE, Template1, out TemplateSize, out EnrollQuality);

                        if (ufs_res == UFS_STATUS.OK)
                        {
                            Console.WriteLine("2nd extraction succeeded");
                        }
                        else
                        {
                            Console.WriteLine("2nd extraction failed");
                            return;
                        }

                        System.Buffer.BlockCopy(Template0, 0, fingerprint.data, 0, Template0.Length);
                        System.Buffer.BlockCopy(Template1, 0, fingerprint.data, Template0.Length, Template1.Length);
                        fingerprint.flag  = 0; //Not Duress Finger
                        fingerprint.index = 0; //1st Finger



                        Array.Clear(userBlob[0].accessGroupId, 0, BS2Environment.BS2_MAX_ACCESS_GROUP_PER_USER);

                        Console.WriteLine("Which access groups does this user belongs to? [ex. ID_1 ID_2 ...]");
                        Console.Write(">>>> ");
                        int      accessGroupIdIndex = 0;
                        char[]   delimiterChars     = { ' ', ',', '.', ':', '\t' };
                        string[] accessGroupIDs     = Console.ReadLine().Split(delimiterChars);

                        foreach (string accessGroupID in accessGroupIDs)
                        {
                            if (accessGroupID.Length > 0)
                            {
                                UInt32 item;
                                if (UInt32.TryParse(accessGroupID, out item))
                                {
                                    userBlob[0].accessGroupId[accessGroupIdIndex++] = item;
                                }
                            }
                        }

                        Marshal.StructureToPtr(fingerprint, curFingerObjs, false);
                        curFingerObjs += structSize;

                        result = (BS2ErrorCode)API.BS2_EnrolUser(sdkContext, deviceId, userBlob, 1, 1);
                        if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                        {
                            Console.WriteLine("Failed : {0}", result);
                            return;
                        }
                    }
                }
            }
        }