simatic-s7-webserver-api
simatic-s7-webserver-api copied to clipboard
Problem with PlcProgramBrowseAsync with Struct[]
Discussed in https://github.com/siemens/simatic-s7-webserver-api/discussions/74
Originally posted by micheleBridi March 19, 2024
I'm trying to make the browser of a datablock 42, its structure is this:
But when I try to browse AlarmsTime of type struct[] I get this error: The dimensions and edges of the array-indexes do not match the typeinformation of the plc. Did you provide a (correct) index?
the code I'm using is this:
` public async Task PlcProgramBrowse() { try { var allMyPlcProgramBlocks = (await requestHandler.PlcProgramBrowseAsync(ApiPlcProgramBrowseMode.Children)).Result;
foreach (var block in allMyPlcProgramBlocks.Where(f => f.Db_number is 42))
await RetrieveInfo(block);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public async Task RetrieveInfo(ApiPlcProgramData block) { try { if (block.Has_children ?? false) { var items = (await requestHandler.PlcProgramBrowseAsync(ApiPlcProgramBrowseMode.Children, block)).Result;
block.Children = items;
foreach (var child in block.Children)
child.Parents = GetFather(block);
foreach (var item in items)
{
try
{
switch (item.Datatype)
{
case ApiPlcProgramDataType.Struct:
case ApiPlcProgramDataType.DataBlock:
await RetrieveInfo(item);
break;
default:
Symbolics.Add(item);
break; } } catch (Exception e) { Console.WriteLine(e.Message); } } } } catch (Exception e) { Console.WriteLine(e.Message); } }
public List<ApiPlcProgramData> GetFather(ApiPlcProgramData myPlcProgramDataBlock) { var result = new List<ApiPlcProgramData>();
if (myPlcProgramDataBlock.Parents != null && myPlcProgramDataBlock.Parents.Count != 0)
result.AddRange(myPlcProgramDataBlock.Parents);
result.Add(myPlcProgramDataBlock);
return result;
} `