Communication between UR and Cognex

Hi all,

I’m having some issues to create a communication between cognex camera and UR10 robot. Please see the same code in below:

Connected:=socket_open(“192.168.1.124”,30008,"socket0)
Wait:1.0
socket_send_string(“admin”,“socket0)
socket_send_byte([13,10],“socket0”)
wait:0.01
ustat2=socket_read_line(“socket0)
wait:0.01
socket_send_string(””,"socket0)
socket_send_byte([13,10],“socket0”)
wait:0.01
pstat=socket_read_line("socket0)
wait:0.01

but not able to login the camera. the screenshot of UR teachpendant screen:

It’s giving error that invalid password. But there is no password. Do you have any idea?

Thanks for your help.

I tried with 2 different Cognex cameras both have the same issue.

Hey Sibel,

Welcome to the forum. First of all let me advice you to use the UR Script instead of Polyscope for the connection. That makes things a lot easier. and readable. Script should be available under the advanced tab, and there you can choose between a single line of code or a file (choose the file).

Which firmware are you running? Below is an example script to connect to the Cognex, but it is designed for firmware version 3.3+.

Let me know if this works for you or if you still get any more problems. Take note that the port and IP should be replaced with the port and IP you setup on the camera.

#Connect to a cognex camera, tested on UR Firmware 3.3

### Configuration of camera settings, adjust where needed ###

port = 10000
ip = "192.168.0.10"
socket_name = "Cognex"


### Connect to camera and return status ###
socket = socket_open(ip, port, socket_name)	
textmsg("Connection successful?: ", socket)


### After connecting the camera first sends a welcome message and asks for username and password ###

receive = socket_read_string(socket_name)
textmsg(receive)

### Send username ###
socket_send_string("admin" , socket_name)
socket_send_byte([13,10], socket_name)

### Receive request for password ###
receive = socket_read_string(socket_name)
textmsg(receive)
	
### Send password ###

socket_send_string("", socket_name)
socket_send_byte(13, socket_name) # Empty string and list of bytes gave some problems in the past, sending them seperate
socket_send_byte(10, socket_name)

receive = socket_read_string(socket_name)
textmsg(receive)

socket_close(socket_name)

Hi Mathijs,

Thank you so much for your reply. I just managed to try it out. It worked. The communication is established but now I have another issue to read the values on the defined cell. It’s giving [0,nan,nan,nan,nan]. Am I missing anything?

Please see below code & in-sight settings in below:

@Mathijs

In-sight setting image

Hey Sibel,

This has to do with the way Cognex sends its data and how the UR Robot expects to receive it.

Because you haven’t shared the firmware version you are running the code below might not work, I am assuming firmware 3.3+ again.

The UR Code looks like it could be working, to be sure try to clear the TCP receive buffer by adding a socket_read_string after the socket_read_ascii_float.

    socket_send_string("GVA009", socket_name)
    socket_send_byte([13,10], socket_name)

    # Expected format of data string: “(x, y, z)” where x, y, and z are floats or integers
    value_count = 4
    timeout = 5
    receive_list = socket_read_ascii_float(value_count , socket_name, timeout)

    ### There is still some data remaining in the camera buffer, we should empty it.
    buf = socket_read_string(socket_name)

    ### Show the resulting list
    textmsg("Received list:", receive_list)

I think your problem probably has to do something with the formatting of your data in Cognex, see screenshot of UR script manual below. You have to add parentheses. You can add them to the Leading and Trailing text option in the In-Sight settings.

image

Hi @Mathijs,

Sorry I forgot to mention about the firmware version. It’s 3.10 . I added String command as per your suggestion. It worked. I managed to receive the data.

Thank you very much for your help & time.

No problem. I am glad things are working now!