Save cumulative counter value to a flash/permanent storage

Hello guys,

I am using controller SNAP PAC R1, I am wondering if I can store a value to flash memory.

The system need to continuous record a flow and calculate the total for months, so I need to store and extract the accumulated flow value to somewhere in case a power failure.

How should I program it? Use Datalink to store and store and retrieve data logging PC? Or I can store in the controller flash memory?

Thank you for your help!

The command you seek is ‘Save Files To Permanent Storage’.
So save your value to the file area with a comm handle, then every few hours, issue that command to save that file to flash.

I was thinking about this. Then I look into the “Help” content. It said this action:

“All files in the root directory of the file system are saved to its flash memory, replacing files currently in flash memory. (Firmware files, strategy files, and point configuration data are not affected.)”

It did not mention to save a specific data into the storage or flash memory.

Save Files To Permanent Storage

Save Files To Permanent Storage

Control Engine Action


To save the files that are in the root directory of a SNAP PAC, SNAP-LCE, or Ultimate I/O controller’s file system to flash memory.

Typical Use:

To avoid losing files if the brain or controller is turned off or loses power.


  • Copies all files in the root directory of the file system to flash memory, replacing files of the same name.
  • Each file stored in flash memory requires about 72 bytes of overhead.
  • Maximum flash memory file storage in a SNAP PAC R-series, SNAP-LCE, or SNAP Ultimate controller is about 384 KB.
  • Maximum flash memory file storage in a SNAP-PAC S-series controller is about 2.5 MB.

For more information about memory usage in SNAP PAC R- and S-series controllers, see the SNAP PAC Memory Usage technical note (form 1646).

  • Does not affect firmware, strategy, point configuration, or other configuration parameters.

Beno you mentioned about save the value to the file area. How to do this?

Actually this command is to save the entire project to the flash memory, like a snapshot?

No. This command will NOT save the entire project like a snapshot. It will just save the files in the root directory of the controller. To do that you need to stop all the charts from running and use PAC Manager.

Here is some pseudo code that should get you started;

// Get the date and time for the report

// Create the report contents
ReportData = "Report Generated on " + ReportDate + " at " + ReportTime;

// Open the file to append the new data
Report_Status = OpenOutgoingCommunication(ch_Report_File);

// Send the report
TransmitString(ReportData, ch_Report_File);
// Send a carriage return after each line
TransmitChar(10, ch_Report_File);

And the comm handle ‘ch_Report_File’ looks something like this;

1 Like

How many values do you need to store? Could you use persistent variables? These are stored in battery backed RAM so don’t lose their values when the power is lost.

You can also use the historical logging or super trend feature of PAC Display if you have a computer running at all times.

1 Like

Like 10 to 20 of them. It is a Year To Date calculated flow, so I do not think persistent variables work this way. I would like to back up the calculated value every few mins, but persistent variables changes only when engineer modifies it.

They work just like any other variable. Only difference is they remember their value after a power cycle. If you already have the variable for your flow total, just change it to persistent.

1 Like

I totally agree with @philip Now that we have a better grip on what you are looking to do, it sounds perfect for persistent variable use.
(Don’t forget to use OptoTagPerserve when you do your firmware updates and you should maintain that data for many years seamlessly).

Also keep in mind that you will lose your persistent variable values if you change the name of the strategy. For instance, changing the strategy filename by adding a revision letter or number. But like Ben mentioned, if you have a download from OptoTagPreserve you will be fine. It does not care about the strategy name.

Thank you guys, I used persistent and works perfectly fine!

Will work on the OptoTagPerserve later on.