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
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>) *
0
Comments
Interesting. I've never used a variable to declare my button arrays, always a constant.
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.
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...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.
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.
http://www.amxforums.com/showthread.php?1234-Strange-Occurance
--D
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...
I'm not the only one!
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]) //masterIt 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...