Home AMX User Forum AMX Technical Discussion
Options

case of the missing button event

It doesn't do it every time, but most of the time. This button event won't trigger unless I push a button twice. Just rock back and forth between Start and Stop (3 and 4) and you will see.You can see the button press in the Push Message Status Bar, but the code in the event doesn't run, until the second push.

Pushing button 7 which is in a different event works every time.

I stripped the code down to as simple as possible to demonstrate.

Here's a TP file too(mvp-7500):
http://dl.dropbox.com/u/1494916/TESTS.TP4
PROGRAM_NAME='WAT'

DEFINE_DEVICE
dvTP = 10001:1:0

DEFINE_CONSTANT
INTEGER btnStart = 3
INTEGER btnStop = 4
INTEGER btnPause = 5
INTEGER btnReset = 6
INTEGER btnsStates[] = {btnStart,btnStop,btnPause,btnReset}

INTEGER btnsStartedEn[] = {btnStop,btnPause,btnReset}
INTEGER btnsStartedDis[] = {btnStart}

INTEGER btnsStoppedEn[] = {btnStart}
INTEGER btnsStoppedDis[] = {btnStop,btnPause,btnReset}

INTEGER btnsPausedEn[] = {btnStop,btnStart,btnReset}
INTEGER btnsPausedDis[] = {btnPause}

INTEGER btnsResetedEn[] = {btnStart,btnStop}
INTEGER btnsResetedDis[] = {btnPause,btnReset}

DEFINE_TYPE


DEFINE_VARIABLE
VOLATILE INTEGER iSystemState //started, stopped, paused, reset

DEFINE_FUNCTION CHAR[128]EN_STRING(INTEGER _btns[], INTEGER _bEN){
    
    STACK_VAR CHAR _cBtnString[128]
    STACK_VAR INTEGER _i
    //SEND_COMMAND Panel,"'^ENA-500.504&510.515,0'"

    FOR(_i = 1; _i <= MAX_LENGTH_ARRAY(_btns); _i++){
	IF(_i == 1){
	    _cBtnSTring = ITOA(_btns[_i])
	}ELSE {
	    _cBtnSTring = "_cBtnSTring,'&',ITOA(_btns[_i])"
	}
    }
    _cBtnSTring = "'^ENA-',_cBtnSTring,',',ITOA(_bEn)"
    
    RETURN _cBtnSTring
}



DEFINE_START


DEFINE_EVENT
BUTTON_EVENT[dvTP, btnsStates]
{
    PUSH:{
	iSystemState = BUTTON.INPUT.CHANNEL
	SEND_COMMAND dvTP, "'ABEEP'"
	
	SWITCH(iSystemState){
	    CASE btnStart : {
		SEND_STRING 0, "'Start'"
		SEND_STRING 0, EN_STRING(btnsStartedEn,1)
		SEND_STRING 0, EN_STRING(btnsStartedDis,0)
		
		SEND_COMMAND dvTP, EN_STRING(btnsStartedEn,1)
		SEND_COMMAND dvTP, EN_STRING(btnsStartedDis,0)
	    }
	    CASE btnStop : {
		SEND_STRING 0, "'Stop'"
		SEND_STRING 0, EN_STRING(btnsStoppedEn,1)
		SEND_STRING 0, EN_STRING(btnsStoppedDis,0)
		
		SEND_COMMAND dvTP, EN_STRING(btnsStoppedEn,1)
		SEND_COMMAND dvTP, EN_STRING(btnsStoppedDis,0)


	    }
	    CASE btnPause : {
		SEND_STRING 0, "'Pause'"
		
		SEND_STRING 0, EN_STRING(btnsPausedEn,1)
		SEND_STRING 0, EN_STRING(btnsPausedDis,0)
		
		SEND_COMMAND dvTP, EN_STRING(btnsPausedEn,1)
		SEND_COMMAND dvTP, EN_STRING(btnsPausedDis,0)


	    }
	    CASE btnReset : {
		SEND_STRING 0, "'Reset'"
		SEND_STRING 0, EN_STRING(btnsResetedEn,1)
		SEND_STRING 0, EN_STRING(btnsResetedDis,0)
		
		SEND_COMMAND dvTP, EN_STRING(btnsResetedEn,1)
		SEND_COMMAND dvTP, EN_STRING(btnsResetedDis,0)


	    }
	}
	WAIT(2.5){SEND_COMMAND dvTP, "'ABEEP'"}
    }
}
BUTTON_EVENT[dvTP, 7]
{PUSH:
    {
	SEND_COMMAND dvTP, "'ABEEP'"
    }
}
DATA_EVENT[dvTP]
{ONLINE:{ 
    SEND_COMMAND dvTP, "'ADBEEP'"
    }
}
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)

(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *

Comments

  • Options
    ericmedleyericmedley Posts: 4,177
    Interesting. I've never used a constant to declare my button arrays, always a variable.
  • Options
    mushmush Posts: 287
    ericmedley wrote: »
    Interesting. I've never used a constant to declare my button arrays, always a variable.

    Interesting. I've never used a variable to declare my button arrays, always a constant.
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    travis wrote: »
    It doesn't do it every time, but most of the time. This button event won't trigger unless I push a button twice. Just rock back and forth between Start and Stop (3 and 4) and you will see.
    I loaded your code and toggled between pushing buttons 3 & 4 with emulate a device and each time I pushed a button the SEND_STRING 0 showed up. I see that you are enabling/disabling buttons via code so I loaded your TP file into an iPad and pushed the real buttons and it still looks okay. Each time I pushed a button there was a change of colors and the SEND_STRING 0 printed out as expected. If you are missing events somewhere in your other code it might be because the button was disabled at that time?

    As far as the CONSTANT button array vs. VARIABLE button array discussion I almost always use CONSTANTs. If the button array is not going to change why make it a variable? No good can become of it. The few times I have used a variable button array is when I wanted to change the contents of the button array in which case I needed to call REBUILD_EVENT each time. So unless there is a good reason why the button array should be a variable I stick with constants.
  • Options
    travistravis Posts: 180
    Thanks for checking. It does it to me when I use Emulate A Device too. And I showed someone else in the office on the TP, so I don't think I'm doing anything silly like pushing a disabled button. I'm going to try it on an ipad. My controller is an NI-700.


    edit
    If I put a long enough Wait in, it runs the event every time...
    WAIT(2){
    		SEND_COMMAND dvTP, "EN_STRING(btnsStartedDis,0)"
    	    }
    	    SEND_COMMAND dvTP, "EN_STRING(btnsStartedEn,1)"
    
    Wait(1) still has the problem...
  • Options
    AuserAuser Posts: 506
    I have the same issue happening on one particular job when navigating a list (built in software from a bunch of buttons, not using a listbox).

    After pressing the "down" button, no button event is fired the first time I press the "up" button and vice versa. Subsequent button presses (of the same button) fire the event 100% of the time. The obvious similarity between the two circumstances is that button enable/disable commands are being sent to the panel.

    It never got to the top of my list of priorities to fix as the list is only used when configuring the system and it seemed like one of those firmware based bugs that I could burn a lot of time on. I spent a good hour trying to ascertain what was occurring and couldn't get to the bottom of it so left it as was.
    Joe Hebert wrote: »
    As far as the CONSTANT button array vs. VARIABLE button array discussion I almost always use CONSTANTs. If the button array is not going to change why make it a variable? No good can become of it. The few times I have used a variable button array is when I wanted to change the contents of the button array in which case I needed to call REBUILD_EVENT each time. So unless there is a good reason why the button array should be a variable I stick with constants.

    FWIW, you can't pass constant arrays into modules as parameters. I have never encountered problems with "constant" variable integer arrays declared in DEFINE_VARIABLE sections used in events.
  • Options
    viningvining Posts: 4,368
    Auser wrote: »
    FWIW, you can't pass constant arrays into modules as parameters. I have never encountered problems with "constant" variable integer arrays declared in DEFINE_VARIABLE sections used in events.
    I do all the time. You can't pass a constant but I've never had a problem with a constant array. Why I haven't a clue.
  • Options
    dchristodchristo Posts: 177
    You might want to try making a local copy of the parameters you're passing into the function. See this post for some background on a similar problem:

    http://www.amxforums.com/showthread.php?1234-Strange-Occurance

    --D
  • Options
    Thread Drift
    Joe Hebert wrote: »
    As far as the CONSTANT button array vs. VARIABLE button array discussion I almost always use CONSTANTs. If the button array is not going to change why make it a variable? No good can become of it. The few times I have used a variable button array is when I wanted to change the contents of the button array in which case I needed to call REBUILD_EVENT each time. So unless there is a good reason why the button array should be a variable I stick with constants.
    What if you want to pass your button definitions into a Module? An array of variables is the only way to do so, correct? Just make sure you declare the variable as volatile... pretty much the same as declaring the button as a constant from a memory standpoint.

    Sorry for repeating a previous post, I like to tweak Joe just because...
  • Options
    travistravis Posts: 180
    Auser wrote: »
    After pressing the "down" button, no button event is fired the first time I press the "up" button and vice versa. Subsequent button presses (of the same button) fire the event 100% of the time. The obvious similarity between the two circumstances is that button enable/disable commands are being sent to the panel.

    I'm not the only one!
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Maybe you guys found some sort of enable/disable bug in the firmware. What happens if you send the enable/disable commands in the release instead of the push? Does that change the results?
  • Options
    viningvining Posts: 4,368
    B_Clements wrote: »
    What if you want to pass your button definitions into a Module? An array of variables is the only way to do so, correct?
    To repeat what I posted earlier I pass constant arrays or elements of a constant array to modules all the time. You just can't pass a plain constant which to me makes no sense.
    DEFINE_CONSTANT //COUNTS
    
    CHAR AVR_1		= 1 ;
    CHAR AVR_2		= 2 ;
    
    DEFINE_CONSTANT //ARRAYs
    
    DEV dvUI_AVRArry[AVR_NUM_NUM_UIs]= 
    	  {
    	  dvTP_AVR_1,//1st floor
    	  dvTP_AVR_2,//master
    	  dvTP_AVR_3,//purple
    	  dvTP_AVR_4,//blue
    	  dvTP_AVR_5,//pasqaule's
    	  dvTP_AVR_6,//1st fl guest
    	  dvTP_AVR_7,//3rd fl tp no AVR
    	  dvR4_AVR_1,//media	
    	  dvR4_AVR_2,//master	
    	  dvR4_AVR_3,//kitchen	
    	  dvR4_AVR_4,//bar
    	  dvR4_AVR_5,//purple	
    	  dvR4_AVR_6,//blue	
    	  dvR4_AVR_7,//tan	
    	  dvR4_AVR_8 //guest	  
    	  } 
    	  
    DEV dvAVR_Arry[AVR_NUM_AVRs] =     
    	  {	
    	  dvAVR_1,     //1
    	  dvAVR_2      //2
    	  }        
    
    DEV vAVRcom_Arry[AVR_NUM_AVRs] =     
    	  {	
    	  vAVRcom_1,   //1
    	  vAVRcom_2    //2
    	  }               
    
    INTEGER AVR_INSTANCE[AVR_NUM_AVRs] =  
    	  {
    	  AVR_1,
    	  AVR_2
    	  }  
    	  
    CHAR AVR_IP_PORT[AVR_NUM_AVRs][24] =  //if using a serial server or IP  
    	  {
    	  '',//192.168.9.123:4670',
    	  ''	  
    	  }
    
    DEFINE_MODULE 'VAV_DEN_AVR2310_comm'   AVR_COMM_1(vAVRcom_Arry[AVR_1],dvAVR_Arry[AVR_1],AVR_IP_PORT[AVR_1],AVR_INSTANCE[AVR_1],
    						       nDeBug_AVR[AVR_1]) //media
    DEFINE_MODULE 'VAV_DEN_AVR2310_comm'   AVR_COMM_2(vAVRcom_Arry[AVR_2],dvAVR_Arry[AVR_2],AVR_IP_PORT[AVR_2],AVR_INSTANCE[AVR_2],
    						       nDeBug_AVR[AVR_2]) //master
    
  • Options
    Tested with a 1200VG
    Joe Hebert wrote: »
    I loaded your code and toggled between pushing buttons 3 & 4 with emulate a device and each time I pushed a button the SEND_STRING 0 showed up. I see that you are enabling/disabling buttons via code so I loaded your TP file into an iPad and pushed the real buttons and it still looks okay. Each time I pushed a button there was a change of colors and the SEND_STRING 0 printed out as expected. If you are missing events somewhere in your other code it might be because the button was disabled at that time?

    As far as the CONSTANT button array vs. VARIABLE button array discussion I almost always use CONSTANTs. If the button array is not going to change why make it a variable? No good can become of it. The few times I have used a variable button array is when I wanted to change the contents of the button array in which case I needed to call REBUILD_EVENT each time. So unless there is a good reason why the button array should be a variable I stick with constants.

    It consistently missed the button press for me. I found that the TP is getting confused if you slightly delay the second SEND_COMMAND to TP things work fine...
Sign In or Register to comment.