<< Click to Display Table of Contents >> Navigation: NmxDLL Referenz > HowTo > Sampling > Start endless time-based sampling |
For the following sample code, endless sampling with a system having 32 measurement channels and 64 digital in-/outputs is shown.
64 digital in-/outputs means there are 8 bytes each.
The sample rate shall be 1000 Samples/s.
The DLL-internal buffer shall be large enough to buffer for 5 seconds, which equals 5000 samples.
C / C++: Start with all measurement channels and digital I/Os
unsigned long ulNElements = 0;
// ###-> 1. Reset list of sampling elements
if (NMX_Sampling_Reset_1(pHandle) == NST_SUCCESS) {
// List of sampling elements has been reset successfully.
}
else {
// Failed resetting the list of sampling elements.
// Do some error handling.
return;
}
// ###-> 2/3. Add sampling elements
if ( (NMX_Sampling_AddChannelsAll_1(pHandle, &ulNElements) == NST_SUCCESS) &&
(NMX_Sampling_AddDigiInAll_1(pHandle, &ulNElements) == NST_SUCCESS) &&
(NMX_Sampling_AddDigiOutAll_1(pHandle, &ulNElements) == NST_SUCCESS) ) {
// Successfully added all sampling elements
}
else {
// Failed adding sampling elements
// Do some error handling.
return;
}
// ###-> 4. Prepare sampling with 1000 Samples/s (= 1000µs sample period)
if (NMX_Sampling_PrepareTime_1(pHandle, 1000/*µs*/, 5000/*Buffer-Size*/, 0/*0=NoLimit*/) == NST_SUCCESS) {
// Sampling successfully prepared
}
else {
// Failed preparing sampling
// Do some error handling.
return;
}
// ###-> 5. Start sampling
if (NMX_Sampling_Start_1(pHandle) == NST_SUCCESS) {
// Start successful.
// Reading sampled data should start now/soon to avoid a buffer overflow.
}
else {
// Failed starting sampling
// Do some error handling.
return;
}
C / C++: Start with a selection of measurement channels and digital inputs
unsigned long ulNElements = 0;
// ###-> 1. Reset list of sampling elements
if (NMX_Sampling_Reset_1(pHandle) == NST_SUCCESS) {
// List of sampling elements has been reset successfully.
}
else {
// Failed resetting the list of sampling elements.
// Do some error handling.
return;
}
// ###-> 2/3. Add measurement channels 0, 5 & 17
// Add digital input byte 0
if ( (NMX_Sampling_AddChannel_1(pHandle, 0, &ulNElements) == NST_SUCCESS) &&
(NMX_Sampling_AddChannel_1(pHandle, 5, &ulNElements) == NST_SUCCESS) &&
(NMX_Sampling_AddChannel_1(pHandle, 17, &ulNElements) == NST_SUCCESS) &&
(NMX_Sampling_AddDigiInByte_1(pHandle, 0, &ulNElements) == NST_SUCCESS) ) {
// Successfully added selected sampling elements
}
else {
// Failed adding sampling elements
// Do some error handling.
return;
}
// ###-> 4. Prepare sampling with 1000 Samples/s (= 1000µs sample period)
if (NMX_Sampling_PrepareTime_1(pHandle, 1000/*µs*/, 5000/*Buffer-Size*/, 0/*0=NoLimit*/) == NST_SUCCESS) {
// Sampling successfully prepared
}
else {
// Failed preparing sampling
// Do some error handling.
return;
}
// ###-> 5. Start sampling
if (NMX_Sampling_Start_1(pHandle) == NST_SUCCESS) {
// Start successful.
// Reading sampled data should start now/soon to avoid a buffer overflow.
}
else {
// Failed starting sampling
// Do some error handling.
return;
}
Delphi: Start with all measurement channels and digital I/Os
// ###-> 1. Reset list of sampling elements
if cNmx.Sampling_Reset_1(pHandleNmx) = NST_SUCCESS then begin
// List of sampling elements has been reset successfully.
end
else begin
// Failed resetting the list of sampling elements.
// Do some error handling.
exit;
end;
// ###-> 2/3. Add sampling elements
if (cNmx.Sampling_AddChannelsAll_1(pHandleNmx, ulNElements) = NST_SUCCESS) And
(cNmx.Sampling_AddDigiInAll_1(pHandleNmx, ulNElements) = NST_SUCCESS) And
(cNmx.Sampling_AddDigiOutAll_1(pHandleNmx, ulNElements) = NST_SUCCESS) then begin
// Successfully added all sampling elements
end
else begin
// Failed adding sampling elements
// Do some error handling.
exit;
end;
// ###-> 4. Prepare sampling with 1000 Samples/s (= 1000µs sample period)
if cNmx.Sampling_PrepareTime_1(pHandleNmx, 1000{µs}, 5000{BufferSize}, 0{0=NoLimit}) = NST_SUCCESS then begin
// Sampling successfully prepared
end
else begin
// Failed preparing sampling
// Do some error handling.
exit;
end;
// ###-> 5. Start sampling
if cNmx.Sampling_Start_1(pHandleNmx) = NST_SUCCESS then begin
// Start successful.
// Reading sampled data should start now/soon to avoid a buffer overflow.
end
else begin
// Failed starting sampling
// Do some error handling.
exit;
end;
Delphi: Start with a selection of measurement channels and digital inputs
// ###-> 1. Reset list of sampling elements
if cNmx.Sampling_Reset_1(pHandleNmx) = NST_SUCCESS then begin
// List of sampling elements has been reset successfully.
end
else begin
// Failed resetting the list of sampling elements.
// Do some error handling.
exit;
end;
// ###-> 2/3. Add sampling elements
if (cNmx.Sampling_AddChannel_1(pHandleNmx, 0, ulNTotal) = NST_SUCCESS) And
(cNmx.Sampling_AddChannel_1(pHandleNmx, 5, ulNTotal) = NST_SUCCESS) And
(cNmx.Sampling_AddChannel_1(pHandleNmx, 17, ulNTotal) = NST_SUCCESS) And
(cNmx.Sampling_AddDigiInByte_1(pHandleNmx, 0, ulNTotal) = NST_SUCCESS) then begin
// Successfully added selected sampling elements
end
else begin
// Failed adding sampling elements
// Do some error handling.
exit;
end;
// ###-> 4. Prepare sampling with 1000 Samples/s (= 1000µs sample period)
if cNmx.Sampling_PrepareTime_1(pHandleNmx, 1000{µs}, 5000{BufferSize}, 0{0=NoLimit}) = NST_SUCCESS then begin
// Sampling successfully prepared
end
else begin
// Failed preparing sampling
// Do some error handling.
exit;
end;
// ###-> 5. Start sampling
if cNmx.Sampling_Start_1(pHandleNmx) = NST_SUCCESS then begin
// Start successful.
// Reading sampled data should start now/soon to avoid a buffer overflow.
end
else begin
// Failed starting sampling
// Do some error handling.
exit;
end;
C# / .Net: Start with all measurement channels and digital I/Os
UInt32 ulNElements = 0;
// ###-> 1. Reset list of sampling elements
if (cNmx.Sampling_Reset_1(pDevice) == NMX_MSTATUS.SUCCESS) {
// List of sampling elements has been reset successfully.
}
else {
// Failed resetting the list of sampling elements.
// Do some error handling.
return;
}
// ###-> 2/3. Add sampling elements
if ( (cNmx.Sampling_AddChannelsAll_1(pDevice, ref ulNElements) == NMX_MSTATUS.SUCCESS) &&
(cNmx.Sampling_AddDigiInAll_1(pDevice, ref ulNElements) == NMX_MSTATUS.SUCCESS) &&
(cNmx.Sampling_AddDigiOutAll_1(pDevice, ref ulNElements) == NMX_MSTATUS.SUCCESS) ) {
// Successfully added all sampling elements
}
else {
// Failed adding sampling elements
// Do some error handling.
return;
}
// ###-> 4. Prepare sampling with 1000 Samples/s (= 1000µs sample period)
if (cNmx.Sampling_PrepareTime_1(pDevice, 1000/*µs*/, 5000/*Buffer-Size*/, 0/*0=NoLimit*/) == NMX_MSTATUS.SUCCESS)
// Sampling successfully prepared
}
else {
// Failed preparing sampling
// Do some error handling.
return;
}
// ###-> 5. Start sampling
if (cNmx.Sampling_Start_1(pDevice) == NMX_MSTATUS.SUCCESS) {
// Start successful.
// Reading sampled data should start now/soon to avoid a buffer overflow.
}
else {
// Failed starting sampling
// Do some error handling.
return;
}
C# / .Net: Start with a selection of measurement channels and digital inputs
UInt32 ulNElements = 0;
// ###-> 1. Reset list of sampling elements
if (cNmx.Sampling_Reset_1(pDevice) == NMX_MSTATUS.SUCCESS) {
// List of sampling elements has been reset successfully.
}
else {
// Failed resetting the list of sampling elements.
// Do some error handling.
return;
}
// ###-> 2/3. Add sampling elements
if ( (cNmx.Sampling_AddChannel_1(pDevice, 0, ref ulNElements) == NMX_MSTATUS.SUCCESS) &&
(cNmx.Sampling_AddChannel_1(pDevice, 5, ref ulNElements) == NMX_MSTATUS.SUCCESS) &&
(cNmx.Sampling_AddChannel_1(pDevice, 17, ref ulNElements) == NMX_MSTATUS.SUCCESS) &&
(cNmx.Sampling_AddDigiInByte_1(pDevice, 0, ref ulNElements) != NMX_MSTATUS.SUCCESS) ) {
// Successfully added all sampling elements
}
else {
// Failed adding sampling elements
// Do some error handling.
return;
}
// ###-> 4. Prepare sampling with 1000 Samples/s (= 1000µs sample period)
if (cNmx.Sampling_PrepareTime_1(pDevice, 1000/*µs*/, 5000/*Buffer-Size*/, 0/*0=NoLimit*/) == NMX_MSTATUS.SUCCESS)
// Sampling successfully prepared
}
else {
// Failed preparing sampling
// Do some error handling.
return;
}
// ###-> 5. Start sampling
if (cNmx.Sampling_Start_1(pDevice) == NMX_MSTATUS.SUCCESS) {
// Start successful.
// Reading sampled data should start now/soon to avoid a buffer overflow.
}
else {
// Failed starting sampling
// Do some error handling.
return;
}