Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpiCore)  1.26.2
Auxiliary function
Collaboration diagram for Auxiliary function:

Functions

MLPIRESULT mlpiContainerSetName (const MLPIHANDLE connection, const MlpiContainerHandle handle, const WCHAR16 *name)
 
MLPIRESULT mlpiContainerGetName (const MLPIHANDLE connection, const MlpiContainerHandle handle, WCHAR16 *name, const ULONG numElements)
 
MLPIRESULT mlpiContainerGetInformation (const MLPIHANDLE connection, const MlpiContainerHandle handle, MlpiContainerInformation *info)
 
MLPIRESULT mlpiContainerGetTagList (const MLPIHANDLE connection, const MlpiContainerHandle handle, WCHAR16 *tagList, const ULONG numElements)
 
MLPIRESULT mlpiContainerGetItemInformation (const MLPIHANDLE connection, const MlpiContainerHandle handle, MlpiContainerItemInformation *info, const ULONG numElements, ULONG *numElementsRet)
 
MLPIRESULT mlpiContainerGetSingleItemInformation (const MLPIHANDLE connection, const MlpiContainerHandle handle, const ULONG index, WCHAR16 *tag, const ULONG numElements, MlpiContainerItemInformation *info)
 
MLPIRESULT mlpiContainerGetNumberOfContainer (const MLPIHANDLE connection, ULONG *number)
 
MLPIRESULT mlpiContainerGetHandlesOfContainer (const MLPIHANDLE connection, MlpiContainerHandle *handles, const ULONG numElements, ULONG *numElementsRet)
 

Detailed Description

Contains additional functions for getting more detailed information about the properties and structure of a container.

Attention
The addresses of the variables of the container content might change on every download, reset origin or online change of the PLC application, so you have to stop and destroy each regarding container before you load or change the PLC application!

These functions are not needed for simple reading and writing using containers. Use them only if you want to dive deeper into the container system of the MLPI.

Function Documentation

MLPIRESULT mlpiContainerSetName ( const MLPIHANDLE  connection,
const MlpiContainerHandle  handle,
const WCHAR16 name 
)

Using this function, you can assign a descriptive name to your container. The name can be any string. Duplicates are allowed. It is not necessary to give your container a name, but the name is used on diagnosis messages and might be useful for debugging and maintaining your application.

Parameters
[in]connectionHandle for multiple connections.
[in]handleHandle of the container. Use mlpiContainerCreate to create a container.
[in]nameString containing a name for the container. Maximum length is defined by MLPI_CONTAINER_NAME_MAX_LENGTH.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 // let's call our container 'Batman'
2 MLPIRESULT result = mlpiContainerSetName(connection, hContainer, L"Batman");
3 if (MLPI_FAILED(result)) {
4  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
5  return result;
6 }
MLPIRESULT mlpiContainerGetName ( const MLPIHANDLE  connection,
const MlpiContainerHandle  handle,
WCHAR16 name,
const ULONG  numElements 
)

Using this function, you can read out the name of your container. The name can be any string with a maximum size of MLPI_CONTAINER_NAME_MAX_LENGTH. Use the function mlpiContainerSetName to set the name.

Parameters
[in]connectionHandle for multiple connections.
[in]handleHandle of the container. Use mlpiContainerCreate to create a container.
[out]nameString where the container name will be stored.
[in]numElementsNumber of WCHAR16 elements in 'name' available to write.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 WCHAR16 name[MLPI_CONTAINER_NAME_MAX_LENGTH+1] = {'\0'};
2 MLPIRESULT result = mlpiContainerGetName(connection, hContainer, name, _countof(name));
3 if (MLPI_FAILED(result)) {
4  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
5  return result;
6 }
7 
8 printf("\nName of container: %s", W2A16(name));
MLPIRESULT mlpiContainerGetInformation ( const MLPIHANDLE  connection,
const MlpiContainerHandle  handle,
MlpiContainerInformation info 
)

Use this function to read various pieces of information about your container. This includes time of creation, size, number of items, and type (read/write). You have to pass the container handle.

Parameters
[in]connectionHandle for multiple connections.
[in]handleHandle of the container. Use mlpiContainerCreate to create a container.
[out]infoPointer to struct which will receive the container information.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 // read container information
2 MlpiContainerInformation info;
3 memset(&info, 0, sizeof(info));
4 
5 MLPIRESULT result = mlpiContainerGetInformation(connection, hContainer, &info);
6 if (MLPI_FAILED(result)) {
7  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
8  return result;
9 }
10 
11 // print container information
12 printf("\nname: %s", W2A16(info.name));
13 printf("\nnumItems: %d", info.numItems);
14 printf("\ndataSize: %d", info.dataSize);
15 printf("\nnumElementsTagList: %d", info.numElementsTagList);
16 printf("\naccessFlag: %d", info.accessFlag);
17 printf("\ndateTime: %04d/%02d/%02d %02d:%02d:%02d.%04d",
18  info.dateTime.year,
19  info.dateTime.month,
20  info.dateTime.day,
21  info.dateTime.hour,
22  info.dateTime.minute,
23  info.dateTime.second,
24  info.dateTime.milliSecond);
MLPIRESULT mlpiContainerGetTagList ( const MLPIHANDLE  connection,
const MlpiContainerHandle  handle,
WCHAR16 tagList,
const ULONG  numElements 
)

This function returns the tag list of a container. This is the same tagList that was used to create the container with the function mlpiContainerCreate.

Parameters
[in]connectionHandle for multiple connections.
[in]handleHandle of the container. Use mlpiContainerCreate to create a container.
[out]tagListString where the tag list will be stored.
[in]numElementsNumber of WCHAR16 elements in 'name' available to write.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 // read container information
2 MlpiContainerInformation info;
3 memset(&info, 0, sizeof(info));
4 
5 MLPIRESULT result = mlpiContainerGetInformation(connection, hContainer, &info);
6 if (MLPI_FAILED(result)) {
7  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
8  return result;
9 }
10 
11 // allocate enough memory and read item information
12 WCHAR16 *tagList = new WCHAR16[info.numElementsTagList+1];
13 mlpiContainerGetTagList(connection, hContainer, tagList, info.numElementsTagList+1);
14 if (MLPI_FAILED(result)) {
15  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
16  delete [] tagList;
17  return result;
18 }
19 
20 // print the tagList
21 printf("\n%s", W2A16(tagList));
22 
23 delete [] tagList;
MLPIRESULT mlpiContainerGetItemInformation ( const MLPIHANDLE  connection,
const MlpiContainerHandle  handle,
MlpiContainerItemInformation info,
const ULONG  numElements,
ULONG numElementsRet 
)

This function returns the item information of a container as an array of struct. Each element in the array contains information about a single item within the container. This includes information about type, size and offset of the item within the container data stream. You can use this function to read out information about the memory layout of the container data stream that gets returned by mlpiContainerUpdate.

Parameters
[in]connectionHandle for multiple connections.
[in]handleHandle of the container. Use mlpiContainerCreate to create a container.
[out]infoPointer to an array where the requested information about the items will be stored.
[in]numElementsNumber of elements in 'info' available to write.
[out]numElementsRetReturns the number of elements actually read. This is the number of items in the container.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 // read container information
2 MlpiContainerInformation info;
3 memset(&info, 0, sizeof(info));
4 
5 MLPIRESULT result = mlpiContainerGetInformation(connection, hContainer, &info);
6 if (MLPI_FAILED(result)) {
7  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
8  return result;
9 }
10 
11 // allocate enough memory and read item information
12 ULONG numElementsRet = 0;
13 MlpiContainerItemInformation *itemInfos = new MlpiContainerItemInformation[info.numItems];
14 mlpiContainerGetItemInformation(connection, hContainer, itemInfos, info.numItems, &numElementsRet);
15 if (MLPI_FAILED(result)) {
16  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
17  delete [] itemInfos;
18  return result;
19 }
20 
21 // loop over all items and print information of each item in the container
22 printf("\nOffset | Size | Type ");
23 printf("\n-------+------+------");
24 for (ULONG i=0; i<numElementsRet; i++) {
25  printf("\n %6d %5d %4d", itemInfos[i].offset, itemInfos[i].dataSize, itemInfos[i].type);
26 }
27 
28 delete [] itemInfos;
MLPIRESULT mlpiContainerGetSingleItemInformation ( const MLPIHANDLE  connection,
const MlpiContainerHandle  handle,
const ULONG  index,
WCHAR16 tag,
const ULONG  numElements,
MlpiContainerItemInformation info 
)

This function returns the item information of a single item in a container. It returns information about type, size and offset of the item within the container data stream. You can use this function to read out information about the memory layout of the container data stream that gets returned by mlpiContainerUpdate. This is similar to the function mlpiContainerGetItemInformation. But only a single item is returned including its tag.

Parameters
[in]connectionHandle for multiple connections.
[in]handleHandle of the container. Use mlpiContainerCreate to create a container.
[in]indexIndex of the item to return information for. Use mlpiContainerGetInformation to read the number of available items in a container.
[out]tagString where the tag of the item will be stored.
[in]numElementsNumber of WCHAR16 elements in 'tag' available to write.
[out]infoPointer to a struct where the requested information about the item will be stored.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 // read container information
2 MlpiContainerInformation info;
3 memset(&info, 0, sizeof(info));
4 
5 MLPIRESULT result = mlpiContainerGetInformation(connection, hContainer, &info);
6 if (MLPI_FAILED(result)) {
7  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
8  return result;
9 }
10 
11 // loop over all items and print information of each item in the container
12 printf("\nOffset | Size | Type | Tag ");
13 printf("\n-------+------+------+-------------");
14 
15 for (ULONG i=0; i<info.numItems; i++) {
16  MlpiContainerItemInformation itemInfo;
17  memset(&itemInfo, 0, sizeof(itemInfo));
18  WCHAR16 tag[512] = {'\0'};
19 
20  // read item info
21  MLPIRESULT result = mlpiContainerGetSingleItemInformation(connection, hContainer, i, tag, _countof(tag), &itemInfo);
22  if (MLPI_FAILED(result)) {
23  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
24  return result;
25  }
26 
27  // print it
28  printf("\n %6d %5d %4d %s", itemInfo.offset, itemInfo.dataSize, itemInfo.type, W2A16(tag));
29 }
MLPIRESULT mlpiContainerGetNumberOfContainer ( const MLPIHANDLE  connection,
ULONG number 
)

This function returns the total number of containers created on the device. Also including containers of other applications.

Parameters
[in]connectionHandle for multiple connections.
[out]numberReturns the total number of allocated containers on the device.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 ULONG numContainers = 0;
2 
3 // read how many containers are available
4 MLPIRESULT result = mlpiContainerGetNumberOfContainer(connection, &numContainers);
5 if (MLPI_FAILED(result)) {
6  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
7  return result;
8 }
9 printf("\nFound %d container(s) on the device", numContainers);
MLPIRESULT mlpiContainerGetHandlesOfContainer ( const MLPIHANDLE  connection,
MlpiContainerHandle handles,
const ULONG  numElements,
ULONG numElementsRet 
)

Returns the handles of all containers that were previously created on the device.

Parameters
[in]connectionHandle for multiple connections.
[out]handlesPointer to an array which will receive all container handles of the device.
[in]numElementsNumber of elements in 'handles' available to write.
[out]numElementsRetReturns the number of elements actually read. This is the number of handles returned.
Returns
Return value indicating success (>=0) or error (<0).
Example:
1 ULONG numContainers = 0;
2 
3 // read how many containers are available
4 MLPIRESULT result = mlpiContainerGetNumberOfContainer(connection, &numContainers);
5 if (MLPI_FAILED(result)) {
6  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
7  return result;
8 }
9 printf("\nFound %d container(s) on the device", numContainers);
10 
11 // get the handles of all containers and print the names of the containers
12 if (numContainers) {
13  MlpiContainerHandle *containers = new MlpiContainerHandle[numContainers];
14 
15  ULONG numElementsRet = 0;
16  MLPIRESULT result = mlpiContainerGetHandlesOfContainer(connection, containers, numContainers, &numElementsRet);
17  if (MLPI_FAILED(result)) {
18  printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
19  delete [] containers;
20  return result;
21  }
22 
23  // print the name of each container
24  for (ULONG i=0; i<numContainers; i++) {
25  WCHAR16 name[K_CONTAINER_NAME_MAX_LENGTH+1];
26  MLPIRESULT result = mlpiContainerGetName(connection, containers[i], name, _countof(name));
27  if (MLPI_SUCCEEDED(result)) {
28  printf("\n%d: %s", i, W2A16(name));
29  } else {
30  printf("\n%d: could not retrieve name of container", i);
31  }
32  }
33 
34  delete [] containers;
35 }