Home AMX User Forum NetLinx Studio

Can a device only have one buffer message?

Trying to read/write to a file for names & numbers. I have tried creating a buffer which didn't work, and data.text clears out other messages as they come in. Never the less, this doesn't work:
BUTTON_EVENT[dcNAMES]
{
    PUSH:
    {
	nCURRENT_NAME = GET_LAST(dcNAMES)
	TO[BUTTON.INPUT]
    }
    HOLD[20]:
    {
	SEND_COMMAND dvTP,"'@AKB-',uPRESETS[nCURRENT_NAME].cNAMES"
    }
    RELEASE:
    {
	WAIT_UNTIL(nDONE)
	{
	    uPRESETS[nCURRENT_NAME].cNAMES = cDATA
	    SEND_COMMAND dvTP_VTC,"'^TXT-',ITOA(nCURRENT_NAME + 499),',0,',uPRESETS[nCURRENT_NAME].cNAMES"
	    fnWRITE_FILE('VTC Presets.csv')
	}
    }
}

BUTTON_EVENT[dcNUMBERS]
{
    PUSH:
    {
	nCURRENT_NUM = GET_LAST(dcNUMBERS)
	TO[BUTTON.INPUT]
    }
    HOLD[20]:
    {
	SEND_COMMAND dvTP,"'@AKP-',ITOA(uPRESETS[nCURRENT_NUM].nNUMBERS)"
    }
    RELEASE:
    {
	WAIT_UNTIL(nDONE)
	{
	    uPRESETS[nCURRENT_NUM].nNUMBERS = nDATA
	    SEND_COMMAND dvTP_VTC, "'^TXT-',ITOA(nCURRENT_NUM + 603),',0,',uPRESETS[nCURRENT_NUM].nNUMBERS"
	    fnWRITE_FILE('VTC Presets.csv')
	}
    }
}

How can I hold a value in one buffer without clearing the other? Is this possible?

Comments

  • ericmedleyericmedley Posts: 4,177
    You can put the get_last statement in both the Hold and release events too.
  • a_riot42a_riot42 Posts: 1,624
    Not sure what you are trying to do here, but I would strongly advise against using wait_until in a button event. Its not incorrect but can lead to some difficult to find bugs. Having written AMX code for 10 years, I've never used it once, nor needed to.
    Paul
  • mjones2620mjones2620 Posts: 86
    ericmedley wrote: »
    You can put the get_last statement in both the Hold and release events too.

    Ahhh, this worked. THANKS!
  • mjones2620mjones2620 Posts: 86
    a_riot42 wrote: »
    Not sure what you are trying to do here, but I would strongly advise against using wait_until in a button event. Its not incorrect but can lead to some difficult to find bugs. Having written AMX code for 10 years, I've never used it once, nor needed to.
    Paul

    I'm parsing the message in the keyboard/keypad and I don't want it to write to file until after the message is parsed. Putting the Get_last in my release statement worked.

    This was code tweaked from my P2 class... they tought us WAIT_UNTIL. I kind of like it.
  • ericmedleyericmedley Posts: 4,177
    mjones2620 wrote: »
    I'm parsing the message in the keyboard/keypad and I don't want it to write to file until after the message is parsed. Putting the Get_last in my release statement worked.

    This was code tweaked from my P2 class... they tought us WAIT_UNTIL. I kind of like it.

    I would agree with a_riot42. If you are parsing for a data string from a UI upon keypad/keyboard entry, I'd probably initiate it in the data_event and then call a function. For example: what happens if the user hits abort on the keypad? Or the panel goes offline? Stuff like that...

    I'm glad the fix worked. :)
  • mjones2620mjones2620 Posts: 86
    ericmedley wrote: »
    I would agree with a_riot42. If you are parsing for a data string from a UI upon keypad/keyboard entry, I'd probably initiate it in the data_event and then call a function. For example: what happens if the user hits abort on the keypad? Or the panel goes offline? Stuff like that...

    I'm glad the fix worked. :)

    If user hits abort I am using the CANCEL_ALL_WAITS function.
  • DHawthorneDHawthorne Posts: 4,584
    mjones2620 wrote: »
    If user hits abort I am using the CANCEL_ALL_WAITS function.

    I wouldn't recommend that. What if you need a wait elsewhere that shouldn't be affected? And what if one gets added 6 months from now, and you forget the cancel_all is in there?
  • viningvining Posts: 4,368
    mjones2620 wrote: »
    If user hits abort I am using the CANCEL_ALL_WAITS function.

    Cancel_all_waits and wait_until should be forgotten and never used. As soon as you think you need them to make something work you should throw out what you've written, get a good night's sleep and start from scratch in the morning. :)
  • viningvining Posts: 4,368
    If you're trying to use a single data event handler to process multiple devs you could do something like this for populating and processing your buffers:
    DEFINE_DEVICE
    
    dvDevice_1	= 5001:1:0;
    dvDevice_2	= 5001:2:0;
    dvDevice_3	= 5001:3:0;
    
    DEFINE_CONSTANT
    
    NUM_DEVs 	= 3;
    
    DEV dvDev_Arry[NUM_DEVs]= 
         {
          dvDevice_1
         ,dvDevice_2
         ,dvDevice_3
         }
    
    DEFINE_VARIABLE
    
    CHAR cDev_Buffers[NUM_DEVs][2048];
    
    DATA_EVENT[dvDev_Arry]
    
         {
         ONLINE:
    	  {
    	  //initialize devs
    	  }
         STRING:
    	  {
    	  STACK_VAR INTEGER nIndx;
    	  
    	  nIndx = GET_LAST(dvDev_Arry);
    	  
    	  cDev_Buffers[nIndx] = "cDev_Buffers[nIndx],DATA.TEXT";
    	  
    	  if(find_string(cDev_Buffers[nIndx],"$0D,$0A",1))
    	       {
    	       //pass the index to the parsing function so you know which dev you're processing
    	       fnParseBuffer(nIndx,REMOVE_STRING(cDev_Buffers[nIndx],"$0D,$0A",1));
    	       }
    	  }
         }
    
Sign In or Register to comment.