Keep variable value between program runs

I got a URCap, where I need to store a changing number between runs, how do I do that?

To initiate the value I am using variableFactory.createGlobalVariable, but it makes it reset very time the program is started.

I think the only way is to use installation variables but I Dont know if u can access them via URCAPS ( I dont use it).
regards,
Alexander Apostolidisi

where did you implement it? Your described behavior matches a ProgramNodeContribution. I think it should work inside a ProgramNodeService as it initializes only one Instance during Runtime

I did it in ProgramNodeContribution, when I try doing it in ProgramNodeService I can’t get the entire URCap to work any longer.

What part would I put it into, at the ProgramNodeService? I might be using a wrong location.

sorry i didn’t get the fact that you intended to save the variable in PolyScope, not just a java variable. That’s not possible through ProgramNodeServices as they are created before variable initializiation.

I think the main Problem is that the variable is initialized during every run of your Contribution.
Try initializing the Variable through PolyScope and edit it within the generateScript method (e.g. your_var = 1)…
If that works try initializing the variable through the urcap, e.g. inside the openView (or somewhere that is triggered once, like the constructor) Method and save a initialized flag with the programmodel.

That is what I am already doing, but the problem is the way it writes it in the program

From the program .script file.

  # end: URCap Installation Node
  global parts_c=0
  while (True):
    $ 1 "Robot-program"

This will reset the counter every time it is started.

I have also tried to attach i to another function, which is only executed when I press a button, and the variable still shows up the same way.

did you try to use the ClientSendScript Class to solve this?:

I just tried, and it works… BUT… As soon as I start the program, the variable is removed again.

What I do right now, is to use the function to set the variable when a new reference point is selected, and as soon as it is selected, the variable I set, is showing up under the variables tab. But pressing the start button, makes the variable disappear again.

Do I need to have a daemon running?

I just did a test with the python script running on my computer, and that works fine, and it stores the number, as the script sets the value in the rpc server, and then just ask for that value as the first thing when the program starts.

The daemon should also continue to run, even when the program is stopped?

The daemon may be your best shot. This can be used to buffer the variable value.
You can have the daemon start automatically, when the robot starts, and it will keep running until the robot is powered down.

Adding a daemon to it worked. Now it can remember the value, and the script inside the ur program, can request and send values to the daemon. :slight_smile: