I have a question about the best way to initialize persistent variables contained in a function block. I have the following function block:
Setpt: SETPTSTRUCT; //where SETPTSTRUCT is a structure containing all my persistent variables
I then go to PersistentVars, and "Declarations/Add all instance paths", and I'll get something like this:
// Generated instance path of persistent variable
That all works fine, but I would now like to initialize one of the variables in Setpt. So, I do something like this, in Main_PRG
Test1: TEST_FB:= (Setpt:= (Name:= 'Test 1'));
I would expect to see Main_PRG.Test1.Setpt.Name set to 'Test 1' when the PLC boots up. However, I've discovered that this only works if don't have the instance paths set in PersistentVars. After I've done step 2 above (Add all instance paths), the initialization doesn't happen anymore.
I assume this is because the declarations in PersistentVars get initialized after my program variables. I can sort through my PersistentVars, and initialize everything in there, but that's pretty tedious, as they're not sorted by program.
Is there way to initialize the persistent variables from the function block declaration in a program POU?
Log in to post a comment.