Need some help on program about keywords.
All my greetings.I learn to use this program in my company.
The trouble is , if I could use this codes beblow :
PUSH[device1,chnl1]
{
PUSH[device2,chanl2]
{
"codes to be executed"
}
}
or how can I achieve this perpose to execute the codes under this condition :after push two buttons in certain order.
The trouble is , if I could use this codes beblow :
PUSH[device1,chnl1]
{
PUSH[device2,chanl2]
{
"codes to be executed"
}
}
or how can I achieve this perpose to execute the codes under this condition :after push two buttons in certain order.
Comments
BUTTON_EVENT[devTP,1] BUTTON_EVENT[devTP,2] BUTTON_EVENT[devTP,3] BUTTON_EVENT[devTP,4] BUTTON_EVENT[devTP,5] BUTTON_EVENT[devTP,6] { PUSH: { local_var integer nLastBtn ; stack_var integer nBtn ; nBtn = Button.Input.Channel ; switch (nBtn) { case 1: { ON [devTP,1] ; } case 2: { if (nLastBtn == 1) { ON [devTP,2] ; } } case 3: { //do something or nothing ; } case 4: { //do something or nothing ; } case 5: { //do something or nothing ; } case 6: { //do something or nothing ; } } nLastBtn = nBtn ; } }May I take my project for example, there is a VGA switcher needs to be controled with 8 inputs and 8 outputs.I design the User's interface menu on my touch pannel showing buttons represent for those inputs and outputs,also with a button "SWITCH" .My plan is when User touch AN INPUT-button on touchpannel,then select AN OUTPUT-button and use the "SWITCH" button to confirm . ONCE the controller receive this confirm message,it send a string to switcher to execute this instruction.
so , is this method workable?
This is why i ask for...i'm a beginner in this area.So it is very kind of you to help me out.
Thanks again.
DEFINE_CONSTANT INTEGER NUM_INPUTS = 8 INTEGER NUM_OUTPUTS = 8 INTEGER INPUT_CHANNELS = { 1,2,3,4,5,6,7,8} INTEGER OUTPUT_CHANNELS = { 21,22,23,24,25,26,27,28} DEFINE_MUTUALLY_EXCLUSIVE ([dvTP,1]..[dvTP,8]) BUTTON_EVENT[dvTP,INPUT_CHANNELS] { PUSH: { ON[dvTP,BUTTON.INPUT.CHANNEL] { } BUTTON_EVENT[dvTP,OUTPUT_CHANNELS] { PUSH: { ON[dvTP,BUTTON.INPUT.CHANNEL] { } BUTTON_EVENT[dvTP,APPLY_SWITCH] { PUSH: { STACK_VAR INTEGER CNTR STACK_VAR INTEGER CNTR2 CNTR = 1 WHILE(![dvTP,INPUT_CHANNELS[CNTR]] AND CNTR< NUM_INPUTS) { CNTR++ } IF([dvTP,INPUT_CHANNELS[CNTR]]) { FOR(CNTR2 = 1; CNTR2 <= NUM_OUTPUTS;CNTR2) { IF([dvTP,OUTPUT_CHANNELS[CNTR2]]) SEND_COMMAND vdvSWITCHER,"'INPUT=',ITOA(CNTR),'OUTPUT=',ITOA(CNTR2)" } //Might also want to turn off ALL input and output channels at this point depending on app. } } }I think this is correct, but I don't have time to compile it and try it. Basically, I am using the button feedback to track the selected inputs and outputs to be applied. I made the inputs mutually exclusive to prevent more than one input being selected at once. Make sure the buttons on the touchpanel are set to allow CHANNEL feedback.
Jeff
P.S.
This is written in Netlinx, but it shouldn't be too difficult to switch to Axcess.
My advice is to never depend on button feedback for an evaluation; button feedback should be used only for its main purpose: feedback. If the panel should go offline for any reason, and you're not driving the feedback with a variable - the panel will lose all feedback states. And if you are using a variable to drive feedback - why not just use that for any evaluations; variables don't lose their values unless the program is restarted (except for persistant variables), feedback is lost when a panel goes offline.
Just food for thought . . .
One nice thing about his code is that you can select multiple outputs for a given input and have the code make the switches with one button push. Probably, the Apply_Switch buttons should clear all the input and output selections, as suggested.
Here's another way to do it (I'm sure there are infinitely many ways), though it's not nearly as compact and doesn't allow for multiple outputs for a given input. It's also possible to have an input or output selected without having the appropriate button feedback; a problem that can easily be corrected with a couple feedback lines in main or with a data_event handler. There are other solutions.
I avoid the use of DEFINE_MUTUALLY_EXCLUSIVE just because of personal preference (mostly because it has given me trouble with multiple touchpanel situations) and I also use character variables as integers, which some people may not like. I'm not even sure that I like it, but it works in this case (the type_cast function eliminates warnings).
DEFINE_DEVICE dvTP = 131:1:0 dvSwitcher = 5001:1:0 DEFINE_VARIABLE constant char cInpBtn[] = {1,2,3,4,5,6,7,8} constant char cOutBtn[] = {9,10,11,12,13,14,15,16} constant char cSwitchBtn = 17 char cSwitchIn char cSwitchOut define_function funClearInput() { stack_var char i for(i = 1; i < 9; i++) { off[dvTP,cInpBtn[i]] } } define_function funClearOutput() { stack_var char i for(i = 1; i < 9; i++) { off[dvTP,cOutBtn[i]] } } define_function funSwitch() { send_string dvSwitcher,"ITOA(cSwitchIn),'*',ITOA(cSwitchOut),'!',13" funClearInput() funClearOutput() } DEFINE_EVENT button_event[dvTP,type_cast(cInpBtn)] { push: { funClearInput() cSwitchIn = get_last(cInpBtn) on[button.input] } } button_event[dvTP,type_cast(cOutBtn)] { push: { funClearoUTput() cSwitchOut = get_last(cOutBtn) on[button.input] } } button_event[dvTP,cSwitchBtn] { push: { funSwitch() to[button.input] } }There's probably a dozen other ways to do this and if it works, it works. Everyone has there own preferences and quirks and as long as it works it's not wrong it's just different.
DEFINE_DEVICE dvTPSwitcher = 10001:1:0 ; dvSwitcher = 5001:1:0 ; DEFINE_VARIABLE volatile integer nSwitcherBtnArry[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17} ; BUTTON_EVENT [dvTPSwitcher,nSwitcherBtnArry] { PUSH: { stack_var integer nSwitcherIN ; stack_var integer nSwitcherOUT ; stack_var integer nBtn ; nBtn = get_last(nSwitcherBtnArry) ; Select { ACTIVE (nBtn >= 1 && nBtn <= 8)://select switcher input { stack_var integer i ; nSwitcherIN = nBtn ; for (i = 1 ; i <= 8 ; i ++)//handle input feedback { if (nBtn == i) { ON [dvTPSwitcher,nSwitcherBtnArry[i]] ; } else { OFF [dvTPSwitcher,nSwitcherBtnArry[i]] ; } } } ACTIVE (nBtn >= 9 && nBtn <= 16)://select switcher output { stack_var integer i ; nSwitcherOUT = nBtn ; for (i = 9 ; i <= 16 ; i ++)//handle output feedback { if (nBtn == i) { ON [dvTPSwitcher,nSwitcherBtnArry[i]] ; } else { OFF [dvTPSwitcher,nSwitcherBtnArry[i]] ; } } } ACTIVE (nBtn == 17)://take in & out { TO [dvTPSwitcher,nSwitcherBtnArry[17]] ; send_string dvSwitcher,"ITOA(nSwitcherIN),'*',ITOA(nSwitcherOUT),'!',13,10" ; } } } }edit note: I forgot the push!
added 2nd = to if
Thank you.