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):
socket_send_line(str_cat(q,"\r\n"))
resp = ""
global i = 0
while resp == "":
resp = socket_read_string(socket_name="sock1",timeout=5)
i = i+1
sleep(1)
end
return resp
end
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