I am trying to login to an external device via Telnet socket communication that has a user/pass field, but without success. Currently, I can login onto the device (on a Unix machine) with the
telnet command. Upon successful connection, I get this response, where
<input> is my input for each field:
telnet xxx.xxx.xxx.xxx 23
And I am successfully logged on.
I am trying to mimic this with URScript (abridged version):
1 socket_open(“xxx.xxx.xxx.xxx”,23) #Open socket at Telnet port
2 userPrompt = socket_read_string() #Reads "User: "
3 didSendUser = socket_send_line(“username”) #Send username with newline appended
4 passPrompt = socket_read_string() #Reads "Password: "
5 didSendPass = socket_send_line(“password”) #Send password with newline appended
Currently, the program reaches line 4, where it indefinitely times out. I’ve checked the value of
userPrompt, which is as expected: "User: ". Line 3 also executes successfully, as
didSendUser is True.
It seems as though the device is not processing my input, since the device never sends "Password: " back to the program. This makes me think I’ll need a separate thread to handle output, but I want to make sure that is correct before I go through with it.
Thanks in advance.
EDIT: PLEASE READ:
As it turns out, telnet requires not only a newline
\n, but also a carriage return
\r right before hand. For example:
That said, the URScript implementation still hangs up after sending the username. I’ve confirmed my above solution works in a python implementation, so I’ve temporarily resorted to XMLRPC implementation using a python server. I will occasionally troubleshoot the URScript implementation and update if I find a solution.
SOLUTION: This function works for sending string commands via Telnet:
socket_send_byte(13) #send carriage return (CR)
socket_send_byte(10) #send line feed (LF)
Please read my edit.
for my application with telnet command , I use URscript for login User & Password :
for login user :
Did you mean
socket_send_byte(10,“TelnetSocket”), hence byte 13 = CR, 10 = LF?
I had the same problem with telnet with “\n”.
I mean :
1°) socket_send_byte(13,“TelnetSocket”) = CR
As @jbm said, using
socket_send_byte(13) followed by
socket_send_byte(10) seems to work great. Thanks for the suggestion. I’ll mark that as the solution in my original post.