Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with PlcProgramBrowseAsync with Struct[] #75

Open
KircMax opened this issue Apr 12, 2024 Discussed in #74 · 0 comments
Open

Problem with PlcProgramBrowseAsync with Struct[] #75

KircMax opened this issue Apr 12, 2024 Discussed in #74 · 0 comments
Labels
bug Something isn't working

Comments

@KircMax
Copy link
Collaborator

KircMax commented Apr 12, 2024

Discussed in #74

Originally posted by micheleBridi March 19, 2024
I'm trying to make the browser of a datablock 42, its structure is this:
image

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 GetFather(ApiPlcProgramData myPlcProgramDataBlock)
{
var result = new List();

 if (myPlcProgramDataBlock.Parents != null && myPlcProgramDataBlock.Parents.Count != 0)
     result.AddRange(myPlcProgramDataBlock.Parents);

 result.Add(myPlcProgramDataBlock);

 return result;

}
`

@KircMax KircMax added the bug Something isn't working label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant