Hello Guest it is March 28, 2024, 08:19:15 PM

Author Topic: Notify plugin or have plugin detect when OEM Button is pushed  (Read 8746 times)

0 Members and 1 Guest are viewing this topic.

Notify plugin or have plugin detect when OEM Button is pushed
« on: December 06, 2011, 07:39:23 PM »
Is it possible to have Mach notify a plugin, or have a plugin detect, when an OEM Button is pushed?

I've been pouring over the Wiki and documents for a couple weeks now and either its not mentioned, or my brain is sufficiently fried so I can't remember anything : )
Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #1 on: December 06, 2011, 08:34:40 PM »
Hi,

I would like to know the same.
It would be nice to have a handler for OEM-Buttons, that are unknown to Mach3, but I didn't find anything yet. The advantage over the actual method is, that there is no vba involved.

A working way to call Plugins from Mach3-Buttons is to have a Button with a vba-script, that calls a function in the DLL:

Code: [Select]
Declare Sub CallDLLFunc Lib "MyPlugin" (ByVal Parameter1 As Double)

Call CallDLLFunc (1.234)

and then the plugin has to have the function exported:

Code: [Select]
EXTERN_C DLLEXPORT void CallDLLFunc(double whatever)
{
  // Do something
}

Steffen

Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #2 on: December 06, 2011, 09:07:36 PM »
Hi Steffen,

I've considered doing it that way too, but it takes a lot more work and then the user can edit the button script and mess it up.

Since posting my cry for help I found Jemmyell's tutorial post (http://www.machsupport.com/forum/index.php/topic,4884.0.html) and on Page 67 he talks about an Object Model Support.  Now I'm programming in C++ .NET and don't want to use MFC because lots of my code is managed, but that did tip me off to something.  In my VC++ project I added a reference to the Mach3.exe file and lo-and-behold a managed class called Mach4 showed up.  Unfortunately I haven't quite yet figured out how to use it, but it does reveal 100+ events that I should be able to listen to, including a DoOEMButtonEventHandler.  Right now I'm in the thick of it, and a couple of the questions running through my mind right are how I get a pointer to the running Mach instance instead of just instantiating the Mach4 class (you'd think there'd be a static reference in the class interface), and how I reference Mach3.exe so it doesn't crash with a File Not Found exception at run time (which I am seeing).

Thanks guys.
Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #3 on: December 06, 2011, 09:10:25 PM »
I'm having this exact problem with the FNF exception... http://www.machsupport.com/forum/index.php/topic,16664.0.html

Scoppio, did you ever get it to work?
Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #4 on: December 06, 2011, 09:14:20 PM »
Turns out there is a lot of information out there if you do forum search for "Mach4"
Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #5 on: December 07, 2011, 01:11:48 AM »
Ok, I've found everything I need to get a hold on Mach from an external program or a plugin via the COM automation interface (http://www.machsupport.com/forum/index.php/topic,11589.0.html).

The one thing that I haven't been able to figure out is how to use all of the great exposed events in C#.  I get a weird exception thrown when I try to do this:
Mach.DoOEMButton += new Mach4.IMyScriptObject_DoOEMButtonEventHandler(Mach_DoOEMButton);
               
The exception says:
Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B196B284-BAB4-101A-B69C-00AA00341D07}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I haven't seen anything on the forums regarding the use of events, but to me the use of events makes total sense or you have to poll dozens of states to keep the external program in sync.

Thanks all
Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #6 on: December 07, 2011, 07:34:59 PM »
In case anyone is interested, or knowledgeable, in these things I thought I'd report back my findings.  I still can't find a way to receive event notifications from Mach, but here's what I know:

I can import the typelib from Mach3.exe, or I can use tlbexp.exe to generate a Mach DLL that works with .NET/C#/CLR.  This library is called "Mach4" and contains a Mach4 interface and a MyScriptObject interface. Mach4 has some methods for controlling Mach's startup and shutdown, and MyScriptObject contains many methods for controlling Mach, examples of which are on this forum.  Along with those, a few other interfaces appear, too, which are fairly well explained by this .NET/COM book: http://www.informit.com/articles/article.aspx?p=25922&seqNum=5 .  Looking at the DLL in the Object Browser of Visual Studio 2008 shows all of these things, and reveals many (100+?) events that Mach supposedly can fire.  After using the previous link and 50 other sites to figure out why I couldn't just add my event handler to the events I have pretty much given up.  I've used every workaround suggested on the internet but it all comes down to the fact that I can't get an IConnectionPointContainer from Mach.  It is frustrating because in the ILDASM.EXE utility I can see a private class in the library (IMyScriptObject_EventProvider which exists just as explained in the link above) that has the IConnectionPointContainer and IConnectionPoint variables, but I can't get to them.  Ultimately I guess that Visual Studio already knew this based on the error message I pasted into my previous post.  I should also mention that I've tried using the Mach.Remote example which is written in MFC C++ and also grabs a hold of Mach3.exe.  The MFC Class Wizard finds the basic classes, but it doesn't see any events.  Internet searching suggests that MFC can't handle events like that and ATL should be used.  I've also seen suggested that mixed-mode C++ can handle it while providing nice CLR/.NET access once you get it all wrapped up.

My old school C++ experience isn't sufficient enough to tell me that I really am out of luck or if I'm just doing it wrong.  Any input or suggestion is more than welcome.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Notify plugin or have plugin detect when OEM Button is pushed
« Reply #7 on: January 18, 2012, 07:09:57 PM »
Hey here is a MUCH, MUCH simpler solution for what your trying to do!!

in Screen designer, put this VB code:  "NotifyPlugins( x)"   where x is some integer, (by the way, I suggest higher range than 10,000).
then in the plugin, in the MyNotify section, capture that ID number that you sent via the screen button.
then do what ever that number represents in your C++ code.

at this link: http://www.machsupport.com/forum/index.php/topic,11543.0.html

This is a "Message Capture" plugin I did, that will display your Notify messages, so you can see what your passing for debugging your plug.

It is doubtfull you have to worry about the "average" user having "screen designer", and then going into your buttons to mess up your code in that button.

the code there would not mean anything to a user any way, i.e. if they saw:  NotifyPlugins(15678)

I doubt SERIOUSLY that it would mean much to them.......

BTW: there IS a major bug that have remained unresolved in the Mach3 COM stuff......... you have been warned......

scott
fun times