# Socket send string issue

**URL:** <https://forum.universal-robots.com/t/socket-send-string-issue/19356>\
**Category:** Technical Questions\
**Created:** [February 18, 2022, 10:44am UTC](https://forum.universal-robots.com/t/socket-send-string-issue/19356 "2022-02-18T10:44:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.hammerton](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@m.hammerton](https://forum.universal-robots.com/u/m.hammerton)\
**Post date:** [February 18, 2022, 10:44am UTC](https://forum.universal-robots.com/t/socket-send-string-issue/19356/1 "2022-02-18T10:44:13Z")

</div>

I have a UR5e polyscope 5.11.7

I’m trying to connect it to a Keyence GT2 sensor via a Keyence DL-EN1 ethernet connector via TCP/IP. (the Keyence expects ASCII code)

I can establish a connection to the unit without any issues.

however when I send the command:  
socket\_send\_string(“M0”,“DL-EN1”) or socket\_send\_string(“M0\r\n”,“DL-EN1”)

I receive on a socket\_read\_string(“DL-EN1”) the error  
“ER,M0,255\r\n” ( 255 indicates “The command format is not correct”)

(I’ve also tried a socket\_send\_line(“M0”,“DL-EN1”) and socket\_send\_line(“M0\r\n”,“DL-EN1”) the effect is the same)

If I make the same connection from my PC using SocketTest v 3 Program  
and send the same information (M0) I receive the correct response m0,+000645125,+000210202.

So to test the syntax I’m sending from the Robot, I set up a socket connection from my UR5e to my PC (again using SocketTest v3 program listening on port 30000 from the robot)  
and using the same commands! the PC receives M0 from the Robot

Its probably me and I’ve missed something simple  
what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 18, 2022, 3:04pm UTC](https://forum.universal-robots.com/t/socket-send-string-issue/19356/2 "2022-02-18T15:04:50Z")

</div>

I’ve never done it before, but in other similar applications, you actually have to escape the quotes themselves like socket\_send\_string(\“MO\”,\“DL-EN1\”). Maybe you could give that a try?

---

<div class="post-metadata">

**Author:** ![anon1947322](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@anon1947322](https://forum.universal-robots.com/u/anon1947322)\
**Post date:** [February 21, 2022, 11:38am UTC](https://forum.universal-robots.com/t/socket-send-string-issue/19356/3 "2022-02-21T11:38:37Z")

</div>

Hi,

just to add we set up a simple python program to replicate the command, which is in bytes

Which sending b’M0/r/n/’

gets us the result.

we are trying to socket send the command through the universal robot.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/f/fdf68867da39ac2f665699a345f03076290fdf37.png)

---

<div class="post-metadata">

**Author:** ![m.hammerton](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@m.hammerton](https://forum.universal-robots.com/u/m.hammerton)\
**Post date:** [February 21, 2022, 11:40am UTC](https://forum.universal-robots.com/t/socket-send-string-issue/19356/4 "2022-02-21T11:40:23Z")

</div>

eric,  
Thanks for your relpy.

> [@eric.feldmann](#):
>
> I’ve never done it before, but in other similar applications, you actually have to escape the quotes themselves like socket\_send\_string(\“MO\”,\“DL-EN1\”). Maybe you could give that a try?

socket\_send\_string(\“M0\”,\“DL-EN1\”)

isn’t accepted by the Robot!

I tried different adaptations of your suggestion but with no affect.

My colleague Chris had some success communicating to the unit with a python program.  
and is seems that it requires a Byte format to correctly send the “M0” and receive a valid reply.

I tried to use the socket\_send\_byte(“M0”)  
but again failed (with "ER,\*\*,255)

---

<div class="post-metadata">

**Author:** ![roguebuck](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/roguebuck/32/4848_2.png) [@roguebuck](https://forum.universal-robots.com/u/roguebuck)\
**Post date:** [February 26, 2022, 1:11am UTC](https://forum.universal-robots.com/t/socket-send-string-issue/19356/5 "2022-02-26T01:11:22Z")

</div>

I may be struggling with a similar issue:

I need to send a string terminated with “\r\n”, but it appears that socket\_send\_line only appends \n. I have tried concatenating “\r” to the end of my string, but the socket\_send\_line function seems to add an extra \. \<\< even right here, i had to type two backslashes to get it to display one. this is expected with escape sequences, but undesired when sending byte strings

edit: i found this today, havent tried it yet: [TCP socket line terminator](https://forum.universal-robots.com/t/tcp-socket-line-terminator/5806)
