Page 1 of 1

Executing Macro with parameters over buttons

Posted: Fri 19. Oct 2018, 11:43
by M. Hofmann
Hello,

I try to send CAN message, which content is calculated by VB script. The script works and can be started over a button of the control panel.

Now I try to achieve that all existing commands can be send via buttons. The command generation use a common logic, that I have implemented in a separate function with parameters.

Until now I did not manage to start this control function with parameters by clicking on a button. How can this be done?

Calling the macro with parameters in the command execute field of the button (like "command 0, 1, 3") did not work. My second approach was to write macros for each button and call the control macro with fix parameters. This works, if the control function and call operation is in the same file. But for this I have to copy the control function in every macro, which is a maintenance hell.

Is there a possibility to call a Macro from another file?

Re: Executing Macro with parameters over buttons

Posted: Fri 19. Oct 2018, 12:31
by PEAK-Support
Maybe you could use a virtual Signal that changed its value depending on the pressed buttom.
This Signal could be used in the same ways as real CAN Signal and so could be read / write from all available ressources with the PCAN-Explorer.

Re: Executing Macro with parameters over buttons

Posted: Fri 19. Oct 2018, 12:38
by M. Hofmann
Is it possible to execute multiple macros with one click on a button? Or do I have to use multiple buttons? One for selecting the command and one for transmitting the message?

Re: Executing Macro with parameters over buttons

Posted: Fri 19. Oct 2018, 12:46
by PEAK-Support
Is it possible to execute multiple macros with one click on a button? Or do I have to use multiple buttons? One for selecting the command and one for transmitting the message?
No, one event - one macro (the VBS engine is a single thread - blocking environment - not possible to run more than one code at a time). As i wrote, i would use a Virtual Signal as "Parameter" and the Buttom that set these Value and call the script...

Re: Executing Macro with parameters over buttons

Posted: Fri 19. Oct 2018, 15:58
by M. Hofmann
The suggestion to use virtual signals and multiple buttons for one action is a little bit too cumbersome.

Thats why I have implemented my own include command. This way I can write the common code in a separate file and reuse it in the button action scripts :)

Maybe it help some of you:

Code: Select all

Sub Include(path)
	const ForReading = 1
	const TristateUseDefault = -2 ' use system settings to decide if ascii or unicode

	Set fs = CreateObject("Scripting.FileSystemObject")
	Set srcF = fs.OpenTextFile(path, ForReading, TristateUseDefault)
	code = srcF.ReadAll
	srcF.Close
	
	ExecuteGlobal code
end sub
For including the file common.pem you only need to write

Code: Select all

Include "common.pem"
Cheers