; This code shows how to use a non-volatile Array in Venom-SC ; NOTE: startup will call init and then main. ; NOTE: Your controller may reset when this code is run - this should only happen ; at most once. Just type 'Y' to clear the memory, then download and run the code again. TO Init Free(2) := 100; Reserve enough NV-RAM for all my NV Arrays. ;[If the above value is changed the controller will reset - that's OK, just run the code again] MAKE nv_array Array(8, 10, NIL) ; Define the array: 8-bit elements, 10 of them. ; Note: this MAKE must only be called once per startup of the controller. ; That's why we put it here in 'init'. ; If you have more than one NV array, or other item that uses the NV RAM area, ; then each item must be created ONCE ONLY, and the items created in the SAME ORDER each time. ; ... your other initialisation code ... END TO main check_array_data_is_OK ; Check the data is uncorrupted by checking the checksum. ; ... the rest of your code. END ; Perform a test (normally at startup) to make sure the array has correct data in it. TO check_array_data_is_OK if nv_array.Valid = FALSE [ nv_array.Copy(default_data_array) ; Reset the data to the default values. Default data array not shown here. nv_array.Checksum tell_operator_parameters_are_reset ; inform the operator of the loss of data. ] else print "NV array data is OK",cr END ; Change an element of the NV array - and set the correct checksum afterwards. ; [You can change several elements and then update the checksum later if you wish] TO change_a_non_vol_data_item(item, new_value) nv_array.(item) := new_value nv_array.Checksum ; Optional: Set the array's checksum, so Valid will return TRUE. END TO tell_operator_parameters_are_reset PRINT "parameters were corrupt and have now been reset" , cr END ;This array contains the default values for the data in the NV array. Array default_data_array(8, 10) 1, 2, 3, 0 END to x nv_array.(0) := nv_array.(0)+1 end