I experienced the same problem: using __VARINFO is working only in PRG context, while it crashes if used inside Function Blocks. I would really appreciate if they would fix this issue
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2019-12-04
Originally created by: scott_cunningham
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I implemented something similar I had to add {attribute 'reflection} above the declaration of the FB with {attribute 'instance-path'} above the string VAR that would contain the path. Then wrote a function to trim off however much I wanted removed by searching for periods, then formatting it with spaces at the periods and removing brackets on arrays while also breaking up the PascalCase to present it a bit nicer for the end-users.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
I experienced the same problem: using __VARINFO is working only in PRG context, while it crashes if used inside Function Blocks. I would really appreciate if they would fix this issue
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 m
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.
Originally created by: scott_cunningham
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.
The help link appears to be broken.
When I implemented something similar I had to add {attribute 'reflection} above the declaration of the FB with {attribute 'instance-path'} above the string VAR that would contain the path. Then wrote a function to trim off however much I wanted removed by searching for periods, then formatting it with spaces at the periods and removing brackets on arrays while also breaking up the PascalCase to present it a bit nicer for the end-users.