Adapting old VBScript macros to PCAN-Explorer 5

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
User avatar
M.Gerber
Design & Documentation
Design & Documentation
Posts: 65
Joined: Mon 13. Sep 2010, 16:34

Adapting old VBScript macros to PCAN-Explorer 5

Post by M.Gerber » Fri 6. Mar 2015, 11:36

Hello VBScript Users!

If you've upgraded PCAN-Explorer from versions 3 or 4 to 5 and want to reuse your macros, some adaptions must be made.

Due to the fact that PCAN-Explorer 5 uses projects and supports more than one CAN connection at the same time, it was necessary to make severe changes to the underlying object model. We saw no possibility to make PCAN-Explorer 4 or older macros work without changes.

Here are a few tips for the most important modifications that must be applied to the old macros.
  1. First of all, the way you would communicate with a CAN bus is different, if you create your own PCAN client objects.

    Where you had the following code:

    Code: Select all

    Set client = PCANClients.Add("Macro")
    client.Device = ActivePCANClient.Device
    client.IsRegistered = True
    client.NetName = ActivePCANClient.NetName
    you have to place this:

    Code: Select all

    Set client = CreateObject("PCAN3.PCANClient")
    client.Device = Connections(1).Device
    client.Name = "Macro"
    Set myConnection = MyClient.Connections.Add(Connections(1).CommunicationObject.NetName)
    If you work like this, you always require an opened project that has at least one active connection, because the macro copies the parameters from that connection.

    You could also specify your own values:

    Code: Select all

    Set client = CreateObject("PCAN3.PCANClient")
    client.Device = "pcan_usb"
    client.Name = "Macro"
    Set myConnection = MyClient.Connections.Add("MyNetName")
    In the PCANMessage.Read and .Write calls, specify the Connection object as the first parameter:

    Code: Select all

    Set msg = client.Messages.Add
    msg.Write myConnection, timestamp
  2. To access the global Receive and Transmit lists, instead of

    Code: Select all

    Set XmtMsg = TransmitMessages(1)
    Set RcvMsg = ReceiveMessages(1)
    write

    Code: Select all

    Set XmtMsg = Connections.TransmitMessages(1)
    Set RcvMsg = Connections.ReceiveMessages(1)
    To configure a new transmit message in the Transmit list, you now must always assign the bus or connection on which the message operates, e.g.:

    Code: Select all

    Set XmtMsg = Connections.TransmitMessages.Add
    Set XmtMsg.Connection = Connections(1)
    XmtMsg.ID = &H100
    XmtMsg.DLC = 8
    XmtMsg.Data(0) = ...
    XmtMsg.Write 0
    Here you don’t need to specify a connection in the TransmitMessage.Write call, as the connection is already assigned.
  3. Tracers. PCAN-Explorer 3 and 4 allowed only one active tracer at the same time, now you can have multiple running tracers. Creating a tracer is identical:

    Code: Select all

    Set doc = Documents.Add(peDocumentKindTrace)
    Set tracer = doc.ActiveWindow.Object.Tracer
    But if you configure a tracer, there are some new properties. Instead of:

    Code: Select all

    tracer.CircularBuffer = False
    You would write:

    Code: Select all

    tracer.BufferType = peTraceBufferTypeLinear
    tracer.BufferSize = 500000
    As you can see, you could now also set the buffer size which was not possible in PCAN-Explorer 3 and 4.

    Starting and stopping is done in the same way, but starting a new tracer now does not automatically stop a previous tracer, as there can be more than one running tracers.
  4. Applying a Symbols file. In PCAN-Explorer 3 and 4 you would write:

    Code: Select all

    Documents.Open "C:\MyProject\MySymbols.sym"
    ExecuteCommand "FileApply"
    In PCAN-Explorer 5, use this code:

    Code: Select all

    Connections(1).SymbolsFileName = "C:\MyProject\MySymbols.sym"
    If the Symbols file is part of the current project, you can omit the path name.
  5. Accessing Symbols. PCAN-Explorer 5 can now have multiple active Symbols files, since each connection can have its own file. So the way to access the symbols is different. In PCAN-Explorer 3 and 4, you could access a symbol in this way:

    Code: Select all

    Set sym = Symbols("MySymbol")
    In PCAN-Explorer 5, you have to specify which Symbols file you want to access:

    Code: Select all

    Set sym = SymbolsManager("MySymbolsFile").Item("MySymbol")
    In this example, ‘MySymbolsFile’ is the file name without path and file name extension ‘.sym’.
This list of changes may not be complete, but the most important issues are covered.

Kind regards
Mark

P.S.: Thanks to Karlheinz Wolf (K.Wolf) for providing this information.

Post Reply