Home AMX User Forum AMX Technical Discussion

define a device as a variable

Is it possible? if so how?, I have perused the manuals etc and dont find a good reference and help appreciated

Comments

  • Chip MoodyChip Moody Junior Member Posts: 727
    It would help to know what you're trying to accomplish, but...
    DEFINE_VARIABLE
    
    DEV TPVar = 10001:1:0
    

    Works just as well as putting it in DEFINE_DEVICE.

    If you have TP1 and TP2 declared in the normal way, you can reference them both through a single variable by doing this:
    DEV TP[] = {TP1,TP2}
    

    - Chip
  • thanks! I think i get the gist

    I was trying to just use one page to operate all the Ir devices I had as they all used the same button interface.

    I worked it round by creating a variable called 'IRdeck' then allowing the push_channel to assign the value
    finally sending command [IRDECK,play] ect where play is a constant.

    it seems to work but if there is a better way to do please let me know let me know.
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    nastables wrote:
    I was trying to just use one page to operate all the Ir devices I had as they all used the same button interface.

    I worked it round by creating a variable called 'IRdeck' then allowing the push_channel to assign the value
    finally sending command [IRDECK,play] ect where play is a constant.

    it seems to work but if there is a better way to do please let me know let me know.
    That's pretty much how I do it as a matter of course for simple IR devices, and I have been doing it since Axcess days: create a device variable, assign whatever you are controlling to it, then send all your IR pulse references to the variable rather than the actual device. This makes it possible to share button channels across devices (handy for G3 panels with limited channels), and makes it easier to use that panel to control multiple rooms (make your device variable an array, and use the room number for an index, then you can reference the controlled device per room and the panel won't lose track when you change rooms).
  • Be careful.
    Chip Moody wrote:
    It would help to know what you're trying to accomplish, but...
    DEFINE_VARIABLE
    
    DEV TPVar = 10001:1:0
    

    Works just as well as putting it in DEFINE_DEVICE.

    - Chip
    Caution!

    If you define a device as a variable and it is not an array of actual devices a Data_Event will not occur.
    DEFINE_VARIABLE
    DEV TPVar = 10001:1:0
    
    DEFINE_EVENT
    DATA_EVENT[TPVar]
    {
      ONLINE:
      {
         // any code put here will not run
      }
    }
    
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    B_Clements wrote:
    Caution!

    If you define a device as a variable and it is not an array of actual devices a Data_Event will not occur.
    DEFINE_VARIABLE
    DEV TPVar = 10001:1:0
    
    DEFINE_EVENT[TPVar]
    {
      ONLINE:
      {
         // any code put here will not run
      }
    }
    

    Assuming you mistyped and meant this:
    DEFINE_VARIABLE
    DEV TPVar = 10001:1:0
    
    DEFINE_EVENT
    DATA_EVENT[TPVar]
    {
      ONLINE:
      {
         // any code put here [b]will[/b] run here
          WAIT 300 SEND_STRING 0, 'hello'      
      }
    }
    
    ..the code will indeed run assuming you have a TP addressed at 10001.
  • Sorry for the typo.

    If it is not a real device, the code won't run.
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    I must have misunderstood what you meant when you said it had to be an array. I assumed these were real devices that were in question. Nevermind... :)
  • Chip MoodyChip Moody Junior Member Posts: 727
    If you define a device as a device, and never connect it to the system, you won't get a DATA_EVENT either. :)

    I think I'm a little tired and just missing something here. Help?

    - Chip
  • Chip Moody wrote:
    If you define a device as a device, and never connect it to the system, you won't get a DATA_EVENT either. :)

    I think I'm a little tired and just missing something here. Help?

    - Chip

    Never mind, Chip.
  • i've being using a similiar bit of coding as the example..

    DEFINE_VARIABLE
    DEV TPVar = 10001:1:0

    and this appears to work fine for data events (i do prefix it with 'volatile') .

    it fact, what i've been working on is this..
    DEFINE_CONSTANT
    integer MAXPANELS = 32

    DEFINE_VARIABLE
    volatile DEV AllPanels[MAXPANELS]

    then, i can add/remove panels/devices to the array.

    here's an example
    if(length_array(AllPanels)<MAXPANELS)
    {
    set_length_array(AllPanels,length_array(AllPanels)+1)
    AllPanels[length_array(AllPanels)].device = 150
    AllPanels[length_array(AllPanels)].port = 1
    AllPanels[length_array(AllPanels)].system = 0
    rebuild_event()
    }

    once the rebuild_event() has run, the panel with create an online event and away you go.

    i know there are other ways to do this. i've described this as an example. there is a method to my madness here. it's to create a 'soft' type of system, that doesn't know/care what gets connected to it. i actually begin with one huge array containing all possible device addresses (well, most of the expected ones). when a device comes online from my main array list, depending on the type, it will get shuffled over to an appropriate array (panels/dms/controllers).
  • GasHedGasHed Junior Member Posts: 31
    No virtual arrays in events

    I assume the issue Brian mentioned with virtual device arrays in DATA_EVENTS holds for other event types (i.e. LEVEL_EVENTS) like the following:

    <code>
    DEFINE_DEVICE
    vdvDEV1 = 34000:1:0
    vdvDEV2 = 34001:1:0

    DEFINE_VARIABLE
    DEV vdvARRAY[] = {vdvDEV1,vdvDEV2}

    LEVEL_EVENT[vdvARRAY,1]
    {
    // Nothing here executes
    }
    </code>

    This would explain some 'problems' I had just today ;)

    Pat
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    No, the issue Brain mentioned only applies to devices that were only defined as DEV variables in the DEFINE_VARIABLE section. Those defined in DEFINE_DEVICE are not affected. I just slapped a quick load on my test master to verify this, and I do in fact get level events from a virtual defined in DEFINE_DEVICE. You have a different problem, I'm afraid, Pat. Even when two virts are stacked in an array, I get LEVEL_EVENTS from the array event table.

    What I believe the difference to be is that devices in DEFINE_DEVICE are run through an internal constructor, and those in DEFINE_VARIABLE are not - in Java or C++ parlance, the difference is between using the "new" keyword (DEFINE_DEVICE) and simply allocating memory space (DEFINE_VARIABLE). That would be the reason there even is a DEFINE_DEVICE section rather than simply tossing it all into DEFINE_VARIABLE.
  • GasHedGasHed Junior Member Posts: 31
    Spirits...

    Hmm... my array of virtual devices in the LEVEL_EVENT seems to work today. Sometimes it's better just not to ask questions...

    Pat
Sign In or Register to comment.