1
VB and the development of wizards / Re: Use VB outside of Mach3 to control a machine
« on: October 24, 2010, 10:36:39 PM »
For those reading this, I've found a way to do what I was after. I can enter a G code line directly into the MDI input line in Mach3 to accomplish my desired move of the XY table. To enter the G code line I run a .VBS script through the other data collection application. The VB script uses SendKeys to pass the text for the MDI input box in Mach3 as shown in the example script below. I have not done extensive testing and if anyone has any pointers on how to do better housekeeping please feel free to post improvements. For now it seems to do the trick and allows me to automate the XY stage to collect multiple samples on my apparatus.
--------------------------------
set WshShell = WScript.CreateObject("WScript.Shell")
'AppActivate usng window title name
'Mach3 must already be running
WshShell.AppActivate "Mach3 CNC Controller"
'short delay to allow window to activate
WScript.Sleep 100
'Send ALT 2 to bring up MDI tab
WshShell.SendKeys "%2"
'Short delay because Mach3 needs a delay here
WScript.Sleep 500
'Send ENTER to activate MDI input line
WshShell.SendKeys "{ENTER}"
WScript.Sleep 100
'Send some G Code
WshShell.SendKeys "X1{ENTER}"
WScript.Sleep 100
WshShell.SendKeys "Y3{ENTER}"
WScript.Sleep 100
'Send ENTER to toggle MDI editing line activation
WshShell.SendKeys "{ENTER}"
'see http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
'for SendKeys info and special codes
-----------------------------------------------
--------------------------------
set WshShell = WScript.CreateObject("WScript.Shell")
'AppActivate usng window title name
'Mach3 must already be running
WshShell.AppActivate "Mach3 CNC Controller"
'short delay to allow window to activate
WScript.Sleep 100
'Send ALT 2 to bring up MDI tab
WshShell.SendKeys "%2"
'Short delay because Mach3 needs a delay here
WScript.Sleep 500
'Send ENTER to activate MDI input line
WshShell.SendKeys "{ENTER}"
WScript.Sleep 100
'Send some G Code
WshShell.SendKeys "X1{ENTER}"
WScript.Sleep 100
WshShell.SendKeys "Y3{ENTER}"
WScript.Sleep 100
'Send ENTER to toggle MDI editing line activation
WshShell.SendKeys "{ENTER}"
'see http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
'for SendKeys info and special codes
-----------------------------------------------