Python Forum
Question about sending escape characters by using sendall function (python2.7).
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about sending escape characters by using sendall function (python2.7).
#1
Shocked 
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.
Larz60+ write May-29-2021, 01:47 PM:
Rather than attach,
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you
expect before hitting the "Post Reply/Thread" button.

Attached Files

.py   test1.py (Size: 439 bytes / Downloads: 288)
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Question concerning function of a a socket pkm 4 3,850 Jun-04-2019, 07:48 AM
Last Post: DeaD_EyE
  How to use fcntl.ioctl() to get output buffer of socket after sendall() operation apsaxena 0 4,745 Dec-09-2016, 12:44 PM
Last Post: apsaxena

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020