Esempio n. 1
0
        public void EnumerateDevices()
        {
            String deviceList = BioNetACSDLL._GetUSNList();

            foreach (var deviceName in deviceList.Split(','))
            {
                if (ActiveDevices.OfType <DeviceIB>().Any(dev => dev.name == deviceName))
                {
                    continue;
                }
                var error = BioNetACSDLL._OpenNetAccessDeviceByUSN(deviceName);
                if (error != 1)
                {
                    break;
                }
                else
                {
                    BioNetACSDLL._CloseNetAccessDevice();
                }

                DeviceIB device = new DeviceIB(deviceName);
                ActiveDevices.Add(device);
            }

            List <DeviceIB> toDeleteList = new List <DeviceIB>();

            foreach (var device in ActiveDevices.OfType <DeviceIB>())
            {
                bool toDelete = true;
                foreach (var deviceName in deviceList.Split(','))
                {
                    if (deviceName == device.name)
                    {
                        toDelete = false;
                    }
                }
                if (toDelete)
                {
                    toDeleteList.Add(device);
                    device.Dispose();
                }
            }
            foreach (var device in toDeleteList)
            {
                ActiveDevices.Remove(device);
            }
        }
Esempio n. 2
0
        private void deviceThread()
        {
            STATE   state = STATE.IDLE;
            COMMAND com   = COMMAND.NONE;

            byte[]   image = null;
            byte[][] resultFeat = null;
            byte[][] imageStack = null;
            byte[][] FingerFeat = null;
            int      firstEnrollCount = 0, secondEnrollCount = 0;
            int      status = 0;

            BioNetACSDLL._AlgoInit();

            Thread.Sleep(1000);
            var error = BioNetACSDLL._OpenNetAccessDeviceByUSN(name);

            if (error != 1)
            {
                throw new Exception("Can't open device");
            }


            int uniqueUsbKey = BioNetACSDLL._GetUSBKey();
            int imageSize    = BioNetACSDLL._GetImgSize();
            int imageWidth   = BioNetACSDLL._GetImgWidth();
            int imageHeight  = BioNetACSDLL._GetImgSize() / BioNetACSDLL._GetImgWidth();

            FingerFeat = new byte[MAX_FEATURE][];
            for (int i = 0; i < MAX_FEATURE; i++)
            {
                FingerFeat[i] = new byte[BioNetACSDLL._GetFeatSize()];
            }

            try
            {
                while (true)
                {
                    cancelToken.Token.ThrowIfCancellationRequested();

                    if (state == STATE.IDLE)
                    {
                        com = queue.Take(cancelToken.Token);
                    }
                    else
                    {
                        // non blocking take
                        if (queue.Count > 0)
                        {
                            com = queue.Take();
                        }
                    }

                    switch (com)
                    {
                    case COMMAND.LIVECAPTURE_START:
                        state = STATE.TEST;
                        break;

                    case COMMAND.SINGLECAPTURE_START:
                        state = STATE.GETSINGLE;
                        break;

                    case COMMAND.ENROLLMENT_START:
                        state      = STATE.GETFINGER_1;
                        resultFeat = new byte[2][];
                        for (int i = 0; i < 2; i++)
                        {
                            resultFeat[i] = new byte[BioNetACSDLL._GetFeatSize()];
                        }

                        imageStack = new byte[ENROLL_IMAGES * 2][];
                        for (int i = 0; i < ENROLL_IMAGES * 2; i++)
                        {
                            imageStack[i] = new byte[imageSize];
                        }

                        firstEnrollCount  = 0;
                        secondEnrollCount = 0;
                        resultBios.Clear();
                        break;

                    case COMMAND.LIVECAPTURE_STOP:
                    case COMMAND.SINGLECAPTURE_STOP:
                    case COMMAND.ENROLLMENT_STOP:
                        state = STATE.IDLE;
                        break;
                    }
                    com = COMMAND.NONE;

                    if (uniqueUsbKey != BioNetACSDLL._GetUSBKey())
                    {
                        if (state != STATE.OFFLINE)
                        {
                            state = STATE.OFFLINE;
                            Ambassador.AddMessage(new MSignal(this, MSignal.SIGNAL.DEVICE_FAILURE));
                        }
                    }

                    switch (state)
                    {
                    case STATE.TEST:
                        image  = new byte[imageSize];
                        status = BioNetACSDLL._GetNetAccessImage(image);
                        switch (status)
                        {
                        // not connected
                        case -1:
                            state = STATE.OFFLINE;
                            SendBaseMessage("Scanner is not connected");
                            break;

                        case 0:
                            SendBaseMessage("Please, touch the scanner");
                            break;

                        default:
                            break;
                        }
                        OnBiometricsCaptured(new FingerImageIB(image,imageWidth,imageHeight));
                        break;

                    case STATE.GETSINGLE:
                        SendBaseMessage("Please, touch the scanner");
                        image  = new byte[imageSize];
                        status = BioNetACSDLL._GetNetAccessImage(image);

                        switch (status)
                        {
                        // not connected
                        case -1:
                            SendPopUpMessage("Scanner is not connected");
                            break;

                        case 0:
                            break;

                        case 1:
                            int qual = BioNetACSDLL._GetIBQualityScore(image);
                            if (qual > NEEDED_QUALITY)
                            {
                                goto default;
                            }
                            SendPopUpMessage("Image quality " + qual + " not enough, keep finger on scanner");
                            OnBiometricsCaptured(new FingerImageIB(image,imageWidth,imageHeight));
                            break;

                        default:
                            OnSingleCaptured(new FingerImageIB(image,imageWidth,imageHeight));
                            state = STATE.LIFTSINGLE;
                            break;
                        }
                        break;

                    case STATE.LIFTSINGLE:
                        image  = new byte[imageSize];
                        status = BioNetACSDLL._GetNetAccessImage(image);
                        BioNetACSDLL._ControlTOUCH(false);
                        switch (status)
                        {
                        // not connected
                        case -1:
                            SendPopUpMessage("Scanner is not connected");
                            break;

                        case 0:
                            state = STATE.GETSINGLE;
                            break;

                        default:
                            //SendPopUpMessage("Please, remove finger from the scanner");
                            break;
                        }
                        break;

                    case STATE.GETFINGER_1:
                        image = new byte[imageSize];
                        state = STATE.GETIMAGE_1;
                        BioNetACSDLL._ChangeGain(0);
                        break;

                    case STATE.GETIMAGE_1:
                        status = BioNetACSDLL._GetNetAccessImageByManual(image);
                        switch (status)
                        {
                        // not connected
                        case -1:
                            SendPopUpMessage("Scanner is not connected");
                            break;

                        case 0:
                            SendBaseMessage("Please, touch the scanner");
                            break;

                        case 1:
                            int qual = BioNetACSDLL._GetIBQualityScore(image);
                            if (qual > NEEDED_QUALITY)
                            {
                                goto default;
                            }
                            SendPopUpMessage("Image quality " + qual + " not enough, keep finger on scanner");
                            OnBiometricsCaptured(new FingerImageIB(image,imageWidth,imageHeight));
                            break;

                        default:
                            Array.Copy(image,imageStack[firstEnrollCount],imageSize);

                            OnBiometricsCaptured(new FingerImageIB(image,imageWidth,imageHeight));

                            firstEnrollCount++;
                            OnSendProgressMessage((firstEnrollCount) * 22);

                            state = STATE.GETEMPTY_1;

                            break;
                        }
                        break;

                    case STATE.GETEMPTY_1:
                        image  = new byte[imageSize];
                        status = BioNetACSDLL._GetNetAccessImage(image);
                        switch (status)
                        {
                        // not connected
                        case -1:
                            SendPopUpMessage("Scanner is not connected");
                            break;

                        case 0:
                            if (firstEnrollCount < 3)
                            {
                                state = STATE.GETFINGER_1;
                            }
                            else
                            {
                                int singeEnrolResult = BioNetACSDLL._Enroll_SingleTemplate(
                                    (byte[])imageStack[0],(byte[])imageStack[1],(byte[])imageStack[2],
                                    (byte[])FingerFeat[0],(byte[])FingerFeat[1],(byte[])FingerFeat[2],
                                    resultFeat[0]);
                                if (singeEnrolResult < 1)
                                {
                                    state = STATE.GETEMPTY_2;
                                }
                                else
                                {
                                    state = STATE.IDLE;
                                    resultBios.Add(new TemplateIB(resultFeat[0]));
                                    SendPopUpMessage("Successfully registered");
                                    OnBiometricsEnrolled(resultBios.ToList());
                                }
                            }
                            break;

                        default:
                            SendPopUpMessage("Please, remove finger from the scanner");
                            break;
                        }
                        break;

                    case STATE.GETFINGER_2:
                        image = new byte[imageSize];
                        state = STATE.GETIMAGE_2;
                        break;

                    case STATE.GETIMAGE_2:
                        status = BioNetACSDLL._GetNetAccessImageByManual(image);
                        switch (status)
                        {
                        // not connected
                        case -1:
                            SendPopUpMessage("Scanner is not connected");
                            break;

                        case 0:
                            SendBaseMessage("Please, touch the scanner");
                            break;

                        case 1:
                            int qual = BioNetACSDLL._GetIBQualityScore(image);
                            if (qual > NEEDED_QUALITY)
                            {
                                goto default;
                            }
                            SendPopUpMessage("Image quality " + qual + " not enough, keep finger on scanner");
                            OnBiometricsCaptured(new FingerImageIB(image, imageWidth, imageHeight));
                            break;

                        default:
                            Array.Copy(image, imageStack[secondEnrollCount], imageSize);

                            OnBiometricsCaptured(new FingerImageIB(image, imageWidth, imageHeight));
                            secondEnrollCount++;
                            OnSendProgressMessage(66 + (secondEnrollCount) * 11);
                            state = STATE.GETEMPTY_2;
                            break;
                        }
                        break;

                    case STATE.GETEMPTY_2:
                        image  = new byte[imageSize];
                        status = BioNetACSDLL._GetNetAccessImage(image);
                        switch (status)
                        {
                        // not connected
                        case -1:
                            SendPopUpMessage("Scanner is not connected");
                            break;

                        case 0:
                            if (secondEnrollCount < 3)
                            {
                                state = STATE.GETFINGER_2;
                            }
                            else
                            {
                                int multiEnrollResult = BioNetACSDLL._Enroll_MultiTemplate(
                                    (byte[])FingerFeat[0], (byte[])FingerFeat[1], (byte[])FingerFeat[2],
                                    (byte[])imageStack[3], (byte[])imageStack[4], (byte[])imageStack[5],
                                    resultFeat[0], resultFeat[1]);
                                if (multiEnrollResult > 0)
                                {
                                    state = STATE.IDLE;
                                    resultBios.Add(new TemplateIB(resultFeat[0]));
                                    resultBios.Add(new TemplateIB(resultFeat[1]));
                                    SendPopUpMessage("Successfully registered");
                                    OnBiometricsEnrolled(resultBios.ToList());
                                }
                                else
                                {
                                    state = STATE.IDLE;
                                    SendPopUpMessage("Can't create template, please repeat");
                                    OnBiometricsEnrolled(null);
                                }
                            }
                            break;

                        default:
                            SendPopUpMessage("Please, remove finger from the scanner");
                            break;
                        }
                        break;

                    case STATE.OFFLINE:
                        break;
                    }
                }
            }
            catch
            {
                BioNetACSDLL._CloseNetAccessDevice();
            }
        }