Home
Downloads
Mach and LazyCam
Plugins
CAM Post Processors
Screensets
Purchase
Support
Forum
Tutorial Videos
Documentation
Yahoo Group
Mach Wiki
German Forum
Italian Forum
Portugese Forum
Resources
Links
User Reviews
User Videos
Contact Us
CNCZone
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
November 23, 2008, 11:12:55 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Select from and to languages
Chinese-simp to English
Chinese-trad to English
English to Chinese-simp
English to Chinese-trad
English to Dutch
English to French
English to German
English to Greek
English to Italian
English to Japanese
English to Korean
English to Portuguese
English to Russian
English to Spanish
Dutch to English
Dutch to French
French to English
French to German
French to Greek
French to Italian
French to Portuguese
French to Dutch
French to Spanish
German to English
German to French
Greek to English
Greek to French
Italian to English
Italian to French
Japanese to English
Korean to English
Portuguese to English
Portuguese to French
Russian to English
Spanish to English
Spanish to French
Machsupport Forum
Mach Discussion
Mach SDK plugin questions and answers.
Automating Mach from external software
Pages:
1
2
»
Go Down
« previous
next »
Author
Topic: Automating Mach from external software (Read 1814 times)
0 Members and 1 Guest are viewing this topic.
davew
Active Member
Offline
Posts: 8
Automating Mach from external software
«
on:
January 23, 2008, 09:48:50 PM »
I have just been introduced to the Mach3 software and am looking for ways of automating it from external software.
In skimming over the manual, I noticed in section 3.1.3, it states that using the OCX it is possible to control Mach3 without its GUI. Where can I find more information on this?
After a few hours of digging around I've come across talk about Plugins, but can't find any "Getting Started" documentation (other than how to setup Visual Studio). At first impression, "plugin" sounds like something used WITHIN Mach3 (and it's GUI), rather than something to control it externally.
Any good pointers on where to start? I'm comfortable with most any development language/environment.
Any assistance greatly appreciated,
Dave
Logged
kcrouch
Active Member
Online
Posts: 20
In way too deep!!!
Re: Automating Mach from external software
«
Reply #1 on:
January 23, 2008, 09:55:58 PM »
Dave,
Have You looked at the Mach3 SDK about half way down the downloads page? It may help.
Kenny
Logged
Having way too much fun! Something must surely be wrong.
jemmyell
Active Member
Offline
Posts: 70
Re: Automating Mach from external software
«
Reply #2 on:
January 24, 2008, 11:31:40 AM »
Hi, look at the version 2.0 programmer information on this page:
http://www.machsupport.com/artsoft/downloads/downloads.htm
Mach3 has an Automation Object Model that can be used to control it externally. My plugin tutorial and sample file set also show how to use this from inside a plugin. There is a 'RemoteControl' application download on the downloads page that shows how to use the object model from a C++ program (for VC++ 2003).
-James Leonard
Logged
-James Leonard
www.DragonCNC.com
-
www.LeonardCNCSoftware.com
-
www.CorelDRAWCadCam.com
davew
Active Member
Offline
Posts: 8
Re: Automating Mach from external software
«
Reply #3 on:
January 24, 2008, 12:31:52 PM »
Thanks guys. I guess I was looking mainly at the menus of the website and not drilling down into each page enough.
I've got both VS2005 & VS2003, so I'll give it a look.
Dave
Logged
jemmyell
Active Member
Offline
Posts: 70
Re: Automating Mach from external software
«
Reply #4 on:
January 24, 2008, 12:39:34 PM »
You are welcome!
Get the latest Mach3, it has an embedded typelib. Then just point VS2003 at it and do a create class from typelib. You can then see all the automation methods. Only a plugin has access to Mach3's internal data blocks directly.
The VBscript docs and some searches on macros will give you a good start on what the object methods can be used for.
-James Leonard
Logged
-James Leonard
www.DragonCNC.com
-
www.LeonardCNCSoftware.com
-
www.CorelDRAWCadCam.com
davew
Active Member
Offline
Posts: 8
Re: Automating Mach from external software
«
Reply #5 on:
February 16, 2008, 02:29:03 PM »
Ok, I've got my hands dirty and I'm back with a few questions...
First, thanks James for your Plugin tutorial and whoever wrote MachRemote.
I've developed an application in C# (VS2005) and have been tasked with making it automate Mach3.
What I've done is created a DLL which exports many of the functions of the Mach3.exe Object Model. I used James' Plugin Tutorial as a reference to get started. I then imported these functions into C# and wrapped them with a C# class (which handles connection, exceptions, etc).
This isn't a plugin. I'm not doing anything with dialogs. I'm just setting DRO's, pushing buttons, etc.
So far it is working well except for when I shutdown my app and restart it. After the first time I run, future runs of my app fail to connect to Mach3. If I shutdown Mach3 and restart it, everything is fine (until I shutdown my app and restart it).
I've added some debug code and discovered subsequent runs are failing with a result code (HRESULT) of 1 from GetActiveObject(clsid,NULL,&lpUnk) (see Mach3ObjectModelStartup() in Plugin Tutorial; page 73/92 in V01).
So I started by looking at the shutdown code where I detach from Mach3. In the plugin tutorial, it appears to only be calling "CoUninitialize();" (see Mach3ObjectModelShutdown(VOID); page 74/92 in V01).
However, in MachRemote, I find this code in CMachRemoteDlg::OnBnClickedDisconnect():
scripter.DetachDispatch(); //detach the scripter object
//mach4.ShutDown(); //then shutdown MAch3's interface..
With only the CoUninitialize() call in Plugin Tutorial, Mach 3 would complain on exit with an Art Code of 9991. After I added the scripter.DetachDispatch(), this complaint went away (mostly at least). If I add the "mach4.ShutDown()", this creates an additional error.
Any insights on what I'm missing?
Why doesn't the Plugin Tutorial call scripter.DetachDispatch()? (oversight? am I missing something?)
Why is mach4.ShutDown() commented out in MachRemote?
Any insights appreciated,
Dave
Logged
jemmyell
Active Member
Offline
Posts: 70
Re: Automating Mach from external software
«
Reply #6 on:
February 16, 2008, 02:35:48 PM »
Hi Dave,
It is the difference in the process models I believe. The Mach3 plugins run in-process to Mach3 so it is too late for me to detach the dispatch interface at the point the plugin shutdown code gets called (I got a crash myself for trying it...).
The scripter.detach() call should return the IDispatch pointer, so try releasing it as so:
IDispatch tmp = scripter.detach;
tmp->Release();
-James
Logged
-James Leonard
www.DragonCNC.com
-
www.LeonardCNCSoftware.com
-
www.CorelDRAWCadCam.com
davew
Active Member
Offline
Posts: 8
Re: Automating Mach from external software
«
Reply #7 on:
February 16, 2008, 02:53:24 PM »
Quote from: jemmyell on February 16, 2008, 02:35:48 PM
The scripter.detach() call should return the IDispatch pointer, so try releasing it as so:
IDispatch tmp = scripter.detach;
tmp->Release();
James,
Here's the shutdown code I ended up with, based on your suggestion:
LPDISPATCH tmp = scripter.DetachDispatch(); //detach the scripter object
tmp->Release();
// mach4.ShutDown();
CoUninitialize();
Unfortunately this didn't appear to help. I'm stilling getting HRESULT of 1 from GetActiveObject on my subsequent runs.
Logged
jemmyell
Active Member
Offline
Posts: 70
Re: Automating Mach from external software
«
Reply #8 on:
February 16, 2008, 02:58:29 PM »
Dave, I am totally clueless as to C#, but in VB (6) setting the object to Nothing would release all references. It looks like you are somehow still holding a reference to Mach3.
Since you have your code in a DLL you should be sure the DLL is unloading also. If not, maybe you have a persistant state in the DLL?
-James
Logged
-James Leonard
www.DragonCNC.com
-
www.LeonardCNCSoftware.com
-
www.CorelDRAWCadCam.com
davew
Active Member
Offline
Posts: 8
Re: Automating Mach from external software
«
Reply #9 on:
February 16, 2008, 03:07:55 PM »
Figured it out...
I was just digging around CMach4.h and realized the ShutDown() call is to close the Mach3 app. ...not what I was trying to accomplish.
After a bit more digging, I noticed we're doing an AttachDispatch for both mach4 and scripter...but only doing the DetachDispatch for scripter.
This code is working for me well now:
scripter.DetachDispatch(); //detach the scripter object
mach4.DetachDispatch();
CoUninitialize();
Thanks for your thoughts/time on a Saturday afternoon!
Dave
Logged
Pages:
1
2
»
Go Up
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Mach Discussion
-----------------------------
=> General Mach Discussion
=> Mach3 under Vista
=> Quantum
=> Mach SDK plugin questions and answers.
=> VB and the development of wizards
=> Brains Development
=> Video P*r*o*b*e*i*n*g
=> Mach Screens
=> Feature Requests
=> Non English Forums
=> FAQs
===> Finished Plugins for Download
===> Screen designer tips and tutorials
===> Works in progress
===> Finished Screens
===> Flash Screens
===> JetCam screen designer
===> Italian
===> French
===> Spanish
===> Chinese
===> German
===> Russian
===> Romanian
===> Japanese
===> Vietnamese
-----------------------------
*****VIDEOS*****
-----------------------------
=> *****VIDEOS*****
-----------------------------
General CNC Chat
-----------------------------
=> Share Your GCode
=> Show"N"Tell ( What you have made with your CNC machine.)
=> Building or Buying a Wood routing table.. Beginnners guide..
=> Show"N"Tell ( Your Machines)
-----------------------------
G-Code, CAD, and CAM
-----------------------------
=> G-Code, CAD, and CAM discussions
=> Lazy Cam (Beta)
-----------------------------
Third party software and hardware support forums.
-----------------------------
=> LazyTurn
=> dspMC/IP motion controller
=> Third party software and hardware support forums.
=> Newfangled Solutions Wizards
=> Mach3 and G-Rex
=> Modbus
=> NC Pod
=> PoKeys
=> SmoothStepper USB
=> Promote and discuss your product .
=> Sieg Machines
-----------------------------
Tangent Corner
-----------------------------
=> Tangent Corner
=> Competitions
=> Polls
=> Bargain Basement
-----------------------------
Support
-----------------------------
=> Downloads
=> One on one phone support.
=> Forum suggestions and report forum problems.
===> XML files
===> Post Processors
===> Macros
===> Tutorials
===> Others
===> Beta Brains
===> Screen Sets
===> Documents
===> MACH TOOL BOX
Loading...