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.
- 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:you have to place this:Code: Select all
Set client = PCANClients.Add("Macro") client.Device = ActivePCANClient.Device client.IsRegistered = True client.NetName = ActivePCANClient.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.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)
You could also specify your own values:In the PCANMessage.Read and .Write calls, specify the Connection object as the first parameter:Code: Select all
Set client = CreateObject("PCAN3.PCANClient") client.Device = "pcan_usb" client.Name = "Macro" Set myConnection = MyClient.Connections.Add("MyNetName")
Code: Select all
Set msg = client.Messages.Add msg.Write myConnection, timestamp
- To access the global Receive and Transmit lists, instead of
write
Code: Select all
Set XmtMsg = TransmitMessages(1) Set RcvMsg = 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(1) Set RcvMsg = Connections.ReceiveMessages(1)
Here you don’t need to specify a connection in the TransmitMessage.Write call, as the connection is already assigned.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
- 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:
But if you configure a tracer, there are some new properties. Instead of:
Code: Select all
Set doc = Documents.Add(peDocumentKindTrace) Set tracer = doc.ActiveWindow.Object.Tracer
You would write:Code: Select all
tracer.CircularBuffer = False
As you can see, you could now also set the buffer size which was not possible in PCAN-Explorer 3 and 4.Code: Select all
tracer.BufferType = peTraceBufferTypeLinear tracer.BufferSize = 500000
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. - Applying a Symbols file. In PCAN-Explorer 3 and 4 you would write:
In PCAN-Explorer 5, use this code:
Code: Select all
Documents.Open "C:\MyProject\MySymbols.sym" ExecuteCommand "FileApply"
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.
- 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:
In PCAN-Explorer 5, you have to specify which Symbols file you want to access:
Code: Select all
Set sym = Symbols("MySymbol")
In this example, ‘MySymbolsFile’ is the file name without path and file name extension ‘.sym’.Code: Select all
Set sym = SymbolsManager("MySymbolsFile").Item("MySymbol")
Kind regards
Mark
P.S.: Thanks to Karlheinz Wolf (K.Wolf) for providing this information.