TWINCAT make function block persistent

nachovr

Member
Join Date
Aug 2014
Location
Spain
Posts
4
Hello to everyone.

My question here is whether it is possible to write/read on the NVRAM an instance of a function block.

I have a function block that relies on an internal counter to give a result. I don't want this counter to be lost upon reset of the PLC so I thought I could use FB_NovRamReadWrite to store it on the NOVRAM but it doesn't seem to work.

I have tried with basic data types and it works ok, I can write/read an integer but is not the same with the function block.

So is it a limitation on twincat or is it possible to store an instance of a FB?

Thanks
 
Hello nachovr,

I've stored structures, arrays and any kind of variables into the retain memory, but, I've never tried to store an instance of a function block...

How are you trying to do it and which kind of PLC are you using (BX,ARM,PC...)? How big it is the Function block in terms of memory consumption?

Thinking loud:
In any other variable kind you have only a set of bits that are filled with data, with a function block you have data and PLC program, you should not be able to store that behavior, neither the position where the program pointer was at the moment you stopped the machine... the call stack would for sure not be equal and therefore the behavior of the surrounding code could not be the same.

If you want to store the variables defined into a function block, then you could put them in different structures given different scopes (INPUT, OUTPUT, VAR...) and store those structures...

Being curious here: what do you want to get? and... you speak about a TWinCAT limitation, what have you used that allow this and how it works?

Good luck!
 
You can NOT store the function block itself, however you can store the variables.
Inside a FB that is impossible due to position, however you can store them in global memory using markers or using global persistent.
for each instance you will need to make this var (you may use an array and structures
 
Hello there,

I finally managed to store the instance of the function block. No need to do anything fancy, I had some problems in the code where data was being overwritten in some other part of the program.

Having a look into the DPRAM online it only stores the variables of the FB, so it just works as with any other variable
 
Cool, so you are storing the contents of the FB, all the data and so and in case you have a state machine inside the FB the data part is stored and I guess the FB will continue it's work at that point...

Could be interesting...
 

Similar Topics

Hi, I have just started programming in TWINCAT to get some experience in structured text. I have just finished my first function block but I have...
Replies
6
Views
3,286
To Codesys and TwinCAT experts, if you could spare some time to help this newbie, I will be so very grateful, just please promise not to laugh too...
Replies
2
Views
2,088
Hello: I am working on TwinCAT 3. I have a variable 'Allow_Control'. Whenever this variable is 'TRUE' I want the Function FCN_ON_ACSwitch(); to...
Replies
3
Views
1,964
Hello everyone, In my PLC program I want to know if there is a new device is plugged in. Normally you use Twincat to scan new devices. Now I...
Replies
3
Views
1,620
Hello i am using TwinCAT and am having trouble creating a function that i want. basically this is what i want: i have two conditions that when...
Replies
24
Views
4,917
Back
Top Bottom