Option Explicit

' Constants from PCAN4 Type Library, see also Constants.vbs in
'  PCAN-Explorer Samples directory
Const pcanErrorOk = 0

' Create and initialize a new PCAN client object
'  and create a CAN connection
Dim MyClient, MyConnection
Set MyClient = CreateObject("PCAN4.PCANClient")
MyClient.Device = "pcan_usb"
MyClient.Name = "ReceiveClient"
Set MyConnection = MyClient.Connections.Add("TestNet")
' Open the reception filter
MyConnection.RegisterMsg 0, &H7FF, False, False

' Create a new message object that is used to receive messages
Dim msg
Set msg = MyClient.Messages.Add

' Wait until 10 message have been received
Dim count, str
Do
  Do While Not msg.Read
    ' Wait for a message
    WScript.Sleep 1
  Loop
  If msg.LastError = pcanErrorOk Then
    str = str & "ID = " & msg.ID & "  DLC = " & msg.DLC & vbCrLf
    count = count + 1
  End If
Loop While count < 10
MsgBox str,,"Received Messages"
