CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Wed Apr 24, 2019 7:10 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Jun 07, 2018 5:42 pm 
Offline

Joined: Mon Jul 18, 2011 2:18 pm
Posts: 16
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


Top
   
PostPosted: Fri Jun 08, 2018 1:49 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 302
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:

Code:
{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):

Code:
PROGRAM PLC_PRG
VAR
   Instance1 : MyFB;
   Instance2 : MyFB;
END_VAR

Instance1();
Instance2();


Attachment:
instance_names.png


You do not have the required permissions to view the files attached to this post.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


Top
   
PostPosted: Fri Jun 08, 2018 3:24 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 271
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


Top
   
PostPosted: Fri Jun 08, 2018 8:17 pm 
Offline

Joined: Mon Jul 18, 2011 2:18 pm
Posts: 16
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


Top
   
PostPosted: Thu Jun 28, 2018 1:13 pm 
Offline

Joined: Mon Nov 03, 2014 7:15 am
Posts: 48
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 :mrgreen:

Have fun!

Alfred


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Tue Jul 03, 2018 9:53 pm 
Offline

Joined: Mon Jul 18, 2011 2:18 pm
Posts: 16
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


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Thu Jul 05, 2018 3:38 pm 
Offline

Joined: Mon Nov 03, 2014 7:15 am
Posts: 48
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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited