Attribute VB_Name = "Start" Public Function BitShiftRight(ByVal intValue As Long, ByVal intShiftBy As Byte) As Variant 'Bit shifts a value to the right Dim lngShiftVal As Long lngShiftVal = 2 ^ intShiftBy BitShiftRight = Fix(intValue / lngShiftVal) End Function Public Function BitShiftLeft(ByVal intValue As Long, ByVal intShiftBy As Byte) As Variant 'Bit shift a value to the left Dim lngShiftVal As Long lngShiftVal = 2 ^ intShiftBy '1 BitShiftLeft = Fix(intValue * lngShiftVal) '2 End Function Public Sub Main() Dim handle As Long Dim result As Long Dim biostatoinID As Integer Dim numOfLog As Long Dim currentTime As Long Dim numOfUser As Long Dim numOfTemplate As Long Dim templateData() As Byte Dim fingerprintConfig As BSFingerprintConfig Dim ptr As Long Dim checksum As Long Dim seconds As Long Dim userHdr As BSUserhdr Dim userHdrs() As BSUserhdr Dim logRecord() As BSLogRecord Dim password As String result = BS_InitSDK() result = BS_OpenSocket("192.168.1.31", 1470, handle) If result <> 0 Then Debug.Print "Cannot open the communication channel : " & result Exit Sub End If result = BS_GetBiostationID(handle, biostationID) If result <> 0 Then Debug.Print "Cannot get the ID : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_SetBiostationID(handle, biostationID) If result <> 0 Then Debug.Print "Cannot set the ID : " & result BS_CloseSocket (handle) Exit Sub End If ReDim logRecord(32767) result = BS_ReadLog(handle, 0, 0, numOfLog, logRecord(0)) If result <> 0 Then Debug.Print ("Cannot read log record : " & result) BS_CloseSocket (handle) Exit Sub End If Debug.Print "Read " & numOfLog & " log records" seconds = DateDiff("s", "1/1/1970", Now) currentTime = seconds - 86400 ' local time result = BS_ReadLog(handle, currentTime, 0, numOfLog, logRecord(0)) If result <> 0 Then Debug.Print "Cannot read log record : " & result BS_CloseSocket (handle) Exit Sub End If Debug.Print "Read " & numOfLog & " log records" result = BS_ClearLogCache(handle) numOfLog = 0 Debug.Print "Please place finger on sensor" While numOfLog = 0 result = BS_ReadLogCache(handle, numOfLog, logRecord(0)) If result <> 0 Then Debug.Print "Cannot read log record : " & result BS_CloseSocket (handle) Exit Sub End If Wend result = BS_GetUserDBInfo(handle, numOfUser, numOfTemplate) If result <> 0 Then Debug.Print "Cannot get uesr DB info : " & result BS_CloseSocket (handle) Exit Sub End If Debug.Print "Enrolled user : " & numOfUser & " template : " & numOfTemplate userHdr.ID = 1 userHdr.reserved1 = 0 userHdr.adminLevel = 241 userHdr.securityLevel = 260 userHdr.statusMask = 0 userHdr.accessGroupMask = &HFFFFFFFF userHdr.username$ = "Test User" + Chr(0) ' null termination userHdr.department$ = "R&D" + Chr(0) ' null termination userHdr.numOfFinger = 1 userHdr.duressMask = &H0 ReDim templateData(384 * userHdr.numOfFinger * 2 - 1) For i = 0 To (userHdr.numOfFinger * 2) - 1 result = BS_ScanTemplate(handle, templateData(i * 384)) If result <> 0 Then Debug.Print "Cannot get the template data : " & result BS_Enable (handle) BS_CloseSocket (handle) Exit Sub End If checksum = 0 For j = 0 To 384 - 1 checksum = checksum + templateData(i * 384 + j) Next j userHdr.checksum(Int(i / 2) + 1) = BitShiftRight(checksum, 8) userHdr.checksum(Int(i / 2)) = checksum And &HFF Next i result = BS_DeleteAllUser(handle) If result <> 0 Then Debug.Print "Cannot delete all user : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_EnrollUser(handle, userHdr, templateData(0)) If result <> 0 Then Debug.Print "Cannot enroll a user : " & result BS_Enable (handle) BS_CloseSocket (handle) Exit Sub End If result = BS_Disable(handle, 20) result = BS_ReadFingerprintConfig(handle, fingerprintConfig) If result <> 0 Then Debug.Print "Cannot read fingerprint configuration : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_WriteFingerprintConfig(handle, fingerprintConfig) If result <> 0 Then Debug.Print "Cannot write fingerprint configuration : " & result BS_Enable (handle) BS_CloseSocket (handle) Exit Sub End If result = BS_GetTime(handle, timeVal) If result <> 0 Then Debug.Print "Cannot get time : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_SetTime(handle, timeVal) If result <> 0 Then Debug.Print "Cannot set time : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_GetUserInfo(handle, 1, userHdr) If result <> 0 Then Debug.Print "Cannot get user info(1) : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_GetUser(handle, 1, userHdr, templateData(0)) If result <> 0 Then Debug.Print "Cannot get user(1) : " & result BS_CloseSocket (handle) Exit Sub End If ReDim userHdrs(10) result = BS_GetAllUserInfo(handle, userHdrs(0), numOfUser) If result <> 0 Then Debug.Print "Cannot get all user : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_DeleteUser(handle, 1) If result <> 0 Then Debug.Print "Cannot delete user(1) : " & result BS_CloseSocket (handle) Exit Sub End If result = BS_GetLogCount(handle, numOfLog) If result <> 0 Then Debug.Print "Cannot get log count : " & result BS_CloseSocket (handle) Exit Sub End If Debug.Print "log count : " & numOfLog BS_Enable (handle) result = BS_Reset(handle) If result <> 0 Then Debug.Print "Cannot reset device : " & result BS_CloseSocket (handle) Exit Sub End If BS_CloseSocket (handle) End Sub