Page 1 of 1

Automatic Run of Macro

Posted: Fri 27. Mar 2015, 16:34
by JCheese
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

Re: Automatic Run of Macro

Posted: Sat 28. Mar 2015, 10:21
by PEAK-Support
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 7270 times

Re: Automatic Run of Macro

Posted: Mon 30. Mar 2015, 13:37
by JCheese
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

Re: Automatic Run of Macro

Posted: Mon 30. Mar 2015, 22:10
by PEAK-Support
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.

Re: Automatic Run of Macro

Posted: Mon 30. Mar 2015, 22:15
by JCheese
Great thanks

J