Art,
I'm really close to getting this working. I worked with Microsoft support to get the Visual Basic side of it working. I now have a VB program that can connect to a running instance of Mach3 and send it GCode commands using the Code() function. My only problem is that most of the time the ActiveX connection only works once. The next time I try to connect, I get an exception.
Here's the code from my VB program:
Module Module1
Function Main() As Integer
Dim GCodeCommand As String
Dim Mach As Mach4.IMach4
Dim ScriptObject As Mach4.IMyScriptObject
Dim ReturnCode As Integer
ReturnCode = 0
GCodeCommand = ""
For Each Argument As String In My.Application.CommandLineArgs
GCodeCommand = GCodeCommand + Argument + " "
Next
If (GCodeCommand <> "") Then
Try
Mach = GetObject(, "Mach4.Document")
ScriptObject = Mach.GetScriptDispatch()
ScriptObject.Code(GCodeCommand)
Catch
ReturnCode = -2
End Try
Else
ReturnCode = -1
End If
Return ReturnCode
End Function
End Module
This is a simple program that takes a G Code command from the command line and sends it to Mach3. Then the program terminates. My problem is that usually the next time I run the program, the call to GetObject throws an exception saying that it cannot connect to the ActiveX server. Once this happens, it continues to happen until I close and reopen Mach3. It always works the first time after starting Mach3, and sometimes it works multiple times in a row. But once it fails, it's done.
I suspect that I'm missing some cleanup code, but I'm not sure what it would be. I tried waiting for the movement to complete via IsMoving before terminating my program, but that didn't make a difference. I saw that the C++ code sample calls DetachDispatch, but as far as I can tell those functions are part of the OLE class in C++ and are not available in VB.
Do you have any ideas what could be causing this problem?