Python Forum
Question about sending escape characters by using sendall function (python2.7). - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Question about sending escape characters by using sendall function (python2.7). (/thread-33796.html)



Question about sending escape characters by using sendall function (python2.7). - lzfneu - May-28-2021

Hi all,

I intend to send function strings to my device, and use python 2.7 socket programming and sendall() function, at the end of the command '\r\n' escape characters should be added according to the protocal and I try to write the command in the following lines:

send_str='function_strings'
con.sendall(send_str+'\r\n')

or write the command like this:

con.sendall(send_str+r'\r\n')

however, I did not receive any respond from my device and have no idea how to correctely send the escape characters in sendall function. I have also attached my short code in the attachment.

Thank you very much in advance.


RE: Question about sending escape characters by using sendall function (python2.7). - Gribouillis - May-29-2021

It is very simple. The string '\r\n' contains two characters: a carriage return and a line feed. The string r'\r\n' contains four characters: a backslash, the letter r, another backslash, the letter n. You need to know what the server is expecting but this is independent from Python programming.