1
Mach SDK plugin questions and answers. / Re: VS2008 Add Reference
« on: May 21, 2009, 11:49:03 PM »
OK, I figured this out thanks to zip file that babinda01 posted. I'm on vista, not sure that matters.
If you are in VS and want to control Mach via C# (and presumably VB), then you can start by creating a project, and then doing Project -> Add Reference and selecting the Mach3.exe.
Your project will have a new reference added called Mach4.
Add a button on your form. Make you code look as follows. Each time you hit a button, Mach will drive to the coords 2,2 and 6,3.
Don't try this connected to a real machine until you've studied it a bit.
If you are in VS and want to control Mach via C# (and presumably VB), then you can start by creating a project, and then doing Project -> Add Reference and selecting the Mach3.exe.
Your project will have a new reference added called Mach4.
Add a button on your form. Make you code look as follows. Each time you hit a button, Mach will drive to the coords 2,2 and 6,3.
Don't try this connected to a real machine until you've studied it a bit.
Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// I had to run VS as admin for this to work. I'm on Vista.
// Need this to drive Mach
using System.Runtime.InteropServices;
namespace Mach3ControltoControlPlugin
{
public partial class Form1 : Form
{
// Add these two lines
private Mach4.IMach4 Mach = null;
private Mach4.IMyScriptObject Script = null;
public Form1()
{
InitializeComponent();
}
// This is the button handler. Make it look like this.
private void button1_Click(object sender, EventArgs e)
{
Mach = (Mach4.IMach4)Marshal.GetActiveObject("Mach4.Document");
Script = (Mach4.IMyScriptObject)Mach.GetScriptDispatch();
//_scripter.SetDRO(1, 3.3);
Script.Code("G1 X2 Y2 F400");
while (Script.IsMoving() != 0)
{
System.Threading.Thread.Sleep(25);
}
Script.Code("G1 X6 Y3 F400");
while (Script.IsMoving() != 0)
{
System.Threading.Thread.Sleep(25);
}
}
}
}