Sampling notifications

<< Click to Display Table of Contents >>

Navigation:  NmxDLL Reference Guide > HowTo > Sampling > Get sampling status >

Sampling notifications

Notifications are very useful to get informed about any changes of the sampling. For a complete list of all available notifications, please consult the chapter "Notifications".

To receive the notifications, these must be registered. Depending on the selected notification type (messages or callbacks), a message handler or a callback function must be implemented.

In the following sample code, message based notifications are used.

 

C / C++


// Define Message. In VisualStudio, WM_USER is defined in WinUser.h as:

// #define WM_USER 0x0400

#define WM_MESSAGE_SAMPLING_NEWDATA                        (WM_USER + NMXNOTIFY_SAMPLING_NEW_DATA)                        // Message for "new sampling data" received

#define WM_MESSAGE_SAMPLING_ALLRECEIVED                (WM_USER + NMXNOTIFY_SAMPLING_ALL_DATA_RECEIVED)        // Message for "all sampling data has been received"

#define WM_MESSAGE_SAMPLING_FINISHED                (WM_USER + NMXNOTIFY_SAMPLING_FINISHED)                        // Message for "sampling is finished"

#define WM_MESSAGE_SAMPLING_ERROR                        (WM_USER + NMXNOTIFY_SAMPLING_ERROR)                        // Message for "sampling error"

#define WM_MESSAGE_SAMPLING_BUFFER_OVERFLOW        (WM_USER + NMXNOTIFY_SAMPLING_BUFFER_OVERFLOW)                // Message for "sampling buffer overflow in DLL"

#define WM_MESSAGE_SAMPLING_TIMEOUT                        (WM_USER + NMXNOTIFY_SAMPLING_TIMEOUT)                        // Message for "sampling: timeout receiving data"

 

 

// ###-> Register notifications, e.g. directly after connecting.

if (NMX_RegisterMessage_1(pHandleNmx, NMXNOTIFY_SAMPLING_NEW_DATA, static_cast<HWND>(Handle.ToPointer()), WM_MESSAGE_SAMPLING_NEWDATA, 0, 0) != NST_SUCCESS) {

 // Handle error

}

if (NMX_RegisterMessage_1(pHandleNmx, NMXNOTIFY_SAMPLING_ALL_DATA_RECEIVED, static_cast<HWND>(Handle.ToPointer()), WM_MESSAGE_SAMPLING_ALLRECEIVED, 0, 0) != NST_SUCCESS) {

 // Handle error

}

if (NMX_RegisterMessage_1(pHandleNmx, NMXNOTIFY_SAMPLING_FINISHED, static_cast<HWND>(Handle.ToPointer()), WM_MESSAGE_SAMPLING_FINISHED, 0, 0) != NST_SUCCESS) {

 // Handle error

}

if (NMX_RegisterMessage_1(pHandleNmx, NMXNOTIFY_SAMPLING_ERROR, static_cast<HWND>(Handle.ToPointer()), WM_MESSAGE_SAMPLING_ERROR, 0, 0) != NST_SUCCESS) {

 // Handle error

}

if (NMX_RegisterMessage_1(pHandleNmx, NMXNOTIFY_SAMPLING_BUFFER_OVERFLOW, static_cast<HWND>(Handle.ToPointer()), WM_MESSAGE_SAMPLING_BUFFER_OVERFLOW, 0, 0) != NST_SUCCESS) {

 // Handle error

}

if (NMX_RegisterMessage_1(pHandleNmx, NMXNOTIFY_SAMPLING_TIMEOUT, static_cast<HWND>(Handle.ToPointer()), WM_MESSAGE_SAMPLING_TIMEOUT, 0, 0) != NST_SUCCESS) {

 // Handle error

}

 

// ###-> Implement message handler

// Please note: Keep the code in the message handler as short as possible.

// Do not update the GUI from within the message handlers.

protected:        virtual void WndProc(Message% m) override

{

 /* Listen for operating system messages. */

 switch (m.Msg)

 {

         case WM_MESSAGE_SAMPLING_NEWDATA:

                 break;

 

         case WM_MESSAGE_SAMPLING_ALLRECEIVED:

                 break;

 

         case WM_MESSAGE_SAMPLING_FINISHED:

                 break;

 

         case WM_MESSAGE_SAMPLING_ERROR:

                 break;

 

         case WM_MESSAGE_SAMPLING_BUFFER_OVERFLOW:

                 break;

 

         case WM_MESSAGE_SAMPLING_TIMEOUT:

                 break;

 default:

         /* Pass all standard messages to the GUI form. */

         Form::WndProc(m);

         break;

 }

}

 

 

Delphi


// Define Message for "new static data available"

const WM_MESSAGE_NMX_SAMPLING_NEW_DATA      = WM_USER + NMXNOTIFY_SAMPLING_NEW_DATA;

  WM_MESSAGE_NMX_SAMPLING_FINISHED          = WM_USER + NMXNOTIFY_SAMPLING_FINISHED;

  WM_MESSAGE_NMX_SAMPLING_ALL_DATA_RECEIVED = WM_USER + NMXNOTIFY_SAMPLING_ALL_DATA_RECEIVED;

  WM_MESSAGE_NMX_SAMPLING_ERROR             = WM_USER + NMXNOTIFY_SAMPLING_ERROR;

  WM_MESSAGE_NMX_SAMPLING_BUFFER_OVERFLOW   = WM_USER + NMXNOTIFY_SAMPLING_BUFFER_OVERFLOW;

  WM_MESSAGE_NMX_SAMPLING_TIMEOUT           = WM_USER + NMXNOTIFY_SAMPLING_TIMEOUT;

 

// Declaration of message handler. Integrate it into the class declarations.

procedure OnMessageSamplingNewData(var Msg: TMessage); message WM_MESSAGE_NMX_SAMPLING_NEW_DATA;

procedure OnMessageSamplingFinished(var Msg: TMessage); message WM_MESSAGE_NMX_SAMPLING_FINISHED;

procedure OnMessageSamplingAllDataReceived(var Msg: TMessage); message WM_MESSAGE_NMX_SAMPLING_ALL_DATA_RECEIVED;

procedure OnMessageSamplingError(var Msg: TMessage); message WM_MESSAGE_NMX_SAMPLING_ERROR;

procedure OnMessageSamplingBufferOverflow(var Msg: TMessage); message WM_MESSAGE_NMX_SAMPLING_BUFFER_OVERFLOW;

procedure OnMessageSamplingTimeout(var Msg: TMessage); message WM_MESSAGE_NMX_SAMPLING_TIMEOUT;

 

// ###-> Register notification, e.g. directly after connecting.

if NMX_RegisterMessage_1(pNmxHandle, NMXNOTIFY_SAMPLING_NEW_DATA, MainForm.Handle, WM_MESSAGE_NMX_SAMPLING_NEW_DATA, 0, 0) <> NST_SUCCESS then begin

  // Registering notification failed. Do some error handling

end;

if NMX_RegisterMessage_1(pNmxHandle, NMXNOTIFY_SAMPLING_FINISHED, MainForm.Handle, WM_MESSAGE_NMX_SAMPLING_FINISHED, 0, 0) <> NST_SUCCESS then begin

  // Registering notification failed. Do some error handling

end;

if NMX_RegisterMessage_1(pNmxHandle, NMXNOTIFY_SAMPLING_ALL_DATA_RECEIVED, MainForm.Handle, WM_MESSAGE_NMX_SAMPLING_ALL_DATA_RECEIVED, 0, 0) <> NST_SUCCESS then begin

  // Registering notification failed. Do some error handling

end;

if NMX_RegisterMessage_1(pNmxHandle, NMXNOTIFY_SAMPLING_ERROR, MainForm.Handle, WM_MESSAGE_NMX_SAMPLING_ERROR, 0, 0) <> NST_SUCCESS then begin

  // Registering notification failed. Do some error handling

end;

if NMX_RegisterMessage_1(pNmxHandle, NMXNOTIFY_SAMPLING_BUFFER_OVERFLOW, MainForm.Handle, WM_MESSAGE_NMX_SAMPLING_BUFFER_OVERFLOW, 0, 0) <> NST_SUCCESS then begin

  // Registering notification failed. Do some error handling

end;

if NMX_RegisterMessage_1(pNmxHandle, NMXNOTIFY_SAMPLING_TIMEOUT, MainForm.Handle, WM_MESSAGE_NMX_SAMPLING_TIMEOUT, 0, 0) <> NST_SUCCESS then begin

  // Registering notification failed. Do some error handling

end;

 

// ###-> Implement message handlers

// Please note: Keep the code in the message handlers as short as possible.

// Do not update the GUI from within the message handlers.

 

C# / .Net


// Define Messages. In VisualStudio, WM_USER is 0x0400

const int WM_USER = 0x400;

const int WM_MESSAGE_SAMPLING_NEW_DATA = WM_USER + 0x20;

const int WM_MESSAGE_SAMPLING_FINISHED = WM_USER + 0x21;

public const int WM_MESSAGE_SAMPLING_ALL_DATA_RECEIVED = WM_USER + 0x22;

public const int WM_MESSAGE_SAMPLING_ERROR = WM_USER + 0x28;

public const int WM_MESSAGE_SAMPLING_BUFFER_OVERFLOW = WM_USER + 0x29;

public const int WM_MESSAGE_SAMPLING_TIMEOUT = WM_USER + 0x2A;

 

 

// ###-> Register notifications, e.g. directly after connecting.

NMX_MSTATUS tStatus = NMX_MSTATUS.UNKNOWN;

tStatus = cNmx.RegisterMessage_1(pDevice, NMX_NOTIFICATION.SAMPLING_NEW_DATA, Handle, WM_MESSAGE_SAMPLING_NEW_DATA, 0, 0);

if (tStatus != NMX_MSTATUS.SUCCESS) { /* Do some error handling */ }

tStatus = cNmx.RegisterMessage_1(pDevice, NMX_NOTIFICATION.SAMPLING_ALL_DATA_RECEIVED, Handle, WM_MESSAGE_SAMPLING_ALL_DATA_RECEIVED, 0, 0);

if (tStatus != NMX_MSTATUS.SUCCESS) { /* Do some error handling */ }

tStatus = cNmx.RegisterMessage_1(pDevice, NMX_NOTIFICATION.SAMPLING_FINISHED, Handle, WM_MESSAGE_SAMPLING_FINISHED, 0, 0);

if (tStatus != NMX_MSTATUS.SUCCESS) { /* Do some error handling */ }

tStatus = cNmx.RegisterMessage_1(pDevice, NMX_NOTIFICATION.SAMPLING_ERROR, Handle, WM_MESSAGE_SAMPLING_ERROR, 0, 0);

if (tStatus != NMX_MSTATUS.SUCCESS) { /* Do some error handling */ }

tStatus = cNmx.RegisterMessage_1(pDevice, NMX_NOTIFICATION.SAMPLING_BUFFER_OVERFLOW, Handle, WM_MESSAGE_SAMPLING_BUFFER_OVERFLOW, 0, 0);

if (tStatus != NMX_MSTATUS.SUCCESS) { /* Do some error handling */ }

tStatus = cNmx.RegisterMessage_1(pDevice, NMX_NOTIFICATION.SAMPLING_TIMEOUT, Handle, WM_MESSAGE_SAMPLING_TIMEOUT, 0, 0);

if (tStatus != NMX_MSTATUS.SUCCESS) { /* Do some error handling */ }

 

 

// ###-> Implement message handler

// Please note: Keep the code in the message handler as short as possible.

// Do not update the GUI from within the message handlers.

protected override void WndProc(ref Message m)

{

  // Listen for operating system messages.

  switch (m.Msg)

   {

      case WM_MESSAGE_SAMPLING_NEW_DATA:

          break;

 

      case WM_MESSAGE_SAMPLING_FINISHED:

          break;

 

      case WM_MESSAGE_SAMPLING_ALL_DATA_RECEIVED:

          break;

 

      case WM_MESSAGE_SAMPLING_ERROR:

          break;

 

      case WM_MESSAGE_SAMPLING_BUFFER_OVERFLOW:

          break;

 

      case WM_MESSAGE_SAMPLING_TIMEOUT:

          break;

 

      default:

          /* Pass all standard messages to the GUI form. */

          base.WndProc(ref m);

          break;

     }

}