VERSION 5.00
Begin VB.Form frmMain 
   BorderStyle     =   3  'ũ  ȭ 
   Caption         =   "Form1"
   ClientHeight    =   10275
   ClientLeft      =   45
   ClientTop       =   345
   ClientWidth     =   6885
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   10275
   ScaleWidth      =   6885
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows ⺻
   Begin VB.PictureBox Picture1 
      Height          =   10575
      Left            =   0
      Picture         =   "frmMain.frx":0000
      ScaleHeight     =   10515
      ScaleWidth      =   1755
      TabIndex        =   36
      Top             =   0
      Width           =   1815
   End
   Begin VB.Frame Frame4 
      Caption         =   "4) Verification"
      Height          =   1815
      Left            =   2040
      TabIndex        =   34
      Top             =   7800
      Width           =   4695
      Begin VB.OptionButton radioTextFIR 
         Caption         =   "Text stream of FIR"
         Height          =   255
         Left            =   1680
         TabIndex        =   17
         Top             =   720
         Width           =   2535
      End
      Begin VB.OptionButton radioBinaryFIR 
         Caption         =   "Binary of FIR"
         Height          =   255
         Left            =   1680
         TabIndex        =   16
         Top             =   360
         Value           =   -1  'True
         Width           =   2655
      End
      Begin VB.CommandButton btnVerify 
         Caption         =   "Verify"
         Height          =   375
         Left            =   3120
         TabIndex        =   18
         Top             =   1320
         Width           =   1215
      End
      Begin VB.Line Line4 
         BorderColor     =   &H8000000A&
         X1              =   240
         X2              =   4440
         Y1              =   1200
         Y2              =   1200
      End
      Begin VB.Label Label12 
         Caption         =   "Verify with..."
         Height          =   255
         Left            =   240
         TabIndex        =   35
         Top             =   360
         Width           =   1215
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "3) Enrollment"
      Height          =   1455
      Left            =   2040
      TabIndex        =   32
      Top             =   6240
      Width           =   4695
      Begin VB.CheckBox chkAutoDetect 
         Caption         =   "Auto Detect"
         Height          =   180
         Left            =   360
         TabIndex        =   37
         Top             =   1080
         Width           =   1335
      End
      Begin VB.CommandButton btnRemove 
         Caption         =   "Remove"
         Height          =   375
         Left            =   1800
         TabIndex        =   14
         Top             =   960
         Width           =   1215
      End
      Begin VB.CommandButton btnEnroll 
         Caption         =   "Enroll"
         Height          =   375
         Left            =   3120
         TabIndex        =   15
         Top             =   960
         Width           =   1215
      End
      Begin VB.TextBox txtPayload 
         Appearance      =   0  '
         Height          =   270
         Left            =   1320
         TabIndex        =   13
         Top             =   360
         Width           =   3015
      End
      Begin VB.Line Line3 
         BorderColor     =   &H8000000A&
         X1              =   240
         X2              =   4440
         Y1              =   840
         Y2              =   840
      End
      Begin VB.Label Label11 
         Caption         =   "Payload:"
         Height          =   255
         Left            =   240
         TabIndex        =   33
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "2) Device info."
      Height          =   2295
      Left            =   2040
      TabIndex        =   28
      Top             =   3840
      Width           =   4695
      Begin VB.CommandButton btnSelect 
         Caption         =   "Select"
         Height          =   375
         Left            =   3120
         TabIndex        =   10
         Top             =   720
         Width           =   1215
      End
      Begin VB.TextBox txtWidth 
         Appearance      =   0  '
         Enabled         =   0   'False
         Height          =   270
         Left            =   3480
         TabIndex        =   11
         Text            =   "Text1"
         Top             =   1440
         Width           =   855
      End
      Begin VB.TextBox txtHeight 
         Appearance      =   0  '
         Enabled         =   0   'False
         Height          =   270
         Left            =   3480
         TabIndex        =   12
         Text            =   "Text1"
         Top             =   1800
         Width           =   855
      End
      Begin VB.ComboBox comboDevice 
         Height          =   300
         Left            =   1320
         Style           =   2  'Ӵٿ 
         TabIndex        =   9
         Top             =   360
         Width           =   3015
      End
      Begin VB.Line Line2 
         BorderColor     =   &H8000000A&
         X1              =   240
         X2              =   4440
         Y1              =   1200
         Y2              =   1200
      End
      Begin VB.Label Label10 
         Alignment       =   1  ' 
         Caption         =   "Width of image (pixel):"
         Height          =   255
         Left            =   720
         TabIndex        =   31
         Top             =   1440
         Width           =   2535
      End
      Begin VB.Label Label9 
         Alignment       =   1  ' 
         Caption         =   "Height of image (pixel):"
         Height          =   255
         Left            =   720
         TabIndex        =   30
         Top             =   1800
         Width           =   2535
      End
      Begin VB.Label Label8 
         Caption         =   "Device ID:"
         Height          =   255
         Left            =   240
         TabIndex        =   29
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "1) Init Info. for BSP"
      Height          =   3615
      Left            =   2040
      TabIndex        =   19
      Top             =   120
      Width           =   4695
      Begin VB.CommandButton btnRefresh 
         Caption         =   "Refresh"
         Height          =   375
         Left            =   1800
         TabIndex        =   7
         Top             =   3120
         Width           =   1215
      End
      Begin VB.CommandButton btnSet 
         Caption         =   "Set"
         Height          =   375
         Left            =   3120
         TabIndex        =   8
         Top             =   3120
         Width           =   1215
      End
      Begin VB.TextBox txtIdentifySecuLevel 
         Appearance      =   0  '
         Height          =   270
         Left            =   3480
         TabIndex        =   6
         Text            =   "Text1"
         Top             =   2520
         Width           =   855
      End
      Begin VB.TextBox txtVerifySecuLevel 
         Appearance      =   0  '
         Height          =   270
         Left            =   3480
         TabIndex        =   5
         Text            =   "Text1"
         Top             =   2160
         Width           =   855
      End
      Begin VB.TextBox txtEnrollSecuLevel 
         Appearance      =   0  '
         Height          =   270
         Left            =   3480
         TabIndex        =   4
         Text            =   "Text1"
         Top             =   1800
         Width           =   855
      End
      Begin VB.TextBox txtDefaultTimeout 
         Appearance      =   0  '
         Height          =   270
         Left            =   3480
         TabIndex        =   3
         Text            =   "Text1"
         Top             =   1440
         Width           =   855
      End
      Begin VB.TextBox txtSamplesPerFinger 
         Appearance      =   0  '
         Enabled         =   0   'False
         Height          =   270
         Left            =   3480
         TabIndex        =   2
         Text            =   "Text1"
         Top             =   1080
         Width           =   855
      End
      Begin VB.TextBox txtNecessaryNum 
         Appearance      =   0  '
         Height          =   270
         Left            =   3480
         TabIndex        =   1
         Text            =   "Text1"
         Top             =   720
         Width           =   855
      End
      Begin VB.TextBox txtMaxFinger 
         Appearance      =   0  '
         Height          =   270
         Left            =   3480
         TabIndex        =   0
         Text            =   "Text1"
         Top             =   360
         Width           =   855
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000A&
         X1              =   240
         X2              =   4440
         Y1              =   3000
         Y2              =   3000
      End
      Begin VB.Label Label7 
         Alignment       =   1  ' 
         Caption         =   "Security level for identify:"
         Height          =   255
         Left            =   720
         TabIndex        =   27
         Top             =   2520
         Width           =   2535
      End
      Begin VB.Label Label6 
         Alignment       =   1  ' 
         Caption         =   "Security level for verify:"
         Height          =   255
         Left            =   720
         TabIndex        =   26
         Top             =   2160
         Width           =   2535
      End
      Begin VB.Label Label5 
         Alignment       =   1  ' 
         Caption         =   "Security level for enroll:"
         Height          =   255
         Left            =   720
         TabIndex        =   25
         Top             =   1800
         Width           =   2535
      End
      Begin VB.Label Label4 
         Alignment       =   1  ' 
         Caption         =   "Default timeout (ms):"
         Height          =   255
         Left            =   720
         TabIndex        =   24
         Top             =   1440
         Width           =   2535
      End
      Begin VB.Label Label3 
         Alignment       =   1  ' 
         Caption         =   "Samples per finger:"
         Height          =   255
         Left            =   720
         TabIndex        =   23
         Top             =   1080
         Width           =   2535
      End
      Begin VB.Label Label2 
         Alignment       =   1  ' 
         Caption         =   "Necessary enroll num:"
         Height          =   255
         Left            =   720
         TabIndex        =   22
         Top             =   720
         Width           =   2535
      End
      Begin VB.Label Label1 
         Alignment       =   1  ' 
         Caption         =   "Max finger for enroll:"
         Height          =   255
         Left            =   720
         TabIndex        =   21
         Top             =   360
         Width           =   2535
      End
   End
   Begin VB.Label labelStatus 
      Appearance      =   0  '
      BackColor       =   &H80000005&
      BorderStyle     =   1  ' 
      Caption         =   "Label1"
      ForeColor       =   &H80000008&
      Height          =   375
      Left            =   2040
      TabIndex        =   20
      Top             =   9720
      Width           =   4695
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Declaration global variables
Dim WithEvents objUCBioBSP As UCBioBSPCOMLib.UCBioBSP
Attribute objUCBioBSP.VB_VarHelpID = -1

Dim objDevice As IDevice                ' Device object
Dim objExtraction As IExtraction        ' Extraction object
Dim objMatching As IMatching            ' Matching object

Dim szTextEnrolledFIR As String
Dim binaryEnrolledFIR() As Byte

Private Sub SetButtonStatus()
    If szTextEnrolledFIR <> "" Then
        btnEnroll.Caption = "Modify"
        btnVerify.Enabled = True
        btnRemove.Enabled = True
    Else
        btnEnroll.Caption = "Enroll"
        btnVerify.Enabled = False
        btnRemove.Enabled = False
    End If
End Sub
Private Sub btnEnroll_Click()
    Dim szPayload As String
    
    ' Get Payload
    szPayload = txtPayload.Text
    
    If chkAutoDetect.Value = True Then
        Call objDevice.SetAutoDetect(1)
    Else
        Call objDevice.SetAutoDetect(0)
    End If
    
    
    ' Enroll
    Call objExtraction.Enroll(szPayload, szTextEnrolledFIR)
    
    If objUCBioBSP.ErrorCode = 0 Then
        ' Get binary encoded FIR data
        binaryEnrolledFIR = objExtraction.FIR
        
        ' Get text encoded FIR data
        szTextEnrolledFIR = objExtraction.TextFIR
        
        labelStatus.Caption = "Succeeded to enroll."
    Else
        labelStatus.Caption = "Failed to enroll - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
    
    ' Set button status
    Call SetButtonStatus
End Sub

Private Sub btnRefresh_Click()
    txtMaxFinger.Text = objUCBioBSP.MaxFingersForEnroll
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    txtNecessaryNum.Text = objUCBioBSP.NecessaryEnrollNum
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    txtSamplesPerFinger.Text = objUCBioBSP.SamplesPerFinger
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    txtDefaultTimeout.Text = objUCBioBSP.DefaultTimeout
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    txtEnrollSecuLevel.Text = objUCBioBSP.SecurityLevelForEnroll
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    txtVerifySecuLevel.Text = objUCBioBSP.SecurityLevelForVerify
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    txtIdentifySecuLevel.Text = objUCBioBSP.SecurityLevelForIdentify
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR

    labelStatus.Caption = "Succeeded to get information."
    Exit Sub

ERROR:
    labelStatus.Caption = "Failed to get Information. (" & objUCBioBSP.ErrorDescription & ")"
    
End Sub

Private Sub btnRemove_Click()
    szTextEnrolledFIR = ""
    
    ' Set button status
    Call SetButtonStatus
End Sub

Private Sub btnSelect_Click()
    ' Select device type
    nNameID = 0
    If comboDevice.ListIndex > 0 Then
        nNameID = objDevice.EnumDeviceNameID(comboDevice.ListIndex - 1)
    End If
    
    If comboDevice.ListIndex > 0 Then
        iDeviceID = objDevice.DeviceID(nNameID, objDevice.EnumDeviceInstance(comboDevice.ListIndex - 1))
    Else
        iDeviceID = &HFF 'Auto
    End If
    
    ' Close Device if before opened
    Call objDevice.Close(objDevice.OpenedDeviceID)
    
    ' Open device
    Call objDevice.Open(iDeviceID)
    
    If objUCBioBSP.ErrorCode = 0 Then
        btnEnroll.Enabled = True

        labelStatus.Caption = "Succeeded to open device."
        
        If comboDevice.ListIndex > 0 Then
            nNameID = objDevice.EnumDeviceNameID(comboDevice.ListIndex - 1)
            If nNameID <> 0 Then
                labelStatus.Caption = labelStatus.Caption & " - " & objDevice.EnumDeviceDescription(comboDevice.ListIndex - 1)
            End If
            
        Else
            labelStatus.Caption = labelStatus.Caption & " - " & "Auto Detect Device"
        End If
    Else
        btnEnroll.Enabled = False
        labelStatus.Caption = "Failed to open device! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
    
    txtWidth.Text = objDevice.ImageWidth(iDeviceID)
    txtHeight.Text = objDevice.ImageHeight(iDeviceID)
   
End Sub

Private Sub btnSet_Click()
    objUCBioBSP.MaxFingersForEnroll = txtMaxFinger.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    objUCBioBSP.NecessaryEnrollNum = txtNecessaryNum.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    objUCBioBSP.SamplesPerFinger = txtSamplesPerFinger.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    objUCBioBSP.DefaultTimeout = txtDefaultTimeout.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    objUCBioBSP.SecurityLevelForEnroll = txtEnrollSecuLevel.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    objUCBioBSP.SecurityLevelForVerify = txtVerifySecuLevel.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    objUCBioBSP.SecurityLevelForIdentify = txtIdentifySecuLevel.Text
    If objUCBioBSP.ErrorCode <> 0 Then GoTo ERROR
    
    labelStatus.Caption = "Succeeded to set information."
    Exit Sub

ERROR:
    labelStatus.Caption = "Failed to set Information. (" & objUCBioBSP.ErrorDescription & ")"
End Sub

Private Sub btnVerify_Click()
    ' Verify
    If radioBinaryFIR.Value Then
        Call objMatching.Verify(binaryEnrolledFIR)  ' Verify with binary FIR
    Else
        Call objMatching.Verify(szTextEnrolledFIR)  ' Verify with text encoded FIR
    End If
    
    If objUCBioBSP.ErrorCode <> 0 Then
        labStatus.Caption = "Verify Function Failed ! - " & objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
        Exit Sub
    End If

    ' Check result of verify
    If objMatching.MatchingResult Then
        ' Check payload
        If objMatching.IsPayloadExisted Then
            labelStatus.Caption = "Verify Succeeded! [" & objMatching.TextPayload & "]"
        Else
            labelStatus.Caption = "Verify Succeeded!"
        End If
    Else
        ' Show fail message.
        labStatus.Caption = "Verify Failed!"
    End If
    
    Call MsgBox(labelStatus.Caption, vbInformation)
End Sub

Private Sub Form_Load()
    ' Set default value
    szTextEnrolledFIR = ""
    
    btnEnroll.Enabled = False
    btnRemove.Enabled = False
    btnVerify.Enabled = False


    ' Create UCBioBSP object
    Set objUCBioBSP = New UCBioBSPCOMLib.UCBioBSP
    Set objDevice = objUCBioBSP.Device
    Set objExtraction = objUCBioBSP.Extraction
    Set objMatching = objUCBioBSP.Matching
    
    ' Check initialize object
    If objUCBioBSP.ErrorCode = 0 Then
        ' Get UCBioBSP version
        frmMain.Caption = "VB Sample - UCBioBSP Version : " & objUCBioBSP.MajorVersion & "." & objUCBioBSP.MinorVersion

        ' Enumerate Device
        Dim i As Integer
    
        Call objDevice.Enumerate
        labelStatus.Caption = objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    
        comboDevice.AddItem "Auto_Detect"
        For i = 0 To objDevice.EnumCount - 1
            nNameID = objDevice.EnumDeviceNameID(i)
            If nNameID <> 0 Then
                comboDevice.AddItem objDevice.EnumDeviceName(i) & " - " & objDevice.EnumDeviceDescription(i)
            End If
        Next i
        
        comboDevice.ListIndex = 0
        
        Call btnRefresh_Click
        Call btnSelect_Click
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly
    End If
    
End Sub


