Hello Guest it is November 08, 2024, 09:20:02 PM

Author Topic: MachPluginWizard v1.1 BETA Release  (Read 85476 times)

0 Members and 1 Guest are viewing this topic.

Re: MachPluginWizard v1.1 BETA Release
« Reply #20 on: October 28, 2009, 03:06:14 AM »
Hey Ed,

Thanks for the great Wizard and more importantly the fantastics tutorial videos. They are great. I wish i was checking this section back in march, i would have taken the plugin challenge much earlier.
Are you still active on this forum?

Will much of this change with V4?

Anyway, just wanted to say thanks, so... thanks!

Matt
Re: MachPluginWizard v1.1 BETA Release
« Reply #21 on: December 13, 2009, 04:57:30 PM »

1.  Is there a way to set the Mach error label like  MachErrorMsg("*********x") or SetMachError("*********x")? From the Shuttle Plugin:

   void SetMachError(Cstring Message){
      CString *err = &MainPlanner->LastError;
      if(err != NULL )
      *err = Message;"}

In Ed's -TrajectoryControl structure LastError is a LPCSTR pointer. In C++/CLI I came up with:

   void SetMachError(LPCSTR Message){   
      LPCSTR err =   (LPCSTR)&MainPlanner->LastError;
      if(err != nullptr )
      err = Message;// Compiles NO OUTPUT
}
   
Has anybody figured this out?


Kurt, I solved the same problem with the following piece of code:

void SetMachError(char* msg){
   void *temp = &MainPlanner->LastError;
   if( temp != NULL) *(CString*)temp = msg;  //need #include <atlstr.h>    
}

One more tip: put the include atlstr.h before setting default namespaces in order to prevent name ambiguities.

I hope it helps.

Re: MachPluginWizard v1.1 BETA Release
« Reply #22 on: July 21, 2010, 09:28:09 AM »
Hi Ed,

First of all I would like to thank you A LOT for the excellent job you have performed and most of all for the so clear videos you posted.

I must say that I am impressed.

I am pretty new on SDK and plugin development, and I just wanted to try to hook an usb device to Mach3 via a plugin.
Well I know that's simple... but not so much !

I have installed your framework and successfully compiled and run it (it was quite simple thanks to your tutorials)

On the other hand I have a C++ code using a HID dll to communicate with my device (a simple PIC18F4550) --> it works fine

To start with pulgins I wanted to reference this dll into your code and call it.

I have added a reference to it into Visual Studio
I have modified the code to refrence the namesapce : using namespace HIDClass;
and just added a dll call to check the usb attachement : MCHPHIDClass::USBHIDClassInit (0x4D8, 0x003F, 64);

Well just two lines of modifications... The compilation and link are OK

but when running on the second line (the call to the dll) I have a fatal error :

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.
Additional information: Impossible de charger le fichier ou l'assembly 'HID class, Version=1.0.3376.23070, Culture=neutral, PublicKeyToken=null' ou une de ses dépendances. Le fichier spécifié est introuvable.

Which in english means that the dll is not found...

Any help please, I have the feeling to be "so close" to the success !!!

Here is the plugin.cpp full code (just two lines moded from the original)

Thanks in advance
JP

Code: [Select]
//=====================================================================
//
// Plugin.cpp - the optional custom part of the plugin
//
// this source file can be filled with the actual custom code that
// makes the plugin work. it is the choice of the developer to enable
// which functions will be used from the available MachDevice calls.
//
// if this is a mixed mode dll each function can be declared as either
// an unmanaged or managed function.
//
// please see the documentation in Plugin.h for the #define statements
// that control each functions compilation.
//
// if this is a mixed mode dll and you need to keep global managed
// reference please see the MG class in ManagedGlobal.h
//
// please read the notes and comments in MachDevice.cpp for general
// information and disclaimers.
//
//=====================================================================

#include "stdafx.h"
#include "Plugin.h"
#include "MachDevice.h"
#include "ConfigDialog.h"
#include "PlugInControlDialog.h"
#include "XYZDemoDialog.h"
#include "XMLNetProfile.h"
#include "ManagedGlobal.h"

#include <stdlib.h>

//---------------------------------------------------------------------
// the default namespace for managed functions and classes
//---------------------------------------------------------------------
using namespace HIDClass;
using namespace TestMachWizard;

//---------------------------------------------------------------------
// data area
//---------------------------------------------------------------------

int menuStart; // the starting menu id

//---------------------------------------------------------------------
//
// piInitControl() - Plugin extension of InitControl()
//
// XML file can NOT be accessed since SetProName hasn't
// been called yet
//
// called EVEN if plugin is disabled
//
//---------------------------------------------------------------------

#ifdef PI_INITCONTROL
#ifdef _MANAGED
#pragma PI_MIX_INITCONTROL
#endif
bool piInitControl()
{
menuStart = GetMenuRange(MENU_COUNT);

return true;
}
#endif

//---------------------------------------------------------------------
//
// piSetProName() - Plugin extension of SetProName()
//
// XML file CAN be accessed
//
// called EVEN if plugin is disabled
//
//---------------------------------------------------------------------

#ifdef PI_SETPRONAME
#ifdef _MANAGED
#pragma PI_MIX_SETPRONAME
#endif
char* piSetProName(LPCSTR name)
{
XYZDemoConfig^ xyzDemoConfig = gcnew XYZDemoConfig;
XMLNetProfile^ profile = gcnew XMLNetProfile(gcnew String(ProfileName), "TestMachWizardPlugin", true);

profile->Load();

xyzDemoConfig->enableDlg = profile->ReadBool("Dlg"   , false);
xyzDemoConfig->enableX   = profile->ReadBool("Axis/X", true);
xyzDemoConfig->enableY   = profile->ReadBool("Axis/Y", true);
xyzDemoConfig->enableZ   = profile->ReadBool("Axis/Z", true);

MG::xyzDemoConfig = xyzDemoConfig;

return "TestMachWizard-Author-v1.0.0.0";
}
#endif

//---------------------------------------------------------------------
//
// piPostInitControl() - Plugin extension of PostInitControl()
//
// XML file can NOT be accessed
//
// called ONLY if plugin is enabled
//
//---------------------------------------------------------------------

#ifdef PI_POSTINITCONTROL
#ifdef _MANAGED
#pragma PI_MIX_POSTINITCONTROL
#endif
void piPostInitControl()
{
HMENU hMachMenu = GetMenu(MachView->MachFrame->m_hWnd);
HMENU hPluginMenu = 0;
int machMenuCnt = GetMenuItemCount(hMachMenu);
MENUITEMINFO mii;
LPTSTR txt;

for (int i = 0; i < machMenuCnt; i++)
{
mii.cbSize     = sizeof(MENUITEMINFO);
mii.fMask      = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_STRING;
mii.dwTypeData = NULL;

if (GetMenuItemInfo(hMachMenu, i, true, &mii))
{
txt = (LPTSTR) malloc(++mii.cch);
mii.dwTypeData = txt;

if (GetMenuItemInfo(hMachMenu, i, true, &mii))
{
if (strcmp(txt, "PlugIn Control") == 0)
{
hPluginMenu = mii.hSubMenu;
i = machMenuCnt;
}
}

free(txt);
}

if (hPluginMenu)
{
InsertMenu(hPluginMenu, -1, MF_BYPOSITION, menuStart  , "TestMachWizard");
}
}

XYZDemoDialog^ xyzDemoDialog = gcnew XYZDemoDialog();

xyzDemoDialog->labelX->Visible = MG::xyzDemoConfig->enableX;
xyzDemoDialog->labelY->Visible = MG::xyzDemoConfig->enableY;
xyzDemoDialog->labelZ->Visible = MG::xyzDemoConfig->enableZ;

xyzDemoDialog->textBoxX->Visible = MG::xyzDemoConfig->enableX;
xyzDemoDialog->textBoxY->Visible = MG::xyzDemoConfig->enableY;
xyzDemoDialog->textBoxZ->Visible = MG::xyzDemoConfig->enableZ;

xyzDemoDialog->Visible = MG::xyzDemoConfig->enableDlg;

MG::xyzDemoDialog = xyzDemoDialog;
//MCHPHIDClass::USBHIDClassInit (0x4D8, 0x003F, 64);
}
#endif

//---------------------------------------------------------------------
//
// piConfig() - Plugin extension of Config()
//
// called if user presses CONFIG in Config|Config Plugins
// even if plugin is disabled
//
// XML file CAN be accessed
//
//---------------------------------------------------------------------

#ifdef PI_CONFIG
#ifdef _MANAGED
#pragma PI_MIX_CONFIG
#endif
void piConfig()
{
ConfigDialog^ configDialog = gcnew ConfigDialog();

configDialog->ShowDialog();
MCHPHIDClass::USBHIDClassInit (0x4D8, 0x003F, 64);
}
#endif

//---------------------------------------------------------------------
//
// piStopPlug() - Plugin extension of StopPlug()
//
//---------------------------------------------------------------------

#ifdef PI_STOPPLUG
#ifdef _MANAGED
#pragma PI_MIX_STOPPLUG
#endif
void piStopPlug()
{
XYZDemoConfig^ xyzDemoConfig = MG::xyzDemoConfig;
XMLNetProfile^ profile = gcnew XMLNetProfile(gcnew String(ProfileName), "TestMachWizardPlugin", true);

if (profile->Load())
{
if (MG::xyzDemoDialog) xyzDemoConfig->enableDlg = MG::xyzDemoDialog->Visible;

profile->WriteBool("Dlg"   ,xyzDemoConfig->enableDlg);
profile->WriteBool("Axis/X",xyzDemoConfig->enableX);
profile->WriteBool("Axis/Y",xyzDemoConfig->enableY);
profile->WriteBool("Axis/Z",xyzDemoConfig->enableZ);

profile->Save();
}
}
#endif

//---------------------------------------------------------------------
//
// piUpdate() - Plugin extension of Update()
//
// XML file can NOT be accessed
//
// called ONLY if plugin is enabled
//
// WARNING - when you enable a plugin it immediately is added
// to the update loop. if you haven't initialized some items
// because PostInitControl() hasn't been called you can get
// some problems!!!
//
//---------------------------------------------------------------------

#ifdef PI_UPDATE
#ifdef _MANAGED
#pragma PI_MIX_UPDATE
#endif
void piUpdate()
{
if (MG::xyzDemoDialog)
{
XYZDemoDialog^ xyzDemoDialog = MG::xyzDemoDialog;

xyzDemoDialog->textBoxX->Text = GetDRO(800).ToString("F4");
xyzDemoDialog->textBoxY->Text = GetDRO(801).ToString("F4");
xyzDemoDialog->textBoxZ->Text = GetDRO(802).ToString("F4");
}
}
#endif

//---------------------------------------------------------------------
//
// piNotify() - Plugin extension of Notify()
//
// among other notices this is where we are notified when the
// user clicks on our 'PlugIn Control' menu item.
//
// XML file CAN be accessed on a menu item notify
//
//---------------------------------------------------------------------

#ifdef PI_NOTIFY
#ifdef _MANAGED
#pragma PI_MIX_NOTIFY
#endif
void piNotify(int id)
{
if (id == menuStart)
{
PlugInControlDialog^ pluginControlDialog = gcnew PlugInControlDialog();
XYZDemoConfig^ xyzDemoConfig = MG::xyzDemoConfig;

xyzDemoConfig->enableDlg = MG::xyzDemoDialog->Visible;

pluginControlDialog->checkBoxDlg->Checked = xyzDemoConfig->enableDlg;
pluginControlDialog->checkBoxX->Checked   = xyzDemoConfig->enableX;
pluginControlDialog->checkBoxY->Checked   = xyzDemoConfig->enableY;
pluginControlDialog->checkBoxZ->Checked   = xyzDemoConfig->enableZ;

if (pluginControlDialog->ShowDialog() == DialogResult::OK)
{
xyzDemoConfig->enableDlg = pluginControlDialog->checkBoxDlg->Checked;
xyzDemoConfig->enableX   = pluginControlDialog->checkBoxX->Checked;
xyzDemoConfig->enableY   = pluginControlDialog->checkBoxY->Checked;
xyzDemoConfig->enableZ   = pluginControlDialog->checkBoxZ->Checked;

XYZDemoDialog^ xyzDemoDialog = MG::xyzDemoDialog;

xyzDemoDialog->labelX->Visible = xyzDemoConfig->enableX;
xyzDemoDialog->labelY->Visible = xyzDemoConfig->enableY;
xyzDemoDialog->labelZ->Visible = xyzDemoConfig->enableZ;

xyzDemoDialog->textBoxX->Visible = xyzDemoConfig->enableX;
xyzDemoDialog->textBoxY->Visible = xyzDemoConfig->enableY;
xyzDemoDialog->textBoxZ->Visible = xyzDemoConfig->enableZ;

xyzDemoDialog->Visible = xyzDemoConfig->enableDlg;
}
}
}
#endif

//---------------------------------------------------------------------
//
// piDoDwell() - Plugin extension of DoDwell()
//
//---------------------------------------------------------------------

#ifdef PI_DODWELL
#ifdef _MANAGED
#pragma PI_MIX_DODWELL
#endif
void piDoDwell(double time)
{
}
#endif

//---------------------------------------------------------------------
//
// piReset() - Plugin extension of Reset()
//
//---------------------------------------------------------------------

#ifdef PI_RESET
#ifdef _MANAGED
#pragma PI_MIX_RESET
#endif
void piReset()
{
}
#endif

//---------------------------------------------------------------------
//
// piJogOn() - Plugin extension of JogOn()
//
//---------------------------------------------------------------------

#ifdef PI_JOGON
#ifdef _MANAGED
#pragma PI_MIX_JOGON
#endif
void piJogOn(short axis, short dir, double speed)
{
}
#endif

//---------------------------------------------------------------------
//
// piJogOff() - Plugin extension of JogOff()
//
//---------------------------------------------------------------------

#ifdef PI_JOGOFF
#ifdef _MANAGED
#pragma PI_MIX_JOGOFF
#endif
void piJogOff(short axis)
{
}
#endif

//---------------------------------------------------------------------
//
// piPurge() - Plugin extension of Purge()
//
//---------------------------------------------------------------------

#ifdef PI_PURGE
#ifdef _MANAGED
#pragma PI_MIX_PURGE
#endif
void piPurge(short flags)
{
}
#endif

//---------------------------------------------------------------------
//
// piProbe() - Plugin extension of Probe()
//
//---------------------------------------------------------------------

#ifdef PI_PROBE
#ifdef _MANAGED
#pragma PI_MIX_PROBE
#endif
void piProbe()
{
}
#endif

//---------------------------------------------------------------------
//
// piHome() - Plugin extension of Home()
//
//---------------------------------------------------------------------

#ifdef PI_HOME
#ifdef _MANAGED
#pragma PI_MIX_HOME
#endif
void piHome(short axis)
{
}
#endif

JP
« Last Edit: July 21, 2010, 09:31:19 AM by freedom2000 »
Re: MachPluginWizard v1.1 BETA Release
« Reply #23 on: July 27, 2010, 12:55:49 PM »
Ed!

Excellent work.  Thanks for contributing to the community!

I thought I would provide a note that the wizard fails under Windows7/Visual Studio 2010.

The first problem was that the wizard was not installed in the proper place, so I manually copied it.  Then when running it from VS2010, I simply get the error message that the wizard failed to create the project.

Are you still developing the plugin?  If so, I would be happy to help work thru and test VS2010 support.  If not, any chance you wish to contribute the source to the cause?

Thanks!
Carl


Carl

Re: MachPluginWizard v1.1 BETA Release
« Reply #24 on: August 02, 2010, 08:22:09 AM »


To start with pulgins I wanted to reference this dll into your code and call it.

I have added a reference to it into Visual Studio
I have modified the code to refrence the namesapce : using namespace HIDClass;
and just added a dll call to check the usb attachement : MCHPHIDClass::USBHIDClassInit (0x4D8, 0x003F, 64);

Well just two lines of modifications... The compilation and link are OK

but when running on the second line (the call to the dll) I have a fatal error :

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.
Additional information: Impossible de charger le fichier ou l'assembly 'HID class, Version=1.0.3376.23070, Culture=neutral, PublicKeyToken=null' ou une de ses dépendances. Le fichier spécifié est introuvable.

Which in english means that the dll is not found...

JP


Hi all,

I have found by myself. It was quite easy just had to put the dll into the Mach3 folder close to Mach3.exe ...

Now the dll is called !

And thanks again to Ed for his wizard
JP
Re: MachPluginWizard v1.1 BETA Release
« Reply #25 on: October 08, 2010, 04:41:09 PM »
Ed - THANKS!

Our Motion plugin is C++ MFC based.  We just substituted your include files and did one cast of LastError as a pointer to CString, and the Plugin now seems fine under VS2008.

Thanks a million.

TK
Re: MachPluginWizard v1.1 BETA Release
« Reply #26 on: July 30, 2011, 12:16:35 PM »

1.  Is there a way to set the Mach error label like  MachErrorMsg("*********x") or SetMachError("*********x")? From the Shuttle Plugin:

   void SetMachError(Cstring Message){
      CString *err = &MainPlanner->LastError;
      if(err != NULL )
      *err = Message;"}

In Ed's -TrajectoryControl structure LastError is a LPCSTR pointer. In C++/CLI I came up with:

   void SetMachError(LPCSTR Message){   
      LPCSTR err =   (LPCSTR)&MainPlanner->LastError;
      if(err != nullptr )
      err = Message;// Compiles NO OUTPUT
}
   
Has anybody figured this out?


Kurt, I solved the same problem with the following piece of code:

void SetMachError(char* msg){
   void *temp = &MainPlanner->LastError;
   if( temp != NULL) *(CString*)temp = msg;  //need #include <atlstr.h>    
}

One more tip: put the include atlstr.h before setting default namespaces in order to prevent name ambiguities.

I hope it helps.




I just thought I'd let everyone know that this code also solved my problem with the Mach Status field.

void SetMachError(char* msg){
   void *temp = &MainPlanner->LastError;
   if( temp != NULL) *(CString*)temp = msg;  //need #include <atlstr.h>    
}

but in order to get it to work, there are two caveats, first, atlstr.h is not included in the express version of visual studio, so I had to compile it on my Visual Studio Pro.  I used Studio 2010 pro to get it working.  Second, since I used the plugin wizard to generate my beginning project, I am using mixed mode code, and this includes the .net framework, so in order to load the atlstr.h header, you will have to load it before your first "using namespace" statement.  For me this was in my stdafx.h  and if you don't load it before your first "using namespace" statement, the errors you will get during compile are that there are several ambiguous statements related to thing in the CLR since .net and atl define a bunch of stuff with the same names.

I hope this helps anyone who, like me, spent hours doing just this one simple little thing.
« Last Edit: July 30, 2011, 12:19:27 PM by newmacher »
Re: MachPluginWizard v1.1 BETA Release
« Reply #27 on: November 08, 2011, 11:10:50 AM »
OK Family & Friends More Tutorials!!


These are preliminary first pass tutorials.

There are still several more sections to be recorded and I will complete them ASAP and let you know.
-Ed

I guess there aren't anymore coming? or is it because of lack of interest?
I too am working on a USB plug-in to custom spindle with  UART.

Nosmo.
« Last Edit: November 08, 2011, 11:23:59 AM by NosmoKing »
load gcode from plugin
« Reply #28 on: August 15, 2013, 07:44:54 AM »
Hi,
I'm trying to load a gcode file from the plugin (i.e.  LoadGCode(filename); )

is the LoadNoRun(LPCTSTR name); method for load gcode file ?
if yes, CMach4View class doesn't have LoadNoRun
if no; How can I do that?

thanks
Re: MachPluginWizard v1.1 BETA Release
« Reply #29 on: March 15, 2017, 02:21:08 AM »
Hi all,

It seems that the tutorial video links by j1sys are removed. Could someone kindly re-upload the tutorial files again? e.g. Dropbox, Drive, would be nice!

Here are the following videos that are no longer available:

www.j1sys.com/MPW_XYZTutor_1.swf     (17Meg, 19min)  Overview
www.j1sys.com/MPW_XYZTutor_2.swf     (13Meg, 29min)  MachDevice.h/MachDevice.cpp
www.j1sys.com/MPW_XYZTutor_3a.swf   (5Meg, 13min)    Plugin.h
www.j1sys.com/MPW_XYZTutor_3b.swf   (11Meg, 27min)  Plugin.cpp

Thanks!