Home AMX User Forum NetLinx Studio

Writing/Reading a Structure to Flash Memory

Greetings,

I would like to save the values of 100 instances of a structure to flash for reloading at startup. The structure is created in a module and cannot be peristent.
DEFINE_TYPE
Structure MyStruck
{
//There are ten various variable types in the structure
}

DEFINE_VARAIBLE
MyStruck MyStructure[100]

If someone could give me a quick explantion on this, it would be much appreciated.

Thank you.

Comments

  • ericmedleyericmedley Posts: 4,177
    Well, one could write the values of the stucture to an arrayed variable(s) that are stored in non-vol ram. In order to ensure that you have the most current values, you'd want to periodically update it as opposed to just doing it at shut down. That way if you had a loss of power, you wouldn't loose whatever value was there.

    Another method that would work in a similar way is to write the variable into a text file in the master's virt disk. You'd have to write some kind of translator to move the data on and off the disk.

    I do this with my very large Cablevision/Satellite TV channels listing.
  • GSLogicGSLogic Posts: 562
    Greetings,

    I would like to save the values of 100 instances of a structure to flash for reloading at startup. The structure is created in a module and cannot be peristent.
    DEFINE_VARIABLE
      LONG  lPos
      SLONG slReturn
      SLONG slFile
      SLONG slResult
      CHAR  sXMLString[50000]
    
    DEFINE_FUNCTION fnSAVE_YOUR_STRUCT_NAME()
    {
      // Convert To XML
      lPos = 1
      slReturn = VARIABLE_TO_XML(YOUR_STRUCT_NAME, sXMLString, lPos, 0)
      
      // Save Structure To Disk ? XML
      slFile = FILE_OPEN('YOUR_STRUCT_NAME.xml', 2)
      slReturn = FILE_WRITE(slFile, sXMLString, LENGTH_STRING(sXMLString))
      slReturn = FILE_CLOSE(slFile)	
    }
    
    DEFINE_FUNCTION fnRELOAD_YOUR_STRUCT_NAME()
    {
      // Read XML File
      slFile = FILE_OPEN('YOUR_STRUCT_NAME.xml',1)
      slResult = FILE_READ(slFile, sXMLString, MAX_LENGTH_STRING(sXMLString))
      slResult = FILE_CLOSE (slFile)	
       
      // Convert To XML
      lPos = 1
      slReturn = XML_TO_VARIABLE (YOUR_STRUCT_NAME, sXMLString, lPos, 0)
    }
    

    This will do the trick!
  • TurnipTruckTurnipTruck Posts: 1,485
    GSLogic wrote:
    [code]
    This will do the trick!
    Thanks Gary for this example. I will begin experimenting with it shortly. Your very helpful posts in this forum are much appreciated and demonstrate your exceptional skill levels in the field of AMX code writing!
Sign In or Register to comment.