Handling byte strings over socket

I am trying to communicate with a Haas CNC via their machine data collection, “Q” commands via URScript. Seems simple enough: send a query, read the response.

You can find documentation here: Machine Data Collection - NGC

here is my urscript:

mxConnect = socket_open(ip, port, "sock1")
def haasQuery(q):
	resp = ""
	global i = 0
	while resp == "":
		resp = socket_read_string(socket_name="sock1",timeout=5)
		i = i+1
    return resp

I tried removing the \n in case the socket_send_line() func was already adding it, but got same behavior.

But it seems that polyscope does not like the response from haas. It appears that polyscope takes the response as invalid. i think this is the case because i increments at a much faster rate than the timeout of 5s.

i believe the responses are a byte string. I believe this is the case because I also use a python script to interact with the haas controller from a PC. the raw responses from the haas look like this:

Sent: b'Q600 1100\r\n'
Received: b'\r\x02MACRO, 1100, 1.00\x02\x02\x02v\r>'

Sent: b'Q500\r\n'
Received: b'\r\x02PROGRAM,MDI,ALARM ON,PARTS,3\x17\r>'

I tried specifying prefix and suffix, but the get the same result:

resp = socket_read_string(socket_name="sock1" prefix="\n\x02", suffix="\x17\n", interpret_escape=True, timeout=5)

I can also test the Haas comms with sockettest and PuTTY, so I know it is serving data, responding and I know the IP, Port is correct. Unfortunately, I have no way of “seeing” the traffic.
How can I get this working, and what is happening to the response to make it invalid? I would be happy to just get the raw string back

I tested on the real thing, specifying the correct socket name.

It looks like socket_send_line() only appends “\n”. I need it to append “\r\n”

So let me rephrase my question:

How do I send a socket line ending in “\r\n”? polyscope seems to be adding an extra “” [trying to type “backslash”, this must be part of my problem] when I try to str_cat my string with “\r\n”:


This appears to be the only thing keeping me from developing a “Zero integration required” machine tending URcap for Haas machines…

Here are some socket_sends and their received strings on the “other end” (a python socket logger)

socket_send_string("Q500", socket_name="sock1") >> b'Q500'
socket_send_string("Q500"+"r\n", socket_name="sock1") >> b'Q500r\\n'
socket_send_string("Q500"+"\r\n", socket_name="sock1") >> b'Q500\\r\\n'
socket_send_line("Q500", socket_name="sock1") >> b'Q500\n'
socket_send_line("Q500"+"\r", socket_name="sock1") >> b'Q500\\r\n'
socket_send_line("Q500"+"\r\n", socket_name="sock1") >> b'Q500\\r\\n\n'

I need to send `b'Q500\r\n'`

I just noticed the way this forum is handling the escape chars. you can see the color formatting changes. Is this caused by HTML implementation in polyscope? It seems to be adding an escape to escape my escape, lol.

@roguebuck Did you have any success with talking to the Haas?