Emulate TP Button Press in Code
jabramson
Posts: 106
I would like to emulate a touch panel button press via code. Basically, I have several buttons that do predefined commands. I'd like to be able to "trigger" those buttons from elsewhere in the code, mainly online/offline event handlers.
Here is the main button event
Here is the main button event
BUTTON_EVENT[dvTP1,701] { PUSH: //Something Occurs }
0
Comments
data_event[dvTV]
{
online:
{
do_push (dvTP1,701)
}
}
Although this may look excessive at first code is always read far more times than it is written. By using a logical name for your function if someone else (or even yourself) is working on your code in the future rather than seeing do_push(tp, 1) and then having to locate it and figure our what the hell its intended to do they can take an educated guess based on the function name - then investigate further if required.
If you have a look in Help -> NetLinx Keywords Help form within NetLinx Studio it will provide you with some more info.
Paul
So if you create a function that just calls a do_push I'd probably just use the do_push but if you can send a direct command then by all means do so.
I too have had no issues with DO_PUSH as long as it is running on the same master as the program. However, I've seen issues with DO_PUSH when it references other masters using M2M. I tend to not use it as I typically do more than one master. But, as Vining says, I've never had it give me trouble on the same master.
The unfortunate thing is, a second DO_PUSH doesn't run the "PUSH" again. It simple restarts the DO_RELEASE timer, and until the RELEASE event happens, the PUSH event won't be available.
Take this bit of pseudo code as an example:
if you ran that silly bit of code you'd see: You'd never see the "BUTTON_1 RELEASED".
Another downfall of the DO_PUSH compared to a PULSE is being able to test the state. A pulsed channel can be tested with something like "IF([dvDevice, CHANNEL])". A DO_PUSH however initiates the change on the Input channel (like a regular button press) and, at least as far as I know, you can only test that state if you've followed the PUSH by setting the corresponding channel ON:
I agree with following any DO_PUSH immediately with a DO_RELEASE. This places the release event immediately behind the PUSH and makes the PUSH immediately available for a second use.
I guess my point is, even .1 seconds can be too long when you aren't *absolutely* sure you will *never* want to run a bit of code more than once in a row. I agree with PhreaK that functions are the better way to handle this sort of thing. To me a DO_PUSH is like duct tape; it's fine once and a while to fix the problem at hand, but making a habit of it is a bad idea.
Hi everyone, Was not sure whether I should just reply to this thread as it seems to be quite related to my question, or to start a new thread.. I'm sure someone will tell me!
Okay, On a channel event (a master power switch going off) my colleague had programmed this to shut down the projectors. However, this is not triggering the electric screens to go back up.
What I thought that instead of sending an off string to the projector, I could emulate the " turn off projector 1" button press, so all the events needed would run. Here is the code below:
CHANNEL_EVENT[DIGITALIO,MasterPower1] // Master Power Warnings
{ON: {IF((PowerSaving)&&(Proj1Power)) {do_push: [vPanelOne,2]}} // this is my bodged line
//{ON: {IF((PowerSaving)&&(Proj1Power)) {SEND_STRING PROJ1,ProjPowerOff} //this is my colleagues original line
// IF((PowerSaving)&&(ProjModeSELECT=2)&&(Proj2Power)) {SEND_STRING PROJ2,ProjPowerOff}}
OFF: { }}
FYI, this is what Button_Event[vPanelOne,2] does:
Button_Event[vPanelOne,2] // Projector 1 Power OFF
{Push:
{CALL'PROJ1_POWER_OFF'
ON[PROJ1_COOLING_SWITCH]
ON[Proj1FakeCooling] WAIT 1200 {OFF[Proj1FakeCooling]}
Proj1ErrorTrap = 11
CALL'PROJ1_COOLING'
IF (PROJ2_ON_SWITCH || PROJ2_OFF_SWITCH)
{SWITCH (Proj2Source)
{CASE 'PC': CALL 'PC_SELECT_PROJ2'
CASE 'Laptop': CALL 'LAPTOP_SELECT_PROJ2'
CASE 'Doc Cam': CALL 'DOCCAM_SELECT_PROJ2'
CASE 'DVD': CALL 'DVD_SELECT_PROJ2'
CASE 'VHS': CALL 'VHS_SELECT_PROJ2'}}}}
Also, how do you paste code in not like I have done above? I see it in its own box within a post when most other people do it.. Seems a much more sensible way to do it.
Thanks again,
David
To get the code box, you use the BB code [noparse]" [/noparse][/font][/size]
You'll get this:
See this page for all the BB codes: http://www.amxforums.com/misc.php?do=bbcode
-Nick