Pixelman - For Developers

Principles

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:

Implementation

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 .

Plugin initialization and identification

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?

Function registration

Plugin can register some functions to MpxManager. Registered functions are acessible for other plugins. There are two types of functions:

Call-back function registration

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.

Error Handling

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);