CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

VAR_INFO from inside of a FB to get info on the instance.
https://forum.codesys.com/viewtopic.php?f=11&t=10187
Page 1 of 1

Author:  yannickasselin1 [ Mon Dec 02, 2019 11:21 pm ]
Post subject:  VAR_INFO from inside of a FB to get info on the instance.

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.

Author:  singleton [ Tue Dec 03, 2019 7:53 am ]
Post subject:  Re: VAR_INFO from inside of a FB to get info on the instance.

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

Author:  yannickasselin1 [ Tue Dec 03, 2019 3:59 pm ]
Post subject:  Re: VAR_INFO from inside of a FB to get info on the instance.

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.

Author:  scott_cunningham [ Wed Dec 04, 2019 4:16 am ]
Post subject:  Re: VAR_INFO from inside of a FB to get info on the instance.

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.

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/