Home AMXForums Archive Threads AMX Hardware

Telnet ? Push TP button

Joe HebertJoe Hebert Junior MemberPosts: 2,159
Is there a command available to emulate the push of a touch panel button via Telnet?

Thanks,
Joe

Comments

  • JMadsenJMadsen Junior Member Posts: 6
    Telnet ? Push TP button

    Joe,

    I know this is a very old post, but did you, or someone else for that matter, ever find out if this is possible?

    The reason I ask is that I would like to do the same, but can?t see how I can do it from the telnet commands available, which off cause may just tell me the obvious in that it isn?t possible!

    Thanks,

    J
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    JMadsen wrote:
    ...did you, or someone else for that matter, ever find out if this is possible?
    I never found a way.
  • ericmedleyericmedley Senior Member - 4000+ posts Posts: 4,177
    Joe Hebert wrote:
    Is there a command available to emulate the push of a touch panel button via Telnet?

    Thanks,
    Joe
    I suppose failing that you could write your own telnet like routine to get the job done. You'd have to pick a different port number but most telnet programs allow you to choose any port you like. But, then again, using something like Netlinx Diagnostics would do the job very well.
  • NMarkRobertsNMarkRoberts Junior Member Posts: 455
    Try this

    I hacked this out of my environment so you will have to do some work to get it to compile.

    Sorry about the ghastly tabbing, it looks fine in my editor!
    (*** iTelnetServer.axi ***)
    
    (*
    This include contains all the code to accept incoming telnet sessions on selected
    ports and to respond to command line instructions.
    *)
    
    (*
    (******************************************************************************)
    define_device
    (******************************************************************************)
    
    dTelnetServer                                    = 0:3:0
    *)
    
    (******************************************************************************)
    define_constant
    (******************************************************************************)
    
    nTokenCountMax                                   = 100
    
    (******************************************************************************)
    define_variable
    (******************************************************************************)
    
    volatile char    sTelnetServerBuffer[1000]       = ''
    volatile integer bTelnetServerOpen               = False
    volatile integer bTelnetServerOnline             = False
    volatile integer bTelnetServerEcho               = False 
    
    (******************************************************************************)
    define_function TelnetServerSend       (
      char    sArgString[]                 )
    (******************************************************************************)
    {
    (*
    DebugString('TelnetServerSend',sArgString)
    *)
    send_string dTelnetServer,"sArgString,sCRLF"
    } (* TelnetServerSend *)
    
    (******************************************************************************)
    (*
    Listen for incoming telnet connections on a given port
    *)
    define_function integer TelnetServerOpen(
      dev     dArgDevice                   ,
    	integer nArgPort                     )
    (******************************************************************************)
    {
    stack_var integer nMyResult
    stack_var integer bMyServerOpen
    stack_var char    sMyComment[100]
    
    sMyComment                                       = 'TelnetServerOpen'
    
    (*
    DebugNumber("sMyComment,' Local Port[',itoa(dTelnetServer.Port), (* 3,4       *)
    											 ']Server Port'",nArgPort)                 (* 8001,8002 *)
    *)
    nMyResult                                        = type_cast(ip_server_open(dTelnetServer.Port,  (* Local port to open       *)
                                                                                nArgPort          ,  (* Server port to listen on *)
    																																					  ip_tcp) * -1)
    
    bMyServerOpen                                    = False
    
    switch (nMyResult)
      {
    	case 0: 
    	  {
    		Debug("sMyComment,' successful'")
    		bMyServerOpen                                = True
    		}
    		
    	case 1: 
    	  {
    		Error("sMyComment,' invalid server port'")
    		}
    		
    	case 2: 
    	  {
    		Error("sMyComment,' invalid value for Protocol'")
    		}
    	case 3: 
    	  {
    		Error("sMyComment,' unable to open communication port'")
    		}
    	
    	default: 
    	  {
    		ErrorNumber("sMyComment,' unknown result'",nMyResult)
    		}
    	}
    	
    return bMyServerOpen;
    } (* TelnetServerOpen *)
    
    (******************************************************************************)
    (*
    Handle string on incoming telnet session
    *)
    define_function TelnetHandleServerBuffer()
    (******************************************************************************)
    {
    stack_var char    sMyString      [1000]
    stack_var char    sMyStringAgain [1000]
    stack_var char    sMyTerminator  [10]
    stack_var char    sMyToken1      [100]
    stack_var char    sMyTokens      [nTokenCountMax][100]
    stack_var integer nMyTokens      [nTokenCountMax]
    stack_var integer nMyTokenCount
    (*
    DebugHex('TelnetHandleServerBuffer',sTelnetServerBuffer)
    *)
    (* When telnet session first established a bunch of junk arrives with top bit set *)
    while (    (StringNotEmpty(sTelnetServerBuffer)          )
           and (   (left_string(sTelnetServerBuffer,1) > '~')   (* Last printable character in ASCII *)
                or (left_string(sTelnetServerBuffer,1) < '!'))) (* First printable characterin ASCII *)
      {
    	sTelnetServerBuffer                              = EndString(sTelnetServerBuffer,2)
    	}
    
    sMyTerminator                                      = "cLF"
    
    while (find_string(sTelnetServerBuffer,sMyTerminator,1))
      {
    	(*
    	DebugHex('Terminator',sTelnetServerBuffer)
    	*)
    	
    	sMyString                                        = remove_string(sTelnetServerBuffer,sMyTerminator,1)
    	sMyString                                        = TruncateString(sMyString) (* Ditch trailing whitespace, CR, LF *)
    	sMyStringAgain                                   = sMyString
    	
    	while (    (StringNotEmpty(sMyString)     )
    	       and (nMyTokenCount < nTokenCountMax))
    		{
    		nMyTokenCount++
    		sMyTokens[nMyTokenCount]                       = RemoveString(sMyString,' ')
    		nMyTokens[nMyTokenCount]                       = atoi(sMyTokens[nMyTokenCount]) (* May fail gracefully *)
    		}
    	
    	(* First token is always a keyword *)
    	sMyToken1                                        = upper_string(sMyTokens[1])
    	
    	(*
    	DebugHex('TelnetHandleServerBuffer Token',sMyTokens[1])
    	*)
    	
    	(* First token is the keyword *)
    	switch (sMyToken1)
    		{			
    		case 'HELLO':
    			{
    			TelnetServerSend('Gidday')
    			}
    			
    		case 'REBOOT': 
    			{
    			TelnetServerSend('Rebooting')
    			RebootController()
    			}
    			
    		case 'PUSH':
    			{
    			(*
    			PUSH <Channel>			
    			Pulse the incoming touchpanel 
    			*)
    			if (   (nMyTokens[2] = 0  )
    					or (nMyTokens[2] > 255))
    				{
    				TelnetServerSend("'Bad channel[',sMyTokens[2],']'")
    				}
    			else
    				{
    				do_push(dTouchpanel,nMyTokens[3])
    				TelnetServerSend("'Pulse channel[',sMyTokens[2],']'")
    				}
    			}
    
    		case '?':
    			{
    			TelnetServerSendHelp()
    			}
    		
    		default:
    			{
    			TelnetServerSend("'iTelnetServer unknown  keyword[',sMyToken1,']'")
    			DebugHex('Unknown keyword',sMyTokens[1])
    			}				
    		}
    	}
    } (* TelnetHandleServerBuffer *)
    
    (******************************************************************************)
    define_function TelnetServerSendHelp   ()
    (******************************************************************************)
    {
    TelnetServerSend("'### Commands are case insensitive ###'    ,sCRLF,
                      '#?         This help'                     ,sCRLF,
    									'#HELLO     How are you doing?'            ,sCRLF,
    									'#REBOOT    Reboot the controller'         ,sCRLF,
    									'#PUSH 128  do_push touchpanel'            ,sCRLF")
    } (* TelnetServerSendHelp *)
    
    (******************************************************************************)
    define_event
    (******************************************************************************)
    
    data_event[dTelnetServer]
      {
      onerror:
        {
    		(*
        ErrorNumber('dTelnetServer onerror',type_cast(data.number))
    		*)
        }
    
    	online:
    		{
    		(* A telnet connection has been made *)
    		(*
    		Debug('dTelnetServer online')		
    		*)
    		TelnetServerSendHelp()
    		bTelnetServerOnline                              = True
    		wait 50
          {
    	    (* Clear the junk that appears at first connection *)
    			sTelnetServerBuffer                            = ''
    	    }
    		}
    	
    	offline:
    		{
    		(* 
    		This happens when a telnet session is disconnected 
    		and it appears to close the server which then needs reopening
    		*)
    		(*
    		Debug('dTelnetServer offline')		
    		*)
    		bTelnetServerOnline                              = False
    		bTelnetServerOpen                                = False (* Prompt server to be reopened *)
    		}
    	
    	string:
    		{
    		(*
    		DebugHex('dTelnetServer string',data.text)
    		*)
    		sTelnetServerBuffer                              = "sTelnetServerBuffer,data.text"
    		if (bTelnetServerEcho)
    		  {
    			send_string dTelnetServer,data.text (* No CRLF *)
    			}
        TelnetHandleServerBuffer()
    		}
    	}
    
    (******************************************************************************)
    define_program
    (******************************************************************************)
    
    wait nTelnetServerOpenDelayTenths
    	{
    	if (not bTelnetServerOpen)
    		{
    		(*
    		Debug("'Open telnet server bOpen[',itoa(bTelnetServerOpen),
    													 ']bOnline[',itoa(bTelnetServerOnline),']'")
    		*)
    		bTelnetServerOpen                            = TelnetServerOpen(dTelnetServer,nTelnetServerPort)
    		}
    	}
    
    (*** End of iTelnetServer.axi ***)
    
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    I hacked this out of my environment so you will have to do some work to get it to compile.
    If you want a CLI, all you need to do are SEND_STRINGs to a VIRTUAL device. Much less work and far less code/overhead. IMO
  • JMadsenJMadsen Junior Member Posts: 6
    I hacked this out of my environment so you will have to do some work to get it to compile.

    That's perfect ? this is exactly what I need!

    Thanks,

    Jesper
Sign In or Register to comment.