<< Click to Display Table of Contents >> Navigation: NmxDLL Referenz > HowTo > Sampling > Reading sampled data > Read Row-Wise |
Reading row-wise is quite simple. The function NMX_Sampling_ReadRow32_1 is called for each sample and provides the data for all sampling elements. The following example shows this visually.
According to this example, NMX_Sampling_ReadRow32_1 must be called 9 times. The function/return parameters are as follows:
Function call |
ulMaxSamples |
pulSamplesCopied |
pudSampleNo |
1 |
≥ 6 |
6 |
0 |
2 |
≥ 6 |
6 |
1 |
3 |
≥ 6 |
6 |
2 |
4 |
≥ 6 |
6 |
3 |
5 |
≥ 6 |
6 |
4 |
6 |
≥ 6 |
6 |
5 |
7 |
≥ 6 |
6 |
6 |
8 |
≥ 6 |
6 |
7 |
9 |
≥ 6 |
6 |
8 |
C / C++
// ###-> Get Number of Sampling elements. This could be done one-time after starting sampling, since this value does not change.
unsigned long ulNSamplingElements = 0; // --> Columns
if (NMX_Sampling_GetStatus_1(pHandleNmx, NULL, &ulNSamplingElements, NULL, NULL) != NST_SUCCESS) {
// Error reading sampling status. Do some error handling.
return;
}
// ###-> Read newest data. This code could for example be done after the notification NMXNOTIFY_SAMPLING_NEW_DATA.
signed long *aslSamples = new signed long[ulNSamplingElements];
unsigned long ulSamplesCopied = 0;
unsigned long long udSampleNo = 0;
NMX_STATUS tResult = NST_SUCCESS;
do {
tResult = NMX_Sampling_ReadRow32_1(pHandleNmx, aslSamples, ulNSamplingElements, &ulSamplesCopied, &udSampleNo);
if (tResult == NST_SUCCESS) {
// New row has been read-out. Use the data, e.g. copy it to your own array or ring-buffer.
}
else if (tResult == NST_SAMPLING_NO_DATA_AVAILABLE) {
// No more data available. Wait until new data has arrived.
break;
}
else {
// An error occurred. Do some error handling.
break;
}
} while (1);
Delphi
var
ucStatus: byte;
udSamplesReceived: uint64;
udSamplesMax: uint64;
ulNElements: cardinal;
aslSamples: packed array of integer;
ulSamplesCopied: cardinal;
udSampleNo: uint64;
tResult: NMX_STATUS;
begin
ucStatus := 0;
udSamplesReceived := 0;
udSamplesMax := 0;
ulNElements := 0;
// ###-> Get Number of Sampling elements. This could be done one-time after starting sampling, since this value does not change.
if cNmx.Sampling_GetStatus_1(pHandleNmx, ucStatus, ulNElements, udSamplesReceived, udSamplesMax) <> NST_SUCCESS then begin
// Error reading sampling number of sampling elements. Do some error handling.
exit;
end;
// ###-> Read newest data. This code could for example be done after the notification NMXNOTIFY_SAMPLING_NEW_DATA.
SetLength(aslSamples, ulNElements);
while (true) do begin
tResult := cNmx.Sampling_ReadRow32_1(pHandleNmx, aslSamples, Length(aslSamples), ulSamplesCopied, udNoFirstSample);
if tResult = NST_SUCCESS then begin
// New row has been read-out. Use the data, e.g. copy it to your own array or ring-buffer.
end
else if tResult = NST_SAMPLING_NO_DATA_AVAILABLE then begin
// No more data available. Wait until new data has arrived.
break;
end
else begin
// Error reading sampled data. Do some error handling.
break;
end;
end;
end;
C# / .Net
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 */
Int32[] aslValues = new Int32[ulNElements];
while (true)
{
for (Int32 I = 0; I < aslValues.Length; I++) aslValues[I] = Int32.MaxValue;
/* Read samples from DLL into local array */
UInt32 ulSamplesCopied = 0;
NMX_MSTATUS tStatus = cNmx.Sampling_ReadRow32_1(pDevice, aslValues, ref ulSamplesCopied, ref udNoFirstSample);
if (tStatus == NMX_MSTATUS.SUCCESS)
{
// New row has been read-out. Use the data, e.g. copy it to your own array or ring-buffer.
}
else if (tStatus == NMX_MSTATUS.SAMPLING_NO_DATA_AVAILABLE)
{
// No more data available. Wait until new data has arrived.
break;
}
else
{
// An error occurred. Do some error handling.
break;
}
}