Home AMX User Forum NetLinx Studio

How to get Input Text from "text input" button.

Hi everyone,

I have a button, whose type is "text input" and I am trying to get the value from it using NetLinx code.

I tried the following method, but it didn't work:

SEND_COMMAND PANEL,"'?TXT-80,0'" // 80 is the address port of the button

CUSTOM_EVENT[INPUT_BUTTON_IP, 1001] // Text
{
SEND_STRING 0,"'ButtonGet Id=',ITOA(CUSTOM.ID),' Type=',ITOA(CUSTOM.TYPE)"
SEND_STRING 0,"'Flag =',ITOA(CUSTOM.FLAG)"
SEND_STRING 0,"'VALUE1 =',ITOA(CUSTOM.VALUE1)"
SEND_STRING 0,"'VALUE2 =',ITOA(CUSTOM.VALUE2)"
SEND_STRING 0,"'VALUE3 =',ITOA(CUSTOM.VALUE3)"
SEND_STRING 0,"'TEXT =',CUSTOM.TEXT"
SEND_STRING 0,"'TEXT LENGTH =',ITOA(LENGTH_STRING(CUSTOM.TEXT))"
}

When the event is triggered the TEXT is empty or whatever that was initially set in the TEXT property of the specific state.

I guess I am doing something wrong.
Can you please help me out with this issue?

Sincerely,

David Gevorkyan

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    If you are using a text input button, the text is sent to the master when you push the done button (look at the keyboard or keypad popups in the templates). You don't need to request the text, it will generate a string event on port 1 of the touch panel. All you need to do is monitor the Data_Event for the String: to occur.

    Jeff
  • Thanks a lot Jeff,

    That worked perfectly.
    One more question: I want the inputted text to be an IP address, for that reason I tried the following Input Mask - [0|255]{.}[0|255]{.}[0|255]{.}[0|255], but that doesn't work. Is this syntax incorrect?

    Sincerely,

    David
  • Spire_JeffSpire_Jeff Posts: 1,917
    davidgev wrote: »
    Thanks a lot Jeff,

    That worked perfectly.
    One more question: I want the inputted text to be an IP address, for that reason I tried the following Input Mask - [0|255]{.}[0|255]{.}[0|255]{.}[0|255], but that doesn't work. Is this syntax incorrect?

    Sincerely,

    David

    It seems the documentation is a little lacking (an example would be nice :) ), but it looks like { and } are moving to other text fields. I think what you need are literals. Try [0|255]\.[0|255]\.[0|255]\.[0|255]

    Jeff
  • Hi Jeff,

    Thanks again. I tried the proposed version with literals, but that doesn't seem to work.
    Will do the validation in the code, however it would be nice to have it as a mask.

    Sincerely,

    David
  • Joe HebertJoe Hebert Posts: 2,159
    davidgev wrote:
    Will do the validation in the code, however it would be nice to have it as a mask.
    You can accomplish validation with a mask; however, you need to use 4 text inputs (one for each of the dotted quads) instead of one. The help file states you can only have 1 range per text input.

    The attached zip contains a TP file that has an IPKeypad popup which is a copy of the __keypadExtend popup from the system page with a couple of minor tweaks. Five minutes of work.

    You can drop the file into panel preview and you?ll see that you can type the first quad and then hit the dot key to take you to the next quad. Or you can click on any of the text inputs and then type.

    The code below demonstrates the keypad in action for changing an IP. Most of the code is just error trapping for the Abort key and checking to make sure every text input has some data along with a few lines of fluff.

    I?m sure there are better ways but this should give you a good start.

    Have fun.
    DEFINE_DEVICE
    
    dvTP	= 10001:1:0
    
    DEFINE_VARIABLE _
    
    VOLATILE CHAR 		cIPAddress[14] = '192.168.10.11'
    VOLATILE CHAR 		cTempIPAddress[14]
    VOLATILE INTEGER 	nBadEntry
    
    
    DEFINE_EVENT
    
    DATA_EVENT[dvTP] {
    
       ONLINE: {
          SEND_COMMAND dvTP, "'^TXT-1,0,',cIPAddress"
       
       }
    
       STRING: {
          
          // We need to make sure the Abort buton wasn't pushed.
          // And we also need to make sure that none of the quads are empty (an empty field automatically returns an underscore.)
          // Note: Sometimes an empty field doesn't return an _ but I dont' know why.
          SELECT {
          
    	 ACTIVE (FIND_STRING(DATA.TEXT,'IPQUAD1-',1) && !FIND_STRING(DATA.TEXT,'ABORT',1)): {
    
    	    // this is the first of the 4 strings returned, time to reset our stuff
    	    nBadEntry=0
    	    cTempIPAddress = ""
    
    	    REMOVE_STRING(DATA.TEXT,'IPQUAD1-',1)
    	    
    	    IF (FIND_STRING("DATA.TEXT",'_',1)) { //must have left the field blank so let's flag this address as invalid
    	       nBadEntry++
    	    }
    	    ELSE { //we're good so let's start the address
    	       cTempIPAddress = "DATA.TEXT,'.'"
    	    }
    	 
    	 }
    
    	 ACTIVE (FIND_STRING(DATA.TEXT,'IPQUAD2-',1) && !FIND_STRING(DATA.TEXT,'ABORT',1)): {
    
    	    REMOVE_STRING(DATA.TEXT,'IPQUAD2-',1)
    	    
    	    IF (!nBadEntry) {  //skip it if we already know the address is invalid
    	    
    	       IF (FIND_STRING("DATA.TEXT",'_',1)) { //must have left the field blank so let's flag this address as invalid
    		  nBadEntry++
    	       }
    	       ELSE { //we're still good so let's append dotted quad 2
    		  cTempIPAddress = "cTempIPAddress,DATA.TEXT,'.'"
    	       
    	       }
    	       
    	    }
    	 
    	 }
    
    	 ACTIVE (FIND_STRING(DATA.TEXT,'IPQUAD3-',1) && !FIND_STRING(DATA.TEXT,'ABORT',1)): {
    
    	    REMOVE_STRING(DATA.TEXT,'IPQUAD3-',1)
    
    	    IF (!nBadEntry) {  //skip it if we already know address is invalid
    	    
    	       IF (FIND_STRING("DATA.TEXT",'_',1)) { //must have left the field blank so let's flag this address as invalid
    		  nBadEntry++
    	       }
    	       ELSE {  //still rolling so let's append dotted quad 3
    		  cTempIPAddress = "cTempIPAddress,DATA.TEXT,'.'" 	//append dotted quad 3
    	       }
    	    }
    	 
    	 }
    
    	 ACTIVE (FIND_STRING(DATA.TEXT,'IPQUAD4-',1) && !FIND_STRING(DATA.TEXT,'ABORT',1)): {
    
    	    REMOVE_STRING(DATA.TEXT,'IPQUAD4-',1)
    
    	    IF (!nBadEntry) {  //skip it if we already know address is invalid
    	    
    	       IF (FIND_STRING("DATA.TEXT",'_',1)) { //must have left the field blank so let's flag this address as invalid
    		  nBadEntry++
    	       }
    	       
    	       IF (!nBadEntry) {  //if we jumped through all the hoops lets update the address
    	       
    		  cIPAddress = "cTempIPAddress,DATA.TEXT"	//dotted quad address completed
    		  SEND_COMMAND dvTP, "'^TXT-1,0,IP Accepted'"
    		  WAIT 10 SEND_COMMAND dvTP, "'^TXT-1,0,',cIPAddress"
    		  
    	       }
    	    
    	    }
    	    
    	    IF (nBadEntry) {  //IP entry error - flag the user
    	    
    	       SEND_COMMAND dvTP, "'^TXT-1,0,Sorry'"
    	       WAIT 5 SEND_COMMAND dvTP, "'^TXT-1,0,Incomplete Address'"
    	       WAIT 10 SEND_COMMAND dvTP, "'^TXT-1,0,IP Not changed'"
    	       WAIT 20 SEND_COMMAND dvTP, "'^TXT-1,0,',cIPAddress"
    	    
    	    }
    	 
    	 }
    
    
          }
          	 
                
          
       }
    
    }
    
  • Thanks Joe!
  • Joe HebertJoe Hebert Posts: 2,159
    You?re welcome.
    I just noticed that cIPAddress and cTempIPAddress should have been declared with a length of 15 not 14.
Sign In or Register to comment.