Home AMX User Forum NetLinx Studio

Button & channel events

I seem to be having a hard time grasping Netlinx. Not sure why, as I had great luck with Axcess for years and I've programmed other various languages for over a decade.

Why doesn't the following work? :
DEFINE_CONSTANT
devchan dcLivingRoomLamps[] = {{dev_tp_computer,101}, {dev_tp_kitchen,101}, 
{dev_tp_masterbed,101}, {dev_tp_theater,101}, {dev_ctrl_frontdoor,3}}

DEFINE_LATCHING
[dcLivingRoomLamps]

DEFINE_EVENT
button_event [dcLivingRoomLamps] 	{ push: to[dcLivingRoomLamps] }
channel_event [dcLivingRoomLamps] 	{ on: send_string dev_radia1,"'1L100',13"
					  off: send_string dev_radia1,"'1L0',13" }

It seems so basic but it's driving me crazy. Sometimes, for no apparent reason, the touchpanels get out of sync with the on/off status. And it will actually work backwards, one panel will be off while the others (and the lights) are on, and they'll all toggle each other.

Please advise.

Comments

  • Hi amxhobbyist
    I assume that you have the panels all set to
    " page tracking " and have them combined within the program.
  • frthomasfrthomas Posts: 176
    OK amxhobbyist,

    dcLivingRoomLamps is an array. An array is not a variable or a button or something that can be pushed. It is only a container for a number of such items.

    So when in the button_event you TO the array, you're not TOing a state variable for the lamp, you're TOing all the individual buttons.

    Same for the channel event. It will trigger whenever ONE of the buttons inside the array switches from ON to OFF or the reverse.

    In your code, there is nothing that guarantees all buttons are in sync. This is not what an array does. An array is just a programming shortcut to handle mutliple things together.

    Depending on timing, I see as very likely and normal the behavior you're experiencing.

    For example, what you could do it have a viarable to hold the lamp state, toggle it in the button event, and implement a function to turn the lights on or off depending on the variable state. You also need to iterate over the devchan array to set them all to the variable value (if you're using their feedback, which does not seem to be the case in your code).

    Hope this helps

    Fred
  • Thank you for the responses.

    Thomas -- No, all panels are different so I do not combine them, they just have some common elements.

    Fred -- I understand better now. I know how arrays work in typical programming - I guess I just assumed Netlinx was combining the devices for me.

    Perhaps a better way would be to perform all operations on a virtual device, then set [dcLivingRoomLamps] equal to the virtual device in mainline. I'll have to do some playing to find the most efficient way to do this. I don't think holding state in variables is efficient - makes for too many different objects to track in code. In Axcess I relied upon the state of one of my touchpanels, so maybe relying on the state of a virtual device is my best bet under Netlinx.

    Thanks again.
  • DHawthorneDHawthorne Posts: 4,584
    Definitely combine your common buttons with a virtual. Making them an array does not do this automatically, but you can just combine the array with the virtual. Then you can treat the virtual as a single device and everything in the array will just follow it.
  • frthomasfrthomas Posts: 176
    Just for the sake of absolute clarity: For the method proposed by DHawthorne to work, you need to use the DEFINE_COMBINE call, which *is* what syncs the buttons, regardless of them being in the array or not.

    Fred
  • Got it. Very much appreciate your responses.
Sign In or Register to comment.