Event message routine will be in the following format.
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
m.Msg
Message ID is passed.
m.WParam
ID is passed in lower 2 bytes. The channel number of counter in that the event occurred is passed in higher 2 bytes.
m.LParam
The parameter peculiar to event is passed.
Example 1 for processing message
If there is only 1 device that uses the event, the determination of device by ID is not particularly necessary. The following code shows an example for displaying a message box when an event occurs.
Select Case Message
Case AIOM_CNTE_DATA_NUM
MsgBox "Device ID: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Comparison count match"
Case AIOM_CNTE_ORERR
MsgBox "Device ID: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Count overrun"
Case AIOM_CNTE_ERR
MsgBox "Device ID: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Count operation error"
Example 2 for processing message
If there are multiple devices that use the event, you need to determine which device generated event. The following code is an example for using an event on 2 devices (ID1 and ID2).
If m.WParam = ID1 Then
Select Case Message
Case AIOM_CNTE_DATA_NUM
MsgBox "Device 1: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Comparison count match"
Case AIOM_CNTE_ORERR
MsgBox "Device 1: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Count overrun"
Case AIOM_CNTE_ERR
MsgBox "Device 1: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Count operation error"
End Select
Else
Select Case Message
Case AIOM_CNTE_DATA_NUM
MsgBox "Device 2: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Comparison count match"
Case AIOM_CNTE_ORERR
MsgBox "Device 2: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Count overrun"
Case AIOM_CNTE_ERR
MsgBox "Device 2: " & m.WParam & Chr$(13) & "Current counter value: " & m.LParam, , "Count operation error"
End Select
End If