Mach2 6.11 Custom
Mach2 6.11 Custom
Customisation Guide
Contents
Contents
1.
2.
2.2
2.2.1
2.2.2
2.3
2.4
2.4.1
2.4.2
2.5
2.6
2.6.1
3.
3.2
3.3
3.3.1
3.3.2
3.3.3
3.3.4
3.4.1
3.4.2
3.4.3
3.4
3.5
3.6
3.7
3.8
4.
4.2
4.2.1
4.2.2
ii
Rev 6.11-A6
Contents
4.3
4.4
4.4.1
4.4.2
4.4.3
4.4.4
4.4.5
4.4.6
4.4.7
4.4.8
4.4.9
4.4.10
4.4.11
4.4.12
4.4.13
4.5.1
4.5.2
4.5.3
4.5.4
4.5
4.6
5.
5.2
5.3
5.3.1
5.3.2
5.3.3
5.3.4
5.3.5
5.4.1
5.4.2
5.4.3
5.4.4
5.4.5
5.4.6
5.4
6.
6.2
6.3
7.
7.2
7.2.1
7.2.2
7.2.3
7.2.4
Rev 6.11-A6
Contents
7.2.5
8.
9.
10.
Index.................................................................................................... 2
iv
Rev 6.11-A6
Preface
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.
Rev 6.11-A6
1-1
Preface
1-2
Rev 6.11-A6
Communication Routes
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.1
Electrical connections
If you have set up your own system you will have been through the process of connecting
switches like the home switches to pins of the parallel port(s) and using the dialogs to tell
Mach2 which pins are used for which function. This is shown at the bottom left of figure
2.1. Notice we have shown the limit and EStop switches directly controlling the drive
electronics because this is the safest technique and recommended in this manual. Your
switches might, of course, control Mach2 via the parallel port(s). This would change the
arrows from the switches on the diagram to go into the port(s) instead of the motor drives
box.
Mach2 makes extensive use of these signals during running. This is shown by the arrow
into the "brain".
Some switches (currently 3) can be assigned to input pins as OEM Trigger signals. These
can be configured to do what you wish by issuing an "OEM code" command directly to
Mach2 - just like pressing a screen button does. They do not, however, need anything on a
screen to do this. The OEM Button codes that are issued by each signal are defined using
the Config>Set Axis Hotkeys dialog.
2.2
Keystroke connections
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:
Rev 6.11-A6
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.
2-2
Rev 6.11-A6
Communication Routes
2.2.2
if the code defined in the Config>Ports and Pins Input Pins dialog it will turn
On (key down) or Off (key up) the signal to which it is attached. This, used
with a keyboard emulator, gives a mechanism for extending the number of
input pins far beyond those available on the two parallel ports. Not all signals
can be made "virtual" like this and you are advised not to use the mechanism
for safety critical operations.
You may consider using having real push buttons (or perhaps a membrane switch pad)
beside the screen which can be labelled for different functions on each screen (making soft
keys like in a bank ATM) or be used for a common function like screen changing. This is
illustrated top right of figure 2.1.
A rotary encoder (MPG) connected by keyboard emulator can be used to send jog axis
hotkeys to jog axes or to send the codes for hotkeys for buttons like Raise/Lower spindle
speed or override feedrate.
This keystroke processing mechanism is shown by the blue lines on figure 2.1 from the
"keyboard devices" to the screen buttons and the Input Pins dialog.
2.3
Rev 6.11-A6
2-3
Communication Routes
2.4
VB Script connections
A part program is written using G and M codes. It is, however, also possible to program
Mach2 in another language called VB Script. This is a subset of the Microsoft Visual Basic
language which is available in many applications besides Mach2, including Microsoft
Office. While it would be possible to totally control a machine tool using Mach2 with a VB
Script program, the facility is really intended to help customise the environment in which a
G-code part program runs.
2.4.1
VB Script program
By being put in a macro and called from within a part program, the MDI line
of the G-code attached to a button. The last of these methods being suitable if
the program is too big to attach directly to the button or is required to be used
as a macro from a part program as well as a button.
call VB the functions and subroutines defined by the macro writer or provided
by Mach2 as its interface to scripts.
The predefined interface functions and subroutines are defined in detail in chapter 4 below.
The main ones allow the script to issue G-code commands, to read and write the values of
DROs, to inspect LEDs (and for User LEDs, to set them), and to send Function and OEM
codes to Mach2 thus simulating what a user does when s/he clicks a screen button.
Additionally a macro can test the values of input signals, set output signals, access internal
data such as motor tuning parameters and use parallel and serial ports not used by Mach2
itself.
2.4.2
Mach2 macro
As already mentioned, a macro is a piece of VB Script. Each macro has a name like M134.
The M is used at the start of every macro name and the number can be any integral value up
to 99999 that is not used to define a built-in M-code. These built-in numbers are listed in
chapter 11. Thus for example, M12, M50, M16543 are all valid macro names; while M3,
M-56, M0234, M567.4 are not valid names.
Standard macros will use the number range up to M999, Original Equipment Manufacturers
(OEMs) are advised to use M1000 to M89999 and end-users can avoid naming conflicts by
using M90000 to M99999.
Each macro is stored as text in its own file whose name is the macro name with file
extension ".m1s". Thus one would find files: M12.m1s, M50.m1s and M16543.m1s on a
system with the above macros in it. The macro files are collected in a folder called
"Macros" within the Mach2 folder.
A macro is called just like an ordinary M-code command by:
2-4
Rev 6.11-A6
Communication Routes
2.5
Windows' control
The final elements shown in figure 2.1 are the standard devices that control Windows.
Common examples are the mouse, and trackball. Windows also supports a gaming joystick
and throttle. This can be used for jogging and overriding jog and feed rates.
2.6
Other customisation
2.6.1
Global hotkeys
Config>Set Axis Hotkeys allows you to set up the keys which will jog the axes when the
Jog Mode button is displayed on the current screen. Click the button for the axis and
direction you want to set and then type the keystroke to be used. It is your responsibility to
make sure they are unique and do not clash with other hotkeys you might want to use. See
appendix 1 or use Screen Tweak to prepare a list of standard hotkeys.
These hotkeys can very usefully be generated by a profiler such as KeyGrabber to provide
jogging support from Human Interface Devices or buttons and encoders attached to a
keyboard emulator.
You can also define hotkeys which will select the MDI window, will select a DRO and will
display the File>Load G-code dialog. These are useful if you are controlling Mach2 without
a mouse or similar pointing device.
Rev 6.11-A6
2-5
Communication Routes
2-6
Rev 6.11-A6
Screen Designer
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.
3.1
3.2
Rev 6.11-A6
3-1
Screen Designer
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.
3.3
3.3.1
When Mach2 is running, Buttons and Bitmap buttons can of course be "pressed" by clicking
the mouse. They can also have a "hotkey" assigned to them. Pressing that key on the
keyboard when the button is visible is equivalent to clicking it with the mouse.
The "hotkey" is defined by its "Mach2 scancode". Screen Designer allows you to type the
key you want to use and it will store and display (in decimal notation) the associated
scancode.
If you need to check these codes at any time then you can calculate the value by hand as
follows:
Lookup the ASCII value of the code for the key (For letters it is the uppercase version
of the character for other keys it is the code of the unshifted character i.e. 5
rather than %). Thus, for example, spacebar = 32, A = 65, / = 47 etc. If you do not
have a printed table of these codes then entering "ASCII code table" into your
favorite search engine should find one.
If your hotkey is to be a given key together with Shift, Ctrl or Alt depressed (or
indeed a combination of these) then add, to the basic code, the following values
(in decimal)
Shift
Ctrl
Alt
Mach2 Customisation Guide
1,024
32,768
2,048
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.
3.3.2
This is the most direct way of making a new button work. You can provide some G-code or
VB Script to be executed when it is clicked. You need to check the appropriate radio button
to say what type of code you have written in the edit box. As an example look at figure 8.3
and the G50 button on the MDI screen of 1024.set. You will see that the latter (not
unexpectedly!) issues the command "G50".
You can define buttons using G-code to do whatever you want that can be done by a single
MDI line. The VB Script program, indeed almost always will, have multiple lines and can
be up to 64k characters long!
Beware: If you use G-code like this, then any scaling which is active on axes at the time
you click the button will be applied to the coordinates built into your button. The problem
does not, of course, apply to zero values, which is a common case, whatever scaling is
applied.
Hint: Remember that a button will only be operated by its hotkey if it is on the persistent or
3-3
Screen Designer
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.
3.3.3
Notice, after double clicking a button, that there is a long list of radio buttons for functions
that a button can call. Cycle Start uses the one called "Run". One possibility is "OEM code"
which we will look at later. The button has a title given in its "Button Text" box and can be
activated by a "Hot key" (Alt-R in fact). The user is reminded of this in the title - some
buttons are very small so the shortcut is given in a separate label. Mach2 identifies keys by
their scancode. Alt-R is code 2162. If you click Set Hot Key and type any other key (or
Shift/Ctrl/Alt key combination) this will set a new hot key for Cycle Start. You will see its
scan code. For safety set it back to Alt-R.
The list of shortcuts used on the standard screens is given in Appendix 1.
Close the dialog by OK
3.3.4
Now look at the properties of the Flood button by double clicking it. You will notice that its
function is defined as OEM code 113 in the list of radio buttons. OEM codes are a way of
extending the range of buttons for more esoteric purposes without the list of names
becoming much too long. The allocation of named functions and OEM codes to buttons on
the standard screens is given online in Appendix 2.
If you look at the properties on the MDI button you will see that its OEM code is 2. Codes
1 to 15 are used to select the fifteen possible screens. If you look at the codes in all the
screen selection buttons you will see which screen # is allocated to each and this will tie up
with the rather odd order you will have discovered at the beginning of this section.
Set colours
Group controls
Equally space vertically
Equally space horizontally
3.4
3-4
Rev 6.11-A6
Screen Designer
3.4.1
Alignment icons
The first four icons on the bar align the appropriate edge of selected controls with that same
edge of the master control. For example "Align with left edge" would move all the controls
selected horizontally so all the left hand sides were in a vertical line with the left edge of the
master one. Figure 3.3 shows the DROs just after drawing. They are then selected with the
top one chosen last and Align Left Edge clicked. Figure 3.4 shows the result.
You need to be slightly careful as if you align left and, say, top then all the controls will be
on top of each other. If this happens by accident then you need to deselect them by clicking
on a blank bit of screen, select them one by one and drag them apart.
3.4.2
Sizing icons
In the example the controls are different sizes. This would not happen if you had used the
clipboard to duplicate them but it is easy to make them all the same width and or height as
the master of the selection. Figures 3.5 and 3.6 show this done in two stages with the two
"Make same.." icons.
The size of a control, other than a button, will determine the size of any text in it.
3.4.3
Finally the "Equally space " icons can be used to space the selected controls equally. The
result of this is shown in figure 3.7.
It is worth spending a bit of time experimenting with these icons on different types of
control to get a feel for what can be done to make a neat layout with very few clicks of the
mouse.
You should get into the habit of saving your layout frequently as the current version of the
Screen Designer has no Edit>Undo facility.
You are strongly advised to save any changes in a layout with a name of your own
choosing. If you just change 1024.set then, as this is replaced at each Mach2 upgrade, you
will lose your changes.
Rev 6.11-A6
3-5
Screen Designer
3.5
3.5.1
Notice that DROs have a hotkey associated with them. When this key is pressed when
Mach2 is running the appropriate DRO will be selected for data input. This is very useful in
systems that are run without a mouse.
Some controls are very simple (e.g. the joystick ball) while others are complex (LEDs are
different colors, can flash etc.).
3.5.2
If a label has some reserved text in it then this text is replaced when Mach2 runs by
information about what is happening (e.g. the name of the part program which is loaded).
The following intelligent labels are defined in the current version:
3.5.2.1
System labels
File (the part program), Error (the last Mach2 error message), Mode (the current modes of
the system), Profile (the name of the current profile file)
3.5.2.2
User Labels/Tickers
3.5.3
DRO groups
3-6
Rev 6.11-A6
Screen Designer
3.5.4
Use of Bitmaps
The location of the file containing a Windows bitmap is given in the setup dialog for bitmap
buttons and for background
bitmaps. All files must be in
the Mach2 Bitmaps folder or in
folders below it in the tree. It is
convenient to group all the
bitmaps for a custom layout in
a folder within Mach2\Bitmaps
to make them easy to maintain
and to distribute to other users.
Screen Designer will always
store the path relative to
Mach2\Bitmaps in the layout
file and it is this path that is
displayed in the dialog after
you have used Browse to locate
a bitmap file. This can be seen
in figure 3.1.
3.5.4.1
Bitmap buttons
Bitmap buttons when created are empty and transparent. In Screen Designer a black border
is drawn but such a button will be invisible on the screen when Mach2 is running. Such a
button can be though of as a "hotspot" on the screen with its function being indicated on a
background bitmap below it. An example is given in the next section.
3.5.4.2
A set of related DROs buttons LEDs etc. can be placed "in" a frame or bezel by placing a
suitable bitmap "underneath". A example is shown in figure 3.9. You should complete the
placing of the controls before drawing the bitmap as it is more difficult to select the handles
to resize the controls when the bitmap is present.
Screen designer provides two options on the Edit menu to assist with bitmaps as
backgrounds. Edit>Paste Exact pastes an object in exactly the same place on a screen as the
place from which it was Cut or Copied. If you wish to change the size or position of
controls on a bitmap then you can cut it and paste it temporarily on an unused screen. Now
move the controls and when finished you can Cut from the temporary screen and Paste
Exact to restore the position of the bitmap.
If you want to make big changes to a screen then you might cut and paste all the bitmaps to
the temporary screen at one time.
After re-pasting bitmaps back to their proper place they will of course be on top of the
layers of objects. Edit>Bitmaps to Back allows you to put all the bitmaps on the current
screen behind the other controls.
You can use one bitmap file for many backgrounds or bezels. A basic size of 100 pixels
square works well for coloured backgrounds.
Stretching a square bezel to become very long and thin will distort the width of the border
so you might need to have more than one basic shape. Try to minimise the different styles
and colour schemes or your screens will look cluttered and be more difficult to use.
3.5.4.3
Although the controls in Screen Designer are quite flexible, you can achieve an even more
interesting presentation by putting all the graphic detail in a large background bitmap.
Rev 6.11-A6
3-7
Screen Designer
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.5.4.4
The Screen Designer does not copy the bitmaps when you place them on the screen at
design time; it just sets up a link
to the image file path relative to
the Mach2\Bitmaps folder. The
bitmap is loaded when Mach2
itself is run. This means that you
can replace the bitmaps with ones
of your own design and by giving
them the names used by the
original designer of the screen
you can customise the
appearance of your system
without having to run Screen
Designer or having to place or
size the bitmaps. Figure 3.11
shows this done to the set of
DROs shown in figure 3.9
3.6
3-8
Rev 6.11-A6
Screen Designer
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.
3.8
Rev 6.11-A6
3-9
Screen Designer
3-10
Rev 6.11-A6
4.
4.1
Figure 4.1 shows the dialog box setting up a button that will increment the feedrate in this
way. This operation is performed using the Screen Designer program. Full details of this are
given below. For the present we concentrate on the VB Script code. Most of it is shown in
the edit box of the dialog. The complete code is as follows:
Rev 6.11-A6
4-1
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.
4.2
Sample macros
4.2.1
A simple macro
The following is code to form a very simple Mach2 macro. Suppose it is stored in a file
M99990.m1s (the extension is letter-m, figure-one, letter-s). The call M99991 could be
included in the file at the beginning of each part program you want to run. If you set a
feedrate by the F-word before running the program then it will use that rate otherwise the
macro will ask the operator for a value.
Rem Default feedrate setting macro
Dim NewRate, FRateFunCode
FRateFunCode = 18
' easier to read program if you use a variable
If GetDRO (FRateFunCode) = 0 Then
Newrate = Question ("What should the feedrate be for this job")
Call SetDRO (FRateFunCode, Newrate)
End If
4.2.2
The following is more complicated example of a Mach2 macro. Suppose it is stored in the
file M99992.m1s It might be useful to edit M99992 into the start of a part program if the
post-processor that created the program has not taken care to set all the modal values at the
start of the program. It would also be handy macro to call by M99992 Q100 S2000 from
manual data input (MDI) to set up a feed and speed and the modes before running a
program.
Rem
'
'
Rem
'
'
'
Rem
'
Rem
'
'
'
4-2
Rev 6.11-A6
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.
4.3
and
and
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.
Rev 6.11-A6
4-3
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")
4.4
4.4.1
Code "G1X10" & Feed ' variable Feed has been set to something like
'
"F150"
4.4.2
As you have seen in the earlier examples, a macro read and change the data in a DRO. It
can also read the state of any LED and simulate the action of clicking a screen button. To
access these operations on Mach2 controls you use the codes used internally by Mach2 and
its Screen Designer for the DRO, LED or button operation you want to use.
There are, for historical reasons, two different code lists for each type of control. The
original built in controls are described by their Function Code. Later features have controls
described by so called "OEM" Codes. You will have seen the reason for this if you have
already tried Screen Designer. If you have not used Screen Designer have a look at the
figure showing the Properties of the Standard Cycle Start button in this chapter. The buttons
that are defined by checking one of the Radio Buttons in the dialog are referred to by
Function Codes. Buttons defined by checking OEM Code and entering a Code value in the
box are referred to by OEM Codes.
DROs and LEDs can be defined that have no meaning to Mach2 being solely for you use.
There are 255 of each denoted by "OEM" codes 1000 to 1254. You must refer to them
using special functions with "User" in the name to make it obvious that they are not
controlling Mach2 itself.
The Function code numbers start at zero in the top-left and count up across the screen. Thus
in the Set Button screen, Run (i.e. the Cycle Start button) is Function = 0 and Zero Y is
Function = 9. Rather than looking up codes using Screen Designer, you may find it more
convenient to refer to the complete table of codes in the appendix.
Although we use literal values (like 14) in the examples you are strongly advised to assign
the values you want to use to variables at the beginning of your macro and then use the
variables in calls to the routines. This will make your program much easier to read. Thus the
first LED example in a complete script would be:
Mach2 Customisation Guide
4-4
Rev 6.11-A6
LEDs
DROs
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..
Rev 6.11-A6
4-5
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
4.4.3
The current value of Mach2 internal variables can be read using the GetParam
function.
Function GetParam (name as String) as Double
This returns a numeric value corresponding to the name of the given variable which is
provided as a string (constant or variable)
The corresponding routine SetParam sets the value of the variable to newVal.
Sub SetParam (name as String, newVal as Double)
Examples:
Rem interrogate drive arrangements
mechProp1 = GetParam ("StepsPerAxisX")
Rem make C acceleration be same as X for slaving
Call SetParam("AccelerationC", GetParam ("AccelerationX"))
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.
4.4.4
Mach2 has a block of variables which can be used in part programs. They are identified
by # followed by a number (the parameter address). The contents of the Tool and Fixture
tables are in these parameters but there are many values that can be used by the writer of
a part program.
These machine variables can be accessed within macros by GetVar and SetVar.
Mach2 Customisation Guide
4-6
Rev 6.11-A6
4.4.5
When a macro is called from the MDI line or within a part program then data can be
passed to it by P, Q, and S words on the line. The values of these words are "read" in the
macro using the Param functions.
Function Param1 () as Double ' gets P word
Function Param2 () as Double ' gets Q word
Function Param3 () as Double ' gets S word
4.4.6
Scripts can communicate with the operator by displaying a dialog box with a prompt into
which the user can type numeric data. The Question function prompts for one item.
The GetCoord routine prompts for the values of X, Y, Z and A coordinates.
The other strategy, probably more suited to scripts attached to buttons, is to provide
DROs of a screen into which data is set before running the macro. These can of course
also display results from the script.
User Intelligent Labels and Tickers enable messages to be displayed.
Function Question (prompt as String) as Double
The string in prompt is displayed in a modal dialog titled "Answer this. The dialog
contains an edit box. The value of the function is set to the number in this when OK is
clicked.
Sub GetCoord (prompt as String)
As with Question, a modal dialog titled "Enter Coordinates" displays prompt. This has
four edit boxes labelled X, Y, Z and A into which values can be typed. GetCoord itself
does not return the values to the macro code. These must be fetched by GetXCoor,
GetYCoor etc.
Function GetXCoor () as Double
Function GetYCoor () as Double
Function GetZCoor () as Double
Function GetACoor () as Double
Outputting text, warnings etc
Sub Message (text as String)
Writes the message on the Error intelligent label and in the History log file.
Sub PlayWave (pathname as String)
Plays a Windows .WAV file (e.g. a chime to warn of an event or error).
Sub Speak (text as String)
A development feature for speaking a text string. Requires detailed setup for which some
information is available in the MACHDN online archive.
Rev 6.11-A6
4-7
This group of functions deals with loading and running G-code and features for the
Teach MDI and wizard systems
Sub LoadRun (pathname as String)
Loads the given file of G-code and starts its execution.
Sub OpenTeachFile (pathname as String)
Opens the given file for G-code and starts writing of commands executed (e.g. by MDI)
to it.
Sub LoadTeachFile ()
Loads the G-code of the currently open teach file so it can be executed
Mach2 Customisation Guide
4-8
Rev 6.11-A6
Sub CloseTeachFile ()
Closes the currently open Teach or wizard file and stops commands being written to it.
4.4.8
Sub ToggleScreens()
Switches between displaying the .SET and .SSET screen sets. This is employed on the
standard screens to switch between the "complex" and "simple" screen sets but could be
used for any purpose such a screens with and without a fourth axis or screens optimised
for daytime and nighttime working.
Function GetPage () as Integer
Returns the number of the screen in the set presently being displayed. Used to remember
where the user is when running a wizard.
Sub SetPage (page as Integer)
Used to display a given screen of a set, typically on return from a wizard. Equivalent to
using DoOEMButton with the screen number.
Sub Savewizard ()
Saves the information in the local controls on a wizard screen in the
wizardname.SET.DEFS file so that the values are on the screen when the wizard is
next run.
4.4.9
Scripts can access the input signals (both on parallel ports and defined virtually in
response to keycodes) such as the state of home and limit switches and can control
output signals.
Function IsActive (sigNo as Integer) as Boolean
Sub ActivateSignal (sigNo as Integer)
Sub DeActivateSignal (sigNo as Integer)
IsActive tests input signals. It will return True if the signal is active (i.e. its LED
would be lit on the Diagnostics screen). In other words this test is after the application of
the Active Hi/Active Lo configuration of the signal hot a test of "0 volts" or "5 volts" on
the signal's pin.
ActivateSignal and DeActivateSignal similarly control the logical state of
output pins. Mach2 will apply the Active Hi/Active Lo configuration to establish the
electrical state required.
Function IsSuchSignal (sigNo as Integer) as Boolean
Returns TRUE if the signal is enabled. It is used to avoid things like digitising if the
machine has no probe input defined.
For all these routines, the required signal is coded using the values defined in the
appendix.
Sub SetTriggerMacro (script as String)
Defines the number of a macro to be executed when an OEMTrigger is set (slightly
unexpectedly on the Config>SetHotkeys dialog) to generate OEM code 277. This
provides script execution without the requirement for a screen button as intermediary.
For example if:
SetTriggerMacro 456
has been executed then a signal on any OEMTrigger configured to 277 will run the code
in the file M543.M1S when activated.
Rev 6.11-A6
4-9
4.4.10
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 Configure>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))
4.4.11
Foreign ports
Scripts can access ports on the PC which are additional to the one (or perhaps two)
parallel port(s) defined in Configure>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.
4.4.12
As described above the script code and Mach2 itself run in two separate processes. You
can test to see in Mach2 is busy or idle by calling:
Function IsMoving () as Boolean
This will return True if Mach2 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 = GetDRO (2) ' get Z value in case it has been Z inhibited
4-10
Rev 6.11-A6
4.4.13
Option Explicit
Dim TxtChoice, CutDepth, StartX, EndX, StartZ, EndZ
CutDepth = Param1()
While CutDepth <= 0
' the P word is not given
CutDepth = Question ("What depth of cut do you want each pass?")
Wend
StartX = Question ("What is X of left end?")
EndX = Question ("What is X of right end?")
While EndX <= StartX
EndX = Question ("X right must be > left. What is it?")
Wend
StartZ = Question ("What is Z of top of material?")
EndZ = Question ("What is desired final Z?")
While EndZ >= StartZ
EndZ = Question ("Final Z must be below initial Z. What is it?")
Wend
code "G0Z" & StartZ
CurrZ = StartZ
' top of work
code "G0X" & EndX
' cutter to right
code "G1Z" & CurrZ
'feed down for first cut
While CurrZ > EndZ
CurrZ = CurrZ CutDepth
If CurrZ < EndZ Then
CurrZ = EndZ
End If
code "G1Z" & CurrZ
code "G1X" & StartX
code "G0Z" & (CurrZ + 0.1)
code "G0X" & EndX
Rev 6.11-A6
4-11
feed down
cut pass
avoid scratching surface
back to right end
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.
4.5
In order to understand some of the limitations of macros and to help you debug them, you
need to understand what Windows and Mach2 do when you run a script from a button or a
macro from a part program or MDI.
There are three stages in running a script. The last two proceed in parallel:
Analysis: The lines of text in your script or macro file are read by the Windows VB Script
engine and converted into a more compact internal symbolic form.
Macro run-time: The VB Script program is run. At this stage the user will be asked and
will answer questions. Calls to the Mach2 functions will be made. These will return values
or state of an input pin (IsActive()) and write requests for G-code to be executed
(Code etc.).
The function ismoving() can be called to see if the G-code runtime thread (see below) is
executing commands. It returns a non-zero value if commands are being executed or moves
are buffered.
G-code run-time: Mach2 which is running as a separate "thread" executes the G-code.
This scheme has several implications for you which are described below.
4.5.2
Errors discovered in the analysis stage ( e.g. mis-spelling while as whyle) are reported
with the offending line displayed. This will make them fairly easy to correct.
Unless you have a Microsoft debugger from Visual Studio installed on your computer,
errors at macro run-time do not give any useful diagnostics. Errors can range from the
wrong number of arguments passed to a function, division by zero etc. You may be able to
work out where they are from the Questions asked, by putting in extra "dummy" Questions
or by the use of On Error Resume Next followed by a call to the Mach2 Question
function to display the error message stored in the global variable err.description.
Note that, as any G-code issued is not running in synchronism with the script, you cannot
tell where you are by seeing the axes move or the DROs change.
Errors when the G-code runs can be very difficult to trace as Mach2 tends to ignore requests
it does not understand rather than flag them up to you. You will just have to "dry run" the
macro code to see exactly what is being requested. It is sometimes helpful to store a line of
G-code that you have constructed in a variable so that you can print it in a "debugging"
Question or Message to check that it looks right.
4-12
Rev 6.11-A6
4.5.3
Stuck in a rut?
As you have some very powerful control structures it is quite easy to get a script stuck in a
loop. For example in this code fragment EndX is mistyped EndZ
While EndX <= StartX
EndZ = Question ("X right must be > left. What is it?")
Wend
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
CurrZ = CurrZ CutDepth
If CurrZ < EndZ Then
CurrZ = EndZ
End If
code "G1Z" & CurrZ
code "G1X" & StartX
code "G0Z" & (CurrZ + 0.1)
code "G0X" & EndX
Wend
feed down
cut pass
avoid scratching surface
back to right end
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.
4.5.4
Rev 6.11-A6
4-13
4.6
4-14
Rev 6.11-A6
4-15
4-16
Rev 6.11-A6
Designing Wizards
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.
5.1
What is a wizard?
A Mach2 wizard is feature which allows you to create a G-code part program by filling in
some simple information on a special screen or screens. Wizards provide open-ended
capability to Mach2 as they can be written and shared by users and are trivial to install on a
system.
Examples of wizards supplied with the standard release of Mach2 allow cutting circular and
rectangular pockets, digitising a model and engraving text.
Wizard functions can replace the need to use a full CAD/CAM software system for some
prototype work. You do not need to be able to write or understand G-code to use a wizard
although the code generated can be a useful learning resource. You can, for example, see
the steps required to cut a pocket by looking at the code produced by running the wizard.
5.2
The user chooses a wizard from the table of those installed on the system
Mach2 sets aside the standard screens and displays the wizard screen (or possibly
the first of a set)
The user provides information to the wizard by entering values in DROs and by
using buttons to switch LEDs On and Off. For example the diameter of a pocket,
the depth of each cut and the required spindle rotation could be specified.
The wizard checks that the data that has been provided describes a possible
operation. It is, for example, very difficult to cut a 1" diameter pocket with a 30mm
diameter cutter!
The wizard then writes a file (like a Teach file) containing the G-code to perform
the required task and loads this into Mach2
Finally the user exits from the wizard and returns to the normal Mach2 screens.
Before attempting to design your own wizard you need to be familiar with using Screen
Designer and writing your own VB Script to attach to buttons or to use in macros. In
addition, you should experiment with the standard wizards. You will see that they have
slightly different user interfaces because they are written for different purposes by different
people.
The following sections give a step-by-step tutorial for how the Digitize wizard works and
some general advice on creating easy to use and reliable wizards.
We will assume, in this chapter, that Mach2 is set up in metric units although, of course,
you can use inch units just as well.
Creating a wizard that works for you is quite straightforward; it is much more difficult to
include all the checks to guide a user who does not really understand machining.
5.3
Rev 6.11-A6
5-1
Designing Wizards
detail the use of user DROs, 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.
5.3.1
Inside the Digitize folder we will put a further folder called Bitmaps. It is best that you keep
bitmaps which are used for a particular wizard's screen(s) in its own bitmaps directory.
This helps to keep the clutter down on your system. Now that we have created the folders
necessary to hold the wizard, we can begin to create our wizard.
A wizard is simply a
screen which is used
for data entry by the
user and has some
buttons to start using
the data when it is
complete. Most
wizards will generate
G-code to be run after
leaving the wizard
Figure 5.2 The smart labels identifying the wizard
screen. While it is
possible for wizard to actually run G-code, this is an advanced use of the wizard and it is
not recommended for inexperienced wizard writers.
The Digitize wizard will have a single screen that you create by running the Screen
Designer program. If you have not got a shortcut set up for it then run
C:/Mach2/Mach1Screen.exe When this loads you will have a blank set of screens with
screen #1 being displayed
The first thing to do is tell the program who wrote this wizard. See figure 5.2. To do this we
create a label which says the word Author followed by the author's name. We also want to
be able to describe to the user what this wizard will do so we create a label which begins
with Desc which tells the program that the following text is the description to be displayed
in the wizard selector. These two "smart labels" will not appear on screen when the wizard
is run; they are only used for the wizard selector dialog.
Mach2 Customisation Guide
5-2
Rev 6.11-A6
Designing Wizards
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
5.3.2
Although this screen looks complete it does not yet do anything. The next job is to define
the functions of each control. Consider the Width DRO.
As you can see, in figure 5.4, it is given an OEM code of 1001. Any DRO which has a
higher value than 1000 is called a User DRO. These User DROs are places to input, display
and remember numbers. They can be used to save settings when a user wishes those settings
to be persistent from one the wizard to another. So we continue by setting up the nine DROs
which we intend to use to provide the data for our program. Each is given its own DRO
number.
You can see that the wizard has a button to test the file size that will be created by running
the finished wizard. This is important, as the user may not realise the implications of
probing at locations that are too close together! Let us look at how this button can be made
to work. Figure 5.5 shows what double-clicking the finished button gives.
Its function is chosen by the Radio button Execute VB Script. When this button is pressed
the VB Script inside the button will be run.
Rev 6.11-A6
5-3
Designing Wizards
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.
5.3.3
To understand generating code let us look at the Create and Load G-code button and
analyze what it does
Here is the script which is stored in the create code button.
XWidth = GetUserDRO(1001)
YWidth = GetUserDRO (1002)
Safe = GetUserDRO (1003)
Min = GetUserDRO (1004)
Stepx = GetUserDRO (1005)
Stepy = GetUserDRO (1006)
Feed = GetUserDRO (1008)
It starts by assigning values to the variables for easy of reading the code
Rem now open a digitize.tap file
Rem all code commands then go to file.
OpenTeachFile "Digitize.tap"
The above line tells the system to open to teach file named digitize.tap. This is very
important because without opening this file system will attempt to run the lines of code as it
creates them. We just want them saving to run when we return to the main Mach2 screens..
code "(Digitize File)"
This puts out a G-code comment to the file so you'll know what it is when it is in the Gcode window
5-4
Rev 6.11-A6
Designing Wizards
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"
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.
Rev 6.11-A6
5-5
Designing Wizards
5.3.4
Now let us take a look at a bit of script which is run in the wizard itself. This will actually
move the machine when the script is activated. The digitize wizard does not use any such
code but as there are a couple things to worry about when designing that type of wizard and
we need to look at them.
Here is an example script which makes a tool move down to table, hit a switch, move back
up, so that we know the length of the tool.
Code "G28.1Z0"
While IsMoving()
Wend
The first line initiates the move and the next two lines cause the system to wait until the
movement previously command it has completed. This is very important. Because the script
runs in its own thread, synchronizing movements can be very complex. These two lines
allow you to synchronize the movement you have asked for to ensure further commands do
not happen too early. Always use the While IsMoving()/Wend loop when in any doubt.
As another more complete example:
Code "G31Z-100"
While IsMoving()
Wend
In the above lines we command a probe movement of the tool downwards from the home
switch. It will stop when the tool hits a switch. Now that it has stopped, we can set the Z
axis DRO to be zero with
SetDro(2,0)
The next two lines to move up 3 mm, which we would have previously calculated as the
deceleration distance all the tools at that speed.
Code "G91"
Code "G0Z-3"
And finally, reset the Z. DRO to zero. Our tool is now zeroed.
Code "SetDRO(2,0)"
Code "G90"
5.3.5
Other precautions
You must take particular care when writing a macro to try to not call other macros.
Unknown effects can be seen when one attempts to call a macro from a macro. The macro
interpreter also can only hold so many lines at a time, is therefore good practice to issue a
While /Wend loop every few lines of code if they command movement.
All macros in Mach2 run in their own thread. This can create problems in certain
circumstances so a designer is advised to take flow into account. This is very important
when G-code statements that modify the state of Mach2 are used. Things like feedrate
changes, spindle speed, signal changing, condition testing need to be thought out to avoid
problems if they reported too early. Take the following situation:
Code "G31Z-10
Code "G92Z0
Code "G1Z5
In these three lines, one would expect that the Z axis would probe downwards to a
maximum depth of -10 mm, then zero the DRO and move to +5mm. What will happen
instead though is that the Z will begin probing downwards, the G92 statement will zero the
DRO while the Z moves down, the Z will finish at an unknown negative coordinate. Then it
will lift way up to +5. This is because of the asynchronous nature of the macro interpreter.
To do this properly, you need to have a
While IsMoving()
Wend
Mach2 Customisation Guide
5-6
Rev 6.11-A6
Designing Wizards
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
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.2
Screen Design
A major component of any good wizard is the operator interface. So, the first step is to get
out a piece of paper and sketch a design of the screen layout. The screen should have a nice
work flow - uncluttered and intuitive. Inputs and DROs should be appropriately labelled,
and functional controls should be grouped if possible (i.e. spindle controls, coolant, units,
etc). To help the user to enter data is entered into the correct DROs, you can use bitmaps as
diagrams. The circular pocket wizard shows good examples of this technique with both line
and photographic illustrations.
5.4.3
The VB Script code on buttons is the core of the wizard screens and can be made to do
many different
tasks. There is
a minimum of
three buttons
that need to
Figure 5.6 Wizard interface buttons
appear in every
wizard Exit, Post G Code, and Save Settings.
The code for Exit is:
CloseTeachFile
call LoadStandardLayout()'reload the main screenset of Mach2
Post Code is responsible for outputting the actual G-code to implement your wizard.
While the VB Script can be input directly into the button using its edit box in Screen
Designer, it is better done in Notepad or in a code editor like ConText. After initially
writing out the code the text editor, it can be put into the button by using copy (Ctrl-C) and
paste (Ctrl-V). If you use a good editor you will get the benefits of syntax highlighting
which will make your code easier to check.
We recommend using the line Options Explicit at the top of each piece of VB Script
and declaring all the variables with Dim statements. This will avoid strange bugs caused by
misspelled variable names.
Rev 6.11-A6
5-7
Designing Wizards
5.4.4
Error checking
The example below shows a simple wizard that checks its data before using it.
Step One: Get the information from the wizard screen
PointX_1 = GetOEMDRO (1010) 'Get value from DRO# 1010
PointY_1 = GetOEMDRO (1011) 'Get value from DRO# 1011
PointX_2 = GetOEMDRO (1012) 'Get value from DRO# 1012
PointY_2 = GetOEMDRO (1013) 'Get value from DRO# 1013
Depth = ABS (GetOEMDRO (1014)) * -1
Rem Get value from DRO# 1014 and make it negative
Feed = GetOEMDRO (1015) 'Get value from DRO# 1015
5-8
Rev 6.11-A6
Designing Wizards
5.4.5
There are 3 major pieces required to properly document the wizard the folder name where
the wizard is stored, the description, and the author. All three pieces of information are
displayed on the Pick wizard dialog. The column on the left most side is the name of the
directory in which the wizard screen file resides. This directory is located in the
<Mach2>/Addons folder. It is important to name the wizard appropriately, i.e. Circular
Pocket as opposed to wizard_01. The center column holds a description of the wizard's
function. The description is added by placing a label control on your wizard screen design
and setting the text to be Desc this would be the description. The Desc is how Mach2
knows that it is a description and all of the text after the Desc is what is displayed. This
label is hidden from view when actually running the wizard screen. The right side column
displays the authors name. Setting this is exactly like setting up the description place a
label control on your wizard screen design and set the text to be Author your name here.
This label is also hidden from view on the running wizard screen. You should always
include an author label on your wizards so that you can receive proper credit for all of your
hard work.
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 its 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.
Rev 6.11-A6
5-9
Designing Wizards
5-10
Rev 6.11-A6
Reference Tables
6.
6.1
Note: The shortcuts for any given special layout can be found in the CSV file which can be exported
using Mach2ScreenTweak
Rev 6.11-A6
6-1
Reference Tables
6.2
Type
1 X DRO
Function
1 Y DRO
No
1 Z DRO
No
1 A DRO
No
1 B DRO
No
1 C DRO
No
1 X Vel DRO
No
1 Y Vel DRO
No
1 Z Vel DRO
No
1 A Vel DRO
No
1 B Vel DRO
10
No
1 C Vel DRO
11
No
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
12
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
6-2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
33
34
Rev 6.11-A6
Reference Tables
Type
Function
1 Z axis Ref Sw DRO
1 A axis Ref Sw DRO
1 B axis Ref Sw DRO
1 C axis Ref Sw DRO
1 True spindle DRO
1 Worst Case DRO
1 Tool X Offset DRO
1 Tool Z Offset DRO
1 Tool Dia DRO
1 Tool Tip Rad DRO
1 Touch Corr DRO
1 Fixture # DRO
1 Part X Offset DRO
1 Part Y Offset DRO
1 Part Z Offset DRO
1 Part A Offset DRO
1 Part B Offset DRO
1 Part C Offset DRO
1 CPU Spd DRO
1 Safe Z DRO
1 Overidden Feed Rate
1 Pulley DRO
1 Max Speed DRO
1 Velocity per Rev DRO
1 X Scale DRO
1 Y Scale DRO
1 Z Scale DRO
1 A Scale DRO
1 B Scale DRO
1 C Scale DRO
1 Lowest Torch Correction DRO
1 Threading Entrance Angle DRO
1 Max Entrance Points DRO
1 Rotational Time Error DRO
1 Entrance Trigger DRO
1 Time Correction Derivative DRO
1 Normal Spin Counts DRO
1 Current Spin Counts DRO
1 Spin Adder DRO
1 Spin up/down incr.
1 Stock Size DRO
1 Laser X Grid
1 Laser Y Grid
1 Repetitions DRO
1 Lower Z-Inhibit By DRO
1 Z-Inhibit DRO
1 Port Bit-test DRO (diagnostic)
1 Anti-dive limit DRO
1 X Machine Coord DRO
1 Y Machine Coord DRO
1 Z Machine Coord DRO
Rev 6.11-A6
Reference Tables
Type
Function
1 A Machine Coord DRO
1 B Machine Coord DRO
1 C Machine Coord DRO
1 Blend factor DRO
1 reserved
1 G73 Pull-off value
1 Tangential lift threshold angle
1 Tangential lift Z level
1 reserved
1 reserved
1 reserved
1 CV Feedrate
1 Feed override increment value
1 Blended Velocity DRO
1 Elapsed DRO
14
No
1 Estimate DRO
15
No
16
No
17
No
1 Feedrate DRO
18
No
1 Tool
24
No
1 Rot A diameter
25
No
1 Rot B diameter
26
No
1 Rot C diameter
27
No
28
No
30
No
30
No
31
No
31
No
32
No
32
No
33
No
33
No
34
No
34
No
35
No
35
No
36
No
4 Cycle start
No
4 Pause
No
4 Rewind
No
4 Stop
No
4 Single
No
4 Resume
No
4 Edit File
No
4 Zero All
No
4 Zero X
No
6-4
Rev 6.11-A6
Reference Tables
Type
4 Zero Y
Function
4 Zero Z
10
No
4 Zero A
11
No
4 Zero B
12
No
4 Zero C
13
No
4 Feedrate reset
14
No
4 Estimate Job
15
No
16
No
4 GotoZs
17
No
4 Coord System
18
No
4 Verify
20
No
4 Reset
21
No
4 Ref X
22
No
4 Ref Y
23
No
4 Ref Z
24
No
4 Ref A
25
No
4 Ref B
26
No
4 Ref C
27
No
4 Joystick Toggle
28
No
4 Softlimits Toggle
29
No
30
No
4 Jog Toggle
31
No
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
32
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Program Run
MDI
Toolpath
Positioning
Diagnostics
Corrections
Tables
Inc Inc Up
Inc Inc Down
Reset Interp
Jog mode toggle
Goto Safe Z
Home Z then X then Y, A, B, C - set machine coords
Units
Mach coords
Feed raise
Feed lower
Spindle CW, reset THC height
Slow Jog Up
Slow Jog Dn
Flood toggle
Mist toggle
Edit G-code
Zero radius DRO on X
Zero radius DRO on Y
Zero radius DRO on Z
Rev 6.11-A6
6-5
1
2
3
4
5
6
7
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Reference Tables
Type
Function
4 Software limits
4 Touch button for Tool length offset
4 Tool Tab Save
4 Fixture Tab Save
4 Torch Enable Toggle
4 Torch Cal Zero
4 Enc Load X
4 Enc To X
4 Enc Load Y
4 Enc To Y
4 Enc Load Z
4 Enc To Z
4 Tool Path Toggle
4 Zero X Encoder
4 Zero Y Encoder
4 Zero Z Encoder
4 Tool Offset Tog
4 Fixture Off
4 Go Home
4 Part X Offset Touch
4 Part Y Offset Touch
4 Part Z Offset Touch
4 Part A Offset Touch
4 Part B Offset Touch
4 Part C Offset Touch
4 Tool X Offset Touch
4 Tool Z Offset Touch
4 Joy Throttle select
4 Touch Corr Enable Toggle
4 Auto Lim Override Toggle
4 OverRide Limits
4 SS on Act4 Toggle
4 reserved
4 reserved
4 reserved
4 Units/rev - Units/min toggle
4 Set this line as next to execute
4 Jog Follow
4 Joystick ON
4 Joystick OFF
4 Regen toolpath display
4 Zero X-Z to stock as defined in DROs (Turn)
4 Coordinate mode (G90/91)
4 Raise spindle speed
4 Lower spindle speed
4 Laser Probe Enable Toggle
4 Zero laser grid at current location
4 Z inhibit toggle
4 Ignore Tool Change toggle
4 Close current file
4 Re-load last file
Mach2 Customisation Guide
6-6
Reference Tables
Type
Function
FCode IsOEM OEMCode
4 Jog increment cycle
32
Yes
171
4 Clear error label
32
Yes
172
4 Spindle CCW toggle
32
Yes
173
4 Parallel Port Encoder3 MPG Jog Toggle
32
Yes
174
4 Cycle axis controlled by MPG
32
Yes
175
4 Block Delete "switch" toggle
32
Yes
176
4 Optional Stop "switch" toggle
32
Yes
177
4 Offline toggle
32
Yes
178
4 Display Abs Machine coordinates (i.e. macnine coords ON)
32
Yes
179
4 Display Work + G92 coordinates (i.e. Machine coords OFF)
32
Yes
180
4 Display Work coords (i.e. not with G92)
32
Yes
181
4 Home X, Home Z (Turn)
32
Yes
184
4 Select X for MPG
32
Yes
185
4 Select Y for MPG
32
Yes
186
4 Select Z for MPG
32
Yes
187
4 Select A for MPG
32
Yes
188
4 Select B for MPG
32
Yes
189
4 Select C for MPG
32
Yes
190
4 Select Jog Increment 1
32
Yes
191
4 Select Jog Increment 2
32
Yes
192
4 Select Jog Increment 3
32
Yes
193
4 Select Jog Increment 4
32
Yes
194
4 Select Jog Increment 5
32
Yes
195
4 Select Jog Increment 6
32
Yes
196
4 Select Jog Increment 7
32
Yes
197
4 Select Jog Increment 8
32
Yes
198
4 Select Jog Increment 9
32
Yes
199
4 Select Jog Increment 10
32
Yes
200
4 Feed override Off
32
Yes
201
4 Feed override Jog
32
Yes
202
4 Feed override Feed
32
Yes
203
4 Jog mode Continuous
32
Yes
204
4 Jog mode Step
32
Yes
205
4 Joystick On
32
Yes
206
4 Joystick Off
32
Yes
207
4 Clear Z tool offset (Turn)
32
Yes
208
4 Clear X tool offset (Turn)
32
Yes
209
4 Set stock correction to Zero (Turn)
32
Yes
210
4 Home X Home Z (Turn)
32
Yes
211
4 Home X (Turn)
32
Yes
212
4 Home Z (Turn)
32
Yes
213
4 Show recent G-code files list
32
Yes
214
4 Display history
32
Yes
215
4 Load G-code
32
Yes
216
4 Tool flip toggle (Turn front/rear toolposts)
32
Yes
217
4 Z-inhibit ON
32
Yes
218
4 Z-inhibit OFF
32
Yes
219
4 Port Bit-Test Set (diagnostic)
32
Yes
220
4 Anti-dive enabled toggle
32
Yes
221
4 THC Anti-dive OFF
32
Yes
222
4 THC Anti-dive ON
32
Yes
223
Rev 6.11-A6
6-7
Reference Tables
Type
Function
4 Flood ON
4 Flood OFF
4 Mist ON
4 Mist OFF
4 Load Teach file
4 Toolpath Machine/Job toggle
4 Display wizard selection window
4 Load the normal screens when wizard done
4 Simple Complex screen toggle
4 Output 4 ON
4 Output 4 OFF
4 Output 5 ON
4 Output 5 OFF
4 Output 6 ON
4 Output 6 OFF
4 Set Help context
4 Def-Ref all axes
4 Tangential toggle
4 Save XYZ to G59.254 work offset
4 do G0G53 to G59.254 offset location
4 Move to G59.254 with midpoint selection
4 Toggle Jog Mode through Cont/Step/MPG as relevant
4 Force Referenced on all axes
4 CV feed toggle
4 CV feed OFF
4 CV feed ON
4 Disable movement on axis X
4 Disable movement on axis Y
4 Disable movement on axis Z
4 Disable movement on axis A
4 Disable movement on axis B
4 Disable movement on axis C
4 Engine OFFline
4 Engine ONline
4 Select encoder jog on axis X
4 Select encoder jog on axis Y
4 Select encoder jog on axis Z
4 Select encoder jog on axis A
4 Select encoder jog on axis B
4 Select encoder jog on axis C
4 Select Step value 1
4 Select Step value 2
4 Select Step value 3
4 Select Step value 4
4 Select Step value 5
4 Select Step value 6
4 Select Step value 7
4 Select Step value 8
4 Select Step value 9
4 Select Step value 10
4 Set Jog mode STEP
Mach2 Customisation Guide
6-8
Reference Tables
Type
Function
FCode IsOEM OEMCode
4 Set Jog mode CONT
32
Yes
276
4 Code for OEMTriggers runs the macro in SetTriggerMacro
32
Yes
277
6 Reset LED
0
No
6 Inch LED
No
6 MMs LED
No
6 Idle LED
No
6 Start LED
No
6 Pause LED
No
No
6 X ref LED
No
6 Y ref LED
No
6 Z ref LED
No
6 A ref LED
10
No
6 B ref LED
11
No
6 C ref LED
12
No
6 Dwell LED
13
No
14
No
6 Fixture LED
16
No
6 Active 1 LED
21
No
6 Active 2 LED
22
No
6 Active 3 LED
23
No
6 Active 4 LED
24
No
6 Digitize In LED
25
No
6 Index LED
26
No
6 Limit OV LED
27
No
28
No
29
No
30
No
31
No
32
No
33
No
34
No
35
No
36
No
37
No
38
No
39
No
40
No
41
No
42
No
43
No
44
No
45
No
6 Enable 1 LED
46
No
Rev 6.11-A6
6-9
Reference Tables
Type
6 Enable 2 LED
Function
6 Enable 3 LED
48
No
6 Enable 4 LED
49
No
6 Enable 5 LED
50
No
6 Enable 6 LED
51
No
55
No
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
56
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
G92 LED
Spindle CW LED
Mist LED
Flood LED
Jog mode Cont LED
Jog mode Incr LED
Mach coords warn LED
Feed override LED
Estimating LED
Emergency LED
A radius corr. LED
B radius corr. LED
B radius corr. LED
Software limits LED
Torch En LED
True spindle Acc LED
True spindle Dec LED
Tool Path LED
Tool Offset on LED
Part Offset on LED (always in 6.11)
Throttle is Slow Jog LED
Throttle is Feedrate LED
reserved
Auto Lim override LED
Override Limits/home switches LED
SS on Act4 LED
THC Arc Good LED
Torch Up active LED
Torch Down active LED
Feed per Min
Feed per Rev
X Scale LED
Y Scale LED
Z Scale LED
A Scale LED
B Scale LED
C Scale LED
reserved
Abs Coordinate Mode LED
Incremental Coordinate Mode LED
Threading Sync Mode LED (Turn)
Laser Probe enabled LED
Z-Inhibit ON LED
Ignore Tool Change ON LED
6-10
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Rev 6.11-A6
Reference Tables
Type
Function
6 CV Mode ON LED
6 M30 Repeats Enabled LED
6 CV mode OFF LED
6 MPG Jog On LED
6 Engine NOT using enhanced mode LED
6 MPG Jogs X axis LED
6 MPG Jogs Y axis LED
6 MPG Jogs Z axis LED
6 MPG Jogs A axis LED
6 MPG Jogs B axis LED
6 MPG Jogs C axis LED
6 Block Delete On LED
6 Optional Stop On LED
6 Offline indicator LED
6 Threading feed related to true Spindle speed LED
6 Index signal awaited LED (Turn)
6 Anti-dive enabled LED
6 Spindle speed stable LED
6 IJ Mode is Absolute LED
6 IJ Mode is Incremental LED
6 G-code teaching file is open LED
6 Offset in effect on at least one axis
6 reserved
6 Output 4 Active LED
6 Output 5 Active LED
6 Output 6 Active LED
6 Pause Active LED
6 Tangential control Active LED
6 Single Step mode Active LED
6 Jogging enabled LED
6 CV feed enabled LED
6 Axis inhibited X LED
6 Axis inhibited Y LED
6 Axis inhibited Z LED
6 Axis inhibited A LED
6 Axis inhibited B LED
6 Axis inhibited C LED
6 Diameter mode active (Turn) LED
6 Timing signal active (Turn) LED
Rev 6.11-A6
6-11
Reference Tables
6.3
Signal codes
SigName
XLimitPlus
XLimitMinus
Xhome
YLimitPlus
YLimitMinus
YHome
ZLimitPlus
ZLimitMinus
ZHome
ALimitPlus
ALimitMinus
AHome
BLimitPlus
BLimitMinus
BHome
CLimitPlus
CLimitMinus
CHome
Activation1
Activation2
Activation3
Activation4
Digitize
Index
LimitOverride
Emergency
THCOn
THCOff
THCUp
THCDown
OEMTrigger1
OEMTrigger2
OEMTrigger3
DigTrigger
Enable1
Enable2
Enable3
Enable4
Enable5
Enable6
ExtAct1
ExtAct2
ExtAxt3
ChargePump
SigInput
SigCode
Yes
0
Yes
1
Yes
2
Yes
3
Yes
4
Yes
5
Yes
6
Yes
7
Yes
8
Yes
9
Yes
10
Yes
11
Yes
12
Yes
13
Yes
14
Yes
15
Yes
16
Yes
17
Yes
18
Yes
19
Yes
20
Yes
21
Yes
22
Yes
23
Yes
24
Yes
25
Yes
26
Yes
27
Yes
28
Yes
29
Yes
29
Yes
30
Yes
31
No
0
No
1
No
2
No
3
No
4
No
5
No
6
No
7
No
8
No
9
No
10
6-12
Rev 6.11-A6
7.
7.1
7.2
Using Mach2ScreenTweak
7.2.1
Introduction
7.2.2
Installation
7-1
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.3
Figure 7.1 shows the main screen after loading the standard 1024.SET from Mach2Mill
Release 1.00.
You will find it worthwhile "playing" before you read on in this manual. Just avoid the Save
As operation!
The Principal Layout table shows the contents of the persistent screen and the 15 user
screens of the layout. The buttons control what is to be done with the screens in the
Principal Layout.
7-2
Rev 6.11-A6
7.2.4
7.2.4.1
Open .SET
This prompts for a Layout file to open as the Principal Layout. You can select Mill (.SET)
or Turn (.LSET) files to be displayed in the dialog.
When opened a copy is held within the program and the .SET file is closed so it can be used
in Mach2 or Screen Designer while Mach2Tweak is in use. When a file is opened then the
other buttons will be enabled.
All changes are performed on the Principal Layout. The Additional Layout (see below) is
used as a source to import screens.
The Principal Layout contains information on colors to be used for controls which will be
saved by Mach2ScreenTweak but is not otherwise processed by it.
This button is also implemented in the File menu.
7.2.4.2
CSV Save
This will prompt for the name of a .CSV file to contain information about each control in
the Layout. The format is self-evident when studied in conjunction with the definition of
Layout file to be provided in the Mach2Mill/Turn manuals.
The .CSV file can be imported into Microsoft Excel or, probably better, Microsoft Access
for analysis and documenting the implemented controls in the standard or custom screens.
This button is also implemented in the File menu.
Notice that in the current release the code is not able to export the actual VB Script attached
to buttons. This may be upto 64 kBytes for any one button. ScreenTweak replaces it with a
descriptive message. This means that an exportedlayout is not suitable for re-import. It can
however be used for its main purpose of analysing the codes and positions of controls.
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.
7.2.4.4
The Edit All Controls button opens the dialog for manipulation of individual controls in the
Layout. For full detail see section 4.
Not all operations are available, or meaningful, across the whole Layout and have to be
performed on individual screens.
7.2.4.5
Edit Undo
The Edit>Undo allows you to "undo" operations performed on the Principal Layout. Undo
will cause the Principal Layout to revert to its condition before the last operation or, if a
sequence of several identical ones have been performed one after the other, to its condition
before the first one of the sequence.
For example, suppose an MDI screen is moved up by three consecutive clicks on Move Up
from being screen number 6. Undo would move it back from being screen 3 to screen 6. If,
however, it was moved up 4 steps by Move Up the moved down by one Move Down Undo
would make it move from screen 3 to screen 2, i.e. where it was before the Move Down
which is the last operation and so is what is undone.
7.2.5
An individual screen can be selected by clicking its entry in the table. Screens are identified
by their number (as used in Screen Designer), their Screen Caption, the captions on
Rev 6.11-A6
7-3
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.
7.2.5.2
Update Buttons
When screens are moved up and down the list then the buttons (typically on the Persistent
screen but they can be anywhere) are updated to display the correct screen by=ut their
shortcut keys (probably F-keys) and captions are not changed.
Update Buttons will alter any button that had a Function key shortcut in the original layout
to have the F-key number corresponding to its screen number. For example screen 2 would
be displayed in Mach2 on pressing F2. This is not done if the existing shortcut is not a
function key. So the MDI (M) screen from older Layouts would continue to be selected by
letter-M.
In addition Update Buttons will prompt for the new text to be on the button caption so that,
for example, if it is being changed to F9 then you can enter "Short Diags (F9)"
This function is more obvious in use than it appears when explained (I hope!)
7.2.6
An additional layout (which can be the same file as the Principal one) is opened and
summarised on the lower part of the screen. Its only role is to be a source of screens to be
appended to the Principal Layout.
A layout stored in a CSV file, such as would be exported (see above) can also be loaded.
Notice that the current release of the import and export functions do not handle fields with "
(dQuote) reliably so import should not be used.
7.2.6.1
An entry in the Additional Layout table is selected. When the Append to Principal Layout
button is clicked then its controls are placed on the first empty screen of the Principal
Layout. This appears like "appending" the screen from the Additional to the Principal
Layout.
There are some point to note:
The screens in the Additional Layout are "identified" by number, label and
captions of buttons that display them in Mach2. When imported to the
Principal Layout, as "new" screens, the buttons are not likely to exist and of
course the screen number changes. You can use the count of controls as a
guide to the correct screen having been appended. If you always use Screen
Caption labels (i.e those starting with a ) in your Additional Layouts then
you will know what is happening.
It is possible that the screen appended contains buttons that select other
screens in the Additional Layout (or indeed unusually the screen itself). These
would not have any meaning when in the context of the Principal Layout so
7-4
Rev 6.11-A6
they are not appended with all the other controls. This "disappearance" of
controls is noted in a confirmation dialog after the append.
7.2.7
Sequences of appends can be undone like any other operation on the Principal
Layout.
Control Manipulation
Although ScreenTweak is not a replacement for Screen Designer it does have some limited
features which manipulate controls rather than whole screens. These are displayed on the
dialog accessed by the Edit all Controls and Control Edit buttons on the main screen. The
screen is shown in figure 7.2
7.2.7.1
Re-scale controls
The controls on an individual screen or all screens of a layout can be re-scaled to fit
different resolutions of display.
Mach2ScreenTweak will try to guess the current resolution by looking at the "bottom right"
control in the selected screen or the layout. If this is wrong then you can override it by
clicking the appropriate radio button. Now choose the resolution of the display on which
you want to use the screen or layout and click Re-scale.
The following should be noticed:
Rev 6.11-A6
The dialog automatically closes to avoid you being tempted to repeatedly Rescale (getting smaller and smaller or bigger and bigger!)
Because the font size of captions on buttons is fixed in Mach2 you will
probably find that the caption is too big at a new resolution. Screen Designer
has to be used to abbreviate captions but you have the controls reasonably
placed.
Screens with bitmap buttons do not suffer from this problem.
Scaling down and then back up again will, of course, cause you loss of
resolution due to rounding effects.
7.2.7.2
Re-order DROs
In Mach2 the arrow keys can be used to cycle through a group of DROs (e.g. all the axis
DROs). The order of this cycling is the order of original creation of the DROs in Screen
Designer and may not be logical.
You can re-order the DROs on a selected screen to run down a column or across the screen
as a row using the radio buttons to choose the logic. Multiple columns/rows can be ordered
and small errors in the placing of the DROs are ignored.
7.2.8
Screen Designer uses an admirably simple structure for Layout data. This causes some
difficulties when mechanically processing Layouts. For example there is no link, other than
the visual one, between labels like "Dwell" and the LED indicating it. Screens are only
identified by their overall appearance rather than a "caption". This can cause problems in
Mach2ScreenTweak.
7.2.8.1
Screen captions
The caption problem is overcome by use of a special "Caption Label" on screens. When you
design a screen to be "tweaked" you should place somewhere on it a label that starts with
the "curly-S" section symbol. For example you might have Compact Diagnostics. The
is easily typed by the sequence Alt-0167 on the numeric pad (Num Lock being ON). You
can also paste it from the Windows Character Map utility (in Accessories>System Tools).
The Caption Label can, of course, be visible if you have the space or can be off the bottom
of the screen. Hint: you can work on a bit of screen not normally seen in Mach2 by
temporarily switching off View>Toolbar and View>Status Bar in Screen Designer.
The main screens issued with Mach2 have Caption Labels which are "hidden" in normal use
below the Reset button.
7.2.8.2
As many existing screens will not have Caption Labels, Mach2ScreenTweak looks to see
what buttons are programmed to display a screen and will use the button captions of the
first two found to help identify a screen. Notice, as mentioned above, that this is little help
on screens appended from the Additional Layout.
7.3
7.3.1
Int32
Count of controls in Layout = n
ControlRec
Information record for Control 1
ControlRec
... for Control 2
ControlRec
ControlRec
ControlRec
etc.
ControlRec
... for Control n
ColorsRec = 10 x Int32
Colors for Layout
7-6
Rev 6.11-A6
7.3.2
ControlRec
Int32
Int32
Int32
C-String
C-String
C-String
Int32
Int32
C-String
Int32
Int32
Int32
Int32
Int32
C-String
Int32
Int32
Int32
Int32
Int32
Control Function
Control Type
Displayed on Screen number
Text on control
G-code text
Path of bitmap file
HorizCode
VertCode
Label
Color
OEM Code value
HotKey code
Flash flag
Red/Green flag
Format code
Tabbing group
PosX1
PosY1
PosX2
PosY2
Most of the
fields of the
Byte8 Count of characters in string n = 0 to 255
ControlRec
Char8 Char8 Char8 Char8 Char8 etc. Char8 Char8 Char8
are dedicated
to data for a
Figure 7.5 Storage of character strings
particular
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
Control
DRO
Scrollbar
Bitmap
Conventional Button
Jogball
LED
7-7
7
8
9
10
11
7.3.2.3
Label
Bitmap Button
Manual Data Entry (MDI)
G-code window
Toolpath display
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
DRO
Conventional button
LED
Bitmap button
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
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.8
For Jogball controls the code gives the axes to be jogged for horizontal and vertical
"movement" of the "ball". Axis coding is X = 0, Y = 1, Z = 2, A = 3, B = 4, C = 5
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
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
7.3.2.12
Flash Flag
RedGreen Flag
LED will change colour from Red to Green when signal is active. Color value is ignored
7.3.2.14
Tabbing Group
7.3.3
Color32
Color32
Color32
Color32
Color32
Color32
Color32
Color32
Color32
Color32
Background
DRO
DROSelected
MDI
MDISelected
Label
DRONumerals
MDIText
G-code
G-codeText
ColorsRec
The format of the ColorsRec is given in figure 7.6. A Color32 value has its most significan
byte = 0 and the following three bytes the unsigned intensity (i.e. range 0 to 255) of the
colors Red, Green and Blue in decreasing significance. Thus Yellow (i.e. Red and Green)
would be coded using hexadecimal notation as 0x00FFFF00 i.e. decimal 16776960.
The color chooser dialog in Screen Designer displays the individual RGB values for a
control.
Rev 6.11-A6
7-9
7-10
Rev 6.11-A6
8.
8.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.
Rev 6.11-A6
8-1
8.1.2
Installation
8.1.2.1
The files
The KeyGrabber software is automatically installed by the Mach2 installer. You may wish
to setup a desktop or quickstart bar shortcut to it. If you do not start the KeyGrabber
program then its installation will have no effect on your system.
8.1.2.2
Windows compatibility
You will get the best results out of KeyGrabber by making sure that your Windows has
been upgraded to include DirectX version 9. See the Microsoft website for full details of
upgrades.
8.1.2.3
KeyGrabber can be run by double-clicking the KeyGrabber.exe file, in the Mach2 folder, or
a shortcut to it. You will need to do this to set up how keys and buttons are to be
interpreted. You can then run ScreenDesigner or Mach2 and choose the Mach2 profile by
hand.
For everyday use, most Mach2 users will either use the standard Mach2Mill or Mach2Turn
shortcuts that are setup when Mach2 is installed. These can easily be adapted to run
KeyGrabber first and then automatically start Mach2 with the originally specified profile
(i.e. Mill, Turn or indeed your own custom Mach2 profile).
Right click on the shortcut, choose Properties from the menu and modify its Target property
by replacing "Mach2.exe" with "KeyGrabber.exe". Leave the text starting /p alone this is
what specifies the Mach2 XML profile to use. See chapter 5 for further details of Mach2
profiles. You may want to use a different KeyGrabber configuration for each Mach2
profile. Details of how to do this are given below.
8.1.2.4
Shortcut Icons
If you setup a shortcut on the desktop as described above then you will find that its Icon is
the KeyGrabber smiley face. This is a useful reminder that you are using keygrabber. If you
wish you can replace the Icon in the shortcut with one from Mach2 or indeed from any
other place.
Right-click on the shortcut and choose Properties from the menu. Click Change Icon
Use Browse to choose the program file containing the icon you wish use for the shortcut.
This is probably Mach2.exe. Then choose the icon out of the possible set in the display.
Some programs may have several others only offer one.
If you have a graphics program which will create Windows Icons then you can design your
own and use it by browsing to its .ico file rather than a .exe file.
8.1.3
Configuring KeyGrabber
When KeyGrabber runs for the first time it will create a file called Default.grab and this
name is displayed in the caption of its window.
You can use File>Save As to save your current configuration under a different name and
File>Open (or information in the shortcut Target described later) to specify that you want to
use a non-default configuration.
There are four area to configure. You may not wish to use all of them and may, of course,
not have the hardware to do so.
Keyboard Keys
Keyboard Encoders
Human Interface Devices (HID)
Misc Settings
8-2
Rev 6.11-A6
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:
8.1.4
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
Rev 6.11-A6
8-3
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.
The Block modifiers check boxes are provided to allow you to specify that the state of the
corresponding modifier button/key is to be ignored (i.e. not sent to Mach2) for this Source
button. This might be used for a signal coming from a switch like a Home switch where the
same code is to be recognised irrespective of the Shift, Ctrl or Alt keys being depressed at
the time.
Mach2 Customisation Guide
8-4
Rev 6.11-A6
Note: If you have a keyboard emulator which provides hardware key repeat (typematic) on
its inputs then KeyGrabber will ignore this.
8.1.5
When you are happy with the way your encoder counts then click OK.
You now have to configure the entries in the Up Key and Down Key columns of the table.
Double-click (or right-click Define) the relevant cell and enter the required code (see figure
18.5).These will typically be the hotkeys that are setup in Config>Axis Hotkeys and used to
jog the Mach2 axis involved or be the hotkey codes on the buttons to increment/decrement
the feedrate or spindle speed.
Note 1: Some USB keyboard emulators are limited to a maximum of 8 keys simultaneously
pressed. Each encoder can press up to 2 keys so do not use more than 4 encoders on this
type of emulator
(3 if you are
using it for other
functions as
well). You
cannot use an
emulator which
has repeats on
these inputs.
Note 2: The
response speed
of the keyboard
system is limited
so don't expect to
connect up a
2000 cpr encoder
and spin it fast!
About 25 Hz (40
msecs for a cycle
of the A or B
Figure 8.5 Defining Up and Down keys
inputs) seems to
work reliably on a typical Mach2 configuration. This is 10 rpm on a 32 cpr digital
potentiometer. For jogging or the like a few steps lost at speed would not really matter as
you will probably be watching the work or DROs.
Rev 6.11-A6
8-5
8.1.6
Configuring HIDs
8.1.6.1
Human Interface Devices (HIDs) support many different types of control. Example include
an "analogue" or proportional joystick or throttle (termed by Microsoft, slightly confusingly
for us, Axes), a Point of View (POV) pad or hat (like an 8 way digital joystick) and buttons.
If your HID has more than 32 buttons then you must have DirectX version 9 installed in
Windows.
Plug in your HID's USB interface. Windows should recognise it with a chime or, if it is the
first time you have connected, it should recognise the new device (by name) and install
drivers for it. You should not install or run any profiler that was supplied with your HID.
You should then be able to check the basic operation of your HID using the Game
Controllers option of Windows' Control Panel.
8.1.6.2
When you run KeyGrabber, the HID Controllers tab should show a list of all the devices
you have currently plugged in. If you double-click in the Use device? Column this will
toggle the clicked device in and out of use. Right-click or the Properties button will confirm
the configuration of the device. Each device that is "in-use" has a flashing watchdog
confirming (or otherwise) communication with it. A red signal indicates a problem.
When at least one HID is in-use, additional tabs are displayed.
HID Keys
HID Encoders
8.1.6.3
HID Keys
On this tab, see figure 8.6, use the drop-down list to choose the HID you wish to set up. The
table on the HIDs tab is unlike the Keyboard Keys tab as Windows knows how many
buttons a HID has (see Properties) and the table has one line for each HID key/button. You
select the Page you are defining by the drop-down. When Mach2 is running then Page 1
will be used for translation if no Page Select button is pressed. The other pages are selected
by the buttons configured as described below. This selection is always instantaneous (i.e. it
only applied while the button is depressed).
8-6
Rev 6.11-A6
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.
8.1.6.4
HID encoders
Misc Settings
Typematic settings are described in the section on Keyboard Keys Options. Notice that the
same delay, rates and wait count apply to all keys with Typematic enabled whether they be
on a keyboard, keyboard emulator or HID.
An Axis is a direction of analog control like a joystick or position of a throttle or steering
wheel of a game controller. Each axis generates a value in the range -1000 to +1000
depending on its position. Some controllers generate axis signals from switches (rather like
POV controls or indeed which double as POV controls). The switches will generally only
produce the maximum positive and negative values.
The magnitude of values which trigger KeyGrabber to output a keycode are set in the dialog
under Axis parameters. When the axis value numerically exceeds Threshold1 then the code
in Axisn Plus or Axisn Minus will be selected. When the value exceeds Threshold2 then the
code in Axisn Plus2 or Axisn Minus2 will be selected the other values remaining in the keydown state. This could happen very quickly and confuse Mach2 with what appear to be
simultaneous key presses. The Delay time allows the two events to be separated. A time of
300 milliseconds is a useful general setting.
Axes can be joysticks and send "analog" values to Mach2. The sensitivity of these is set by
their Gain. This can be altered for each individual axis at setup time (see below) but "high"
Rev 6.11-A6
8-7
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.
8.1.7
Axes as joysticks
Axes which generate a range of values can very usefully be configured to jog axes and
override feedrate, jogging speeds and spindle speed. These parameters are set up on the
Joysticks tab (figure 8.8)
The dropdown selects which HID to configure. Move the control in the direction you want
to configure to highlight the appropriate row of the table.
The Controls column allows you to define the function for the axis. These should be self
explanatory except for Axis Gain. This allows you to use a axis on the HID to control how
sensitive the other axes will be.
The Gain column is used to set the relative sensitivity of each axis on the HID (e.g. how
much displacement of a joystick gives a given jogging speed). This is overidden by the gain
defined in Misc Settings if you have defined a Joystick Sensitivity button.
The Response Curve is the relationship between the displacement of the controld and the
signal sent to Mach2. The Exponential values give a small output for positions near the
center (zero) value but large values next the extremes. This can allow, for example, very
sensitive control of jogging at low speeds but the possibility of very fast jogging when the
joystick is held fully over.
Reverse allows positive values to be swapped for negative ones to cater for the way in
which the HID is designed or mounted.
8.1.8
If you use more than one machine controlled by a computer the you will probably want to
configure your HID and keyboard emulator differently for each. This is done but having
several .GRAB files. As mentioned above, you can Save As a configuration in a file other
than Default.grab and can use File>Open to open a non-default configuration.
It would however be more convenient to automatically associate the correct .GRAB with its
Mach2.
This is done by including the name of the .GRAB file to be used in the Target field of the
properties of the shortcut used to run KeyGrabber. The .GRAB file name comes before /p
Mach2 Customisation Guide
8-8
Rev 6.11-A6
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.
8.1.9
Your keyboard emulator will probably come programmed with the MAME standard
gaming keycodes and may also allow you to program a set of your own codes. In this case
you can of course use any values but given that KeyGrabber is going to translate them it is
probably best to program in a set of codes that do not clash with those that the actual
keyboard can generate. Values decimal 264 upwards are probably suitable.
KeyGrabber will automatically program the Ultimarc IPAC range of emulators with such a
range of unused keycodes using the IPAC menu. You choose the IPAC configuration and
the speed at which you wish to program. Start fast and slow down if the programming fails.
Beware: To program an IPAC you need to set the MAME/Alt jumper correctly.
Programming an IPAC will loose any existing codes stored in its "Alt" memory. The
MAME codes are not overwritten.
8.1.10
The Testing menu allows you to display a dialog which will give you the code and
mnemonic for any key seen by KeyGrabber. This will test the actual keyboard, switches on
a keyboard emulator, encoders on an emulator, and the buttons, POV and axes on an
enabled HID. You can use this to check that your wiring is correct and to discover the code
that the keyboard or emulator is actually sending to KeyGrabber.
Note: For IPAC users. Notice that the IPAC supports LED outputs indicating the state of
the Num Lock, Caps Lock and Scroll Lock signals of the PC keyboard. These outputs are
Rev 6.11-A6
8-9
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.
8-10
Rev 6.11-A6
9.
Revision history
Rev 6.11-A6
13 November
2004
Rev 6.11-A5
12 November
2004
Rev 6.11- A3
10 November
2004
Rev 6.11-A6
10. Index
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!
sizing of ...................................................... 3-5
sizing to bitmap ........................................... 3-9
spacing of.................................................... 3-5
Toolpath ...................................................... 3-1
Copyright statement ......................................... 1-1
.
.LSET file
layout .......................................................... 7-6
.SET file
layout .......................................................... 7-6
Acknowledgements.......................................... 1-1
ActivateSignal - subroutine.............................. 4-9
B
Backgrounds
bitmap......................................................... 3-7
Bitmap backgrounds ........................................ 3-7
Button
running VB Script from ............................... 3-3
Button codes.................................................... 6-2
F
File format
layout .......................................................... 7-6
Function codes
of screen controls......................................... 4-4
G
G-code execution
in script ....................................................... 4-4
GetCoord - subroutine...................................... 4-7
GetDRO -function............................................ 4-5
GetLED - function ........................................... 4-5
GetOEMDRO - function .................................. 4-5
GetOEMLED -function.................................... 4-5
GetPage - function ........................................... 4-9
GetParam - function......................................... 4-6
GetPortByte - function ................................... 4-10
GetVar - function............................................. 4-6
GetXCoor - function (also for Y, Z, A, B, C).... 4-7
2
Rev 6.11-A6
H
HID
as source of keycodes .................................. 2-3
Hotkey available on all screens - a trick............ 3-3
Hotkey codes
how calculated............................................. 3-2
Hotkeys
DRO ........................................................... 3-6
Hotkeys - global .............................................. 2-5
Human Interface Device ...........................See HID
M
Mach Developers NetworkDN
link to.............................................................. i
Mach2 scancodes
how calculated............................................. 3-2
Mach2ScreenTweak................... See ScreenTweak
MachDN
developers network link................................... i
Macro.......................................See alse VB Script
naming and calling....................................... 2-4
simple example code.................................... 4-2
Macros
coding ......................................................... 4-1
detailed description of an example ............... 4-2
generating g-code sequences within ............. 4-3
interaction with machine operator ................ 4-3
passing parameters to................................... 4-3
Manual Pulse Generator ..........................See MPG
Message - subroutine ....................................... 4-7
MPG
input via keyboard emulator......................... 8-1
I
Icons
on desktop shortcuts for Mach2 ................... 8-2
Intelligent labels .............................................. 3-6
IPAC
limitations on use of pins ............................. 8-9
IPAC programming
by KeyGrabber ............................................ 8-9
IsActive - function for Signal ........................... 4-9
IsFirst - function ............................................ 4-10
IsLoading - function....................................... 4-10
IsMoving - function ....................................... 4-10
IsSuchSignal - function.................................... 4-9
Keyboard emulators
uses for in controlling Mach2....................... 8-1
Keyboard shortcut - Screen Designer ............... 6-1
Keycodes
processing of ............................................... 2-3
Keygrabber
configuring for keyboard or keyboard emulator
keys ........................................................ 8-3
KeyGrabber
analog axis mapping to keycodes ................. 8-7
configuring encoder inputs........................... 8-5
configuring HID inputs................................ 8-6
files used ..................................................... 8-2
generation of keycodes by............................ 2-3
HID Page selection ...................................... 8-6
installation of............................................... 8-2
overview ..................................................... 8-1
profiles (.GRAB files) ................................. 8-8
sending modifer keys................................... 8-4
special keys ................................................. 8-4
troubleshooting............................................ 8-9
Typematic settings....................................... 8-7
Keystrokes
actions of..................................................... 2-1
and their shortcuts ....................................... 2-3
KillExponent - Script subroutine ...................... 4-5
Nudging
controls into position ................................... 3-2
O
OEM codes
of screen controls........................................ 4-4
OpenTeachFile - subroutine ............................. 4-8
P
Param - functions............................................. 4-7
Persistent screen - controls on .......................... 3-1
PlayWave - subroutine ..................................... 4-7
Ports
foreign - access to ...................................... 4-10
Profiler
generation of keycodes by............................ 2-3
Q
Quadrature encoder
as MPG ..............................................See MPG
Question - function .......................................... 4-7
S
Safety warning................................................. 1-1
professional advice ...................................... 1-1
SaveWizard - subroutine .................................. 4-9
Scancodes
how calculated............................................. 3-2
Screen captions................................................ 7-6
Screen controls
accessing by macro code .............................. 4-4
Screen Designer
standard shortcuts ........................................ 6-1
Screen Designer - explained............................. 3-1
L
Label
Intelligent, Ticker formatted ........................ 3-6
Intelligent, User........................................... 3-6
Layout
.SET file...................................................... 3-1
.SSET file.................................................... 3-1
LED codes....................................................... 6-2
LEDs
user defined................................................. 4-8
Rev 6.11-A6
T
Ticker
User defined ................................................ 3-6
ToggleScreens - subroutine .............................. 4-9
Trademarks...................................................... 1-2
Transparent bitmap buttons .............................. 3-7
U
User defined
DROs .......................................................... 4-8
LEDs........................................................... 4-8
V
VB Script
accessing screen controls from ..................... 4-4
coding ......................................................... 4-1
confusion with brackets in calls.................... 4-3
example code............................................... 4-1
executing G-code from................................. 4-4
on buttons.................................................... 3-3
ways to use .................................................. 2-4
VB Script subroutine
Code............................................................ 4-4
W
Waiting for Mach2......................................... 4-10
Wizard
care needed with synchronisation ................. 5-6
Digitize - tutorial ......................................... 5-1
saving of user controls between runs ............ 5-5
self documenting features............................. 5-9
troubleshooting............................................ 5-9
User DROs in .............................................. 5-4
validating use data - an Example .................. 5-7
While IsMoving()/Wend .............................. 5-6
writing VB Script using an external editor.... 5-7
Wizards
designing..................................................... 5-1
what are they ............................................... 5-1
Rev 6.11-A6