Home AMX User Forum NetLinx Studio

Need advice learning Netlinx

I am going insane. Why doesn't this work?
DEFINE_CONSTANT
    dev devAllTouchPanels[] 		= {dev_tp_computer, dev_tp_kitchen, dev_tp_masterbed, dev_tp_theater}
    devchan dcLivingRoomHalogens	= {devAllTouchPanels,102}

channel_event [dcLivingRoomHalogens] 	{ 
    on: { 
	on[dcLivingRoomHalogens] 
    }
    off: {
	off[dcLivingRoomHalogens] 
    }
} 

button_events don't work either. All I want to do is define specific channels that work across all of my panels so I can refer to a single identifier - "If button x is pressed (on any panel), light it up (on all panels) and do y."

The problem is I have dozens of channels like this and I shouldn't have to duplicate PUSH..TO entries for every touchpanel on every channel all throughout the code like I had to in Axcess.

Thanks for any advice...

Edit: Here's how I did this in Axcess:
push[dev_tp_computer,102]
push[dev_tp_kitchen,102]
push[dev_tp_masterbed,102]
push[dev_tp_theater,102]
{
   to[dev_tp_computer,102]
   to[dev_tp_kitchen,102]
   to[dev_tp_masterbed,102]
   to[dev_tp_theater,102]
}
This is ugly, especially when you've got a few dozen structures like this and you decide to add another touchpanel.

Comments

  • The problem looks to be using a DEV array as part of a DEVCHAN. I think you expect

    devchan dcLivingRoomHalogens = {devAllTouchPanels,102}

    To equate to

    {{dev_tp_computer,102}, {dev_tp_kitchen,102}, {dev_tp_masterbed,102}, {dev_tp_theater,102}}

    but I don't believe it works that way. You are better off just keeping the DEV array and channels separate.

    Change to this:
    DEFINE_CONSTANT
        dev devAllTouchPanels[] 		= {dev_tp_computer, dev_tp_kitchen, dev_tp_masterbed, dev_tp_theater}
    
    channel_event [devAllTouchPanels,102] 	{ 
        on: { 
    	on[dcLivingRoomHalogens,102] 
        }
        off: {
    	off[dcLivingRoomHalogens,102] 
        }
    } 
    
    Same applies to a BUTTON_EVENT.
    BUTTON_EVENT[devAllTouchPanels,102]
    {
        PUSH:
        {
            TO[devAllTouchPanels,102]
        }
    }
    
  • Thank you for the reply.

    I changed it as you stated, and it still does not work with a channel_event. It does work with a button_event, which is just fine by me as that's what I originally tried to use, but this whole process seems more awkward than it should be. Why wouldn't it work with a channel_event?

    It's really too bad I can't combine dev arrays with devchan designations. It still makes the code a bit of a hack; if I want to use the pretty devchan designations, I'll have to load each one up with each of the panels:
    dev devAllTouchPanels[] = {dev_tp_computer, dev_tp_kitchen, dev_tp_masterbed, dev_tp_theater}
    
    devchan dcLivingRoomHalogens[] = {{dev_tp_computer,102}, {dev_tp_kitchen,102}, {dev_tp_masterbed,102}, {dev_tp_theater,102}}
    devchan dcLivingRoomLamps[] = {{dev_tp_computer,103}, {dev_tp_kitchen,103}, {dev_tp_masterbed,103}, {dev_tp_theater,103}}
    devchan dcKitchenPanRack[] = {{dev_tp_computer,104}, {dev_tp_kitchen,104}, {dev_tp_masterbed,104}, {dev_tp_theater,104}}
    devchan dcKitchenMain[] = {{dev_tp_computer,105}, {dev_tp_kitchen,105}, {dev_tp_masterbed,105}, {dev_tp_theater,105}}
    devchan dcKitchenSink[] = {{dev_tp_computer,106}, {dev_tp_kitchen,106}, {dev_tp_masterbed,106}, {dev_tp_theater,106}}
    devchan dcKitchenAccent[] = {{dev_tp_computer,107}, {dev_tp_kitchen,107}, {dev_tp_masterbed,107}, {dev_tp_theater,107}}
    
    ... etc, for dozens of channels..
    
    Now imagine adding a couple of touchpanels to the system and the fun you'd have inserting them into code...

    So I can use channel numbers directly in code, but that's uncool if I need to change one. So then I'm back to assigning channel number labels as constants, which works, but boy Netlinx seemed so much prettier when I thought I could use a nice devchan label for everything.

    I can't help but wonder if this is God's punishment to me for being a Perl programmer over the last decade.
  • I did some more fiddling. dev and devchan arrays do both work with a channel_event, but not with PUSHES. I dug into the help docs and it says, "Channel Events are generated by ON, OFF, PULSE, TO, or MIN_TO. " That explains that.

    I still think there should be a way to combine dev arrays with devchan arrays. Sure would make life easier. :)
  • DHawthorneDHawthorne Posts: 4,584
    I've made it a habit to only use DEVCHAN sparingly. It's far more flexible to make a device array, then an integer array and track your event with a combination. For example:
    DEV dvTouchPanels[] = {dvKitchenTP, dvLivingRmTP,dvOtherTP, ...}
    INTEGER nButtons[] = { 1, 2, 3, 4, 5, 6, ...}
    
    BUTTON_EVENT [dvTouchPanels, nButtons]
    

    You can use GET_LAST(nButtons) or DEVICE.INPUT.CHANNEL to determine what button was pressed, and if you have variations among the panels (like audio zones), GET_LAST(dvTouchPanels) to find out which panel sent it. I generally make a lookup table for audio zones so I can use

    cIndex = GET_LAST(dvTouchPanels)
    cZone = cZoneLookup(cIndex)

    I can't say I've ever bothered with CHANNEL_EVENTs, so I don't know off-hand how they would apply.
  • Hi,

    I Thinks what you want to do is the command COMBINE_CHANNELS.

    You create a virtual device in the DEFINE_DEVICE section, then on the DATA_EVENT of the master on the ONLINE you write the following line :

    COMBINE_CHANNELS (vdvTP,102, dev_tp_computer,102,dev_tp_kitchen,102,dev_tp_masterbed,102, dev_tp_theater,102)

    So you can now manage the DEVCHAN vdvTP,102 as a real DEVCHAN with every event.

    Hops that can help you

    Fabrice, ACE
  • Re: Need advice learning Netlinx
    Originally posted by amxhobbyist
    I am going insane. Why doesn't this work?

    DEFINE_CONSTANT
        dev devAllTouchPanels[] 		= {dev_tp_computer, dev_tp_kitchen, dev_tp_masterbed, dev_tp_theater}
        devchan dcLivingRoomHalogens	= {devAllTouchPanels,102}
    
    

    Regardless of any other TO/PUSH/CHANNEL/COMBINE issue to make it work, the code syntax is just plain wrong and should not compile IMHO.
    cwpartridge gave a correct description of what you expect dcLivingRoomHalogens to be, but it can't since it is NOT an array.

    dcLivingRoomsHalogens is a pair (device, channel), with ONE device and ONE channel.
    Now to make it work and as explained by other posters, you can either make a DEVCHAN array (i.e. a list of (device, channel) pairs), or an array of devices in combination with an array of channels. Or use COMBINE to basically manage the array for you (from the event handler perspective; COMBINE does more than an array).

    Maybe it's your Perl background: this language is just too easy going when it comes to lists. In Netlinx, unless it is defined as an array, no variable will ever hold more than one single lonely value.

    Fred
  • Thanks for the info. Yeah, thinking this should work comes from Perl. Perl basically eats up everything you give it and just works; the structure is very loose and flexible.

    Anyhow, I'll just add each panel to each devchan structure. It's still infinitely easier to maintain than Axcess, so I really shouldn't be complaining. But it WOULD be nice if the compiler would allow a combination such as this. It would be relatively easy to check if the specified device in a devchan assignment was a dev array, and automatically expand it for you during the compile.
  • Well, yes but.

    For all its flexibility, as a "normal" language programmer, I find it very hard to understand Perl. The "rigidity" of Netlinx is more "pascal" like in spirit and probably more appropriate to the AMX audience.
    And rather than implement the change you propose in the compiler, I'd suggest complaining violently :-)

    And what you need (i.e. the AMX solution for your problem) is really COMBINE_CHANNELS, maybe with a shortcut to allow combining multiple channels of multiple devices in one go instead of channel per channel.

    Now I agree once you have multiple realistic panels, NetLinx is short of handy tools to manage the identifier load, and it relies on hundred of lines of repeated stuff (bar one ID), making changes painful and error prone. But making the language Perl like would not be my suggestion to help there...

    Fred
Sign In or Register to comment.