I suspect anyone who is used to programming in any modern language feels the same way I do about writing VB macros for Mach3 - It's about as much fun as a root canal with no anesthesia! To make my own life easier until Mach3 v4 comes along, I tossed together a VERY rudimentary pre-processor for my VB scripts, that gives me the ability to use "include" files, and very rudimentary text macros. This not only cuts down on the amount of typing I need to do, and greatly reduces the number of errors, but lets me follow at least a few of the more basic rules of good programming practice, like NOT using hard-coded numbers for things like OEM codes. I can instead use meaningful names, which makes the code MUCH easier to write, read, and maintain. These can be defined in a single place, and used in many places, so they're easy to change if necessary.
If others have any interest in using this (with NO guarantees of any support whatsoever....), I can pretty easily clean it up enough to make it easily usable. It is written in Perl, which does require installing ActiveState Perl, which is a free download from
www.activestate.com, and a total no-brainer to install.
Below is a trivial example of what it does. First, the macro code as I actually write it:
''
' X Axis Plus Edge Finder Macro
''
#filename M910.m1s
#include "Common.def"
#include "Probing.def"
''========================================================================================
'' Start of Macro Code
''========================================================================================
' Set the macro busy flag
#IncrementMacroBusyFlag
' Call the primitive edge finder macro
Code EdgeFindMacro & " P" & XAxis & " Q" & Plus
' Wait until it's done
#WaitUntilSubMacrosDone
' Clear the macro busy flag
#DecrementMacroBusyFlag Here is the code that comes out of the pre-processor, ready to run in Mach3:
''========================================================================================
' Created From: Mid_XPlusEdgeFind.m3m
' Includes:
' Common.def
' Probing.def
''========================================================================================
''========================================================================================
'' Included Definitions:
''========================================================================================
Busy = 1 ' Busy, for waiting for macros to complete
EdgeFindMacro = "M900" ' Edge finder - requires MacroParameter1DRO & MacroParameter2DRO
MacroBusySemaphoreDRO = 1108 ' Busy flag, used by macros. Must be zeroed by top-level macros
Plus = 1 ' Symbol for argument passing
XAxis = 0 ' Symbol for argument passing
''========================================================================================
''
' X Axis Plus Edge Finder Macro
''
'#filename M910.m1s
' #include "Common.def"
' #include "Probing.def"
''========================================================================================
'' Start of Macro Code
''========================================================================================
' Set the macro busy flag
' Macro: #IncrementMacroBusyFlag
BusyFlag = GetUserDRO(MacroBusySemaphoreDRO)
SetUserDRO(MacroBusySemaphoreDRO, BusyFlag + 1)
Sleep 100
' End Macro: #IncrementMacroBusyFlag
' Call the primitive edge finder macro
Code EdgeFindMacro & " P" & XAxis & " Q" & Plus
' Wait until it's done
' Macro: #WaitUntilSubMacrosDone
' Wait until it's done
While GetUserDRO(MacroBusySemaphoreDRO) > BusyFlag
Sleep 100
Wend
' End Macro: #WaitUntilSubMacrosDone
' Clear the macro busy flag
' Macro: #DecrementMacroBusyFlag
BusyFlag = GetUserDRO(MacroBusySemaphoreDRO)
SetUserDRO(MacroBusySemaphoreDRO, BusyFlag - 1)
Sleep 100
' End Macro: #DecrementMacroBusyFlag Notice that DRO, LED, macro numbers are pulled in from the included files (Common.def and Probing.def), so they don't need to be re-defined in every macro. Simple text macros, like the DecrementMacroBusyFlag macro let you easily re-use small sections of tested code.
So, any interest?