Read Column-Wise

<< Click to Display Table of Contents >>

Navigation:  NmxDLL Reference Guide > HowTo > Sampling > Reading sampled data >

Read Column-Wise

Single block

For time-limited sampling, the easiest way is reading all data together after the measurement is finished. In this case, the function NMX_Sampling_ReadColumn32_1 must be called one-time per sampling element. The following example shows this visually:

Sampling_ReadColumn_Single

According to this example, NMX_Sampling_ReadColumn32_1 must be called 6 times. The function/return parameters are as follows:

Function call

ulMaxSamples

ulElementNo

pulSamplesCopied

pudNoFirstSample

1

≥ 22

0

22

0

2

≥ 22

1

22

0

3

≥ 22

2

22

0

4

≥ 22

3

22

0

5

≥ 22

4

22

0

6

≥ 22

5

22

0

The parameter ulDoNotDelete normally is 0. If you need to read all samples again, set it to 1.

 

Multiple blocks

Another possibility is reading data in small blocks.
For endless sampling, this is essential.
For time-limited sampling this can be useful, since it allows analysing/displaying data, while sampling is active.

The following example shows visually, how the data from the example above is read in 3 blocks:

Sampling_ReadColumn_Blocks

According to this example, NMX_Sampling_ReadColumn32_1 must be called 18 times. The function/return parameters are as follows:

Function call

ulMaxSamples

ulElementNo

pulSamplesCopied

pudNoFirstSample

1

5

0

5

0

2

5

1

5

0

3

5

2

5

0

4

5

3

5

0

5

5

4

5

0

6

5

5

5

0

7

9

0

9

5

8

9

1

9

5

9

9

2

9

5

10

9

3

9

5

11

9

4

9

5

12

9

5

9

5

13

≥ 8

0

8

14

14

≥ 8

1

8

14

15

≥ 8

2

8

14

16

≥ 8

3

8

14

17

≥ 8

4

8

14

18

≥ 8

5

8

14

The parameter ulDoNotDelete must be 0.

 

C / C++


// ###-> Get Number of Rows and Columns.

unsigned long long udSamplesReceived = 0; // --> Rows

unsigned long ulNSamplingElements = 0;     // --> Columns

if (NMX_Sampling_GetStatus_1(pHandleNmx, NULL, &ulNSamplingElements, &udSamplesReceived, NULL) != NST_SUCCESS) {

 // Error reading sampling status. Do some error handling.

 return;

}

 

// ###-> Create table/array for sampled data

signed long **aaslSamples = new signed long*[ulNSamplingElements];

unsigned long ulSamplesCopied = 0;

 

for (unsigned long ulColumn = 0; ulColumn < ulNSamplingElements; ulColumn++)

{

 // Create array for this column

 aaslSamples[ulColumn] = new signed long[(unsigned long)udSamplesReceived];

 for (unsigned long ulRow = 0; ulRow < udSamplesReceived; ulRow++) {

         aaslSamples[ulColumn][ulRow] = -2147483647;

 }

 

 // ###-> Read sampled data column-wise

 if (NMX_Sampling_ReadColumn32_1(pHandle, aaslSamples[ulColumn], (unsigned long)udSamplesReceived, ulColumn, 0, &ulSamplesCopied, NULL) != NST_SUCCESS) {

         // Error reading sampled data. Do some error handling.

         return;

 }

}

 

// ###-> Now the data can be processed.

//       First array dimension is columns / sampling elements

//       Second array dimension is rows / samples

 

 

// ###-> Don't forget to delete the array.

delete aaslSamples;

 

Delphi


var

  ucStatus: byte;

  udSamplesReceived: uint64;

  udSamplesMax: uint64;

  ulNElements: cardinal;

  aaslSamples: packed array of array of integer;

  ulColumn: cardinal;

  ulSamplesCopied: cardinal;

  udNoFirstSample: uint64;

begin

  ucStatus := 0;

  udSamplesReceived := 0;

  udSamplesMax := 0;

  ulNElements := 0;

 

  // ###-> Get Number of Rows and Columns.

  if cNmx.Sampling_GetStatus_1(pHandleNmx, ucStatus, ulNElements, udSamplesReceived, udSamplesMax) <> NST_SUCCESS then begin

 // Error reading sampling status. Do some error handling.

 exit;

  end;

 

  // ###-> Create table/array for sampled data

  SetLength(aaslSamples, ulNElements);

  for ulColumn := 0 to ulNElements-1 do begin

    SetLength(aaslSamples[ulColumn], udSamplesReceived);

 

    if cNmx.Sampling_ReadColumn32_1(pHandleNmx,

                                    @aaslSamples[ulColumn][0],

                                    Length(aaslSamples[0]),

                                    ulColumn,

                                    1,

                                    ulSamplesCopied,

                                    udNoFirstSample) <> NST_SUCCESS then begin

      // Error reading sampled data. Do some error handling.

    end;

  end;

 

  // ###-> Now the data can be processed.

  //       First array dimension is columns / sampling elements

  //       Second array dimension is rows / samples

end;

 

C# / .Net


public struct TSampleColumn

{

  public Int32[] aslRows;

}

 

Byte ucStatus = 0;

UInt32 ulNElements = 0;

UInt64 udSamplesReceived = 0;

UInt64 udMaxSamples = 0;

UInt32 ulSamplesCopied = 0;

 

/* Get number of samples, which are available. */

cNmx.Sampling_GetStatus_1(pDevice, ref ucStatus, ref ulNElements, ref udSamplesReceived, ref udMaxSamples);

 

/* Create arrays for sampling data and read it from DLL */

TSampleColumn[] aaslSData = new TSampleColumn[ulNElements];

for (UInt32 ulColumn = 0; ulColumn < ulNElements; ulColumn++)

{

   aaslSData[ulColumn].aslRows = new Int32[udSamplesReceived];

  for (Int32 I = 0; I < aaslSData[ulColumn].aslRows.Length; I++) {

       aaslSData[ulColumn].aslRows[I] = Int32.MaxValue;

   }

 

 

  /* Feel free to do some more error handling here, e.g. check ulSamplesCopied and checking the function return code. */

   cNmx.Sampling_ReadColumn32_1(pDevice,

                                aaslSData[ulColumn].aslRows,

                                0,

                                (UInt32)aaslSData[ulColumn].aslRows.Length,

                                ulColumn,

                                1,

                                ref ulSamplesCopied,

                                ref udMaxSamples);

}