Can a program know the text names of the objects in the devices tree?

Anonymous
2018-06-07
2018-07-05
  • Anonymous - 2018-06-07

    Originally created by: Captive Engineer

    Greetings,

    How is it possible to make the program to read and store in an array of strings the names of objects in the device tree?

    It is possible to enumerate the devices as INode objects using the CAA Device Diagnostics library by way of the .FirstChildNode, .ChildNodeCount, and .NextSiblingNode properties and, for the root INode, the .GetRoot() function. However, I do not find a way to read out the string names of the devices which correspond to the INode objects.

    I do not mean to suggest that the way to accomplish what I'm asking is through the CAA Device Diagnostics library, although that would be very convenient. My reason for mentioning that library is simply to show that it is possible to automatically enumerate the devices in the system, and this library is intended for simple diagnostics which is my purpose in wanting device names as part of my solution. It would be helpful, from a diagnostics perspective, for the program to be able to name the device having diagnostic information and to be able to do so without the programmer having to manually generate a device list in the code and update it whenever device changes are made in the tree.

    Many thanks for whatever suggestions may be offered . . .

    Best regards,
    Captive Engineer

     
  • Anonymous - 2018-06-08

    Originally created by: scott_cunningham

    Maybe this helps you in some way... I've used this to store an array of object names in collections so I can see if I had code mistakes during my development.

    Using the built in query interface, you can create a string for your objects:

    {attribute 'reflection'}
    FUNCTION_BLOCK MyFB IMPLEMENTS __SYSTEM.IQueryInterface
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    Β  Β {attribute 'instance-path'}
    Β  Β {attribute 'noinit'}
    Β  Β (* object's full instance name *)
    Β  Β InstanceNameΒ  Β : STRING;
    END_VAR
    

    Then when you instantiate, the instance name is filled in (you may need to switch from default string to STRING(255) if paths are deep):

    PROGRAM PLC_PRG
    VAR
    Β  Β Instance1 : MyFB;
    Β  Β Instance2 : MyFB;
    END_VAR
    Instance1();
    Instance2();
    

    IMG: instance_names.png

     
  • josepmariarams - 2018-06-08

    Hi.

    Do you need that for the hardware devices or for the fb that you have instantiated in the project?

    I have made a library to create a tree for the fb instances.

    If you need it you can contact with me.

    Sent from my Moto G (5S) Plus using Tapatalk

     
  • Anonymous - 2018-06-08

    Originally created by: Captive Engineer

    Thanks to both Scott and Josep for the responses.

    It is quite interesting to see that there is a way to use pragma attributes (e.g. 'instance-path') to identify function block instances. I expect that I can easily find useful ways to apply this information. Many thanks!

    However, my present need is to see the hardware device names in the device tree. From the application's perspective, there are function block instances that represent these devices, but since the devices are based on objects defined in protected libraries, I don't know of a way to add an instance path string to them. Even if I were able to modify these FB types, I wonder whether the path string would refer to a POU path in the application code or if it would instead show device paths, for example,

    MainController.ProfibusMaster.IO_Station_01

    In this example name, you see that there is no reference to the Application and/or PLC Logic portion of the project, only a reference to one of the hardware objects configured in the device tree. A string containing something like the above example would be acceptable, but how to accomplish this remains as the question.

    If there is some way to bridge the instance-path method to hardware devices, I welcome further suggestions. Alternative approaches to letting the program read device tree names are also appreciated.

    Very kind regards,
    Captive Engineer

     
  • alwoso - 2018-06-28

    Hi Captive Engineer!

    This questions tortures me for a while now. I didn't find an answer in Codesys up to now. Like you did, I use a list of the node properties, but I never found a way to get the name-string of the devices....

    In TwinCat there is a function "FB_ECGetConfSlaves" which does the job at least for the configured slaves (these may be different from the actual connected slaves!). So I think, it is possible in Codesys too, maybe in version 3.5.22 we will see it

    Have fun!

    Alfred

    IMG: FB_ECConfig.png

     
  • Anonymous - 2018-07-03

    Originally created by: Captive Engineer

    Greetings, Alfred.

    I have not used TwinCat (from the world of Beckhoff), but I do use SoMachineMotion, or SoMM (from Schneider).

    In the SoMM System Interface library, there is a function, FC_GetObjNameByLogAddr (see attached image for block form), which returns the name of those objects in the device tree that possess a conforming logical address structure. This helps me achieve part of my wishes with a significant exception: distributed I/O (e.g. Profinet, Profibus) devices do not have the required logical address structure and so cannot be identified by their text name using this function.

    That such a function exists makes me think of two possibilities. First, it may be that calling up the text name of a device tree object is somehow part of the CoDeSys language (maybe some sort of language extension?), but this is simply not described in the available documentation. Another possibility is that some functions in the System Interface library leverage features that are built into the hardware's RTOS (also not really documented). In either case, it seems that whoever wrote the FC_GetObjNameByLogAddr function simply did not consider writing a similar function for devices added to the tree that do not posses the logical address structure. I would like to see the source code in the System Interface library, but like most libraries, this code evidently is protected.

    As you suggest, we can hope that in the next release of CoDeSys, such a function may be made public.

    Kind regards,
    Captive Engineer

    IMG: FC_GetObjNameByLogAddr__Block.png

     
  • alwoso - 2018-07-05

    Hi Captive Engineer!

    I think, the question is, if the information is available in the runtime - if not, there will be no chance to get it in a program.
    If Codesys converts the device tree into a pure list of adresses, that is used by the runtime, you cannot find the name of the device, which is part only of the project, not of the running program.

    So in my opinion, the general task is to put the device names into a structure, that is handled in the runtime - which seems to be done at least for some connections - these can be read with that block from Schneider.

    I tried to get some information from Codesys support months ago, but they couldn't help me - so let'S wait and hope for better times

    Best wishes
    Alfred

     

Log in to post a comment.