Saving a variable between power ups

Moderators: TomKerekes, dynomotion

Post Reply
Roamin
Posts: 25
Joined: Tue Dec 13, 2022 10:34 pm

Saving a variable between power ups

Post by Roamin » Thu Jan 05, 2023 4:31 pm

Hi,

I'm really confused right now. I've been trying for hours to have a variable saved across power ups but to no avail... I set the following :

int *Last_Tool = &persist.UserData[50];
The value starts at 0

Then later after manipulating the variables , it is set this way:

*Last_Tool = Index;

So now the value is set to my last position of my tool holder.

When I power up again , the variable is set to 0 again. How do I make it so that when it powers up , it will retain the last value that was stored in?

I'm really confused. Thanks for you help.

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Saving a variable between power ups

Post by TomKerekes » Thu Jan 05, 2023 5:05 pm

Hi Roamin,

You can save the Current Tool to a PC Disk File to be recovered after a power loss.

See the GetCurrentTool() and SaveCurrentTool() in the Linear4ToolHolders Rev 2.c example
Regards,

Tom Kerekes
Dynomotion, Inc.

Roamin
Posts: 25
Joined: Tue Dec 13, 2022 10:34 pm

Re: Saving a variable between power ups

Post by Roamin » Thu Jan 05, 2023 5:07 pm

Thanks for your input, Tom

Is there no way to directly save it to the flash memory of the Kflop ? Since everything program can be flashed to the Kflop, surely it's possible to save a single variable?

I will start looking into saving to disk, but it seems overkill to save a single byte?

Thanks

User avatar
TomKerekes
Posts: 2677
Joined: Mon Dec 04, 2017 1:49 am

Re: Saving a variable between power ups

Post by TomKerekes » Thu Jan 05, 2023 5:22 pm

In general if the system has a PC we recommend using the resources of the PC and leave KFLOP in its virgin state. Otherwise it can be confusing if KFLOPs are swapped or replaced. If you prefer to Flash data to KFLOP see the examples in the FlashNonVolatile folder.
Regards,

Tom Kerekes
Dynomotion, Inc.

Roamin
Posts: 25
Joined: Tue Dec 13, 2022 10:34 pm

Re: Saving a variable between power ups

Post by Roamin » Fri Jan 06, 2023 8:30 pm

Thanks for that information. I have used the 2 functions you told me about and now my tool changer keeps track of its tool position after power off.

Post Reply