The writeEEPROM function allows writing values to EEPROM. The values in EEPROM are
very save and will survive a complete a software update as well as unexpected power losses
(except during the writing process).
Note: The number of EEPROM write cycles is limited (device dependent). Do not
write to EEPROM too often (e.g. not in a cyclic script or CAN message)!
The maximum usabe EEPROM size for all devices is 28672 bytes.
Prototype:
var result = writeEEPROM (number EEPROM_ADDRESS, number LENGTH,
number/bool/string VALUE);
Parameters:
·
EEPROM_ADDRESS: The start address in the EEPROM to write the data to
·
LENGTH: The data length. The following rules apply:
? If writing a bool, the length needs to be set to 1
? If writing a number, the length needs to be 1, 2, 3 or 4
? If writing a string, the area starting at the address will be reset to 0 in EEPROM and after
that the string will be written (if a string is shorter than the provided length, still the whole
length is reset to 0 before the shorter string is written). If a string is longer than length, only
the given number of bytes will be written to EEPROM.
? EEPROM_ADDRESS + LENGTH may not be greater than the maximum EEPROM size
(28672)
·
VALUE: Currently the following JavaScript data types are supported: number, string and
bool. If e.g. an array object is provided as value parameter, the writeEEPROM function will
fail.
·
Return value (result): If the provided value was written successfully, the number of bytes that
were written are returned. If writing the value to EEPROM failed, undefined will be returned
(observe console error messages when testing the project).
Note: The EEPROM functions will only work on the device, not in the PClient
simulation.
Examples:
var ret = writeEEPROM(0, 4, 0xdeadbeaf);//write the number
0xDEADBEAF into 4 bytes starting at position 0
print("Write 0xdeadbeef: " + ret);
//console output: Write 0xdeadbeef: 4
var ret = writeEEPROM(4, 2, 32767); //write the number 32767
into 2 bytes starting at position 4
print("Write 32767: " + ret);
//console output: Write 32767: 2