Mach3 Automation

Author: Dave
Date: 02.13.16 - 12:39am

So the project I am working on is a mix between a traditional CNC machine and an Arduino project. The short story is I want to record and train paths with rotary encoders and then replay the paths with steppers. You can read more in a seperate blog post here.

Especially for testing and calibration of the two systems I want a quick and easy way to move the steppers while taking readings from the arduino using X/Y coordinate conversions. I know I can control the steppers from Arduino, but I didnt have 2 stepper boards on hand, nor did I want to work out all the GCode details and positioning stuff. I figured I would look for a cheap shot solution.

To replay the full tool paths, I will generate a gcode file from the encoder positions and then run it in Mach3. I already have a license for it, and already had a $50 3 axis sain smart driver board for it, power supply, and old laptop with a parallel port.

I went to setup mach and got looking around the site, it turns out Mach supports a plugin model. I never knew this! You can write traditional plugins that it loads in process using C++ which could be a bit hairy, but it turns out Mach is also an ActiveX exe server and can be automated from external applications very easily !

You can find the VB6 Mach3 Automation Sample here.

This is perfect for this project, especially since I still use VB6 which is a master of simple COM integration. Controlling the steppers to goto a specific X/Y position will literally be a single line of code for me now without having to worry about any of the details.

mach.RunGCode("G0 X2 Y3.5")

Its also worth mentioning that Mach exposed its entire internal macro scripting language interface in this manner. Its very robust and you have access to basically everything. Its pretty awesome and will make for some interesting projects I am sure.

So here is some thoughts for a hybrid test machine:
  • arduino reads encoder output and seds them to serial
  • vb6 app reads position and converts them to X/Y coordinates
  • vb6 app records the positions in a list
  • replay mode, power steppers and click a button in vb6
  • mach is commanded to move to this position for calibration tests
  • coordinates can be adjusted in bulk on the fly if off
  • click vb button to cycle through the list one by one
  • additional I can use the serial link to also control a hobby servo for Z movement to put marker down and mark spots or draw lines
I know its a technology mash up, maybe even sloppy, definitely not for purists, but for a testing app and a minimal effort throw together its pretty elegant. Handing off the complex stuff to a specialized system designed for it and being able to control it with an extremely simple interface.

Certain things such as drawing out test patterns, planing a table flat, or marking grid lines on your table can also be represented easily with a programming interface. These should be much more readable as VB6 or Javascript code than having to generate a GCODE file. Mach does already support its own internal VBA script language though so maybe no need to do externally.

In Javascript it would look like this: (you can see the gcode it generates in your browser here)

//draw 1" grid lines on table with marker

limitY = 15
limitX = 9

//RunGCode, true returns when movement complete.
function go(x,y){mach.RunGCode("G0 X" + x + " Y" + y, true); }
function  x(pos){mach.RunGCode("G0 X"+pos, true); }
function  y(pos){mach.RunGCode("G0 Y"+pos, true); }
function  z(pos){mach.RunGCode("G0 Z"+pos, true); }

function drawRect(x0,y0,w,h){

go(0,0); // home pos
z(0);    // marker down

while(1){ //draw horz X lines
	x(limitX); //all way right
	if(i > limitY) break;
	y(i); //up to next line
	x(0);  //all way left
	if(i > limitY) break;
	y(i); //up to next line

z(1);    //marker up..
go(0,0); //go home
z(0);    //marker down

while(1){ //draw vertical Y lines
	y(limitY); //all way up
	if(i > limitX) break;
	x(i);   //right one
	y(0);  //all way down
	if(i > limitX) break;
	x(i);   //right one

//finally draw rectangle around entire perimiter 

//complete goto center 
go(limitX/2, limitY/2);

Comments: (0)

Leave Comment:
Email: (not shown)
Message: (Required)
Math Question: 39 + 44 = ? followed by the letter: N 

About Me
More Blogs
Main Site
Posts: (year)
2024 (1)
     RegJump Vb
2023 (9)
     VB6 Virtual Files
     File handles across dlls
     python abort / script timeout
     VB6 Python embed w/debugger
     python embedding
     VB6 IDE Enhancements
     No Sleep
     A2W no ATL
2022 (4)
     More VB6 - C data passing
     Vb6 Asm listing
     Byte Array C to VB6
     Planet Source Code DVDs
2021 (2)
     Obscure VB
     VB6 IDE SP6
2020 (4)
     BSTR from C Dll to VB
     Cpp Memory Manipulation
     ActiveX Binary Compatability
2019 (5)
     Console tricks
     FireFox temp dir
     OCX License
     Extract substring
     VB6 Console Apps
2018 (6)
     VB6 UDTs
     VB6 Debugger View As Hex tooltips
     VB6 - C Share registry data
     VB6 Addin Missing Menus
     VB6 Class Init Params
     VB6 isIn function
2017 (6)
     Python and VB6
     Python pros and cons
     download web Dir
     vc rand in python
     VB6 Language Enhancement
     Register .NET as COM
2016 (22)
     VB6 CDECL
     UDT Tricks pt2
     Remote Data Extraction
     Collection Extender
     VB6 FindResource
     DirList Single Click
     Reset CheckPoint VPN Policy
     VB6 BSTR Oddities Explained
     SafeArrays in C
     BSTR and Variant in C++
     Property let optional args
     Misc Libs
     Enum Named Pipes
     Vb6 Collection in C++
     VB6 Overloaded Methods
     VB6 Syncronous Socket
     Simple IPC
     VB6 Auto Resize Form Elements
     Mach3 Automation
     Exit For in While
2015 (15)
     C# self register ocx
     VB6 Class Method Pointers
     Duktape Debug Protocol
     QtScript 4 VB
     Vb6 Named Args
     vb6 Addin Part 2
     VB6 Addin vrs Toolbars
     OpenFile Dialog MultiSelect
     Duktape Example
     DukTape JS
     VB6 Unsigned
     .Net version
     TitleBar Height
     .NET again
     VB6 Self Register OCXs
2014 (25)
     Query Last 12 Mos
     Progid from Interface ID
     VB6 to C Array Examples
     Human Readable Variant Type
     ScriptBasic COM Integration
     CodeView Addin
     ScriptBasic - Part 2
     Script Env
     MSCOMCTL Win7 Error
     printf override
     History Combo
     Disable IE
     API Hooking in VB6
     Addin Hook Events
     FastBuild Addin
     VB6 MemoryWindow
     Link C Obj Files into VB6
     Vb6 Standard Dlls
     CStr for Pascal
     Lazarus Review
     asprintf for VS
     VB6 GlobalMultiUse
     Scintilla in VB6
     Dynamic Highlight
     WinVerifyTrust, CryptMsgGetParam VB6
2013 (4)
     MS GLEE Graphing
     printf for VB6
     C# App Config
     Tero DES C# Test
2012 (10)
     VC 2008 Bit Fields
     Speed trap
     C# Db Class Generator
     VB6 vrs .NET (again)
     FireFox Whois Extension
     git and vb6
     Code Additions
     Compiled date to string
     C# ListView Sorter
     VB6 Wish List
2011 (7)
     C# Process Injection
     CAPTCHA Bots
     C# PE Offset Calculator
     VB6 Async Download
     Show Desktop
     coding philosophy
     Code release
2010 (11)
     Dll Not Found in IDE
     Advanced MSScript Control
     random tip
     Clipart / Vector Art
     VB6 Callback from C#
     Binary data from VB6 to C#
     CSharp and MsScriptControl
     HexDumper functions
     Js Beautify From VB6 or C#
     vb6 FormPos
     Inline Asm w VB6
2009 (3)
     The .NET Fiasco
     One rub on computers
     Universal extractor