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 Sun Dec 08, 2019 3:59 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Dec 02, 2019 11:21 pm 
Offline
Frequent User
Frequent User

Joined: Mon Apr 28, 2014 7:05 pm
Posts: 104
Hi,

Is it possible to use __VARINFO inside a Function block to get info on the instance of the function block like this:

stVarInfo := __VARINFO(THIS^);

If I do this in TwinCat, VisualStudio crashes. I would like to get the name of the instance of the function block from inside the function block.

Thank you.


Top
   
PostPosted: Tue Dec 03, 2019 7:53 am 
Offline

Joined: Thu Aug 04, 2011 11:16 am
Posts: 87
If you just want to have the instance name you can use this attribute pragma:

https://help.codesys.com/webapp/_cds_pr ... n=3.5.15.0


Top
   
PostPosted: Tue Dec 03, 2019 3:59 pm 
Offline
Frequent User
Frequent User

Joined: Mon Apr 28, 2014 7:05 pm
Posts: 104
Thank you,

It works but I also get the name of the TC project and the name of the PLC project in front of the variable name. I should be able to figure a way to get rid of what I don't need using some string functions.

'Tc3_TestRecipe.PLC_TestRecipe.Main.fbTest[0]'

I only need 'Main.fbTest[0]'

Thank you.


Top
   
PostPosted: Wed Dec 04, 2019 4:16 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 309
Those items you don’t want are part of the instance path, that is why they are included. Simply make a function that starts at the string end, and goes backwards until it finds the second period. Then return the MID of the string, starting at that point.

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


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 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