MX Foundation 4
Sampling Service

The sampling service is useful when not all the discrete input state change needs to be captured, but only a snapshot (for display for example). The sampling logic keeps the last record.

When sampling discrete input signals, the use of one MXF_DISCRETE_SAMPREC structure is required.

The mxfDiscreteRxSamplingRead() function must be used to get the sampling data.

Example

The example below shows how a sampling application can collect discrete data values.

HMXF_CHANNEL channel;
HMXF_BUFFER buffer;
uint64 count, byteCount, status;
uint32 i, rc = MAXT_SUCCESS;
...
// Allocate the sampling buffer
if(!rc)
rc = mxfRxSamplingBufferAlloc(channel, sizeof(MXF_DISCRETE_SAMPREC), &buffer, NULL);
// Set kill time at 1 sec.
if (!rc)
rc = mxfRxSamplingKilltimeSet(buffer, 1*1000*1000*1000);
// Start sampling.
if (!rc)
{
rc = mxfRxSamplingStart(buffer);
if (!rc)
printf("Sampling started\n\r");
}
// Monitor sampling data - 2 secs: 20 times*100ms.
for (i = 0; !rc && i < 20; i++)
{
// Waits 100 ms
mxfSleep(100);
// Gets sampling data
rc = mxfDiscreteRxSamplingRead(buffer, MXF_RXSAMPLING_FLAG_DEFAULT, 1, sizeof(MXF_DISCRETE_SAMPREC), &count, &byteCount, &sampRec);
if (!rc)
{
if (count!=0)
{
printf("Timetag %llu - data=0x%08x, edge=0x%08x\n", sampRec.timeTag, sampRec.data, sampRec.edge);
}
}
}
...
Updated 10/23/2023