Macro Basics
Home ] Up ] Basic Concepts ] Serial Connection ] Plotting Basics ] Logging, Saving and Printing ] Interactive Control ] [ Macro Basics ] Macros - Default & Events ] Macro Math Discussion ] Defined Macro Buttons/Menus ] Drawing Basics ] Media and Paths ] Drawing Coordinate Modes ] Plot Objects ] Macro Editor ] Using Templates ] External Applications ] Historical/Logged Data ] Internet ] Binary and Special Data ]

Macros are simply text files containing StampPlot instructions.  Macros may be used for:

bulletPlot configuration including plot objects
bulletEvent handling
bulletData processing
bulletLibraries to be called from the micro or other macros.

Macros are text files with an extension of .spm for version 3, or .txt for version 1 and 2.   The Start-Up Macro is the macro specified to be ran when StampPlot is loaded.

Macros may be written manually in a text editor, such as Windows (TM) NotePad, or by use of the Macro Editor which creates a macro from the current configuration (Pro-licensed required).

bulletSimple Macro:
To create a simple macro, use the Macros menu--> Edit Macro with NotePad
bulletEnter a macro name, such as "Macro Test", answer yes to both questions asking if the file should be created.
bulletCopy and paste the following code:

INIT:
' Clear any plot objects
!POBJ Clear
' Start a new Plot
!NEWP
' Title the plot
!TITL A test of Macros
' Configure for -100 to 100 on Y axis:
!SPAN -100,100
' Set X axis to real time mode
!RTIM ON
' Set background (B) color to black, grid (G) to yellow and scales (S) to red
!COLR B(BLACK) G(YELLOW) S(RED)
'Enable Plotting
!PLOT ON
ENDMAC

bulletSave the text file.
bulletFrom the Macros menu--> Run Macro,   Ensure the name you entered is shown and click OK.
bulletThe macro placed in the Queue and processed.

Note that comments must be on a separate line from the instructions and are identified with an apostrophe.

While macros routines can be a very useful tool, the use of Plot Objects can be used to replace much of their use.

bulletMacro Routines
A Macro may contain multiple routines which may be called independently.  The basic structure of a macro routine is:
Routine_Name:
   instructions
   .
   .
ENDMAC


When a macro is opened without specifying a routine name, the 1st routine, commonly named INIT, will be processed.

bulletCalling Macros and Routines
bulletA macro my be ran through the menu as above, or called from code from the micro or from a macro or object.  Note that the extension is omitted (.spm or .txt).
!MACR macro_name
!MACR Macro Test
DEBUG "!MACR Macro Test",CR

bulletTo call a specific routine within a macro:
!MACR macro_name.routine_name

or, if calling within the same macro,
!MACR .routine_name
bulletUnless a path is specified, a macro is assumed to reside in the Macro directory of StampPlot.
To call a macro in a sub directory of StampPlot's Macro directory:
!MACR subdirectory\macroname
!MACR spp_pobj\X-YPlot


To call a macro outside of the StampPlot Macro directory:
!MACR drive:\directory\name
!MACR c:\my documents\My_Macro


bulletPassing data to a macro
Data may be passed to a macro for processing.  This is useful for library macros which may required data.
!MACR macro_name.routine_name,value, value
Data will be parsed into data markers beginning at %m0.
!MACR My_macro.Add,1,2,3

To specify another data marker to begin parsing at:
!MACR macro_name.routine_name%marker_value,value,value
!MACR My_macro.Add%90,1,2,3

bulletExample using routines.
Create a new macro, copy & paste, save and run.

INIT:
'  clear plot object
!POBJ Clear
'  New plot
!NEWP
'Call routine for setting span
!MACR .SPAN
ENDMAC

SPAN:
' request min scale, 0 default,10 second wait, store into %m10
!MREQ 0,20,Plot minimum scale?,10
' request max scale, 500 default,10 second wait, store into %m11
!MREQ 500,20,Plot maximum scale?,11
!SPAN %m10,%m11
ENDMAC


bulletMacros extended with .spm, may also be ran as an associated file by double-clicking the file in Windows Explorer or directly from a webpage.

bulletMacros may also respond to events and process incoming data. Please see Macros-Default and Events.