missing second button event
Rich Abel
Posts: 104
In a Netlinx system controlling Radia lighting, momentary contact switches are used to generate contact closures. Switch operating logic is: turn light on or off upon release. Ramp light up or down if held.
When a user pushes adjacent light switches on simultaneously, the system only sees one button event.
Device-channel arrays are used for the on and off switches, and the radia module, channel for the loads. The devchan arrays are arranged to share a common index. An integer array is used for the hold state flag for each switch.
The issue isn't electrical, I see the both I/O leds illuminate in testing, yet only one release event registers and only one light is effected. I don't know this for sure, but it seems that one release needs to happen before the second hold or release can commence.
I'm stumped....Anyone have any ideas for me?
Thanks,
Rich Abel
When a user pushes adjacent light switches on simultaneously, the system only sees one button event.
BUTTON_EVENT[dvLSW_ON] { PUSH: // NOT DOING ANYTHING ON PUSH, SHOULD DELETE THIS... { STACK_VAR INTEGER nSW_INDX nSW_INDX = GET_LAST(dvLSW_ON) } HOLD[nHOLDTIME]: { STACK_VAR INTEGER nSW_INDX nSW_INDX = GET_LAST(dvLSW_ON) SEND_STRING dvDEBUG, "'dvLSW_ON HOLD BUTTON_EVENT, nSW_INDX=',ITOA(nSW_INDX),$0D" bRAMP[nSW_INDX] = 1 // SET RAMP FLAG ON[dvLTS[nSW_INDX].DEVICE,(dvLTS[nSW_INDX].CHANNEL + 128)] // START RAMPING UP // RAMP UP CHANNEL IS OFFSET BY +128 } RELEASE: { STACK_VAR INTEGER nSW_INDX nSW_INDX = GET_LAST(dvLSW_ON) SEND_STRING dvDEBUG, "'dvLSW_ON RELEASE BUTTON_EVENT, nSW_INDX=',ITOA(nSW_INDX),$0D" IF(bRAMP[nSW_INDX]) { bRAMP[nSW_INDX] = 0 // CLEAR FLAG OFF[dvLTS[nSW_INDX].DEVICE,(dvLTS[nSW_INDX].CHANNEL + 128)] // STOP RAMPING UP } ELSE { SEND_COMMAND dvLTS[nSW_INDX].DEVICE,"ITOA(dvLTS[nSW_INDX].CHANNEL),'L',cON_PERCENT,'T2',$0D" // DEVCHAN ARRAY DEVICE,"'DEVCHAN ARRAY CHANNEL','L', ON PERCENTAGE,$0D" } // END ELSE } // END RELEASE } // END BUTTON_EVENT[dvLSW_ON]
Device-channel arrays are used for the on and off switches, and the radia module, channel for the loads. The devchan arrays are arranged to share a common index. An integer array is used for the hold state flag for each switch.
The issue isn't electrical, I see the both I/O leds illuminate in testing, yet only one release event registers and only one light is effected. I don't know this for sure, but it seems that one release needs to happen before the second hold or release can commence.
I'm stumped....Anyone have any ideas for me?
Thanks,
Rich Abel
0
Comments
I found this under "Event Handlers" in Netlinx Studio help:
Note: The processing of an event associated with a given member of a device, channel, device-channel, level or device-array must be completed before processing can begin on another event associated with the same array.
I guess I'm breaking that rule in this case since the first button event is still in process when the second button event occurs.
Any suggestions on valid alternate coding approaches to achieve the same functionality accepted....
Rich
One thing that could be going on, if the devchan array has the same exact button device and channel in two places, it will get squirrely because the get_last can only return one value for the array position.
Related to this, if you put a 0 into a devchan array for one of the buttons (thinking it's like a placeholder), the 0 will actually match every possible button. So any function that is a zero will happen all the time no matter what is pressed.
That's a possibility I'll check out.
At my office I setup a master with some switches and have been testing the button event code. Naturally, I can't get it to fail here. However I don't have all of the real devices to run my test with.
Thanks for the suggestion Greg. I'll check that out.
Rich
Yes, i was talking about duplicating the same devchan value in the single array he's diagnosing. Having the same devchan combination used singly in different arrays will not confuse get_last because you can only be looking for the get_last of the array that triggers your current event anyway. Using get_last on an an array that is outside of your current event is also a fun error of another type - it's one of my most common copy/paste errors.
While I agree 100% with Vining in this case I can say that I have found cases where get_last did produce some very squirrelly results or no result at all. I know many of you are super sleuths at this and cannot leave a mystery unsolved and therefore go on fascinating trips to figure it out. I am not always this way myself. If something truly seems to be rattling under the hood, I tend to abandon it pretty quickly. I have my own get_last function called MyGet_last that I grab when I run into issues.
In most cases it something I did to cause it but there are a few where I'm more than certain it's just a ghost in the machine. For the record get_last has served remarkably well.
It could be as simple as a for_loop to check each IO port in question and toggle the corresponding lighting load if that channel is high.