Here is some of the little "Tid Bits", I have picked up here and there, that adds to the already existing "Mach Specific Subroutines". IF you have some that are not listed on the Wiki, or in this list, please post them here, and we can when all is said and done, collect it all in a single "Community" document.
GetMasterInput(0-127)
GetMasterOutput(0-127)
SetMasterOutput(0-127, 0-15bit)
SetMasterInput(0-127, 0-15bit)
Serial port
You can send bytes of raw data to a serial port. The port number (i.e. n in COMn) to be used and the baud rate for transmission is set in Config>Logic. RTS/CTS hardware flow control protocol will be used to control large volumes of data but this will not be normally required. Data is transmitted 8 data bits, 1 stop bit No Parity by a call of SendSerial.
Sub SendSerial (chars as String)
Example: to write the value of X DRO to an LCD display connected to the serial (RS232) port.
Call SendSerial ("X-Axis = " & GetDRO (0))
[edit]
Foreign ports
Scripts can access ports on the PC which are additional to the one (or perhaps two) parallel port(s) defined in Config>Ports and Pins. These are accessed at the basic hardware port address level and you will have to be aware of the details of the individual port addresses, allocation of data and status bits etc.
Function GetPortByte (pAddr as Integer) as Byte
Sub PutPortByte (pAddr as Integer, bData as Byte)
This feature should be used with great care as, if misused, it can interfere with any peripheral on your system, including the hard-drive.
[edit]
Waiting and system features
As described above the script code and Mach3 itself run in two separate processes. You can test to see in Mach3 is busy or idle by calling:
Function IsMoving () as Boolean
This will return True if Mach3 is busy. You should call it in a loop after commanding an axis move or other function which could take a significant time and before reading DROs or LEDs that could be affected by the move.
Example:
Call Code ("G0X12Z100")
While IsMoving ()
WEnd
x = GetOEMDRO (802) ' get Z value in case it has been Z inhibited
Function IsStopped () as Boolean
Returns True if Mach3 is not in the process of executing a part-program.

Can anyone clarify what happens when in Feedhold, SingleStep and waiting for a Shuttle Jog pulse between blocks of code?
Function IsLoading () as Boolean
Returns true if the part program is loading rather than being actually run (e.g. so the toolpath is being generated or regenerated). This can be used to inhibit script actions like Question() in this situation.
Sub SystemWaitFor (sigNo as Integer)
Waits for the given signal to become active. This allows interfacing with physical controls on the machine.
Sub WaitForPoll ()
Waits until a Modbus Poll has taken place. Not sure if this is safe if Modbus is not turned on???. Use this in a loop, e.g. in macropump macro waiting for interesting things to come from the Modbus device.
Function IsFirst () as Boolean
Returns True if this is the first call of the function after Mach3 has exited from the EStop state. This can be used to re-initialse data that would be lost at a n EStop.
Sub LoadLinTable()
Reloads the table giving linearisation data for Mach3 spindle speed.
VB Timers
There are 24 timers, numbered from timer 0 to timer 23.
SetTimer(x) , will reset that timer to 0.
N = GetTimer(x) , will tell you how much time has passed since it was set to
zero. Granularity is in micro seconds.
Example:
if IsActive( INPUT1 ) then
if( Timer( 1 ) > 30 ) then
Speak" 30 seconds have elapsed"
SetTimer( 1 )
endif
else
SetTimer(1)
end if
Swap Axis:
SwapAxix( 2,5)
ResetAxisSwap()
Spindle Speed OVR from outside:
SetParam( "RPMOverRide" , 1 )
Macrocall to plugins:
There is currently a macro call that will notify a plugin.
NotifyPlugins( x) which sends a one number message that can be seen in the
plugins OnNotify function. You cant pass variables, but you can access the
parameters and other system variables, so the macro woudl have to store the call
paramaters somewhere, then notify the plugin with the notify call, the plugin
can then grab whatever parameters it likes in the system variables.
Hello,
You could use a NotifyPlugins(int Message_Number) in VB and that will be
picked up by all plugins in the void myNotify(int message) function..
Use a message of 10000 or greater please when you are doing this
Number Format:
Variable = nfmt(Variable, decimal places truncated to)
Xstep = nfmt(Xstep, 3)
Open HTML G code helpfile:
Shell("explorer.exe " + GetMainFolder()+"Mach3MillGcode.htm")
Set Trigger Macro using "Push User Button" in Brians:
First, you dont put the code in a button, you put it in a macro file. For
example file: m600.m1s
SetMessage( "This is a macro call..")
Then , you have to set that macro to be the default macro call with a call to
SetTriggerMacro( 600 ) at some point in the program, an init string could do
that if the SetTriggerMacro call were in another macro file that is called on
startup. Then the brain will execute m600 whenever that brain termination code is
called.
To Write the Tool Table Data (and tool desc), out to a file to print:
textFilePath = "C:\mach3\ToolInfo.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(textFilePath)
Do Until num=225
num=num+1
N = GetToolDesc(num)
D = GetToolParam(num,1)
L = GetToolParam(num,2)
WD= Gettoolparam(num,3)
WL= Gettoolparam(num,4)
Dt= Date()
Tm= Time()
If N <>"Empty" Then
objTextFile.WriteLine("*Tool"& num &" * "& N &" *Diameter: "& D &"
*Length: "& L &" *Wear Diam"&WD &" *WearLength"&WL & Chr(13) & Chr
(10))
Else
End If
Loop
objTextFile.WriteLine("**")
objTextFile.WriteLine(" Date: " &Dt &" Time: " &Tm)
objTextFile.Close
Dim sCOMMAND As String
sCOMMAND="print c:\mach3\toolinfo.txt"
Shell("c:\winnt2\system32\cmd.exe /c" & sCOMMAND)
End
Deg = Rad* 57.29577
For Mach3 turn there is no A axis but if you want to thread then this
is the way to do it
ToolNum = GetOEMDRO(824)
Desc = GetToolDesc(ToolNum)
Call SetTicker(1, " " & Desc)
Also, here is some other Stuff Art Posted on the Yahoo forum dealing with getting and setting the Tool table:
To Set and Get Tool Table Parameters:
SetToolParam(SHORT toolnum, SHORT param, DOUBLE data) 'param { 1 = tool diamter, 2 = ZOffset, 3 = xwear, 3 = zwear }
GetToolParam(SHORT toolnum, SHORT param) 'param { 1 = tool diamter, 2 = ZOffset, 3 = xwear, 3 = zwear }
Put in #99066 = start angle for the thread in the code
so if you want to do 3 start thread then
#99066 = 0
threading code
#99066 = 120
same threading code
#99066 = 240
same threading code
66 is the DRO number of the start angle for a thread. When used with
#99(DRO number) the DRO is accessible in Gcode.
Serial Port:
Writing:-
Call SendFIFO("M104 S" & S$ & Chr(10)& Chr(13))
Reading:-
D$ = GetFifoEntry()
ClearFiFo()
Parmetric Programming:
THe macro code is shown in the ( ) after the macro call
We have run senarios that redirected all over the place and it still
work.
Example code:
#3=3
o100
G0X#3
#3=[#3+1]
M9999 (If (GetVAR(3) > 6) Then Code" (END M9999)" Else
code"M98 P100 " )
m30
%
SendKeys that will activate Video plugin.
SendKeys "+%(P)V"
Sending Keys
You can easily send keys to the active window, as if the user was pressing keys on the keyboard by using the SendKeys statement.
Shell "notepad", vbNormalFocus
SendKeys "This is a test string"
The code above runs notepad, and sends the keys 'This is a test string' to it. If you want to use special keys, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes shown below:
Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes:
Key Code
SHIFT +
CTRL ^
ALT %
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use "+EC".
To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.
Run two separate G code files.
Store your file in the subroutines directory within Mach and call them with a program like this
O0001 (MAIN PROGRAM)
M98 (SUB_PROG1.TAP)
M98 (SUB_PROG2.TAP)
M30
scott