Hello Guest it is May 19, 2019, 01:10:59 PM

Author Topic: Sending more than one command at a time to Mach3 via API  (Read 2672 times)

0 Members and 1 Guest are viewing this topic.

Sending more than one command at a time to Mach3 via API
« on: April 08, 2014, 07:07:24 PM »
I am using a C# winform app to control a diy pick and place machine via Mach3 and a Smoothstepper Ethernet board. The code I am using uses the Mach4.Document object:

Mach = (Mach4.IMach4)Marshal.GetActiveObject("Mach4.Document");
Script = (Mach4.IMyScriptObject)Mach.GetScriptDispatch();

Then using script.Code(Gcode);  to send the command to Mach3 to move the steppers etc.

I am using this function which checks that the movement has finished before the next command can run:

public bool RunMach3Command(Mach4.IMyScriptObject script, string command)
        {
            try
            {
            script.Code(command);
            }
            catch { }
            try
            {
                while (script.IsMoving() != 0)
                {
                    Thread.Sleep(10);
                }
            }
            catch { }
            return true;
        }

The problem I am experiencing with running the Gcode commands in this way is there is a small pause between each movement which is slowing down the placement of the parts. If I run a set of commands via a Gcode file it runs much faster and smoother but I cant do this as the application needs to use other sensors and inputs to check that things such as component feeders are ready before it can pick the parts.

I have tried to send several commands one after the other without the script.IsMoving() being used but Mach3 seems to choke on the commands and only run the last one.

Is there any way to send several lines of Gcode to Mach3 via the scripting objects so Mach3 runs them all in sequence in the same way it runs a Gcode file or will this be available in Mach 4 when it is released?

The full code for the application is on https://github.com/briandorey/PNPControllerUSB and info about the pick and place machine with some videos of it running on http://briandorey.com/post/DIY-Pick-and-Place-V2-Project-Complete.aspx
Any help or ideas greatly appreciated!