# Communication between UR and Cognex

**URL:** <https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274>\
**Category:** Technical questions\
**Created:** [July 23, 2020, 7:01am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274 "2020-07-23T07:01:14Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sibel](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@Sibel](https://www.robotexchange.io/u/Sibel)\
**Post date:** [July 23, 2020, 7:01am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/1 "2020-07-23T07:01:14Z")

</div>

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:

 ![image](https://www.robotexchange.io/uploads/default/original/2X/8/8b2131f1d9e98d22286e0a4d40dc0119949307c5.jpeg)

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

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Sibel](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@Sibel](https://www.robotexchange.io/u/Sibel)\
**Post date:** [July 23, 2020, 7:32am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/2 "2020-07-23T07:32:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mathijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/mathijs/32/7_2.png) [@Mathijs](https://www.robotexchange.io/u/Mathijs)\
**Post date:** [July 24, 2020, 11:53am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/3 "2020-07-24T11:53:00Z")

</div>

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.

```auto
#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)

```

---

<div class="post-metadata">

**Author:** ![Sibel](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@Sibel](https://www.robotexchange.io/u/Sibel)\
**Post date:** [July 29, 2020, 10:00am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/4 "2020-07-29T10:00:31Z")

</div>

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:

 ![image](https://www.robotexchange.io/uploads/default/original/2X/6/680d14b80b097b78cb1077eb521d5be4ab5d31f0.jpeg)

---

<div class="post-metadata">

**Author:** ![Sibel](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@Sibel](https://www.robotexchange.io/u/Sibel)\
**Post date:** [July 29, 2020, 10:01am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/5 "2020-07-29T10:01:41Z")

</div>

@Mathijs

In-sight setting image

 ![image](https://www.robotexchange.io/uploads/default/original/2X/a/a7d1e1d5e12411cac93ea0cf1955feab77abf9c3.jpeg)

---

<div class="post-metadata">

**Author:** ![Mathijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/mathijs/32/7_2.png) [@Mathijs](https://www.robotexchange.io/u/Mathijs)\
**Post date:** [July 29, 2020, 9:39pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/6 "2020-07-29T21:39:37Z")

</div>

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.

```Python
    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](https://www.robotexchange.io/uploads/default/original/2X/5/5541e370468f19de1afbf789574c18cd1a548e6c.png)

---

<div class="post-metadata">

**Author:** ![Sibel](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/s/7993a0/32.png) [@Sibel](https://www.robotexchange.io/u/Sibel)\
**Post date:** [July 30, 2020, 10:19am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/7 "2020-07-30T10:19:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mathijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/mathijs/32/7_2.png) [@Mathijs](https://www.robotexchange.io/u/Mathijs)\
**Post date:** [July 30, 2020, 10:57am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/8 "2020-07-30T10:57:51Z")

</div>

No problem. I am glad things are working now!

---

<div class="post-metadata">

**Author:** ![vascodias24](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@vascodias24](https://www.robotexchange.io/u/vascodias24)\
**Post date:** [March 1, 2023, 12:05pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/9 "2023-03-01T12:05:05Z")

</div>

Hello!

I’m currently working on a similar project  
I have an In-Sight 2800 Vision Sensor (COGNEX) and a UR10 (Universal Robots), and I want to inspect a few points of a part. To do this I need to trigger the camera in each point.

I’m using Ethernet/IP to communicate between both devices.  
I will attached some images, so you can see what I have already done.  
I opened the connection, and when I run the program It’s TRUE, but I didn’t managed to trigger the camera.

Can anyone help?

Regards,

 ![IMG_6540](https://www.robotexchange.io/uploads/default/original/2X/5/5a5ee1f5eac67bbf80e7cea938b4cf3cbd73de82.jpeg)

---

<div class="post-metadata">

**Author:** ![Mathijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/mathijs/32/7_2.png) [@Mathijs](https://www.robotexchange.io/u/Mathijs)\
**Post date:** [March 1, 2023, 5:35pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/10 "2023-03-01T17:35:10Z")

</div>

Hi Vascodias, could you create a new topic for this?

When doing so, could you convert the PolyScope nodes to UR script with a minimal working code example and post it as code like this:

 ![image](https://www.robotexchange.io/uploads/default/original/2X/9/977dae1718667451407d1ecbd550e84d1a80ccc0.png)  
You will get a code block where you can put the code:  
 ![image](https://www.robotexchange.io/uploads/default/original/2X/c/c010e4fd669d33dacb3624dc28417fb053329553.png)

Could you also make a minimal working job file for the In-Sight Explorer? That way I can actually run some tests and figure out the problem pretty fast. If you create your own topic before the weekend I will gladly help you with this problem and you will have a reply / fix by Monday.

---

<div class="post-metadata">

**Author:** ![vascodias24](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/v/7bcc69/32.png) [@vascodias24](https://www.robotexchange.io/u/vascodias24)\
**Post date:** [March 2, 2023, 10:17am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/11 "2023-03-02T10:17:26Z")

</div>

I already create a new topic!

Thanks!

---

<div class="post-metadata">

**Author:** ![Bhavana](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@Bhavana](https://www.robotexchange.io/u/Bhavana)\
**Post date:** [October 1, 2024, 5:54pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/15 "2024-10-01T17:54:39Z")

</div>

Hi, I am working with cognex 9000 series and ur 5, How do I connect cognex to ur-5 using TCP/IP or Ethernet/IP? How do I set up communication and do the script programming to receive data from cognex? please help me if there is any documentation

---

<div class="post-metadata">

**Author:** ![Bhavana](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@Bhavana](https://www.robotexchange.io/u/Bhavana)\
**Post date:** [October 10, 2024, 5:24pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/16 "2024-10-10T17:24:29Z")

</div>

Hey, I also have the similar problem I am using the port 50000, and I have sent the command “DAT” to get the data from the cognex 9912M, In the cognex I have setup TCP/Ip with the host as cognex IP address, and sending data using WriteDevice() I am getting [0,Nan,nan]. I am not sure why? would you be able to help me with this?

 ![WhatsApp Image 2024-10-10 at 1.23.08 PM (2)](https://www.robotexchange.io/uploads/default/original/2X/4/47e9b2cf98bb6121fc067e91d71d7f344b2f8a8c.jpeg)

---

<div class="post-metadata">

**Author:** ![thijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/thijs/32/4_2.png) [@thijs](https://www.robotexchange.io/u/thijs)\
**Post date:** [October 10, 2024, 10:30pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/17 "2024-10-10T22:30:41Z")

</div>

@mathijs I think we should ask our students to write this How-to:

> [@Connect a Cognex camera to a Universal Robot](https://www.robotexchange.io/docs?topic=2921):
>
> How do I read out a Cognex smart camera from a Universal robot?

---

<div class="post-metadata">

**Author:** ![Bhavana](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@Bhavana](https://www.robotexchange.io/u/Bhavana)\
**Post date:** [October 10, 2024, 11:23pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/18 "2024-10-10T23:23:27Z")

</div>

Yeah, that would be helpful. I tried serial native robot protocol in cognex and I sent GV commands from the ur-5, I got the value from the socket\_read\_string() but, when I use socket\_read\_ascii\_float(), I am still getting[0,nan,nan,nan]

---

<div class="post-metadata">

**Author:** ![Mathijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/mathijs/32/7_2.png) [@Mathijs](https://www.robotexchange.io/u/Mathijs)\
**Post date:** [October 11, 2024, 12:52am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/19 "2024-10-11T00:52:09Z")

</div>

You are close!

The socket\_read\_ascii\_float() function expects the data to be formatted like this:

```auto
(123.456, 12.34, 456.78)

```

you can use the [Format String](https://support.cognex.com/docs/is_572/web/EN/ise/Content/Dialogs/formatstringdialog.htm) function and add the brackets as leading and trailing text.

 ![image](https://www.robotexchange.io/uploads/default/original/2X/7/7f595e4a0e45998d2a03ec555a5cd06433af5bb8.png)

You can get rid of the status code by using the socket\_read\_line function (if you have a CB3).

---

<div class="post-metadata">

**Author:** ![Bhavana](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@Bhavana](https://www.robotexchange.io/u/Bhavana)\
**Post date:** [October 16, 2024, 4:21pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/20 "2024-10-16T16:21:39Z")

</div>

Hey Mathijs, that was helpful. Now i can see the float values. I have one more doubt, If I have to move my ur-5 to these positions, do I need to do the hand eye calibration? I converted the pixel values to millimeters and tried to move to the position but, it did not move to the correct place. So I was wondering, If I have to do hand eye caibration?

 ![WhatsApp Image 2024-10-16 at 12.17.15 PM](https://www.robotexchange.io/uploads/default/original/2X/f/fca98d2aa9533a38fb5da8c11b3d0ea4ccbd0365.jpeg)

---

<div class="post-metadata">

**Author:** ![Bhavana](https://www.robotexchange.io/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@Bhavana](https://www.robotexchange.io/u/Bhavana)\
**Post date:** [October 17, 2024, 3:01pm UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/21 "2024-10-17T15:01:44Z")

</div>

I guess I got it, I did the hand eye calibration and then imported the file, the units were in millimeters now. Thank You for the support! It is very helpful.

---

<div class="post-metadata">

**Author:** ![Mathijs](https://www.robotexchange.io/user_avatar/www.robotexchange.io/mathijs/32/7_2.png) [@Mathijs](https://www.robotexchange.io/u/Mathijs)\
**Post date:** [October 18, 2024, 9:41am UTC](https://www.robotexchange.io/t/communication-between-ur-and-cognex/1274/22 "2024-10-18T09:41:54Z")

</div>

Good to hear you solved the problem ☺
