Need advice learning Netlinx
amxhobbyist
Posts: 90
I am going insane. Why doesn't this work?
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:
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.
0
Comments
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: Same applies to a BUTTON_EVENT.
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:
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 still think there should be a way to combine dev arrays with devchan arrays. Sure would make life easier.
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.
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
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
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.
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