' This VB-Script creates a new message in the PCAN-Explorer Transmit List
'-----------------------------------------------------------------------------
' Copyright (c) 2016 PEAK-System Technik GmbH.  All rights reserved.


Option Explicit

' Constants from PCAN-Explorer Type Library, see also Constants.vbs in
'  PCAN-Explorer Samples\VBScript directory
const peSaveChangesNo = 2

' Create and show the PCAN-Explorer application
Dim app
Set app = CreateObject("PCANExplorer6.Application")
app.MainWindow.IsVisible = True

' Create and configure new project
app.NewProject "Example", ""
Dim MyConnection
Set MyConnection = app.Connections.Add("TestNet@pcan_usb")
MyConnection.IsEnabled = True
If Not MyConnection.IsEnabled Then
  MsgBox "Error while enabling the connection!",,WScript.ScriptName
  app.ActiveProject.Close peSaveChangesNo
  app.Quit
  WScript.Quit
End If
app.ExecuteCommand "ShowReceiveTransmit"

' Create a new cyclic transmit message
Dim MyMessage
Set MyMessage = app.Connections.TransmitMessages.Add
With MyMessage
  .BeginUpdate
  Set .Connection = MyConnection
  .ID = &H100
  .DLC = 4
  .Data(0) = &H11
  .Data(1) = &H22
  .Data(2) = &H33
  .Data(3) = &H44
  .CycleTime = 100
  .Creator = "Script"
  .EndUpdate
End With

' Wait until the message was sent 100 times
While MyMessage.EventCount < 100
  WScript.Sleep 50
Wend

' Cleanup
app.ActiveProject.Close peSaveChangesNo
app.Quit
