Persist add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

persist_id = persist_add(key, type, initial_value)
persist_id = persist_add(key, initial_value) (from AM 3.6)

persist_add is used to create a new persistence object. Persistence objects will be stored to file's making the data within persistence objects available on the next boot of the instrument.

Return value

Argument Type Description
persist_id ID This value can be used for further reference. Functions such as persist_get and persist_put can use this persist_id. Its good practice to store this persist_id in your logic code.

Arguments

# Argument Type Description
1 key String Unique identifier key to be able to keep different persistence objects separated.
2 type String Data type of the persistence object, can be INT, FLOAT, DOUBLE, BYTE, BOOL, STRING, INT[n], FLOAT[n], DOUBLE[n], BYTE[n] or BOOL[n]
3 initial_value Object The initial value of the persistence object. This value will be used when no data is yet available. This argument is optional, when not used, the data is typically initialized with all zero's.

Example (AM/AP 3.5 and lower)

-- Create a new persistence obeject
persist_id = persist_add("mykey", "INT[8]", { 1, 2, 3, 4, 5, 6, 7, 8 })

-- Get the data from the persistence object
mydata = persist_get(persist_id)

-- Put new data into the persistence object
persist_put(persist_id, { 8, 7, 6, 5, 4, 3, 2, 1 } )

Example (AM/AP 3.6 and higher)

-- Create a new persistence obeject
persist_id = persist_add("mykey", { 1, 2, 3, 4, 5, 6, 7, 8 })

-- Get the data from the persistence object
mydata = persist_get(persist_id)

-- Put new data into the persistence object
persist_put(persist_id, { 8, 7, 6, 5, 4, 3, 2, 1 } )