Upload PLC-variabledeclaration (dynamic) (2/2)

Download: 'Read PLC variable declaration'

This sample describes how to upload the PLC symbol information in a more efficient dynamic way.

The PLC symbol information contain the following parts:

Hinweis

We highly recommend to NOT work with this IndexGroup/IndexOffset for ADS communication but instead use handles of symbols for ADS communication.

After uploading the information "name", "datatype" and "length" it makes sense to request a handle for this symbol.

Read the major information via ADS into internal class "CAdsParseSymbols":

// Read major symbol information via ADS from device

AdsSymbolUploadInfo2 info;
nResult = AdsSyncReadReq(&m_amsAddr, ADSIGRP_SYM_UPLOADINFO2, 0, sizeof(info), &info);
if ( nResult == ADSERR_NOERR )
{
// size of symbol information
PBYTE pSym = new BYTE[info.nSymSize];
if ( pSym )
{
// upload symbols (instances)
nResult = AdsSyncReadReq(&m_amsAddr, ADSIGRP_SYM_UPLOAD, 0, info.nSymSize, pSym);
if ( nResult == ADSERR_NOERR )
{
// get size of datatype description
PBYTE pDT = new BYTE[info.nDatatypeSize];
if ( pDT )
{
// upload datatye-descriptions
nResult = AdsSyncReadReq(&m_amsAddr, ADSIGRP_SYM_DT_UPLOAD, 0, info.nDatatypeSize, pDT);
if ( nResult == ADSERR_NOERR )
{
// create class-object for each datatype-description
m_pDynSymbols = new CAdsParseSymbols(pSym, info.nSymSize, pDT, info.nDatatypeSize);
if ( m_pDynSymbols == NULL )
nResult = ADSERR_DEVICE_NOMEMORY;
}
delete [] pDT;
}
}
delete [] pSym;
}
}
}

Get Parent :
The routine Get Parent will jump NOT jump to the direct parent of a child. Instead this command will jump to the next entry of the direct parent.

Get Sibling:
Selecting this option will return the next symbol within the current hierarchy level. Symbols containing child information will be displayed, but the child elements will not be displayed.

Get Child:
If the current symbol contains child-symbol information (so the current symbol is an instance of a datatype description), this command will enter the next hierarchy and return the information about first child object.

Get Next:
Clicking this button the next symbol will be extracted from internal class "CAdsParseSymbols" and be displayed.
Selecting always just this option allows to navigate from first ADS-symbol through the hierarchy symbol tree to the end of list.