Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Kisssys on September 20, 2008, 10:35:14 PM

Title: Loading Code from another program
Post by: Kisssys on September 20, 2008, 10:35:14 PM
I am going to write a small program in Visual basic to take position data from an old graphics tablet and convert it directly to G-code to cut small pieces of
metal on my Plasma cutter.

What is the easiest way to automatically download the new file directly to Mach3.  I could make it so it would act like notepad and accept the file and when modified download
it back to Mach3,  I need Mach 3 to call the program with a different file name each time and I'm not sure how to do that with the OEM call.

If I need to use the SDK ok but I'm pretty green at VB programing and especially about DLL's etc.

Any help on a wizard or Script would be greatly appreciated

Kisssys
Title: Re: Loading Code from another program
Post by: ftkalcevic on October 01, 2008, 09:28:33 PM
When you say "write a small program in Visual Basic" do you mean Mach's Visual Basic scripting, or a standalone Visual Basic application?  VB6 or VB.Net?

For a standalone program, you can use the Mach COM API.  Write your program to do the conversion, save the data to a file, then your program can use the COM API to tell Mach to load the file, and execute it.  The COM API is quite powerful.  Just add a Mach3 COM object reference to your project and browse the methods exposed by the object.  I think there are examples around, but not sure where.  There are some reference counting bugs though with the API.  It can cause Mach to crash when you exit your application.

If you are writing a script, I think you can use the OpenTeachFile/CloseTeachFile/LoadTeachFile methods.  Look at some of the wizards for ideas.  You can load a wizard, then use the "edit button script" menu option to view the code of non-protected wizards.

Frank
Title: Re: Loading Code from another program
Post by: Kisssys on October 02, 2008, 09:33:13 AM
Thanks for the reply, I figured it was too dumb a question for a programmer to ask.

I am using VB2005 express which is the .net framework.  I've used VB6 a fair amount but new to .net.  The Mach Com API is the best way for me to go
but not sure how to start.  I'll try to add the Mach3 COM object reference to my program and see how it goes.  I just need to buckle down and spend a half day and figure it out.

I want the program to autoload the code.  I will be cutting small pieces out on my plasma cutter of varying shapes and sizes, probably never have more than
polygon of 6 sides.  I want to take the shape on my graphics tablet and hit go and it will zip it out.

Thanks again
Kisssys
Title: Re: Loading Code from another program
Post by: Kisssys on October 02, 2008, 02:19:31 PM
I added a reference to Mach4 and used the public procedure LoadGCodeFile and it compiles but seems to go to the DLL and dies.
Not sure about the Imports  or the Dim statement

Any Ideas as to where I'm going wrong
Kisssys

' Test code   

Imports Mach4

Public Class Form1

    Dim CMach4 As New CMach4Doc()

    Private Sub Mach3Load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mach3Load.Click

        CMach4.LoadGCodeFile("C:\test.tap")

    End Sub
End Class
Title: Re: Loading Code from another program
Post by: ftkalcevic on October 02, 2008, 05:43:33 PM
You can't create a new instance of the Mach object.  Mach must be running then attach to it with...


        Dim mach As Mach4.IMach4
        mach = GetObject(, "Mach4.Document")

        Dim scriptObject As Mach4.IMyScriptObject
        scriptObject = mach.GetScriptDispatch()

        scriptObject.LoadFile("d:\Mach3\GCode\roadrunner.tap")



I added a reference to Mach4 and used the public procedure LoadGCodeFile and it compiles but seems to go to the DLL and dies.
Not sure about the Imports or the Dim statement

Using Imports is optional.  It means you don't have to type the full class path.  In this case the Mach4. namespace.
Title: Re: Loading Code from another program
Post by: Kisssys on October 02, 2008, 08:34:17 PM
That worked perfectly.

I never would have fiquired that out, can't thank you enough.

Kisssys