Jump to content
  • 0

Changing a job on a Cognex In-Sight Camera from a UR Robot


Question

Posted

Recently we had a situation where we needed to change a job file on a Cognex In-Sight camera from a UR Robot. 

At first we attempted to do it via Modbus/TCP, but were unable to do so.  So we switched gears and used UR Script.  In the UR Script we use Socket commands to connect to the Cognex camera and use Native Mode commands to perform the job change.

To change a job in Cognex you need to:

  1. Connect on port 23 (Telnet)
  2. Provide username and password
  3. Take the camera offline
  4. Send the job change command
  5. Put the camera back online
  6. Disconnect from the camera

There's more than can be done in terms of fool-proofing and error handling, but this script provides the needed functions to change your job.

Here's the UR Script we created in order to make this work:

# This script uses Sockets in the UR and Native Mode Commands
# to change the job in a Cognex In-Sight Camera

# First thing to do is open a Socket - this is a connection to the Cognex Camera
# The default port for a Native Mode socket is port 23 - TELNET
# Specify the IP address of the camera and port 23
# Name the Socket "CogCam" so that we can refer to the specific socket connection
socket_open("192.168.3.94",23,"CogCam")        #Open Camera UR connection , Port: 23

# The camera should respond with a welcome message and then ask for username
# We do a read from the socket to clear this data
# You could evaluate this response to ensure the port opened correctly
# You could also add a timeout
# socket_read_line(socket_name=’socket_0’, timeout=2)
strOpenResponse=socket_read_line("CogCam")            #get connection response

# Now we need to log into the camera.  The default username is "admin"
# we also need to send Carriage Return and Line Feed characters, so we'll add those
# using bytes with integer value of 13 and 10 respectively
socket_send_string("admin","CogCam")                #Login to Camera 
socket_send_byte(13,"CogCam")
socket_send_byte(10,"CogCam")

# Now we can read the response to the user name - it should now ask for password
# you could evaluate the response, but here we're just clearing the socket 
# of incoming data
# then we'll send an empty string - the default password for admin
EmptySocketData=socket_read_line("CogCam")                    #Empties Queue 
socket_send_string("","CogCam")                                #Password To Camera
socket_send_byte(13,"CogCam")
socket_send_byte(10,"CogCam")

# Now that we should be logged in, again empty the Socket
# then take the camera offline with SO0 command
EmptySocketData=socket_read_line("CogCam")                    #Empties Queue 
socket_send_string("SO0","CogCam")                            #Takes Camera Offline
socket_send_byte(13,"CogCam")
socket_send_byte(10,"CogCam")

# We could parse the response, 0 = fail, 1=pass but we are 
# assuming it worked.
# The advantage of a read is that the script won't send the next
# command until we get a response to the previous command
# Now we send LFJOBNAME.job to the camera to load the job we want
# in this example, our job is 02.job
Status1=socket_read_line("CogCam")
socket_send_string("LF02.job","CogCam")                        #Loads New Job File 
socket_send_byte(13,"CogCam")                
socket_send_byte(10,"CogCam")

# It may take several seconds for the job file to load
# using the socket_read_line without a timeout means we wait for the camera
# to respond to the request
Status2=socket_read_line("CogCam")

# Now that we have a response, we put the camera back online with SO1 command
socket_send_string("SO1","CogCam")                          #Puts Camera Back Online
socket_send_byte(13,"CogCam")
socket_send_byte(10,"CogCam")

# This isn't necessary, but we could check for a 0 or 1 response to see 
# if we are back online or not
Status3=socket_read_line("CogCam")

# Lastly we should close the socket
socket_close("CogCam")

 

JobChangeScript2.script

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...