1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. Fanuc Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

Communication going between cognex and fanuc robot

  • pramtekkar
  • June 5, 2019 at 4:42 PM
  • Thread is Resolved
  • pramtekkar
    Trophies
    3
    Posts
    2
    • June 5, 2019 at 4:42 PM
    • #1

    I am new at socket messaging and got this code for communication between cognex and fanuc. I made few modification.
    I have few doubts.

    Question
    1) What will the code line mp_str='' will do ?
    2) the status of the connection is coming a hug number not a 1 or a 0 ? How should I approach?
    3) What does READ file_var (xs::0::2, ys::0::2, angles::0::2) represent?
    4) READ file_var(mp_str) ?? the file_var will access which file or variable from the cognex? Where am I able to get all the variables read in the fanuc tp pendant?


    PROGRAM SOCKET_MESSAGING
    %COMMENT = 'KL_MAIN V9.1'
    %STACKSIZE = 8096
    %NOLOCKGROUP
    %NOPAUSESHFT
    %NOPAUSE = ERROR + COMMAND + TPENABLE
    %NOBUSYLAMP
    %NOABORT = ERROR + COMMAND
    %INCLUDE KLEVCCDF -- predefined key character code constants
    %INCLUDE KLIOTYPS -- karel IO type definitions
    %INCLUDE KLEVKEYS -- predefined karel key code constants
    %INCLUDE KLEVKMSK -- predefined mask codes for built in functions

    VAR
    file_var : FILE -- for client communication
    tmp_int : INTEGER
    mp_str : STRING[128]
    status : INTEGER -- communication status
    entry : INTEGER
    try : INTEGER
    statuss :STRING[1]
    xs :STRING[9]
    ys :STRING[9]
    angles :STRING[9]
    x :REAL
    y :REAL
    angle :REAL


    CONST
    port_number= 23 --- Socket port number

    BEGIN

    SET_FILE_ATR(file_var, ATR_IA)
    SET_VAR(entry,'*SYSTEM*','$HOSTC_CFG[3].$SERVER_PORT',port_number,status)

    -- Connect the tag
    WRITE TPDISPLAY('Connecting…',CR)
    MSG_DISCO('C3:', status) ----- closing port before start
    -- Need to be called before any tag can be used for socket messgaing (1st parameter is the tag name ,2nd parameter integer that will contain status of the operation)
    MSG_CONNECT ('C3:',status)
    WRITE('Connect Status =',status,CR)
    OPEN FILE file_var('rw','C3:')

    -- Read the In-Sight Welcome message
    WRITE TPDISPLAY('Logging In',CR)
    mp_str =''
    READ file_var(mp_str)
    WRITE TPDISPLAY(mp_str,CR)

    -- Read User: prompt
    READ file_var(mp_str::6::0)
    IF UNINIT(mp_str) THEN
    mp_str = ''
    ENDIF
    WRITE TPDISPLAY(mp_str,CR)
    IF (mp_str <>'User: ') THEN
    WRITE TPDISPLAY('User Failed',CR)
    --Error
    RETURN
    ENDIF

    --Send User Name
    WRITE file_var('admin',CHR(13),CHR(10))

    -- Read Password prompt
    mp_str =''
    READ file_var(mp_str::10::0)
    IF UNINIT(mp_str) THEN
    mp_str = ''
    ENDIF
    WRITE TPDISPLAY(mp_str,CR)
    IF (mp_str <>'Password: ') THEN
    WRITE TPDISPLAY('Password Failed',CR)
    --Error
    RETURN
    ENDIF

    --Send Password
    WRITE file_var('',CHR(13),CHR(10))

    -- Read Login Response
    mp_str =''
    READ file_var(mp_str)
    IF UNINIT(mp_str) THEN
    mp_str = ''
    ENDIF
    WRITE TPDISPLAY(mp_str,CR)
    IF (mp_str <> 'User Logged In') THEN
    WRITE TPDISPLAY('Log In Failed',CR)
    --Error
    RETURN
    ENDIF

    -- Instruction In-Sight to Acquire an Image
    -- (wait for a response)
    WRITE TPDISPLAY('Trigger',CR)
    WRITE file_var ('sw8',CHR(13),CHR(10))

    -- Read Status
    READ file_var (statuss)
    IF statuss <> '1' THEN
    WRITE TPDISPLAY('sw8 Failed',CR)
    RETURN
    ENDIF

    -- Get the value in cell C7
    WRITE TPDISPLAY('Get Value C7',CR)
    WRITE file_var ('gvc007',CHR(13),CHR(10))

    -- Read Status
    READ file_var (statuss)
    IF statuss <> '1' THEN
    WRITE TPDISPLAY('gvc007 Failed',CR)
    RETURN
    ENDIF

    -- Read the data
    -- This will split the information at the quotations "'".
    -- Example String '10.5''9.8''15.9'
    READ file_var (xs::0::2, ys::0::2, angles::0::2)

    --Disconnect Socket
    MSG_DISCO('C3:', status)

    -- Convert the data
    CNV_STR_REAL(xs, x)
    CNV_STR_REAL(ys, y)
    CNV_STR_REAL(angles, angle)
    WRITE TPDISPLAY('X:',x,CR,'Y:',y,CR,'R',Angle,CR)

    END SOCKET_MESSAGING

  • MIRobotGuy
    Reactions Received
    8
    Trophies
    3
    Posts
    34
    • June 7, 2019 at 2:56 PM
    • #2

    Hello,
    Although I am not an expert, I will take a stab at answering these questions...

    1) What will the code line mp_str='' will do ?
    A) This instruction will clear the string before reading it, so that data from the next line will be the only data in this variable, and there will be no residual data.

    2) The status of the connection is coming a hug number not a 1 or a 0 ? How should I approach?
    A) I have created an Excel file that will convert the status value to an error code. Then the error code can be researched in the Fanuc eDocs. I believe this may help point you in the right direction.
    https://www.robot-forum.com/robotforum/too…atus-converter/


    3) What does READ file_var (xs::0::2, ys::0::2, angles::0::2) represent?
    A) This will read the string values from the cognex system. xs, ys, and angles are all strings of 9 characters long. The numbers ::0 and ::2 are format specifiers. Look in the KAREL eDocs under 7.8 FORMATTING TEXT (ASCII) INPUT/OUTPUT for more information about these.

    4) READ file_var(mp_str) ?? the file_var will access which file or variable from the cognex? Where am I able to get all the variables read in the fanuc tp pendant?
    A) similar to #3

    I hope this helps,
    MiRobotGuy

    +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+

    MI Robot Guy

  • Witty
    Trophies
    3
    Posts
    22
    • June 7, 2019 at 5:28 PM
    • #3

    Regarding question 3:
    Take a look at the example string provided: '10.5''9.8''15.9'.

    Code
    READ file_var (xs::0::2, ys::0::2, angles::0::2)

    would cut this example string into substrings to xs, ys, angles with " being the separator. Unfortunately, I can recall, that you can't use " as separator in Cognex - correct my if I'm wrong. So what Cognex might actually send to you will be more like '10.5,9.8,15.9', and you will have to separate the numbers yourself.

    Regarding question 4:
    "The file_var will access which file or variable from the cognex?"
    The ones which you request with Get Value command. In this example code, there's:

    Code
    WRITE file_var ('gvc007',CHR(13),CHR(10))


    So from Fanuc you're sending a command to Cognex, saying: "Get me value of C7". And as an anwer, cognex will send you this value.
    In Cognex In-Sight Explorer you configure the output for the robot system to be available under "Job.Robot.FormatString", so the command to get your inspection results from Cognex would be:

    Code
    WRITE file_var ('gvJob.Robot.FormatString',CHR(13),CHR(10))
  • ESIELI
    Reactions Received
    10
    Trophies
    5
    Posts
    275
    • June 10, 2019 at 4:54 PM
    • #4

    I have done this many times via serial communication. It may differ a little from your code because you're doing socket messaging, but you can see my setup info and code used on my website:
    https://bateautomation.com/2019/01/03/cognex-fanuc-setup/


    Thank you

  • pramtekkar
    Trophies
    3
    Posts
    2
    • July 11, 2019 at 12:36 AM
    • #5

    thank you all for the help. I data format to be transferred from cognex 3d scanner can be in the Ascii type, 16 bit- signed integer and soo on. Please see the attachment. I have created variable in my karel program to accept this data. Ca you please let me know if the variables I declared are wrong and wont accept the data ?
    is my line of code to read the file from cognex application correct?

    PROGRAM Cognex
    %COMMENT = 'KL_SocketMessaging V9.1'
    %STACKSIZE = 8096
    %NOLOCKGROUP
    %NOPAUSESHFT
    %NOPAUSE = ERROR + COMMAND + TPENABLE
    %NOBUSYLAMP
    %NOABORT = ERROR + COMMAND
    %INCLUDE KLEVCCDF -- predefined key character code constants
    %INCLUDE KLIOTYPS -- karel IO type definitions
    %INCLUDE KLEVKEYS -- predefined karel key code constants


    VAR ---- Global Variable declaration
    file_var : FILE -- for client communication
    enc_count: INTEGER
    tmp_int : INTEGER
    tmp_int1 : INTEGER
    tmp_str : STRING[128]
    status : INTEGER -- communication status
    entry : INTEGER
    try : INTEGER
    xs : STRING[128]
    ys : STRING[128]
    angles : STRING[128]
    x : REAL
    y : REAL
    angle : REAL
    comment : STRING[16]
    loop1 :BOOLEAN
    my_pos :XYZWPR


    BEGIN

    MSG_PING('S3:',status)
    WRITE TPDISPLAY('pinging',status)

    SET_FILE_ATR(file_var, ATR_IA)
    SET_VAR(entry,'*SYSTEM*','$HOSTC_CFG[3].$SERVER_PORT',5001,status)

    -- Connect the tag
    WRITE TPDISPLAY('Connecting…',CR)
    MSG_DISCO('S3:', status) ----- closing port before start

    MSG_CONNECT ('S3:',status)
    WRITE('Connect Status =',status,CR)
    loop1= TRUE

    IF status = 0 THEN
    WHILE loop1 = TRUE DO
    WRITE TPDISPLAY('OPENING FILE..',CR)
    OPEN FILE file_var('RW','S3:')
    status=IO_STATUS(file_var)
    IF status = 0 THEN
    FOR tmp_int =1 TO 10 DO
    READ file_var(tmp_str ::10)
    READ file_var(tmp_int ::10)
    IF status <> 0 THEN
    WRITE('Loop Test Fails',CR)
    loop1 = FALSE
    tmp_int = 10
    ENDIF
    ENDFOR
    ENDIF
    ENDWHILE
    ENDIF

    READ file_var(xs::10)
    READ file_var(ys::10)
    READ file_var(ys::10)
    WRITE TPDISPLAY ('disconnecting', CR)
    MSG_DISCO('S3:',status) --Disconnect Socket

    -- Convert the data
    CNV_STR_REAL(xs, x)
    CNV_STR_REAL(ys, y)
    CNV_STR_REAL(angles, angle)
    WRITE TPDISPLAY('X:',x,CR,'Y:',y,CR,'R',Angle,CR)
    END Cognex

    Please let me know how can I proceed to get the right data in the correct format.
    How can I read daa from the cognex file into group inputs?

    Images

    • Capture.PNG
      • 77.9 kB
      • 782 × 553
      • 33
    • cognex data format.jpg
      • 7.62 MB
      • 4,032 × 3,024
      • 52

    Files

    Capture.PNG_thumb 13.7 kB – 211 Downloads cognex data format.jpg_thumb 29.32 kB – 212 Downloads

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download