Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpi4LabVIEW)  1.26.2
Trace buffers
Collaboration diagram for Trace buffers:

Functions

MLPIRESULT mlpiTraceGetNumberOfBuffers (const MLPIHANDLE connection, ULONG *numberOfBuffers)
 
MLPIRESULT mlpiTraceGetBufferList (const MLPIHANDLE connection, MlpiTraceBufferInformation *bufferInfo, const ULONG numElements, ULONG *numElementsRet=0)
 
MLPIRESULT mlpiTraceReadBuffer (const MLPIHANDLE connection, const WCHAR16 *bufferName, const ULLONG startIndex, MlpiTraceMessage *messages, const ULONG numElements, ULONG *numElementsRet=0)
 
MLPIRESULT mlpiTraceGetNewestMessageIndex (const MLPIHANDLE connection, const WCHAR16 *bufferName, ULLONG *newestIndex)
 
MLPIRESULT mlpiTraceGetOldestMessageIndex (const MLPIHANDLE connection, const WCHAR16 *bufferName, ULLONG *oldestIndex)
 
MLPIRESULT mlpiTraceClearAllBuffers (const MLPIHANDLE connection)
 

Detailed Description

Use the following functions to read information on or the content of the trace buffers.

Function Documentation

MLPIRESULT mlpiTraceGetNumberOfBuffers ( const MLPIHANDLE  connection,
ULONG numberOfBuffers 
)

This function returns the number of registered buffers.

Parameters
[in]connectionHandle for multiple connections.
[out]numberOfBuffersNumber of registered buffers.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 ULONG numBuffers=0;
2 
3 MLPIRESULT result = mlpiTraceGetNumberOfBuffers(connection, &numBuffers);
4 if (MLPI_FAILED(result)) {
5  printf("\ncall of MLPI function failed with 0x%08x!", result);
6  return result;
7 }
8 
9 printf("\nNumber of available trace buffers: %d", numBuffers);
MLPIRESULT mlpiTraceGetBufferList ( const MLPIHANDLE  connection,
MlpiTraceBufferInformation bufferInfo,
const ULONG  numElements,
ULONG numElementsRet = 0 
)

This function returns a list of all buffers currently available in the tracing system. The buffer information also contains the name of each buffer. This name can be used with other calls to the tracing system.

Parameters
[in]connectionHandle for multiple connections.
[out]bufferInfoPointer to an array which will receive the buffer information. One element for each buffer.
[in]numElementsArray size of buffer given to function in number of elements.
[out]numElementsRetReturns the actual number of elements returned.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 ULONG numBuffers=0;
2 MlpiTraceBufferInformation buffers[MLPI_TRACE_MAX_BUFFERS];
3 
4 // read array of available buffers
5 MLPIRESULT result = mlpiTraceGetBufferList(connection, buffers, _countof(buffers), &numBuffers);
6 if (MLPI_FAILED(result)) {
7  printf("\ncall of MLPI function failed with 0x%08x!", result);
8  return result;
9 }
10 
11 // print all buffers found
12 printf("\nFound %d Buffers\n", numBuffers);
13 printf("\n BufferName | Locked | MaxSize | ActSize ");
14 printf("\n---------------------+--------+----------+--------- ");
15 for (ULONG i=0; i<numBuffers; i++)
16 {
17  printf("\n%20s", W2A16(buffers[i].bufferName));
18  printf(" |%7s", (buffers[i].isLocked) ? "TRUE" : "FALSE");
19  printf(" | % 8d", buffers[i].maximumBufferSize);
20  printf(" | % 8d ", buffers[i].actualBufferSize);
21 }
MLPIRESULT mlpiTraceReadBuffer ( const MLPIHANDLE  connection,
const WCHAR16 bufferName,
const ULLONG  startIndex,
MlpiTraceMessage messages,
const ULONG  numElements,
ULONG numElementsRet = 0 
)

This functions returns the messages of a given buffer.

Parameters
[in]connectionHandle for multiple connections.
[in]bufferNameName of the buffer to access.
[in]startIndexIndex of the first message to start reading. Should be between the indices of mlpiTraceGetNewestMessageIndex and mlpiTraceGetOldestMessageIndex.
[out]messagesPointer to buffer which will receive the messages.
[in]numElementsArray size of buffer given to function in number of elements.
[out]numElementsRetReturns the actual number of elements(messages) returned.
Returns
Return value indicating success (>=0) or error (<0).
Example
1 WCHAR16 bufferName[] = L"MAIN"; // let's read the buffer called 'MAIN'. Should be available on most targets.
2 MlpiTraceMessage messages[150]; // let's read 150 messages
3 ULLONG oldestIndex = 0;
4 ULLONG newestIndex = 0;
5 
6 // read message index of the newest and oldest available message in the buffer.
7 // We use this information to calculate how many messages are available and to
8 // read the 150 latest messages later on.
9 MLPIRESULT result = mlpiTraceGetOldestMessageIndex(connection, bufferName, &oldestIndex);
10 if (MLPI_FAILED(result)) {
11  printf("\ncall of MLPI function failed with 0x%08x!", result);
12  return result;
13 }
14 result = mlpiTraceGetNewestMessageIndex(connection, bufferName, &newestIndex);
15 if (MLPI_FAILED(result)) {
16  printf("\ncall of MLPI function failed with 0x%08x!", result);
17  return result;
18 }
19 
20 ULLONG numMessages = newestIndex-oldestIndex;
21 printf("\nFound %d messages in buffer %s\n", (ULONG)numMessages, W2A16(bufferName));
22 if (numMessages == 0) {
23  printf("\n->currently no messages to read :-( (tip: enable some modules!)");
24 }
25 else {
26  // limit to array size
27  if (numMessages > _countof(messages)) {
28  numMessages = _countof(messages);
29  }
30 }
31 
32 
33 // now read the buffer to our array
34 ULONG numMessagesReturned = 0;
35 result = mlpiTraceReadBuffer(connection, bufferName, newestIndex, messages, numMessages, &numMessagesReturned);
36 if (MLPI_FAILED(result)) {
37  printf("\ncall of MLPI function failed with 0x%08x!", result);
38  return result;
39 }
40 
41 // print all messages to console.
42 // messages in the array are sorted from newest to oldest.
43 // Therefore, inverse the array when printing to console to get newest message
44 // printed last and to read output from top to bottom (oldest to newest).
45 printf("\n Filename | Line | Module | Type | Message ");
46 printf("\n-----------------------------+------+-------------------+------+------------- ");
47 
48 for (LONG i=numMessagesReturned-1; i>=0; i--) {
49  printf("\n%-*s %-*d %-*s %-*d %s",
50  MLPI_TRACE_FUNCTION_NAME_SIZE, W2A16(messages[i].functionName),
51  5, messages[i].lineNumber,
52  MLPI_TRACE_MODULE_NAME_SIZE, W2A16(messages[i].moduleName),
53  5, messages[i].type,
54  W2A16(messages[i].text)
55  );
56 }
MLPIRESULT mlpiTraceGetNewestMessageIndex ( const MLPIHANDLE  connection,
const WCHAR16 bufferName,
ULLONG newestIndex 
)

This function returns the message index of the newest message available in the given trace buffer. You can use this information for subsequent calls to mlpiTraceReadBuffer to read the newest messages in the buffer.

Note
Each new message that gets added to the trace buffer gets a new unique index. Indices are given in ascending order.
Parameters
[in]connectionHandle for multiple connections.
[in]bufferNameName of the buffer to access.
[out]newestIndexIndex of the newest available trace message.
Returns
Return value indicating success (>=0) or error (<0).
See also
mlpiTraceReadBuffer
MLPIRESULT mlpiTraceGetOldestMessageIndex ( const MLPIHANDLE  connection,
const WCHAR16 bufferName,
ULLONG oldestIndex 
)

This function returns the message index of the oldest message available in the given trace buffer. You can use this information for subsequent calls to mlpiTraceReadBuffer to read the oldest messages in the buffer.

Note
Each new message that gets added to the trace buffer gets a new unique index. Indices are given in ascending order.
Parameters
[in]connectionHandle for multiple connections.
[in]bufferNameName of the buffer to access.
[out]oldestIndexIndex of the oldest available trace message. (newestIndex > oldestIndex).
Returns
Return value indicating success (>=0) or error (<0).
See also
mlpiTraceReadBuffer
MLPIRESULT mlpiTraceClearAllBuffers ( const MLPIHANDLE  connection)

This function clears all buffers. This means that all trace messages currently available and stored in the system will be deleted.

Parameters
[in]connectionHandle for multiple connections.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 // Clear all buffers
2 MLPIRESULT result = mlpiTraceClearAllBuffers(connection);
3 if (MLPI_FAILED(result)) {
4  printf("\ncall of MLPI function failed with 0x%08x!", result);
5  return result;
6 }