Cyclically (Polling)

<< Click to Display Table of Contents >>

Navigation:  NmxDLL Reference Guide > HowTo > Reading static data >

Cyclically (Polling)

Cyclically reading data, also known as polling, is the most simple way. It is done by calling NMX_StaticGet32_1 regularly.

Typically it is called in a time-interval of approximately 30-50 ms.

 

C / C++


// Global definition

#define N_STATIC_CH_DISPLAY                (64)        // Max number of static channels used. Adapt it to your needs.

#define N_DIGIIO_DISPLAY                (128) // Max number of digital inputs used. Adapt it to your needs.

#define N_MAX_BOXES                        (32)        // Max number of boxes supported.

 

 

// ###-> Implement timer and timer-event-handler, Interval e.g. 30ms

private: System::Void tmrStatic_Tick(System::Object^ sender, System::EventArgs^ e) {

 // Disable this timer

 tmrStatic->Enabled = false;

 

 // Update static data, if new data available.

 signed long aslMeasVal[N_STATIC_CH_DISPLAY];

 unsigned char aucHardStat[N_STATIC_CH_DISPLAY];

 unsigned char aucDigiIn[N_DIGIIO_DISPLAY / 8];

 unsigned char aucBoxStatus[N_MAX_BOXES];

 unsigned long ulNUpdates = 0;

 memset(aslMeasVal, 0, sizeof(aslMeasVal));

 memset(aucHardStat, 0, sizeof(aucHardStat));

 memset(aucDigiIn, 0, sizeof(aucDigiIn));

 memset(aucBoxStatus, 0, sizeof(aucBoxStatus));

 if (NMX_StaticGet32_1(pHandleNmx, aslMeasVal, N_STATIC_CH_DISPLAY, aucHardStat, sizeof(aucHardStat), aucDigiIn, sizeof(aucDigiIn), aucBoxStatus, sizeof(aucBoxStatus), &ulNUpdates) == NST_SUCCESS) {

         // New data successfully received. Display, Calculate, Store, ...

 }

 else {

         // Error reading data. Typical error: NST_DX_TIMEOUT_COMMON due to communication breakdown.

 }

 

 // Re-enable this timer

 tmrStatic->Enabled = true;

}

 

 

Delphi


const cMaxTotalChannels = 256;        // Max number of static channels used. Adapt it to your needs.

       cMaxDigiInBytes = 16;                // Max number of digital input bytes used. Adapt it to your needs.

       cMaxBoxes = 32;                        // Max number of boxes supported.

 

// ###-> Implement timer and timer-event-handler, Interval e.g. 30ms

procedure TMainForm.tmrUpdateStaticTimer(Sender: TObject);

var

   aslValues : array [0..(cMaxTotalChannels-1)] of integer;

   aucHardwareStatus : array [0..(cMaxTotalChannels-1)] of Byte;

   aucDigiInBytes : array [0..(cMaxDigiInBytes-1)] of Byte;

   aucBoxStatus : array [0..(cMaxBoxes-1)] of Byte;

   ulUpdateCtr : Cardinal;

   tStatus : NMX_STATUS;

begin

  tmrUpdateStatic := false;

 

  tStatus := NMX_StaticGet32_1(pNmxHandle, @aslValues[0], cMaxTotalChannels,

                                @aucHardwareStatus[0], cMaxTotalChannels,

                                @aucDigiInBytes[0], cMaxDigiInBytes,

                                @aucBoxStatus[0], cMaxBoxes,

                                ulUpdateCtr);

  if (tStatus = NST_SUCCESS) then begin

     // New data successfully received. Display, Calculate, Store, ...

  end

  else begin

     // Error reading data. Typical error: NST_DX_TIMEOUT_COMMON due to communication breakdown.

  end;

 

  tmrUpdateStatic := true;

end;

 

C# / .Net


const int N_STATIC_CH_DISPLAY = 64; // Max number of static channels used. Adapt it to your needs.

const int N_DIGIIO_DISPLAY = 128;   // Max number of digital input bytes used. Adapt it to your needs.

const int N_BOXES_MAX = 32;         // Max number of boxes supported.

 

 

// ###-> Implement timer and timer-event-handler, Interval e.g. 30ms

private void tmrStatic_Tick(object sender, EventArgs e)

{

  /* Disable this timer */

   tmrStatic.Enabled = false;

 

   Int32[] aslMeasVal = new Int32[N_STATIC_CH_DISPLAY];

   Byte[] aucHardStat = new Byte[N_STATIC_CH_DISPLAY];

   Byte[] aucDigiIn = new Byte[N_DIGIIO_DISPLAY / 8];

   Byte[] aucBoxStatus = new Byte[N_BOXES_MAX];

   UInt32 ulNUpdates = 0;

  if (cNmx.StaticGet32_1(pDevice, aslMeasVal, aucHardStat, aucDigiIn, aucBoxStatus, ref ulNUpdates) == NMX_MSTATUS.SUCCESS)

   {

      // New data successfully received. Display, Calculate, Store, ...

   }

   else

   {

      // Error reading data. Typical error: NST_DX_TIMEOUT_COMMON due to communication breakdown.

   }

 

  /* Re-enable this timer */

   tmrStatic.Enabled = true;

}