Option Explicit

' 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 = "SendClient"
Set MyConnection = MyClient.Connections.Add("TestNet")

' Now create and initialize a new transmit message
Dim msg
Set msg = MyClient.Messages.Add
With msg
  .ID = &H100
  .DLC = 4
End With

' Send the message with a cycle time of 100ms
Dim i, timestamp
timestamp = MyClient.GetSystemTime
For i = 1 To 100
  timestamp = timestamp + 100
  msg.Data(0) = i
  msg.Write MyConnection, timestamp
next

' Wait until all messages have been sent before finishing the script,
'  since this would terminate the client and delete all messages
'  that are still in the queue
While not MyClient.XmtQueueEmpty
  WScript.Sleep 500
Wend
