Hello Guest it is November 18, 2019, 11:53:59 AM

Author Topic: Write a plugin for USB  (Read 20757 times)

0 Members and 1 Guest are viewing this topic.

Write a plugin for USB
« on: February 24, 2011, 03:25:43 AM »
Hello I want to write a plugin for Mach3 for use in PCs that do not have a parallel port, I had in mind to capture the signals that Mach3 send to the parallel port, how can I do?

Re: Write a plugin for USB
« Reply #1 on: February 24, 2011, 06:04:57 AM »
I have the same problem. A didn`t have any LPT on my motherboard so i decided to control mi driver trough USB. I have my progrma writen in C# which gets and sends data to my PIC trough the USB using HID. A managed to control a stepe motor trough the PC and now Im working on making Servo controler mith my PIC18F2455.

First i thought that i wil capture the LPT data which Mach3 sends and redirect it to the USB and the PIC but when i dont have a LPT it sounds imposible unles i make some Emulated LPT.
 But now i am workingo on making plugin for Mach3 . I want to do it in C# .NET

I`ve read this topic http://www.machsupport.com/forum/index.php/topic,11589.0.html    and i`m trying to acces the Mach3 , But i get an error

Code: [Select]
System.Runtime.InteropServices.COMException was unhandled
  Message="Невалиден низ за клас (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))"
       at System.Runtime.InteropServices.Marshal.CLSIDFromProgID(String progId, Guid& clsid)
       at System.Runtime.InteropServices.Marshal.GetActiveObject(String progID)
       at Test_Mach3_plugin.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Asen\Documents\Visual Studio 2008\Projects\Test Mach3 plugin\Test Mach3 plugin\Form1.cs:line 33
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Test_Mach3_plugin.Program.Main() in C:\Users\Asen\Documents\Visual Studio 2008\Projects\Test Mach3 plugin\Test Mach3 plugin\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Re: Write a plugin for USB
« Reply #2 on: February 24, 2011, 07:32:06 AM »
Hello I would like to develop the plugin with Visual Studio 2008 and C + +, have already managed to make the first plugin, now the problem is figuring out how Mach3 sends commands to the parallel port to interpret them and send them to USB.


Offline Tweakie.CNC

  • *
  •  8,002 8,002
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Write a plugin for USB
« Reply #3 on: February 24, 2011, 09:34:58 AM »
I think that perhaps you two guys should work together, sharing your accumulated knowledge. Would be a welcomed project for many, once you have cracked it.

Success consists of going from failure to failure without loss of enthusiasm.  Winston Churchill.
Re: Write a plugin for USB
« Reply #4 on: February 24, 2011, 09:54:25 AM »
Hello this is my code:

Code: [Select]

void piUpdate()

    int axis;
    int iMax;
    char c;
if (MG::lamiaForm){
LaMiaForm^ lamiaform = MG::lamiaForm;

lamiaform->textBox1->Text ="";
for(int i=0;i<30;i++)

lamiaform->textBox1->Text +="\r\n" + i.ToString();
c = Engine->OutSigs[i].OutPin;
lamiaform->textBox1->Text += ";" + c.ToString();
c = Engine->OutSigs[i].OutPort;
lamiaform->textBox1->Text += ";" + c.ToString();
lamiaform->textBox1->Text += ";" + Engine->OutSigs[i].Negated.ToString();
lamiaform->textBox1->Text += ";" + Engine->OutSigs[i].Activated.ToString();
lamiaform->textBox1->Text += ";" + Engine->OutSigs[i].active.ToString(); 

I knew that you could see how Mach3Engine->OutSigs announced the step and direction to the parallel port, but so far I could not understand how it works.

Re: Write a plugin for USB
« Reply #5 on: February 24, 2011, 10:50:02 AM »
How do you get this Mach3Engine ? If you can get te step and dir you can make it.

Now i am triyng to make Plugin in diferent way and have done a couple of steps to the succes.I am using  http://www.machsupport.com/forum/index.php/topic,10733.0.html  - Te MachPluginWizard . For now i`ve made simple plugin , accesing the mach3 and reading the X Y and Z axes position values . Now im triyng to include in the plugin my existing program which does the usb job and controls the PIC through te USB.

By the way can you post some info about your controler , the USB interface and how will you control your device(step/dir , position , coils (if step motor) , velociti or smoe other way).
Re: Write a plugin for USB
« Reply #6 on: February 24, 2011, 10:55:39 AM »
You all should read the Mach 3 internals Plug-In writers bible
All about movement plugins is written there.

Re: Write a plugin for USB
« Reply #7 on: February 25, 2011, 06:53:47 AM »
hello, i have try this code
Code: [Select]
i= Engine->TrajIndex;
//lamiaform->textBox1->Text +=
if (MainPlanner->Movements[Engine->TrajIndex].sx!=0)
lamiaform->textBox1->Text += MainPlanner->Movements[Engine->TrajIndex].sx.ToString("F4") ;
lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].sy.ToString("F4");
lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].sz.ToString("F4");
lamiaform->textBox1->Text += "\r\n";

lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].ex.ToString("F4");
lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].ey.ToString("F4");
lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].ez.ToString("F4");
lamiaform->textBox1->Text += "\r\n";

lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].Time.ToString("F4");
lamiaform->textBox1->Text += ";" + MainPlanner->Movements[Engine->TrajIndex].type.ToString("F4");
lamiaform->textBox1->Text += "\r\n";

Engine->TrajIndex = (Engine->TrajIndex+1) & 0xfff;
but mach3 is blocked and not respond, why?

Re: Write a plugin for USB
« Reply #8 on: February 25, 2011, 09:58:43 AM »
I have cracked it a bit :-) - I also have USB controller. It works with different software then Mach, I wanted to enable it with Mach as well.
I will create separate thread for it - so we can join our efforts


« Last Edit: February 25, 2011, 10:12:56 AM by jarekk »
Re: Write a plugin for USB
« Reply #9 on: October 03, 2015, 02:58:42 AM »
I am also looking for plugin for usb.
Has any one made it?
Please guide me with this.