Home AMX User Forum NetLinx Studio

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.

Comments

  • viningvining Posts: 4,368
    You mean something like this, where the statement for case 2 (button 2 pushed) will only execute if button 1 was pushed prior to button 2?
    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 ;
    	  }
         }
    	
    
  • Thanks very much for your help .

    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.
  • viningvining Posts: 4,368
    That's a little different and I don't have time right now to respond but if nothing is posted that answers your question I'll respond when I get back.
  • Spire_JeffSpire_Jeff Posts: 1,917
    One solution would be something like this:
    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.
  • jjamesjjames Posts: 2,908
    Spire_Jeff wrote:
    Basically, I am using the button feedback to track the selected inputs and outputs to be applied.
    Yikes!

    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 . . .
  • HedbergHedberg Posts: 671
    I understand why some people don't think it's a good idea (and they may be right), but depending on the context, I don't have a problem with using feedback the way Jeff proposed. (Actually, I like to see feedback statements in button_events even if I have feedback statements elsewhere in the code. I guess it's sort of a belt and suspenders both sort of thing.) In this case, you can't actuate the Apply_Switch button unless the TP is up and running and on the page where the channel select buttons are located. There's very little danger of a user thinking that an input or output channel has been selected when it hasn't . It's really pretty compact and efficient code, I think. It may need a little tweeking to work properly, I haven't tested it either.

    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]
    	}
    }
    	
    
  • viningvining Posts: 4,368
    This is probably the method I would use. Like "Hedberg" I don't rely on the mutally exclusive function and here I'm handling feedback in the button event. I would probably handle button feedback else where and in a different manner but this is the simple route. I didn't compile and test this but it looks ok.

    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
  • I want to express my profound gratitude to all of you for sharing such valuable experience with me.
    Thank you.
Sign In or Register to comment.