Users can register their own plugins to extent pixelman functionality. Plugins can be prepared to perform various tasks: data filtering (flat-field, masking, smoothing, deconvolutioning), control the progress of measurement, control other hardware (stepper motors, voltage supplies, X-ray tube ...) and many others.
From developer point of view plugin can:
Plugins are implemented as 32bit dynamically linked libraries (dll). Plugins are loaded by MpxManager.dll after their registration (runtime) or during startup if they are already registered. List of paths to registered plugins is held in ini file MpxManager.ini Paths to plugin dlls are stored relatively to location of MpxManager.dll. Therefore if all directory structure is moved or accessed via network the MpxManager will be still able to locate registered plugins.
Dlls can be compiled using any development environment and programming language (preferably in C or C++ as header files are prepared for C). In following text we expect usage of Microsoft Visual C++. Definition of interface between plugin and MpxManager is defined in header file MpxPluginMgrAPI.h. This header file should be included to C or C++ files implementing plugin functionality. No special libraries or object files have to be linked with plugin. Example of simple plugin project for Visual C++ performing flat field corretion is available here .
Each plugin has to export at least one function:
extern "C" __declspec(dllexport) DWORD InitMpxPlugin(const FuncTableType * funcTable);
If any dll contains such function it can be used as MpxManager plugin. When plugin dll is loaded, MpxManager searches for this function and calls it for initialization. Plugin should initialize itself in body of the function. If Initialization is successful it should return 0. The only parameter of InitMpxPlugin function is pointer to table of MpxManager functions prepared for usage from plugin (see definition in MpxPluginMgrAPI.h). Two helper macros have been prepared for easier plugin initialization. If programmer choose to use one of them InitMpxPlugin function don't have to be defined.
PLUGIN_INIT
This macro:
When this macro is used any of MpxManager functions can be accessed for the plugin by simple call using global pointer to function table: mgr->mpxfunc(parameters). For example to get measured data one can call function mpxCtrlGetFrame32 this way:
mgr->mpxCtrlGetFrame32(devID, bufferForData, size, frameIndex, NULL);
PLUGIN_INIT_EXTENDED
This macro does everything as PLUGIN_INIT and moreover contains:
Example 1: Simple "Hello world" plugin. This plugin displays "Hello world" message box during initialization.
#include "MpxPluginMgrAPI.h"
PLUGIN_INIT_EXTENDED
{
MessageBox(NULL,"Hello world","Hello world",MB_OK);
return 0;
}
Isn't it simple?
Plugin can register some functions to MpxManager. Registered functions are acessible for other plugins. There are two types of functions:
Example 2: "Hello world" plugin with registered
menuitem function. This function will be called when user clicks to appropriate
menu item.
#include "MpxPluginMgrAPI.h"
void HelloWorldMenuItemFunc(MENUFUNCPAR par){
MessageBox(NULL,"Hello world","Hello world",MB_OK);
}
PLUGIN_INIT_EXTENDED
{
mgr->addMenuItem("Hello world", "Tests", HelloWorldMenuItemFunc, 0, NULL, 0);
return 0;
}
Example 3: "Hello world" plugin with general
registered function.
#include "MpxPluginMgrAPI.h"
// Definition of function to be registered by manager
// Parameters have no meaning - just demonstrational
void HelloWorldFunc(void* in, void* out)
{
// Let's define structure holding layout of inputs:
struct InParamStucture
{
u32 A; // first input parameter
double B[2]; // second
char C; // third
};
// Retype inputs to simplyfy access to each input parameter:
InParamStucture *par= (InParamStucture*)in;
char message[256];
sprintf(message,"Hello World\r(Inputs: %d,%lg,%lg,%c)",A,B[0],B[1],C);
bool ok=MessageBox(NULL,message,"Hello World",MB_OK);
*((double*)out)=ok; // Set output to some value
}
// Description of parameters of HelloWorldFunc function.
ExtFunctionInfo HelloWorldFuncInfo={
HelloWorldFunc, // Pointer to function performing an action
3, // Number of input parameters
1, // Number of output parameters
{ // List of input parameter descriptions
{TYPE_U32,1,"A"}, // = first input parameter is 32 bit unsigned integer
{TYPE_DOUBLE,2,"B"}, // = second input parameter is array of two doubles
{TYPE_BYTE,1,"C"} // = third input parameter is 8 bit byte
},
{ // List of output parameter descriptions
{TYPE_DOUBLE,1,"Out"} // = output is one double value
},
"HelloWorld", // Name of the plugin = name of this plugin
"Hello world", // Name of registered function = can differ to "C" name
"Function will show message box with gretings", // Description of function purpose
0 // flags = flags
};
PLUGIN_INIT_EXTENDED
{
mgr->addFuncItem(&HelloWorldFuncInfo);
return 0;
}
To be notified about events in MpxManager plugin can register callback function for certain type of event using registerCallback function. Registered callback function is called automatically by MpxManager when appropriate event arises.
Plugin can define also own type(s) of event by addCBEvent function. Then plugin can signal moment of such event to MpxManager by setCBEvent function. Other plugins can register their callback functions which will be called by MpxManager when the event is signaled.
For details see header file.
If some error condition appears plugin can use centralized Error Logging system in MpxManager. Errors are logged to text file.
mgr->logErrorStr(Module, "Error in plugin function: Please call mom (tel. %d)", 0, MomTelNum);