LUA example of read write Flash Memory | LabJack
 

LUA example of read write Flash Memory

3 posts / 0 new
Last post
Charlie
CharlieMason's picture
LUA example of read write Flash Memory

I have a LUA script to create thermostat switching by my T4. I've  MODBUS calls sorted enough to read write temperture set-points to USER_RAM from DaqFactory.

 

I'd like to store these set-points in non volatile memory. I don't expect the values would be altered very often. Have you a working LUA example of storing a variable in INTERNAL_FLASH?

 

I've read https://labjack.com/support/datasheets/t-series/internal-flash but I could really use a working example if available.

Thanks

 

LabJack Support
LabJack Support's picture
I will get a better example

I will get a better example going some time here, but in the meantime you could build off of this basic script:

local write_val = 0x555
local read_val
-- Write the flash key to look at the user section of flash
MB.WA(61800, 0, 2, {0x6615, 0xE336}) -- INTERNAL_FLASH_KEY
-- Erase the section we are going to write
MB.W(61820, 1, 0) -- INTERNAL_FLASH_ERASE
-- Move the write pointer to start at address 0 in the user section
MB.W(61830, 1, 0) -- INTERNAL_FLASH_WRITE_POINTER
-- Write the value
MB.W(61832, 1, write_val) -- INTERNAL_FLASH_WRITE
-- Move the read pointer to address 0 in order to read the value we just wrote
MB.W(61810, 1, 0) -- INTERNAL_FLASH_READ_POINTER
-- Read the value
read_val = MB.R(61812, 1) -- INTERNAL_FLASH_READ
print(string.format("%x", read_val))
-- Stop the script
MB.W(6000, 1, 0)

LabJack Support
LabJack Support's picture
Please find our new example

Please find our new example for writing and reading internal flash attached below. We will likely add this to our lua script examples package in the near future.

*Edit: Added better error handling to the script.

File Attachment: