Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/eidReader/eidReader v2


You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/eidReader/eidReader v2

This example is the version from Fri, 16th Jan 2020.

Project "eidReader v2.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // register MBS Plugin here debugModule.init debugModule.start End EventHandler
EventHandler Function UnhandledException(error As RuntimeException) As Boolean If error <> Nil Then Dim type As String = Introspection.GetType(error).Name debugModule.Log(type + EndOfLine + EndOfLine + Join(error.Stack, EndOfLine)) MsgBox(type + EndOfLine + EndOfLine + Join(error.Stack, EndOfLine)) End If End EventHandler
End Class
EnableSmartCard
End EnableSmartCard
SetSandBoxFalse
End SetSandBoxFalse
Class wMain Inherits Window
ComputedProperty CardStatus As Boolean
Sub Set() If value = True Then OnRead Else OffRead ClearField End If End Set
End ComputedProperty
Control bbeID Inherits BevelButton
ControlInstance bbeID Inherits BevelButton
EventHandler Sub Action() Me.Enabled = False Me.CaptionDelta = -3 pwRC.Visible = True slotManager = New scsm slotManager.OpenFirstSlot lblOSlot.Text = slotManager.SlotID tmrCard.Period = 5000 tmrCard.Mode = Timer.ModeSingle tmrCard.Enabled = True End EventHandler
EventHandler Sub Open() Me.Bold = True 'OffRead End EventHandler
End Control
Control pwRC Inherits ProgressWheel
ControlInstance pwRC Inherits ProgressWheel
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control cPhoto Inherits Canvas
ControlInstance cPhoto Inherits Canvas
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control Label6 Inherits Label
ControlInstance Label6 Inherits Label
End Control
Control Label7 Inherits Label
ControlInstance Label7 Inherits Label
End Control
Control Label8 Inherits Label
ControlInstance Label8 Inherits Label
End Control
Control Label9 Inherits Label
ControlInstance Label9 Inherits Label
End Control
Control Label10 Inherits Label
ControlInstance Label10 Inherits Label
End Control
Control Label11 Inherits Label
ControlInstance Label11 Inherits Label
End Control
Control tfName Inherits TextField
ControlInstance tfName Inherits TextField
End Control
Control tfGN Inherits TextField
ControlInstance tfGN Inherits TextField
End Control
Control tfPoB Inherits TextField
ControlInstance tfPoB Inherits TextField
End Control
Control tfBirthDate Inherits TextField
ControlInstance tfBirthDate Inherits TextField
End Control
Control tfSex Inherits TextField
ControlInstance tfSex Inherits TextField
End Control
Control tfNISS Inherits TextField
ControlInstance tfNISS Inherits TextField
End Control
Control tfNationality Inherits TextField
ControlInstance tfNationality Inherits TextField
End Control
Control tfTitle Inherits TextField
ControlInstance tfTitle Inherits TextField
End Control
Control tfStreet Inherits TextField
ControlInstance tfStreet Inherits TextField
End Control
Control tfPostalCode Inherits TextField
ControlInstance tfPostalCode Inherits TextField
End Control
Control tfMunicipality Inherits TextField
ControlInstance tfMunicipality Inherits TextField
End Control
Control pbSavePict Inherits PushButton
ControlInstance pbSavePict Inherits PushButton
EventHandler Sub Action() If PhotoID <> Nil Then Dim f As FolderItem = GetSaveFolderItem("", "portrait.jpg") If f <> Nil Then PhotoID.Save(f, Picture.SaveAsJPEG) End If End If End EventHandler
End Control
Control Label12 Inherits Label
ControlInstance Label12 Inherits Label
End Control
Control lblOSlot Inherits Label
ControlInstance lblOSlot Inherits Label
End Control
Control lblReadCard Inherits Label
ControlInstance lblReadCard Inherits Label
End Control
Control pwReadCard Inherits ProgressWheel
ControlInstance pwReadCard Inherits ProgressWheel
End Control
Control tmrCard Inherits Timer
ControlInstance tmrCard Inherits Timer
EventHandler Sub Action() dh = slotManager.Dict If dh <> Nil Then If dh.HasKey("LastName") Then wmain.tfName.Text = dh.Value("LastName").StringValue End If If dh.HasKey("FirstName") Then wmain.tfGN.Text = dh.Value("FirstName").StringValue End If If dh.HasKey("PoB") Then wmain.tfPoB.Text = dh.Value("PoB").StringValue End If If dh.HasKey("DoB") Then wmain.tfBirthDate.Text = dh.Value("DoB").StringValue End If If dh.HasKey("Sex") Then wmain.tfSex.Text = dh.Value("Sex").StringValue End If If dh.HasKey("NISS") Then wmain.tfNISS.Text = dh.Value("NISS").StringValue End If If dh.HasKey("Nationality") Then wmain.tfNationality.Text = dh.Value("Nationality").StringValue End If If dh.HasKey("Street") Then wmain.tfStreet.Text = dh.Value("Street").StringValue End If If dh.HasKey("PostalCode") Then wmain.tfPostalCode.Text = dh.Value("PostalCode").StringValue End If If dh.HasKey("City") Then wmain.tfMunicipality.Text = dh.Value("City").StringValue End If PhotoID = slotManager.IDPict If PhotoID <> Nil Then GetPicture End If End If 'bbeID.Enabled = True bbeID.CaptionDelta = 10 pwRC.Visible = False Me.Enabled = False End EventHandler
End Control
EventHandler Sub Close() Self.Close End EventHandler
EventHandler Sub Open() App.AutoQuit = True 'Dim i As Integer 'OnRead If scsm.available Then slotManager = New scsm slotManager.OpenFirstSlot 'lblOSlot.Text = slotManager.SlotID ' 'slotManager.OpenFirstSlot ' 'Dim SlotList() As String = slotManager.SlotNames ' 'If SlotList.Ubound <> -1 Then 'For i = SlotList.Ubound DownTo 0 'pmCardList.AddRow(SlotList(i)) 'Next 'End If Else 'OffRead 'ClearField End If 'OnRead Exception r As UnsupportedOperationException MsgBox r.message End EventHandler
Sub ClearField() cPhoto.Backdrop = Nil cPhoto.Invalidate PhotoID = Nil tfBirthDate.Text = "" tfGN.Text = "" tfMunicipality.Text = "" tfName.Text = "" tfMunicipality.Text = "" tfName.Text = "" tfNationality.Text = "" tfNISS.Text = "" tfPoB.Text = "" tfPostalCode.Text = "" tfSex.Text = "" tfStreet.Text = "" tfTitle.Text = "" End Sub
Sub GetPicture() If PhotoID <> Nil Then cPhoto.Backdrop = PhotoID cPhoto.Invalidate End If End Sub
Sub OffRead() bbeID.Enabled = False bbeID.TextColor = &cC1C1C1 End Sub
Sub OnRead() bbeID.Enabled = True bbeID.TextColor = &c000000 End Sub
Note "Note"
So basically the project workflow is like this : 1. BeID card read button is disabled; 2. They insert the card in the reader and the button gets enabled ; 3. They press on it, it reads all the data and it populates the form, then it disables the button ; 4. Once the card is removed the button gets deactivated; All the steps with disabled and deactivated is to avoid crash, as apparently we have to start the app only with the reader connected to the usb, if we start the app without the reader In the usb then the reader will not work anymore until we restart the app.
Property PhotoID As Picture
Property ReaderID As String
Property dh As Dictionary
Property slotManager As scsm
End Class
Class scsm Inherits TKSmartCardSlotManagerMBS
EventHandler Sub gotSlotWithName(name as string, slot as TKSmartCardSlotMBS, tag as variant) debugModule.Log(CurrentMethodName) Self.currentSlot = slot // connect event AddHandler slot.StateChanged, WeakAddressOf SlotStateChanged slot.SetDelegate If slot.State = slot.kStateValidCard Then Dict = New Dictionary IDPict = Nil debugModule.Log("SmartCardInitiated -> New Dictionary") ReadSlot slot end if End EventHandler
EventHandler Sub slotNamesChanged() debugModule.Log(CurrentMethodName) debugModule.Log(CurrentMethodName + " | Before | OpenFirstSlot") OpenFirstSlot debugModule.Log(CurrentMethodName + " | After | OpenFirstSlot") End EventHandler
Function GetString(items as Dictionary, id as integer) As String Dim m As MemoryBlock = items.Lookup(id, Nil) if m <> nil then debugModule.Log(CurrentMethodName) debugModule.Log("Result : " + DefineEncoding(m, encodings.UTF8)) Return DefineEncoding(m, encodings.UTF8) end if End Function
Sub OpenFirstSlot() debugModule.Log(CurrentMethodName) Dim slotNames() As String = Me.slotNames If Me.slotNames.Ubound = -1 Then // no slot? debugModule.Log("No Slot") ''log "No slot?" Else Dim SlotName As String = slotNames(0) SlotID = SlotName 'Dim SlotName As String debugModule.Log("Selected Slot Name : " + SlotID) 'SlotName = SlotID 'If currentSlot <> Nil Then ' 'If currentSlot.Name = SlotName Then '// already selected 'Return 'End If 'End If debugModule.Log("SmartCardInitiated -> |Before| Me.getSlotWithName SlotName") Me.getSlotWithName SlotName debugModule.Log("SmartCardInitiated -> |After| Me.getSlotWithName SlotName") end if End Sub
Sub ReadSlot(slot as TKSmartCardSlotMBS) debugModule.Log(CurrentMethodName) debugModule.Log("SmartCardInitiated -> |Before| smartcard = slot.makeSmartCard") smartcard = slot.makeSmartCard debugModule.Log("SmartCardInitiated -> |After| smartcard = slot.makeSmartCard") // connect event 'AddHandler smartcard.BeginSessionCompleted, WeakAddressOf SmartcardBeginSessionCompleted 'smartcard.SetDelegate 'smartcard.beginSession smartcard.beginSessionWithDelegate WeakAddressOf SmartcardBeginSessionCompleted End Sub
Sub SlotStateChanged(slot as TKSmartCardSlotMBS) debugModule.Log(CurrentMethodName) Select Case slot.State Case slot.kStateEmpty ''log "Slot "+slot.Name+" is empty." debugModule.Log("Slot "+slot.Name+" is empty.") wMain.CardStatus = False Case slot.kStateMissing ''log "Slot "+slot.Name+" is missing." debugModule.Log("Slot "+slot.Name+" is missing.") Self.currentSlot = Nil wMain.CardStatus = False Case slot.kStateValidCard ''log "Slot "+slot.Name+" is valid card." debugModule.Log("Slot "+slot.Name+" is valid card.") wMain.CardStatus = True Case slot.kStateProbing ''log "Slot "+slot.Name+" is probing." debugModule.Log("Slot "+slot.Name+" is probing.") Case slot.kStateMuteCard ''log "Slot "+slot.Name+" is mute card." debugModule.Log("Slot "+slot.Name+" is mute card.") End Select End Sub
Sub SmartcardBeginSessionCompleted(success as Boolean, error as NSErrorMBS, tag as Variant) debugModule.Log(CurrentMethodName) debugModule.Log("success: "+Str(success)) ''log CurrentMethodName ''log "success: "+str(success) if success then smartcard.readFileWithDelegate(basicInfoFile, WeakAddressOf basicInfoFileReadCompleted) end if End Sub
Shared Function addressFile() As MemoryBlock Dim m As New MemoryBlock(4) m.UInt8Value(0) = &hDF m.UInt8Value(1) = &h01 m.UInt8Value(2) = &h40 m.UInt8Value(3) = &h33 return m End Function
Sub addressFileReadCompleted(FileName as MemoryBlock, Content as MemoryBlock, error as NSErrorMBS, tag as Variant) ''log CurrentMethodName debugModule.Log(CurrentMethodName) If Content <> Nil Then 'Dim items As New Dictionary Dim cursor As Integer = 2 If cursor < content.Size And content.UInt8Value(cursor-2) <> 0 Then 'Dim length As Integer = content.UInt8Value(cursor-1) 'Dim t As Integer = content.UInt8Value(cursor-2) 'items.Value(t) = content.MidB(cursor, length) 'cursor = cursor + length + 2 Dim StreetLen As Integer = content.UInt8Value(1) Dim Street As String = DefineEncoding(content.MidB(2, StreetLen), encodings.UTF8) Dict.Value("Street") = Street debugModule.Log(CurrentMethodName + " : " + "Street = " + Street ) ''log "Street: "+Street Dim postalCodeLen As Integer = content.UInt8Value(1+2+StreetLen) Dim postalCode As String = DefineEncoding(content.MidB(2+2+StreetLen, postalCodeLen), encodings.UTF8) Dict.Value("PostalCode") = postalCode ''log "PostalCode: "+postalCode debugModule.Log(CurrentMethodName + " : " + "PostalCode = " + postalCode ) Dim cityLen As Integer = content.UInt8Value(1+2+2+postalCodeLen+StreetLen) Dim city As String = DefineEncoding(content.MidB(2+2+2+postalCodeLen+StreetLen, cityLen), encodings.UTF8) Dict.Value("City") = city ''log "City: "+city debugModule.Log(CurrentMethodName + " : " + "City = " + city ) debugModule.Log("SmartCardInitiated -> |Before| smartcard.readFileWithDelegate(photoFile, WeakAddressOf photoFileReadCompleted)") smartcard.readFileWithDelegate(photoFile, WeakAddressOf photoFileReadCompleted) debugModule.Log("SmartCardInitiated -> |After| smartcard.readFileWithDelegate(photoFile, WeakAddressOf photoFileReadCompleted)") End If Else Return End If 'debugModule.Log("SmartCardInitiated -> |Before| smartcard.readFileWithDelegate(photoFile, WeakAddressOf photoFileReadCompleted)") ' 'smartcard.readFileWithDelegate(photoFile, WeakAddressOf photoFileReadCompleted) ' 'debugModule.Log("SmartCardInitiated -> |After| smartcard.readFileWithDelegate(photoFile, WeakAddressOf photoFileReadCompleted)") ' End Sub
Shared Function basicInfoFile() As MemoryBlock dim m as new MemoryBlock(4) m.UInt8Value(0) = &hDF m.UInt8Value(1) = &h01 m.UInt8Value(2) = &h40 m.UInt8Value(3) = &h31 return m End Function
Sub basicInfoFileReadCompleted(FileName as MemoryBlock, Content as MemoryBlock, error as NSErrorMBS, tag as Variant) debugModule.Log(CurrentMethodName) ''log CurrentMethodName // split items Dim items As New Dictionary dim cursor as integer = 2 while cursor < content.Size and content.UInt8Value(cursor-2) <> 0 dim length as integer = content.UInt8Value(cursor-1) dim t as integer = content.UInt8Value(cursor-2) items.Value(t) = content.MidB(cursor, length) cursor = cursor + length + 2 wend const kfileStructureVersion = 0 const kcardNumber = 1 const kchipNumber = 2 const kvalidityStart = 3 const kvalidityEnd = 4 const kreleasePlace = 5 const knationalIdNumber = 6 Const klastName = 7 const kfirstName = 8 const kotherName = 9 const knationality = 10 Const kbirthPlace = 11 Const kbirthDate = 12 Const ksex = 13 const knobleCondition = 14 const kdocumentType = 15 const kspecialStatus = 16 const kpictureHash = 17 const kduplicate = 18 const kspecialOrganisation = 19 const kmemberOfFamily = 20 const kprotection = 21 dim cardNumber as string = GetString(items, kcardNumber) 'dim validityStart as string = GetString(items, kvalidityStart) 'dim validityEnd as string = GetString(items, kvalidityEnd) Dim birthPlace As String = GetString(items, kbirthPlace) Dim birthDate As String = GetString(items, kbirthDate) Dim nationalIdNumber As String = GetString(items, knationalIdNumber) dim lastName as string = GetString(items, klastName) dim firstName as string = GetString(items, kfirstName) 'Dim otherName As String = GetString(items, kotherName) dim nationality as string = GetString(items, knationality) 'Dim releasePlace As String = GetString(items, kreleasePlace) Dim Sex As String = GetString(items, ksex) Dict.Value("CardNo") = cardNumber Dict.Value("FirstName") = firstName Dict.Value("LastName") = lastName Dict.Value("PoB") = birthPlace Dict.Value("DoB") = birthDate Dict.Value("Sex") = Sex Dict.Value("NISS") = nationalIdNumber Dict.Value("Nationality") = nationality debugModule.Log(CurrentMethodName + " : " + "CardNo = " + cardNumber ) debugModule.Log(CurrentMethodName + " : " + "FirstName = " + firstName ) debugModule.Log(CurrentMethodName + " : " + "LastName = " + lastName ) debugModule.Log(CurrentMethodName + " : " + "PoB = " + birthPlace ) debugModule.Log(CurrentMethodName + " : " + "DoB = " + birthDate ) debugModule.Log(CurrentMethodName + " : " + "Sex = " + Sex ) debugModule.Log(CurrentMethodName + " : " + "NISS = " + nationalIdNumber ) debugModule.Log(CurrentMethodName + " : " + "Nationality = " + nationality ) ''log "cardNumber: "+cardNumber ''log "validityStart: "+validityStart ''log "validityEnd: "+validityEnd ''log "birthPlace: "+birthPlace ''log "nationalIdNumber: "+nationalIdNumber ''log "lastName: "+lastName ''log "firstName: "+firstName ''log "otherName: "+otherName ''log "nationality: "+nationality ''log "releasePlace: "+releasePlace // next, get address debugModule.Log("SmartCardInitiated -> |Before| smartcard.readFileWithDelegate(addressFile, WeakAddressOf addressFileReadCompleted)") smartcard.readFileWithDelegate(addressFile, WeakAddressOf addressFileReadCompleted) debugModule.Log("SmartCardInitiated -> |After| smartcard.readFileWithDelegate(addressFile, WeakAddressOf addressFileReadCompleted)") End Sub
Shared Function idFile() As MemoryBlock dim m as new MemoryBlock(4) m.UInt8Value(0) = &hDF m.UInt8Value(1) = &h01 m.UInt8Value(2) = &h40 m.UInt8Value(3) = &h38 return m End Function
Shared Function photoFile() As MemoryBlock dim m as new MemoryBlock(4) m.UInt8Value(0) = &hDF m.UInt8Value(1) = &h01 m.UInt8Value(2) = &h40 m.UInt8Value(3) = &h35 return m End Function
Sub photoFileReadCompleted(FileName as MemoryBlock, Content as MemoryBlock, error as NSErrorMBS, tag as Variant) debugModule.Log(CurrentMethodName) debugModule.Log("Get Picture") If Content <> Nil Then 'Dim items As New Dictionary Dim cursor As Integer = 2 If cursor < content.Size And content.UInt8Value(cursor-2) <> 0 Then IDPict = Picture.FromData(content) debugModule.Log("SmartCardInitiated -> |Before| smartcard.endSession") smartcard.endSession debugModule.Log("SmartCardInitiated -> |After| smartcard.endSession") smartcard = Nil debugModule.Log("Set SmartCard to nil") End If Else Return End If End Sub
Property Dict As Dictionary
Property IDPict As Picture
Property SlotDict As Dictionary
Property SlotID As String
Property currentSlot As TKSmartCardSlotMBS
Property smartcard As TKSmartCardMBS
End Class
Module debugModule
Sub init() destFolder = SpecialFolder.Desktop.Child("eidReaderDebugLog") if Not(destFolder.Exists) then destFolder.CreateAsFolder end if End Sub
Sub log(line as string) Dim t As textOutputStream dim d as date if active then if destFile <> nil then d = new Date t = TextOutputStream.Append(destFile) t.WriteLine(d.SQLDateTime + chr(9) + line) t.Close end if end if End Sub
Sub start() Dim dte As date dim t as textOutputStream active = true dte = new date() destFile = destFolder.Child("eidReader-" + Format(dte.Year - 2000, "00") + Format(dte.Month, "00") + Format(dte.Day, "00") + "-" + Format(dte.Hour, "00") + Format(dte.Minute, "00") + Format(dte.Second, "00") + ".debug") if destFile <> nil then t = TextOutputStream.Create(destFile) t.Close end if End Sub
Property active As boolean = false
Property destFile As folderItem
Property destFolder As folderItem
End Module
End Project

See also:

The items on this page are in the following plugins: MBS Mac64bit Plugin.


The biggest plugin in space...