-1
Public axCZKEM1,axCZKEM2 As New zkemkeeper.CZKEM


AddHandler axCZKEM1.OnAttTransactionEx, AddressOf Ax_OnAttTransactionEx
AddHandler axCZKEM2.OnAttTransactionEx, AddressOf Ax_OnAttTransactionEx




Private Sub Ax_OnAttTransactionEx(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, _
                  ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer)

    lbRTShow.Items.Add("RTEvent OnAttTrasactionEx Has been Triggered,Verified OK")
    lbRTShow.Items.Add("...UserID:" & sEnrollNumber)
    lbRTShow.Items.Add("...isInvalid:" & iIsInValid.ToString())
    lbRTShow.Items.Add("...attState:" & iAttState.ToString())
    lbRTShow.Items.Add("...VerifyMethod:" & iVerifyMethod.ToString())

End Sub

this code for real-time Triggering fingerprint device'

First question

How will I know which device triggered this event : this device 'axCZKEM1' or 'axCZKEM2'

when I try put 'sender As Object' with parameter give me error :

"does not have signature compatible with delegate"

ADDITIONAL CONCERN

I've researched the internet based from the pointers you gave me.

FIRST: I am already successful with identifying the Sender Device using a Wrapper Class and my code is as shown below:

Imports zkemkeeper
Imports System
Imports System.Collections.Generic
Public Class myzkem
    Public Property Name
    Private WithEvents CZKEM As zkemkeeper.CZKEM
    Public Event AttEventWrapper(SenderName As String, sEnrollNumber As String, iIsInValid As Integer, iAttState As Integer, iVerifyMethod As Integer, iYear As Integer, iMonth As Integer, iDay As Integer, iHour As Integer, iMinute As Integer, iSecond As Integer, iWorkcode As Integer)
    Public Shared ListOfDevices As New Dictionary(Of String, zkemkeeper.CZKEM)

    Public Sub New(WrapperName As String, CZKEMObject As zkemkeeper.CZKEM)
        Me.Name = WrapperName
        Me.CZKEM = CZKEMObject

    End Sub

    Private Sub HandleEvent(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer, ByVal iHour As Integer, ByVal iMinute As Integer, ByVal iSecond As Integer, ByVal iWorkCode As Integer) Handles CZKEM.OnAttTransactionEx
        RaiseEvent AttEventWrapper(Me.Name, sEnrollNumber, iIsInValid, iAttState, iVerifyMethod, iYear, iMonth, iDay, iHour, iMinute, iSecond, iWorkCode)
    End Sub
End Class

Note: This is the class where I inserted my shared dictionary [ListOfDevices].

SECOND: I created another class with functions containing my CZKEM Object, add and remove handler codes and connection codes.

Imports zkemkeeper
Public Class ZKEMKEEPERClass
    Public CZKEM2 As New zkemkeeper.CZKEM
    Public NewKEM As myzkem
    Public Function ZKEMAddHandler(iDevice As String, iIP As String, iPort As Integer) As Boolean
        If CZKEM2.Connect_Net(iIP, 4370) Then
            If CZKEM2.RegEvent(1, 65535) = True Then
                NewKEM = New myzkem(iDevice, CZKEM2)
                AddHandler NewKEM.AttEventWrapper, AddressOf LoginEvent_1

                MsgBox(iDevice)
                Return True
            Else
                Return False
            End If
        Else
            Return False
        End If

    End Function
    Public Function ZKEMRemoveHandler(iDevice As String, CZKEM As zkemkeeper.CZKEM)
        NewKEM = New myzkem(iDevice, CZKEM)
        RemoveHandler NewKEM.AttEventWrapper, AddressOf LoginEvent_1
        MsgBox(iDevice)
    End Function

    Public Sub LoginEvent_1(ByVal SenderName As String, ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer, ByVal iHour As Integer, ByVal iMinute As Integer, ByVal iSecond As Integer, ByVal iWorkCode As Integer)
        MsgBox(SenderName)
    End Sub
End Class

THIRD: In my main program, I replicate [ZKEMKEEPERClass] to create multiple objects that are all active at the same time.

    Sub CONNECT()
        Dim iIP As String
        Dim iDevice As String
        For x = 1 To 2
            Select Case x
                Case 1
                    iIP = "122.3.47.43"
                    iDevice = "Device 1"
                Case 2
                    iIP = "192.168.10.201"
                    iDevice = "Device 2"
            End Select
            Dim NewConnect As New ZKEMKEEPERClass
            If NewConnect.ZKEMAddHandler(iDevice, iIP, 4370) Then
                MsgBox("success")
            Else
                MsgBox("failed")
            End If
        Next

    End Sub

MY NEW PROBLEM: I can't remove the handler since I cannot identify it from the replicated classes.

Let me know your ideas.

@AConfusedSimpleton

NickNok_27
  • 25
  • 6

1 Answers1

0

I'm not familiar with this particular library, but here's my 2 cents:

You're getting an incompatible signature because the event defined in zkemkeeper.CZKEM will look something like this:

Public event Ax_OnAttTransactionEx(sEnrollNumber As String, iIsInValid As Integer,_ 
    iAttState As Integer, iVerifyMethod As Integer, iYear As Integer, iMonth As Integer,_ 
    iDay As Integer)

There is no argument 'sender' defined and thus if you add it to your handler you will have an incompatible signature.

One possible way to know which device raised the event would be to define your own wrapper class that has property 'name' (or whatever you wanna call it) and defines an event like:

Public event MyWrapperEvent(SenderName As String, sEnrollNumber As String,_
    iIsInValid As Integer, iAttState As Integer, iVerifyMethod As Integer,_
    iYear As Integer, iMonth As Integer, iDay As Integer)

your wrapper class would then hold a reference to a zkemkeeper.CZKEM object

Private WithEvents MyCZKEMObject As zkemkeeper.CZKEM

and it would handle it's Ax_OnAttTransactionEx event internally, by simply raising it's own event which is exactly the same only with 'senderName' added. The handler for it would then look something like:

Private Sub HandleEvent(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer,_ 
     ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, ByVal iYear As Integer,_ 
     ByVal iMonth As Integer, ByVal iDay As Integer) handles MyCZKEMObject.OnAttTransactionEx

    RaiseEvent MyWrapperEvent(Me.Name, sEnrollNumber, iIsInvalid, iAttState, iVerifyMethod, iYear, iMonth, iDay)

End Sub

Then in main program you can create an object of your wrapper class and handle it's 'MyWrapperEvent' Event. You would know which device raised it by checking the 'senderName' property. (Assuming of course you give a unique name to each device)

Update:

Your full wrapper class implementation could look something like this :

Public Class MyWrapperClass
    Public Property Name
    Private WithEvents MyCZKEMObject As zkemkeeper.CZKEM

    Public Event MyWrapperEvent(SenderName As String, sEnrollNumber As  String, iIsInValid As Integer, iAttState As Integer, iVerifyMethod As Integer, iYear As Integer, iMonth As Integer, iDay As Integer)


    Public Sub New(WrapperName As String, CZKEMObject As Zkemkeeper.CZKEM)
        Me.Name = WrapperName
        Me.MyCZKEMObject = CZKEMObject
    End Sub

    Private Sub HandleEvent(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer) Handles MyCZKEMObject.OnAttTransactionEx

        RaiseEvent MyWrapperEvent(Me.Name, sEnrollNumber, iIsInValid, iAttState, iVerifyMethod, iYear, iMonth, iDay)

    End Sub


End Class

'Name' is simply a property declared in your wrapperclass which you use to identify the zkemkeeper.CZKEM object you pass to it. When your wrapper class handles this object's 'Ax_OnAttTransactionEx' event. It simply raises it's own, very similar, event but passes it's 'Name' property as well, which you can use to identify the device.

Note: Passing 'Name' instead of 'Me.Name' works perfectly fine, it is just my personal preference to use the keyword 'me' as i think it keeps my code more clear

  • I'm definitely going to study these things you gave me. I'll give you feedback soon. Thank you very much @AConfusedSimpleton :D – NickNok_27 Apr 25 '19 at 04:09
  • I just don't know where I should get the **Me.Name**: 'RaiseEvent MyWrapperEvent(Me.Name, sEnrollNumber, iIsInvalid, iAttState, iVerifyMethod, iYear, iMonth, iDay)' Can you help me with that? @AConfusedSimpleton – NickNok_27 Apr 25 '19 at 04:53
  • Can you give me an example of how to use the wrapper class (MyWrapperEvent)? Im kind of clueless here :D – NickNok_27 Apr 25 '19 at 06:13
  • I just realized how noob I am when I saw how you created wrapper class Lols. I searched the logic behind it and figured very useful in my other projects. Now, I just need how to use this class in my main program. Can you show me an example in relation to the code above? Thank you very much @AConfusedSimpleton. – NickNok_27 Apr 26 '19 at 02:54
  • I think I figure how to use the wrapper class. Now my problem is how I can create multiple zkemkeeper.CZKEM public objects in a loop Lols. You are really an angel to me @AConfusedSimpleton. – NickNok_27 Apr 26 '19 at 03:43
  • I'm thinking if my wrapper class can accept CZKEMObject(Array) to simply iterate the process but I don't know how. What do you think @AConfusedSimpleton? – NickNok_27 Apr 26 '19 at 03:53
  • @NickNok_27 you could define a dictionary in your wrapperclass that holds a name for each CZKEM object as the key and the object itself as the value. then you would have to define your own Add and Remove methods in your class which handle adding and removing the handlers for each CZKEM object you want to add or remove. have a look at https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/walkthrough-defining-classes for more info on creating classes. – AConfusedSimpleton Apr 26 '19 at 06:31
  • more info on dictionaries can be found here https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.8 and another question was asked recently which applies to your problem as well as you will need to dynamically add and remove event handlers. It can be found here https://stackoverflow.com/questions/55850862/vb-net-how-to-add-a-large-amount-of-events-to-a-single-handle/55851111#55851111 – AConfusedSimpleton Apr 26 '19 at 06:32
  • I've updated my question with sample codes. Please Help @AConfusedSimpleton. – NickNok_27 Apr 26 '19 at 07:48