Automatic Run of Macro

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
JCheese
Posts: 3
Joined: Fri 27. Mar 2015, 16:13

Automatic Run of Macro

Post by JCheese » Fri 27. Mar 2015, 16:34

Hello,

I am familiar with VBS scripting but I am looking for advised on how to do the following:
- automatically run a macro when program opens.
- How do I set my J1939 protocol to active instead of using CAN protocol?

Thanks - JCheese

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Automatic Run of Macro

Post by PEAK-Support » Sat 28. Mar 2015, 10:21

Here the answers:
automatically run a macro when program opens.
This Script should be saved with the extension .vbs and stored in the project directory.
So you could simply run double cklick this file to run and start PE5 with a project and a macro.

Code: Select all

' This VB-Script opens a project in PCAN-Explorer
'-----------------------------------------------------------------------------
' Copyright (c) 2010 PEAK-System Technik GmbH.  All rights reserved.


Dim app
Dim Doc
Set app = CreateObject("PCANExplorer5.Application")

' Open the project
' Replace the Path with your project directory
app.Documents.Open "c:\Users\Support\Documents\PCAN-Explorer 5\Projects\SliderDemo\SliderDemo.peproj"

' Show the application window
app.MainWindow.IsVisible = True

' Replace the Path with your Project AddIns like Panel, Plotter etc.
Set Doc = app.Documents.Open("c:\Users\Support\Documents\PCAN-Explorer 5\Projects\SliderDemo\SliderDemoPanel.ipf")
' Set the last loaded Window as active Windows (set Focus)
Doc.ActiveWindow.IsActive=true
' Load the Macro which is part of your loaded Project
app.Documents.Open("SliderDemo.pem")
' Set the loaded Macro as applyed
app.ExecuteCommand "FileApply"
' and run any command in this Macro file you want
app.ExecuteCommand "SliderDemo"
' Now it's time to show the main application window
app.MainWindow.IsVisible = True
' And toggle the FullScreen Mode
 app.ExecuteCommand "ToggleFullScreen"
' to switch back from Fullscreen press F11
How do I set my J1939 protocol to active instead of using CAN protocol?
Select your Connection and switch in the properties section the Protocol from CAN to J1939:
Select J1939
Select J1939
CAN-J1939.JPG (54.2 KiB) Viewed 7266 times
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

JCheese
Posts: 3
Joined: Fri 27. Mar 2015, 16:13

Re: Automatic Run of Macro

Post by JCheese » Mon 30. Mar 2015, 13:37

Thank you for your reply. Tweeked it to suite exactly what I wanted!

I have another situation. Once this attached macro is running, I want to be able to do something.

I want to have a StopAndClose.VBS that stops the macro running, saves the data as the rest of the traces are and then closes the program. I think I would have to modify the macro for some kind of loop but not sure. Any ideas? I just modified a sample file of a trace macro for what is here.

Thanks again, you are a life saver!
JCheese
Attachments
StartConnectionLog.pem
(3.27 KiB) Downloaded 701 times

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Automatic Run of Macro

Post by PEAK-Support » Mon 30. Mar 2015, 22:10

Here a sample Macro that shows how to quit the started Application

Code: Select all

' This VB-Script generates an Output into the Output Window
'-----------------------------------------------------------------------------
' Copyright (c) 2010 PEAK-System Technik GmbH.  All rights reserved.

Set app = CreateObject("PCANExplorer5.Application")
app.MainWindow.IsVisible = True

app.PrintToOutputwindow "Hello from VBScript"

MsgBox "The script has sent a message to PCAN-Explorer...", vbSystemModal

app.Quit
In the code that you have posted (based on our loosless trace sample) you use a VAR called

Code: Select all

IsRunning
Simple change the state of this VAR to FALSE that ends your Loop.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

JCheese
Posts: 3
Joined: Fri 27. Mar 2015, 16:13

Re: Automatic Run of Macro

Post by JCheese » Mon 30. Mar 2015, 22:15

Great thanks

J

Post Reply