The event message routine has the following format.
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
m.Msg
The message number is passed.
m.WParam
The ID is passed to the lower 2 bytes. The upper two bytes are not currently used.
m.LParam
Parameters specific to each event are passed.
Message Processing Example 1
If there is only one device that uses the event, the device's decision by ID is not particularly necessary. The following code shows an example of displaying a message box when an event occurs.
Select Case Message
Case AIOM_AIE_START
MsgBox "Device ID : " & m.WParam & Chr$(13), , "Sampling start"
Case AIOM_AIE_RPTEND
MsgBox "Device ID : " & m.WParam & Chr$(13) & "Repeat Times : " & m.LParam, , "Repeat end"
Case AIOM_AIE_END
MsgBox "Device ID : " & m.WParam & Chr$(13) & "Sampling Times : " & m.LParam, , "Sampling end"
Case AIOM_AIE_DATA_NUM
MsgBox "Device ID : " & m.WParam & Chr$(13) & "Sampling Times : " & m.LParam, , "Data stored"
Case AIOM_AIE_OFERR
MsgBox "Device ID : " & m.WParam & Chr$(13) & "Sampling Times : " & m.LParam, , "Overflow error"
Case AIOM_AIE_SCERR
MsgBox "Device ID : " & m.WParam & Chr$(13) & "Sampling Times : " & m.LParam, , "Sampling clock period error"
Case AIOM_AIE_ADERR
MsgBox "Device ID : " & m.WParam & Chr$(13) & "Sampling Times : " & m.LParam, , "AD conversion error"
End Select
Message Processing Example 2
When using events on multiple devices, you need to decide which device generated event. The following code is an example of using events on two devices (ID1 and ID2).
If m.WParam = ID1 Then
Select Case Message
Case AIOM_AIE_START
MsgBox "Device 1" & Chr$(13), , "Sampling start"
Case AIOM_AIE_RPTEND
MsgBox "Device 1" & Chr$(13) & "Repeat Times : " & m.LParam, , "Repeat end"
Case AIOM_AIE_END
MsgBox "Device 1" & Chr$(13) & "Sampling Times : " & m.LParam, , "Sampling end"
Case AIOM_AIE_DATA_NUM
MsgBox "Device 1" & Chr$(13) & "Sampling Times : " & m.LParam, , "Data stored"
Case AIOM_AIE_OFERR
MsgBox "Device 1" & Chr$(13) & "Sampling Times : " & m.LParam, , "Overflow error"
Case AIOM_AIE_SCERR
MsgBox "Device 1" & Chr$(13) & "Sampling Times : " & m.LParam, , "Sampling clock period error"
Case AIOM_AIE_ADERR
MsgBox "Device 1" & Chr$(13) & "Sampling Times : " & m.LParam, , "AD conversion error"
End Select
Else
Select Case Message
Case AIOM_AIE_START
MsgBox "Device 2" & Chr$(13), , "Sampling start"
Case AIOM_AIE_RPTEND
MsgBox "Device 2" & Chr$(13) & "Repeat Times : " & m.LParam, , "Repeat end"
Case AIOM_AIE_END
MsgBox "Device 2" & Chr$(13) & "Sampling Times : " & m.LParam, , "Sampling end"
Case AIOM_AIE_DATA_NUM
MsgBox "Device 2" & Chr$(13) & "Sampling Times : " & m.LParam, , "Data stored"
Case AIOM_AIE_OFERR
MsgBox "Device 2" & Chr$(13) & "Sampling Times : " & m.LParam, , "Overflow error"
Case AIOM_AIE_SCERR
MsgBox "Device 2" & Chr$(13) & "Sampling Times : " & m.LParam, , "Sampling clock period error"
Case AIOM_AIE_ADERR
MsgBox "Device 2" & Chr$(13) & "Sampling Times : " & m.LParam, , "AD conversion error"
End Select
End If
MyBase.WndProc(m)
End Sub