Hello Guest it is December 03, 2021, 06:34:14 PM

Author Topic: Use VB outside of Mach3 to control a machine  (Read 8797 times)

0 Members and 1 Guest are viewing this topic.

Use VB outside of Mach3 to control a machine
« on: October 21, 2010, 12:00:41 PM »
I have a piece of equipment in my lab that is designed to acquire data from a single sample and store the data in a file.  I have modified the machine by adding a motorized XY stage (no Z) that allows me to move the stage and position additional samples for analysis. I use Mach3 to control the XY stage.  Using VB script within Mach3 I am able to link the data acquisition program to Mach3 (sort of) to automate the data collection for multiple samples

The following is a thread relating to how I used (sucessfully!) a macropump within Mach3 to move the stage between samples:

http://www.machsupport.com/forum/index.php/topic,8252.0.html

I have a new data acquisition program that allows me to sequence events from within the application and these events include the ability to run an external file.  My hope is that I could simply run a VB script to move the XY stage between samples.  The VB script would likely be very simple, but my question is this:  can I control Mach3 using a VB script from outside the Mach3 program?  If both Mach3 and this data acquisition program are running, can I basically use the data acquisition program to execute individual VB scripts that would in turn tell Mach3 to do basic movements (e.g. move 9 mm to the right)?  I know that I can do this easily from _within_ Mach3, but I'm not sure if it is easy to do this by executing a VB from outside of Mach3.

Thanks for any comments or code suggestions that you may be able to supply.
Re: Use VB outside of Mach3 to control a machine
« Reply #1 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
-----------------------------------------------

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Use VB outside of Mach3 to control a machine
« Reply #2 on: November 04, 2010, 09:37:11 AM »
That is interesting for sure.......  I understand your "Kluky" concerns, I would worry that Mach3 would loose focus and then it would not
recieve the send keys if your other app or something else has the focus.

   Perhaps an alternate solution would be, to for a "Focus" to mach3 when you do the VBS send from the outside app.

another solution, would be you could "automate" this from a plugin (in a way), that you would not need to have mach be in focus.
In your app, you could make and "Save" a motion file singular or multiple lines of code. The plugin could watch for changes to this
file your saving, when it sees a change, it would then run the new motion.

just thoughts, depending on how much you want to fool with it.........

scott
fun times