Mach2 6.11 Custom
Mach2 6.11 Custom
Customisation Guide
Front cover: Brown & Sharpe Universal mill 1862 (with some "artistic" liberties)
Back cover (if present): The old, gear, way of co-ordinating motion on mill table and a
rotary axis
Contents
1. Preface ............................................................................................. 1-1
10. Index.................................................................................................... 2
1. Preface
Any machine tool is potentially dangerous. Computer controlled machines are
potentially more dangerous than manual ones because, for example, a
computer is quite prepared to rotate an 8" unbalanced cast iron four-jaw chuck
at 3000 rpm, to plunge a panel-fielding router cutter deep into a piece of oak or
to mill the clamps holding your work to the table!
This manual tries to give you guidance on safety precautions and techniques
but because we do not know the details of your machine or local conditions we can accept
no responsibility for the performance of any machine or any damage or injury caused by its
use. It is your responsibility to ensure that you understand the implications of what you
design and build and to comply with any legislation and codes of practice applicable to your
country or state.
If you are in any doubt you must seek guidance from a professionally qualified expert
rather than risk injury to yourself or to others.
This document is intended to give details about how to customise the Mach2 system. It
assumes that you are familiar with the contents of Using Mach2Mill or Using Mach2Turn
(still in preparation) as appropriate.
Some customisation, for example, changing keyboard shortcuts or removing unwanted
controls from a screen, is very straightforward and can easily be achieved by a user familiar
with typical Windows applications and the conventions for using them. Other features such
as interfacing special devices like tool-changers and designing wizards for automating
special tasks requires a knowledge of programming and/or hardware. This manual does not
attempt to cover the basic skills but shows how to apply them when customising Mach2.
You are strongly advised to join the online discussion forum for Mach2. This is currently
hosted by Yahoo! A link to join it is on the Company page at www.artofcnc.ca You should
be aware that, while the forum has many engineers with a vast range of experience as
participants, it does not constitute a substitute for a machine tool manufacturer's support
network. If your application requires this level of support then you should buy the system
from a local distributor or an OEM with a distributor network. In that way you will get the
benefits of Mach2 with the possibility of on-site support.
Certain portions of text in this manual are printed "greyed out". They generally describe
features found in machine controllers but which are not presently implemented in Mach2.
The description of a greyed out feature here is not to be taken as a commitment to
implement it at any given time in the future.
Thanks are due to numerous people including the original team who worked at National
Institute for Standards and Testing (NIST) on the EMC project and the innumerable users of
Mach2 without whose experience, materials and constructive comments this manual could
not have been written. Particular thanks are due to Olivier Adler and Brian Barker for their
contributions to the development and documentation of Wizards and to Les Newell for his
KeyGrabber (which now grabs a lot more than key strokes!).
ArtSoft Corporation is dedicated to continual improvement of its products, so suggestions
for enhancements, corrections and clarifications will be gratefully received.
Art Fenerty and John Prentice assert their right to be identified as the authors of this work.
The right to make copies of this manual is granted solely for the purpose of evaluating
and/or using licensed or demonstration copies of Mach2. It is not permitted, under this
right, for third parties to charge for copies of this manual.
Every effort has been made to make this manual as complete and as accurate as possible but
no warranty or fitness is implied. The information provided is on an "as is" basis. The
authors and publisher shall have neither liability nor responsibility to any person or entity
with respect to any loss or damages arising from the information contained in this manual,
Use of the manual is covered by the license conditions to which you must agree when
installing Mach2 software.
2. Communication routes
In this chapter we will look how the hardware of the machine tool and its
user controls, the computer hardware and Mach2 communicate with each
other.
You will probably find it best to skim this chapter and return to it as you look
at the other individual customisations.
Before we can look at customisation in detail you will have to know how the various parts
of your machine communicate with Mach2 and, indeed, how you communicate with it.
Figure 2.1 shows the important communication routes and with the following description
should allow you to understand how they work. The diagram looks complex and this is a
fair reflection of the fact that Mach2 is complex and can be configured to work with many
types of machine. Your system will, almost certainly, not have all the features on it but,
before you start customising, now is a good time to understand the options. Notice the key
which explains what the different type of lines represent.
2.2.1 Keystrokes
A "keystroke" produces a scancode that is sent to your computer using the PS/2 or USB
connectors. They can be generated in three different ways:
• By typing on the computer keyboard
• By closing/opening a switch connected to a keyboard emulator. Such devices
may be connected via the Universal Serial Bus (USB) and/or be daisy-chained
to the main keyboard. They were originally developed by the gaming
community to allow computer games to put in and be controlled by arcade-
like cabinets but are very convenient for machine control applications. It is
also possible to connect an encoder (typically low resolution like those used
as "digital potentiometers" in hi-fi and video equipment) and to generate a
given scancode for each "click" in the clockwise direction and another
scancode for each counterclockwise click.
• By pressing a button or key on a custom keyboard (perhaps like a numeric
pad on a long lead, buttons on a joystick, or a "console"). These options are
Rev 6.11-A6 2-1 Mach2 Customisation Guide
Communication Routes
really just some switches and an emulator in a standard box, probably with
some neat way of labelling the switches. Windows refers to them as Human
Interface Devices (HIDs) Figure 2.2 shows an example with a Mach2
function overlay sheet in place.
A keystroke when Mach2 is running can, of course, do many things: be part of a command
entered in the MDI line, be part of a value entered into a DRO or be a hotkey shortcut. A
real keyboard will be used for all these things but the other sources of keystrokes will
generally only be used for shortcuts.
3. Screen Designer
His chapter describes the features of Mach2 Screen Designer. This program
allows you to customise the released screens and to design your own, from
scratch, both as main screens and for wizards
Mach2Mill comes with a standard set of screen layouts to suit many uses. You are strongly
advised to use a screen resolution of 1024 x 768 pixels if you can, but screens can be
provided for 800 x 600 and 640 x 480 pixels.
The Screen Designer lets you change the layout of any or all of the information displayed
on screen by Mach2. You can, if you wish, design a complete set of custom screens but, as
there are more than 800 individual objects on the standard screens, most users will probably
only want to make detailed changes to the layout.
The screen to use is loaded into Mach2 using the View>Load Screen menu. Screen layouts
are stored in files with the .SET extension or the .SSET extension. The Screen Editor
application is used to edit layout files.
The individual screens within a layout can be moved, deleted, imported etc. using the
ScreenTweak utility (q.v.) This is primarily concerned with manipulating whole screens
while Screen Designer deals with individual controls, their functions and positioning.
By default you will be putting controls on Screen #1. Use the numbered buttons on the
toolbar to select other screens and place controls on them. Try placing some controls on the
"P screen" and see that they actually appear on all screens 1 to 15.
If you click on a control you have placed you will see that it becomes selected and is drawn
with the traditional sizing handles. It can be moved around the screen and resized by
dragging the outline or the relevant handles. You can also move selected objects by
"nudging" them with the left/right/up/down cursor keys. Each keypress moves the control
by one pixel.
Multiple objects can be selected using Shift-click. One selected object in a set can be
deselected by Control-click.
The selected objects can be cut or copied to a clipboard and the contents of the clipboard
can be pasted onto the same or another of the fifteen screens. Notice, that although you can
run more than one copy of Screen Designer at one time editing different .SET files, each
has its own clipboard so you cannot move controls from one file to another using the
clipboard.
When you resize a control, other than a button, with the handles then its contents are scaled
to fit the new size. This is how you decide on the font size for DROs, labels etc.
When you have created a test screen, use Save As to save it with a new file name. Run
Mach2 and load your screen using the View>Load Screens menu. You should never
overwrite the default screens with your designs as these files are likely to be overwritten by
the installer each time you upgrade Mach2 to a new version.
Shift 1,024
Ctrl 32,768
Alt 2,048
Mach2 Customisation Guide 3-2 Rev 6.11-A6
Screen Designer
Thus Shift-A would be 1,089 (65 + 1,024), Alt-/ would be 2,095 (47 + 2,048) and
Shift-Ctrl-Alt-spacebar would be 35,872 (32 + 1,024 + 32,768 + 2,048)
If you have worked with binary numbers then you will recognise that these rather odd
looking numbers are actually powers of two.
currently displayed screen. A useful trick for VB Script or G-code buttons, that you want to
work at all times, is to draw them on the persistent screen but off the bottom of the viewable
area. You can "design" here by hiding the toolbar and status bar using the View menu or by
designing on a higher resolution display than you are going to use with Mach2.
If you are only interested in adding hotkeys, G-code and VB Script then you probably need
to skip to the section on "Properties of other controls" and then read no further about Screen
Designer. Exit not saving any changes to the 1024.SET.
Figure 3.5 - Same width DROs Figure 3.6 - Same size DROs
The size of a control, other than a button, will determine the size of any text in it.
Figure 3.10 illustrates a prototype of such a screen (courtesy of Ken Bell). In such a design
the DROs, labels, LEDs etc. are real Mach2 controls. The buttons are in the bitmap but have
empty bitmaps drawn over them to define the "hotspots".
Figure 3.10 – Screen with all graphics on bitmap and transparent buttons
Another advantage of this type of screen design is that it is fully scalable to different screen
resolutions using ScreenTweak as it does not have the problem of the fixed size text of
conventional buttons.
3.7 Colors
The Screen Designer Clr icon lets you define the colour scheme for your screens and
controls. This is a global setting; it does not relate to the selected items.
This chapter aims to help you write button or macro code of your own which
can range from performing simple tasks (e.g. implementing non-standard M-
codes from other controllers) to performing complex calculations on data
which will be used in the part program. This might simulate, for example,
engine turning as geometric pattern to decorate an object.
Warning: It is not advisable to write macros to call in part programs if you want them to be
portable to other CNC controllers.
If you are considering writing VB Script then you will need to have some experience of
simple computer programming (e.g. in Visual Basic, C or even BASIC). This chapter does
not attempt to teach programming.
All the usual VB Script data and control structures can be used in the program. For details
consult Windows Script 5.6 Documentation available for download by following some
obvious links from:
http://msdn.microsoft.com/scripting/
The Microsoft presentation is rather oriented to scripts of web pages but the documentation
that you can download summarises the data types, control structures, operators etc. very
clearly. You will not need to use advanced features like Classes. Regrettably this
information is not presented in a form which can conveniently be printed out so you might
consider purchase of one on the many books on VB Script.
You will find that there are many operators for manipulating strings, doing trigonometry
etc. VB Script is a complete and very capable language. The only rstrictions within Mach2
scripts are on the use of input/output functions and subroutines.
The first line is a Remark, ignored by Mach2 but useful to remind one what the button does.
The Dim statement declares a variable to use again not essential. GetDRO (18) reads DRO
function code 18 (which is the commanded feedrate) and assigns it to the variable val. The
quote ' character introduces a comment on the end of a line of code. If val is zero then it is
set to 1 otherwise it is incremented by 20%. Finally the new val is stored in the Feedrate
DRO so setting the required rate.
As you can see from the dialog the caption on the button will be "Geometric up". A similar
button might be provided with code for Geometric Down.
TxtChoice = "G20G61"
Case 10
TxtChoice = "G21G64"
Case 11
TxtChoice = "G20G64"
Case Else
Code "(MSG,P word is not valid - defaults are set)"
End Select
Commentary on program
As mentioned before the comments, lines starting with Rem or the text following an
apostrophe ' are not interpreted by the system.
Unlike the C and C++ languages, VB Script is not case sensitive so NEWRATE,
NeWRate, newrate are all the same variable. You can, however, use case to make your
programs easier to read.
Variables can be used in the VB Script code to store numbers or character strings. They do
not have to be declared but using a Dim declaration helps other people to follow your
program.
The program next accesses the value of the P word in the macro call using the Mach2
standard function Param1(). The brackets show that a function is being called. The value,
in this case a number, is assigned to the variable PValue.
Next the Select Case control structure is used to assign a different string to
TxtChoice depending on the value of the P word. Other control structures available
include If Then Else End If and various forms of loop.
The VB Script program can interact with the operator by asking for a value by using the
Mach2 function Question. In the example above no value is used. If a value is required then
the form x = Question ("What is the new X value") is used.
Next the program uses the & operator to concatenate (join) the TxtChoice string which is
already set up with the standard initial G values and uses the Mach2 function Code to send
the string to Mach2 to be interpreted.
Finally the R and S words are accessed by Param2() and Param3() and, if used, are
sent to Mach2 by the function SetFeedRate and another use of Code.
Either is correct and both do the same thing. If you like to group the arguments with
brackets then you need to use the keyword Call as well.
A function can be called and have its result thrown away as in this example:
Question ("Did you know P word was not valid - defaults are set")
JoyStickLEDFn = 14
:
:
bJoy = GetLed (JoyStickLEDFn)
LEDs
Function GetLED (ledFun as Integer) as Boolean
Function GetOEMLED (ledOEMCode as Integer) as Boolean
Function GetUserLED (ledUserCode as Integer) as Boolean
Choose the appropriate routine depending on whether you want to access a built-in,
OEM or User LED. ledUserCode must be in the range 1000 to 1244. The result is
True (i.e. non-zero if converted to an integer) if the LED referred to is alight.
User LEDs, only, can be set on or off by:
Sub SetUserLED (ledUserCode as Integer, cond as Integer)
If cond = 1 the LED will be on. If cond = 0 then it will be Off
Examples:
bJoy = GetLed (14) ' set variable bJoy if Joystick is enabled
If GetOEMLed (29) Then ….. ' see if a Fixture is in use
SetUserLED (1002, 1) ' turn on user LED
DROs
Function GetDRO (droFun as Integer) as Double
Function GetOEMDRO (droOEMCode as Integer) as Double
Function GetUserDRO (droUserCode as Integer) as Double
Choose the appropriate routine depending on whether you want to access a built-in,
OEM or user DRO. droUserCode will be in the range 1000 to 1254. The result is the
current value displayed by the DRO.
Sub SetDRO (droFun as Integer, newValue as Double)
Sub SetOEMDRO (droOEMCode as Integer, newValue as Double)
Sub SetUserDRO (droUserCode as Integer, newValue as Double)
Choose the appropriate routine depending on whether you want to access a built-in,
OEM or user DRO. droUserCode will be in the range 1000 to 1254. The routine sets the
expression provided for newValue into the DRO. Not all DROs can be written. If you
cannot type a value into the DRO on the screen (e.g. X Velocity = function 6) then you
cannot set it in a script.
Sub KillExponent (result as String, smallNumber as String)
Provided to address the problem that VB Script is liable to represent small numbers (e.g.
0.0000012) in scientific (exponent) notation. The routine forces the string to be decimal.
Example:
Call SetDRO (18, GetDRO (18) * 1.1) ' increase feedrate by 10%
Button Commands
Sub DoButton (buttFun as Integer)
Sub DoOEMButton (buttOEMCode as Integer)
Choose the appropriate routine depending on whether you want to use a built-in or OEM
command. Mach2 is instructed by the script to perform the function specified.
There is no provision for the trapping or reporting of errors but as most functions have
an LED associated with them this can be inspected by the script code to check that the
required action has been performed..
Very many "buttons" are toggles or cycle through a range of possible states or values. A
loop containing inspection of an associated LED can be used to set a particular state.
This example would be particularly suitable to be attached to a button.
Example:
Rem This sets the MPG jog on and the wheel to jog the Y axis
Rem There are actually more direct ways to do this in late releases
Rem of Mach2
JogTogButton = 174
JogMPGEn = 175
MPGJogOnLED = 57
MGPJogsY = 60
OK = False
For I = 1 to 2
If Not GetOEMLED (MPGJogOnLED) Then
Call DoOEMButton (JogMPGEn) ' try to enable
Else
OK = True ' MPG is enabled
Exit For
End If
Next I
Rem Could test of OK true here
OK = False
For I = 1 to 6 ' must get there after six axis tries
If Not GetOEMLED (MPGJogsY) Then
Call DoOEMButton (JogTogButton) ' try next one
Else
OK = True ' got right axis selected
Exit For
End If
Next I
Rem Could test OK here as well
Notice that the word "Param" is used here in a different sense to the Machine Parameters
accessed by the # operator from within a part program and in accessing the Q, R & S
word "parameters" to a macro call.
Sub CloseTeachFile ()
Closes the currently open Teach or wizard file and stops commands being written to it.
Option Explicit
CutDepth = Param1()
While CutDepth <= 0 ' the P word is not given
CutDepth = Question ("What depth of cut do you want each pass?")
Wend
While CurrZ > EndZ ' loop for the z planes cut
CurrZ = CurrZ – CutDepth ' Update Z
If CurrZ < EndZ Then
CurrZ = EndZ ' last cut dead to size
End If
code "G1Z" & CurrZ ' feed down
code "G1X" & StartX ' cut pass
code "G0Z" & (CurrZ + 0.1) ' avoid scratching surface
code "G0X" & EndX ' back to right end
Wend
code "G0Z" & StartZ
code "G0X" & StartX
In this macro, which will probably be used from MDI the P word is used to define the depth
of cut in each pass. So a typical call using inch units might be M62 P0.05
The macro then asks a series of questions to establish the X coordinates of the ends of the
bar and the original and desired Z values. These values are validated and re-prompted for if
they are invalid.
A While loop then performs cutting moves with ever decreasing Z until the desired size is
reached.
There is nothing that the operator can type that will correct the invalid EndX value for the
code loops for ever. You can only get out of this by using Control-Alt-Delete and getting
Windows to end the Mach2 program. In this case you must run OCXTest to reset the driver
or re-boot Windows.
If the line in grey in this code
While CurrZ > EndZ ' loop for the z planes cut
CurrZ = CurrZ – CutDepth ' Update Z
If CurrZ < EndZ Then
CurrZ = EndZ ' last cut dead to size
End If
code "G1Z" & CurrZ ' feed down
code "G1X" & StartX ' cut pass
code "G0Z" & (CurrZ + 0.1) ' avoid scratching surface
code "G0X" & EndX ' back to right end
Wend
is omitted or if CutDepth could be zero or negative then the While will run for ever.
This is worse than the loop above because each time round it requests the execution of some
G-code. Eventually the buffer will overflow and may well crash Mach2 in totally
unpredictable ways.
5. Designing wizards
The techniques of VB Script and custom screens can be combined to implement
"conversational programming" of the machining of a design using Mach2. Examples of this
feature have been shown earlier in the manual. This section gives details of how you can
write your own wizards.
detail the use of user DRO’s, teaching files, and restoring the system screens after the
wizard has run.
The wizard creates a part program which moves over a rectangulare area in the X and Y
plane plunging a probe in the tool holder to discover the Z height of a model object on the
table. If you have not used the Digitize wizard, now would be a good time to try it. It does
not matter if you have not got a probe – just stop before actually running the part program.
Next we add the rest of the controls required for the user to define what the wizard is to do.
We can label and tidy them up them later. You should save your layout in the folder you
created for your wizard. The screen will look like figure 5.3
It begins by getting the values of all the User DROs on the screen and assigning their value
to variables. This makes the code doing the calculation much easier to read than if it just
has OEM button numbers. We then do a simple calculation of the Width divided by the
Step times the Height divided by its Step. This is roughly the number of probing positions.
Rem set the current location to 0,0,0 and open the file
code "M40"
code "G92X0Y0Z0"
code "F" & Feed
The above lines start the preamble with a G92 offset and set the feed rate according to what
has been entered in the DRO.
direction = 0
' first iterative loop
for y = 0 to YWidth step Stepy
if direction = 1 then
direction = 0
else
direction = 1
end if
for x = 0 to XWidth step Stepx
if direction = 1 then
code "G0X" & x & "Y" & y & "Z" & Safe
else
code "G0X" & XWidth - x & "Y" & y & "Z" & Safe
end if
code " G31 Z" & Min
code " G0 Z" & Safe
Next x
Next y
if direction = 1 then
code "G0X" & XWidth & "Y" & YWidth & "Z" & Safe
else
code "G0X" & 0 & "Y" & YWidth & "Z" & Safe
end if
All of the above lines to the calculations and write the G31 commands which will actually
do the probing in the program that you creating.
code "G0X0Y0Z" & Safe
code "G0X0Y0Z0 "
code "M30"
And finally wecomplete the program with an M30 to do a rewind.
CloseTeachFile
The above line closes the digitize teach file.
call LoadStandardLayout()
call LoadTeachFile()
In the above to lines tell the program to remove the wizard from the screen and load the
screen layout that Mach2 normally runs with, and then load the Teach file into the system
ready for cutting.
That would be the complete job but a user might want to create several digitizing jobs, and
would not want to re-enter the data each time. The wizard can be provided with a button on
its screen which tells the system to save the current settings when the wizard exits so that
next time and is called the same settings will be in all the DRO's.
To do this we simply create a button, make it run a VB Script routine Savewizard(). This
command tells the system to save all the DRO's that have been used into a file in the
wizard's folder with a .DEF extension.
This saving works as follows. When the wizard is loaded, the first 200 OEM DRO's, ticker
labels and LEDs are saved so that the wizard will not overwrite them. The next 55 DRO's
labels and LEDs if they are changed by the wizard will stay changed when the wizard exits
and control is passed back the Mavh2. If the Savewizard() script call is made then all
255 DROs, LEDs and ticker labels are stored in the .DEFS (for Defaults) file for loading
next time the wizard is called.
after the code G31Z-10 statement. This will make your macro wait until the probe is done
before actually commanding a G92Z0. Subsequent versions of the Mach system will reduce
the need for this sequence but it will never do any harm to include it.
Armed with this basic introduction you can now study other Wizards. The facility is very
powerful but you do need to be very careful in testing your code. Some hints are given in
the next section.
5.4.1 Function
The function of the wizard can range from simple tasks, such as the setting up of work
offsets, to complex routines, such as automated circular pocketing or engraving. In any
case, it is very important that the function is laid out in well designed, logical steps. For
example, to make a cut, you would first have to tell the tool to rapid to the starting point,
then feed to depth, then feed to the end point, then retract the tool. The maths to calculate
the tool paths is best done initially by hand, in order to ensure that you are going to get the
results that you are looking for. If possible, try to make a list of what inputs you are going
to need so that you can easily make DROs and/or LEDs for them when you design your
screen.
5.4.6 Troubleshooting
There are a few things that can be done to help debug the code.
The most important is to have descriptive variable names. This will help in making the code
more readable. For example, instead of having an input for the Rapid Plane and calling it
“x”, name the variable Rapid_Plane – not only does it save you the trouble of having to
jot down a note to tell you that “x” is the Rapid Plane value, but it’s a lot easier to follow
that value through any equations you do with it, to pick out any possible mistakes.
Another good idea is to add a toolpath window and a code window to the wizard screen.
These allow you to view the code and toolpath, and this helps in testing because you can
change the DRO values and check for errors.
Also, be careful when using loops - they are great for doing repetitive tasks, but have the
potential to lockup the computer (endless loops)! To keep this from happening, you can add
an If statement to see if the loop is run more than an arbitrary number of times, and then
break out of the loop if it exceeds that number.
7.2.1 Introduction
Mach2ScreenTweak is a utility program aimed at OEMs, dealers and expert users of
Mach2Mill and Mach2Turn who make use of the "Screen Designer". It is designed to
complement rather that replace that program.
Mach2ScreenTweak is really concerned with manipulating the individual screens within a
Mach2 Layout. In other words it processes .SET files.
The following is a summary of its main features:
Import screen(s) from another layout (perhaps locally designed screens imported into
the standard ones)
Delete screen(s) from a layout
Promote/Demote a screen in a layout so its screen number as used in Screen Designer
corresponds to its "position" in normal use
Allocate F-key numbers to screen selection buttons and input new caption text for
these buttons after screens have been moved or added
Scale down or up the size of a screen or all screens in a layout to work with a different
resolution of display
Re-order the DROs in a group so that the arrow keys traverse them logically (in
columns or rows) rather than in the order in which they were created in Screen
Designer
Export a comma-separated-variable file with a record for each control on the screens
of a layout to analyse and document a layout.
The code is written in Visual Basic (Version 6.0) and the source is available on request for
not-for-profit use. Hopefully this will encourage others to develop and distribute screens,
utilities, filters, wizards etc. in the open way in which Mach2 and its predecessors evolved.
7.2.2 Installation
The utility is distributed as a .ZIP file including the executable Mach2ScreenTweak.exe,
this manual and the standard Microsoft Common Dialog ActiveX controls in
COMDLG32.OCX
Rev 6.11-A6 7-1 Mach2 Customisation Guide
Screen layout file format
The .ZIP also includes a sample layout (TweakSamp.set) that contains 1024 resolution
screens with Caption Labels that can be used to try out appending screens from an
Additional Layout.
Mach2ScreenTweak.exe can be copied into any convenient folder and run from there via a
desktop or quick-start area shortcut.
If your system does not already have it, then you will need to copy COMDLG32.OCX into
the folder C:\Windows\System32.
The utility can be uninstalled by deleting the .EXE file and, if specially installed, the
COMDLG32.OCX
7.2.4.3 Save As
The Save As button prompts for a file in which to save the modified Layout. You may of
course save into the originally opened file but this is discouraged by the absence of a Save
button.
This button is also implemented in the File menu.
button(s) that display them (typically on the Persistent screen) and as a last resort the
number of controls on the screen. Full details of this identification are given in section 5 of
this document.
7.2.5.1 Delete
Deletes the selected screen and moves all those below it in the list up to close the gap. Undo
will of course undo a sequence of consecutive Deletes.
they are not appended with all the other controls. This "disappearance" of
controls is noted in a confirmation dialog after the append.
• Sequences of appends can be undone like any other operation on the Principal
Layout.
7.3.2 ControlRec
Figure 7.4 shows the structure of
each ControlRec. The values are
Int32 Control Function
integers or strings.
Int32 Control Type
Integers are as defined already, some Int32 Displayed on Screen number
of which indicate True/False boolean C-String Text on control
values by being Zero = True, C-String G-code text
nonZero = False. C-String Path of bitmap file
Strings follow the C Language Int32 HorizCode
structure of a one byte character Int32 VertCode
count (unsigned so allowing 0 to 255 C-String Label
characters) followed by the Int32 Color
characters, one per byte, using the Int32 OEM Code value
Windows character set. This is Int32 HotKey code
illustrated in figure 7.5. Care should Int32 Flash flag
be taken if you try to put a " (double- Red/Green flag
Int32
quote) in a string as this character is
C-String Format code
used as the delimiter in CSV files.
Int32 Tabbing group
Note: that although strings and hence Int32 PosX1
ControlRecs are variable length they Int32 PosY1
can be decoded by knowing the Int32 PosX2
format and moving serially through
Int32 PosY2
the file interpreting the character
counts of the strings. Direct access to
records in the layout file are not Figure 7.4 – Structure of record for each Control
possible.
Most of the
fields of the
Byte8 Count of characters in string n = 0 to 255
ControlRec
are dedicated Char8 Char8 Char8 Char8 Char8 etc. Char8 Char8 Char8
to data for a
particular Figure 7.5 – Storage of character strings
type of
control. The values for other controls will be "undefined". The following explains the
purpose of each value. The detailed coding is to be found at the Mach Developers' Network
(MachDN) site. (See Frontispiece for current link)
7.3.2.1 Screen
The number of the screen (1 to 15) on which control will appear. Value 0 will appear on all
screens (i.e. persistent control)
7.3.2.2 Type
The coded type of each control as follows:
Type code Control
1 DRO
2 Scrollbar
3 Bitmap
4 Conventional Button
5 Jogball
6 LED
Rev 6.11-A6 7-7 Mach2 Customisation Guide
Screen layout file format
7 Label
8 Bitmap Button
9 Manual Data Entry (MDI)
10 G-code window
11 Toolpath display
7.3.2.3 Function
The function is a code starting from 0 for each type of control defining what it displays or
does. The code numbers can be obtained by counting (from 0) the radio buttons in the
Screen Designer dialog box that sets up the relevant type of control. The following
functions are extended by OEMcodes (see below):
Control type Function code that is
extended by OEMcode
DRO 12
Conventional button 32
LED 56
Bitmap button 32
7.3.2.4 OEMCode
DROs, LEDs and conventional and bitmap buttons which have special purposes and are not
included on the radio buttons in Screen Designer are accessed via the "OEM" radio button
and an "OEM" code. This is really an extension to the Function. Public OEM codes are
listed in Layouts on the MachDN site. Hint: To manipulate these codes in a database it is
often convenient to combine Function and OEMCode by a formula such as (Function x
1000 + OEMCode) where OEMCode is set to zero if the Function does not use it.
7.3.2.5 Text
For conventional Buttons, this is the caption on the button.
7.3.2.6 GText
For Conventional and Bitmap buttons whose function is 33 this string is the G-code line to
issue.
7.3.2.7 BitMapPath
For Bitmap buttons this is the filename of the .BMP file on the user's machine. (e.g.
C:\Mach2\MyStart.bmp)
7.3.2.9 Label
The string displayed in a Label control. Some values like File, Error are "intelligent" and
are replaced by what they describe at runtime. Labels starting with the S mark (§) are used
as screen captions.
7.3.2.10 Color
Used for LED controls. Green = 0, Red = 1, Yellow = 2
7.3.2.11 HotKey
For Conventional and Bitmap buttons this gives the scan code of the HotKey to activate the
button (or 0 for no HotKey).
Mach2 Customisation Guide 7-8 Rev 6.11-A6
Screen layout file format
8.1 KeyGrabber
8.1.1 Overview
Chapter 8 gives a general description of the control of Mach2 including Human Interface
Devices (HIDs) and keyboard emulators.
KeyGrabber is a utility written by Les Newell, to whom very many thanks are due, which
translates signals from the keyboard, a keyboard emulator or the buttons, Point of View
control or axes control of one or more HIDs into keycodes in Mach2's input buffer. These
keycodes can then be interpreted by Mach2 as jogging hotkeys, screen button/DRO hotkeys
or to activate/deactivate simulated signals. They could be entered into DROs or the MDI
box if you want to implement a numeric keypad or the like..
KeyGrabber, unlike some general profiler programs, knows that it is running with Mach2
(actually it assumes responsibility for starting Mach2 or ScreenDesigner) and so will direct
the HID buttons and the specially defined keycodes from the keyboard emulator or, indeed,
the actual keyboard to Mach2 even if another program has the focus. Hence its name – it
grabs keycodes for Mach2's use.
Many keyboard emulators were originally developed for use by the computer gaming
community to interface the controls of an arcade style cabinet to the PC using the MAME
standard codes. Some, however, can be configured to generate other codesets. KeyGrabber
has a facility for programming the Ultimarc IPAC/2 and IPAC/4 with a set of codes
different from any that can be produced by the PC keyboard. It also identifies these codes
using the signal names of the IPAC.
KeyGrabber will implement Typematic repeating of keycodes from any of its possible
inputs. This is useful for operating screen buttons for spindle speed control, and feed and
jograte override. This Typematic hat three settings for each input. It can be set to be off, to
be at one speed or to change (typically increase) speed after a defined number of repeats.
HIDs can be configured to have up to four separate meanings to each button. This is
particularly useful on devices where the buttons are easy to label such as a membrane
keyboard like the Saitek P8000 (aka Dash/2). The definitions are defined as pages 1 to 4.
You can define arbitrary buttons on the HID to be the page selectors. Buttons such as "Fire"
and "Shift" are often convenient choices.
When Mach2 is running without KeyGrabber it not only recognises the keycodes but
interprets them according to whether the Shift Ctrl or Alt keys on the keyboard are
simultaneously depressed. These keys are called modifiers. For example the standard
layout uses Alt-R for the Cycle Start hotkey, the Ctrl key will switch Jog modes between
Inc and Cont while it is depressed and Shift will cancel a jograte override. KeyGrabber can
be used to define arbitrary HID buttons to produce the Shift Ctrl and Alt modifiers
Finally in this overview, low resolution encoders are a useful human interface to Mach2 for
implementing an MPG style axis jog dial and for rotary panel controls for speed and feed
override. KeyGrabber will interpret a pair of inputs to a keyboard emulator as quadrature A
and B signals and translate these into a keydown/keyup of a user defined keycode for each
clockwise "click" and a similar sequence for another keycode for each counterclockwise
"click". These codes can operate the incremental jog hotkeys or the hotkeys for up/down
buttons within Mach2.
Although, in principle re-mapping codes and the other functions of KeyGrabber are
straightforward, the detail can be confusing. You may find that this appendix is easier to
understand if you experiment with the software and devices as you read it.
8.1.2 Installation
The KeyGrabber window has a tab for each. Additional tabs are displayed when HID
devices are enabled.
The tabs are described in the following sections:
This tab shows a table of keycodes which may be received from the Windows keyboard
port and the corresponding codes to be sent to Mach2. These codes can, of course, come
from an actual keyboard or a keyboard emulator. See figure 8.1.
Either double-click or right-click and choose Define in an entry in the Source key column.
This allows you to define the code you want to be processed. You will be presented with a
dialog asking you to Press a Key. On an emulator this corresponds to making the circuit
connected to the emulator input pin. If the code corresponds to one programmed into an
IPAC then you will be told the terminal label and pin for this input. If the code corresponds
to a key on the keyboard then you will be shown the character on the key (e.g. Q) or a
description of the key (e.g. LEFT for the left cursor arrow).
Where meaningful, a default value of the code to be sent to Mach2 will have been put into
the Translate to column. A double-click or right-click in this entry allows you to redefine it
to any translated value. Good keys are the ones on the numeric keypad, function keys or
multimedia special function keys. Any keyboard emulator code that does not have a default
but which you do not want to translate can be entered by making the circuit connected to
the emulator input pin again with the Translate To Press a Key box showing.
An alternative to pressing a "key" is to choose Special Keys. This displays the options
shown in figure 8.2. You can say that the "key" which you are defining is to be the Shift or
Ctrl modifier or one of 32 unique user key values. These are chosen so as not conflict with
other actual codes. The Alt modifier is not available from the keyboard as Windows makes
priority use of it.
When Mach2 (or Screen Designer) is running then any keycode that is not in the first
column, which will be most of them on you system, will be ignored by KeyGrabber and
sent by Windows to the application which has the focus when the keycode arrives. The
corollary of this is that any key whose code is in the list will not be seen by any application
other than Mach2 while Mach2 is running with the KeyGrabber. You will be warned when
you try to setup keys on the standard keyboard that this will happen. It does become rather
annoying but it might help you being too confused when you first "grab" A, Q, Z and M and
find that Microsoft Word cannot input Monday (ondy) or Zebra (ebr) or worse you cannot
get a password with any of these letters in it accepted!
The final Options column allows you to choose if typematic is to apply to the keycode and
if modifiers will be sent with it. Double-click or right-click and define the cell you want to
set. Figure 8.3 shows the dialog.
The parameters for Typematic which apply to all codes are defined on the Misc. Settings
tab. If you select Two stage typematic then the Translate to keycode will be sent to Mach2
at the specified First rate until Number at first rate codes have been sent. Codes will then
be sent at Second rate.
Note: If you have a keyboard emulator which provides hardware key repeat (typematic) on
its inputs then KeyGrabber will ignore this.
Now press a button on the HID. Its line is selected. By double-clicking or right-click and
Define theTranslate to column then the keycode that this button is to Translate to can be
defined by pressing the appropriate key.
A key can be defined to select an alternative Gain for the Joystick axes. See Misc Settings
for more details.
Special keys like Shift and Ctrl and User defined keys can be set up in exactly the same way
as with the Keyboard Keys dialog but with the additional option to define a button as a HID
Page Select code. By default when you apply a page select code this will be put on all
pages. This can be overidden if required but if you do this you may make it difficult for the
user to access .
Exactly the same procedure is followed to assign codes to POV controls and HID analog
axis controls. They can be used for page selection. For details of how an axis position is
converted to the relevant entry in the table see the section on Misc Settings below.
and "low" gain can be chosen dynamically for all axes using a HID key. When the
configured key is pressed the Joystick Sensitivity Button Down value is used. If the key is
not pressed then the Button Up value is used. This can be used to have high speed jogging
for fast positioning with a button pressed and a very fine control when it is released.
which specifies the Mach2 profile to use. Thus for example if the original shortcut to run
Mach2 to control your lathe was:
C:\Mach2\Mach2 /p Mach2Turn
Then replacing it with a shortcut with a Target of:
C:\Mach2\KeyGrabber.exe Turn.grab /p Mach2Turn
Would run Mach2 with the Mach2 profile Mach2Turn.xml after setting up KeyGrabber
with the Turn.grab configuration.
Hint: If you have several shortcuts for different KeyGrabber and Mach2 profiles then you
are very likely to want to setup different icons for each of them as described above.
shared with three input terminals. These effectively cannot be used, because they are pulled
lo, if the corresponding LED is on.
Windows 2000 command prompt windows intercept keyboard messages before they reach
KeyGrabber. If you have a command prompt window or a DOS application in the
foreground then KeyGrabber will not work from the keyboard.
9. Revision history
Hint: Where there is a choice, most index entries are made using the name of a thing
(e.g. Axis drive) rather than an action (e.g. Tuning) so you will get better results
thinking about the part on which you want information. Thus looking for "Axis drives -
tuning" will give better results than looking for "Tuning - axis drives". For important
information both entries will probably appear.
If you have difficulty because you tried to look something up and the index
entry was missing, please take a moment to e-mail [email protected]
with a note of (a) the words you were looking up and (b) where in the
manual you found the information you wanted - assuming you did!