Home AMX User Forum NetLinx Studio

Structures within structures

Hi, can someone link me to a resource that can explain this? I can post more detail as to what's confusing me but if there's a good link I can just check that out to start.

Thanks

Answers

  • Maybe not the most useful but...

    structure _time
    {
        integer hours;
        integer minutes;
        integer seconds
    }
    
    structure _date
    {
        integer day;
        integer month;
        integer year;
    }
    
    structure _timeStamp
    {
        _time time;
       _date date;
    }
    
    volatile _timeStamp uTimeStamp;
    
    
    uTimeStamp.time.hours = time_to_hour(time);
    
  • PatGPatG Posts: 42

    Cool thanks

  • viningvining Posts: 4,368

    If you go too big and too deep nesting structures you might not enjoying watching them in debug. If you try to mimic deep jason or xml nests debug can really suck.

  • JasonSJasonS Posts: 229
    Also you can't use Variable_To_XML on nested structures, it breaks and corrupts the XML.
  • I believe there is (or used to be) a hard limit on structure depth, like 5 deep or something like that? I've gone past it.

  • PatGPatG Posts: 42

    I'm still lost. Any other links available?

  • JasonSJasonS Posts: 229
    What is your application or what are you having dufficulty with so we can provide more relevant help.
  • fogled@mizzoufogled@mizzou Posts: 549
    edited February 2019

    Since I ended up copying and pasting some code anyway, I'll post a simplified version of the structures I use to store room and device data...


    (***********************************************************)
    (* DATA TYPE DEFINITIONS GO BELOW *)
    (***********************************************************)


    structure deviceip {
    char name[32]
    char ipaddr[20]
    integer ipport
    integer iptype
    dev devid
    }


    structure displaysettings {
    char name[32]
    integer type
    dev devid
    dev vdvdevid
    integer commtype
    deviceip ipcomm[1] //THIS IS PUTTING THE STRUCTURE ABOVE INTO THIS STRUCTURE
    char sercomm[64]
    integer pwr
    integer vmute
    integer feed
    integer follows
    integer status
    integer swtid //VGA Switch ID
    char vport[16] //VGA Port Number
    integer chan
    integer amute
    integer vol
    integer volset
    integer tmp
    integer ipconnect
    integer ipdone
    integer init
    char text[32]
    char buffout[1024] //holds buffer of integer commands as string data for fifo operations
    char buffin[512]
    char lastacmd[512]
    integer lastcmd
    }


    structure audchans {
    char name[20]
    integer unit
    integer id
    integer chan
    integer val
    integer mute
    integer volset
    }


    structure audiodata {
    char name[32]
    integer type
    integer init
    char sernum[16]
    audchans ch[30] //THIS PUTS THE AUDIOCHANNELS ABOVE INTO THIS STRUCTURE
    }


    structure inputs {
    char name[32]
    integer swtid //VGA Switch ID
    char vport[16] //HDMI Switch Video Port (nornally Aud and Vid)
    char aport[16] //HDMI Switch Audio Port (Use separate Aud/Vid for oddball stuff)
    integer follows
    }


    //THIS IS THE MAIN, TOP-LEVEL STRUCTURE:
    structure room {
    char name[32]
    char dbid[12]
    integer status
    displaysettings d[21] //PUTS DISPLAY STRUCTURE (WITH IP SUB_STRUCTURE) IN THIS STRUCTURE
    audiodata audio[1] //PUTS AUDIO DATA STRUCTURE & SUB_STRUCTURES INTO THIS STRUCTURE
    inputs in[16] //PUTS INPUT DATA STRUCTURE INTO THIS STRUCTURE
    helpdata help[1]
    }

    ...then all I have to do to define the whole structure and sub-structure

    (***********************************************************)
    (* VARIABLE DEFINITIONS GO BELOW *)
    (***********************************************************)
    DEFINE_VARIABLE


    persistent room rm[2] //THIS DEFINES TWO ROOMS with all the data cells of the sub-structures underneath them

    Then to get to any cell in the structure:
    stored_volume = rm[this_rm].d[this_device].a[1].ch[this_ch].val

    ...hope that helps if you're still struggling with building and using structures.

  • mushmush Posts: 287

    @JasonS said:
    Also you can't use Variable_To_XML on nested structures, it breaks and corrupts the XML.

    This is not true, we write nested structures to XML all the time. In some cases up to 5 levels.

  • JasonSJasonS Posts: 229
    edited May 2019
    @mush Could you post an example of the code that writes the structure to disk? On an NX or NI processor?
  • viningvining Posts: 4,368

    I use variable to string and string to variable to pass updated structures, a single level, from modules back to the main all the time and use variable to xml to store data on the flash that are 3 levels deep. I've never noticed corrupted data but to be honest I haven't looked for it either.

  • PatGPatG Posts: 42

    Thanks everyone I figured it out.

  • mushmush Posts: 287

    @JasonS
    Sorry for the tardy reply, do you still want code examples?
    The NSX help file has a good example under XML_TO_VARIABLE.
    If you want more let me know and I'll post some of our examples.

  • JasonSJasonS Posts: 229
    I am curious to see it work, I spent a good amount of time on it several years ago. A customer wanted a config file that was human readable and editable outside of the control code. I ended up going with a binary file because every time I tried to generate the XML file (using VariableToXML) with nested structures the XML output was corrupt.
  • ericmedleyericmedley Posts: 4,177

    "JasonS
    I am curious to see it work, I spent a good amount of time on it several years ago. A customer wanted a config file that was human readable and editable outside of the control code. I ended up going with a binary file because every time I tried to generate the XML file (using VariableToXML) with nested structures the XML output was corrupt."

    This is a case where I might jut roll my own file reader. Pinning your hopes on the user getting a file format right every time is a pretty dicey prospect. This might be a good case for a good old fashioned CSV file which Excel et al can open easily enough and even if the format gets jacked up, you cam wrote sp,e cpde to deal with it and repair.

  • mushmush Posts: 287

    @ericmedley
    We use XML editing programs to edit our config files. Using XML allows us to enforce the structure of the XML file as well as the data that is entered. e.g numerical or alpha can be enforced.
    The example provided is for pre-configuring systems. Once the main code is loaded it looks for an existing XML, if one is found and the system is configured by that file. If there are errors in the file they are displayed on the touch panel and in debugging. If a file is not found a fresh one is written to the master.
    This system is very handy when you have to roll out 200+ rooms at a university during summer break!

  • viningvining Posts: 4,368

    I've been using var to xml for my Viewstat scheduling code for a long time and haven't had any issues with corruption using a 3 deep nested structure.

    DEFINE_TYPE
    
    structure sVST_Setting
    
         {
         char cVST_Time[11] ;
         integer nVST_HTemp ;
         integer nVST_CTemp ;
         }
    
    structure sVST_Days
    
         {
         sVST_Setting sVSTSet[4] ;
         }
    
    structure sVST_Stat
    
         {
         sVST_Days sVSTDay[7] ;
         char cVST_Z_NAME[18] ;  //18 is max numbers that fits in vt field at font size.
         char cVST_HoldReleaseTime[8] ;
         integer nVST_Hold ;
         integer nVST_Hold_24 ;
         integer nVST_SchedMode ;
         }
    
    DEFINE_VARIABLE 
    non_volatile sVST_Stat sVSTStat[HVAC_ZONES]
    
Sign In or Register to comment.