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

Fanuc Tcp/Ip app with Karel

  • Damek123
  • February 15, 2021 at 2:38 PM
  • Thread is Unresolved
  • Damek123
    Trophies
    2
    Posts
    13
    • February 15, 2021 at 2:38 PM
    • #1

    Greetings,

    I want to make Python app that would communicate with Fanuc robot via TCP/IP. The goal is to select a program to run on TP.

    I believe that I need to use Karel to read data from Python app. Is it possible to get some small piece of code as an example of how to do that?

    I am totally new in Karel so it would be very helpful just to try some simple example of reading data and calling program in Karel via TCP/IP.

    Thank You!

  • hermann
    Reactions Received
    412
    Trophies
    9
    Posts
    2,629
    • February 15, 2021 at 10:00 PM
    • #2

    There are examples in the documentation of Fanuc. See also

    Simple external HMI without PLC?

  • jmd2777
    Reactions Received
    34
    Trophies
    4
    Posts
    193
    • February 17, 2021 at 9:35 PM
    • #3

    Damek,

    Its not a simple process. You will need to rely heavily on the Fanuc manual for Karel.

    Here is an overview:

    1. You must have Karel and User Socket Messaging software option on the robot

    2. Configure a Socket Messaging server in the Host Comm settings of the robot. Pay attention to the SERVER_PORT setting.

    3. Create the Karel program using the Socket commands. These are in the Karel manual. These will look like the following:

    sock_var : FILE

    STATUS : INTEGER

    MSG_CONNECT('S3', STATUS) --Where S3 is the Server you configured for socket messaging.

    OPEN FILE sock_var ('rw', 'S3') --Where sock_var is a variable you declared of type type FILE.

    You will also need the commands READ, WRITE, BYTES_AHEAD, and MSG_DISCO.

  • hermann
    Reactions Received
    412
    Trophies
    9
    Posts
    2,629
    • February 18, 2021 at 8:54 AM
    • #4

    With a request.get() and the above mentioned thread it should be easier to do the task.

  • Damek123
    Trophies
    2
    Posts
    13
    • February 21, 2021 at 7:29 PM
    • #5

    Thank You. I am currently trying to establish a connection between the Fanuc robot in Roboguide and my Python app.

    Is this even possible? I want the robot to be a client and the app needs to act as a server. Is it possible to simulate that kind of connection in Roboguide? Or it needs to be done on a real robot?

    Thank You!

  • hermann
    Reactions Received
    412
    Trophies
    9
    Posts
    2,629
    • February 22, 2021 at 7:37 AM
    • #6

    Roboguide can do that.

  • Damek123
    Trophies
    2
    Posts
    13
    • February 22, 2021 at 10:37 AM
    • #7

    I tried to follow this topic :

    TCP Karel Client not connecting to server

    I did everything exactly the same but I am still not able to connect to my server.

    What am I doing wrong? Do I need to adjust the client tag setup or something if I want to use Roboguide instead of a real robot?

    Thank You!

  • Damek123
    Trophies
    2
    Posts
    13
    • February 22, 2021 at 11:12 AM
    • #8

    I managed to establish a connection. My next question is how to run the Karel program for connecting to the server and collecting data in the background? I don't want to call it from TP. I want to run it every time I start the controller. Is this possible?

  • hermann
    Reactions Received
    412
    Trophies
    9
    Posts
    2,629
    • February 22, 2021 at 12:54 PM
    • #9

    May be Background programs helps.

  • Damek123
    Trophies
    2
    Posts
    13
    • February 23, 2021 at 9:56 AM
    • #10

    I managed to establish a connection and run a simple program in Karel and in TP in parallel.

    But I have a problem with Roboguide. It keeps crashing every time I manage to establish a connection. Also when I run Karel script parallel with a simple TP program (movements between two points) everything starts lagging and robot movements are very slow and in big steps.

    What am I doing wrong? I attached Karel program and TP program.

    -------------------------------

    PROGRAM kc

    %STACKSIZE = 4000

    %NOLOCKGROUP

    %NOPAUSE=ERROR+COMMAND+TPENABLE

    %ENVIRONMENT uif

    %ENVIRONMENT sysdef

    %ENVIRONMENT kclop

    %ENVIRONMENT bynam

    %ENVIRONMENT fdev

    %ENVIRONMENT flbt

    %INCLUDE klevccdf

    %INCLUDE klevkeys

    %INCLUDE klevkmsk


    VAR

    file_var : FILE

    tmp_int : INTEGER

    tmp_str : STRING[128]

    status : INTEGER

    entry : INTEGER

    loop1 : BOOLEAN

    BEGIN

    label::

    SET_FILE_ATR(file_var, ATR_IA)

    SET_VAR(entry, '*SYSTEM*','$HOSTC_CFG[1].$SERVER_PORT',8000,status)

    WRITE(' VAR status = ',status,CR)

    MSG_CONNECT('C1:',status)

    WRITE(' Connect status = ',status,CR)

    IF status = 1 THEN

    GOTO label_2

    ENDIF

    GOTO label

    label_2::

    MSG_PING('C1:',status)

    IF status = 0 THEN

    MSG_DISCO('C1:',status)

    WRITE('Disconnect status=',status,CR)

    GOTO label

    ENDIF

    GOTO label_2

    END kc

    ----------------------------------------------------


    tp program:

    ---------------------------------------------------

    RUN kc

    LBL[1]

    J PR[1] FINE 100%

    J PR[2] FINE 100%

    JLBL[1]

  • jmd2777
    Reactions Received
    34
    Trophies
    4
    Posts
    193
    • February 23, 2021 at 3:17 PM
    • #11

    It looks like you created a loop with your GOTO statements without any DELAY in the loop. In KAREL you need a DELAY in a loop or it will take all of the CPU resources and lockup the controller. Try adding DELAY 50.

  • Damek123
    Trophies
    2
    Posts
    13
    • February 24, 2021 at 6:35 AM
    • #12

    Thank You, I didn't know that. However, I tried to add some delays into the code but it still doesn't work correctly.

    Every time when my loop is iterating in Karel the robot moves with lag. If I put a delay to 3000 for example, the lag occurs every 3 s. Any advice on how to solve that? (I am doing everything in Roboguide for now so I don't know if a real robot will behave in the same way).

  • hermann
    Reactions Received
    412
    Trophies
    9
    Posts
    2,629
    • February 24, 2021 at 7:56 AM
    • #13

    Do you have only one delay in your code? Where exactly.

    Post your actual code. Should look like:

    Code
    ....... blabla ...
    BEGIN
    label::
    
    delay 50 
    
    SET_FILE_ATR(file_var, ATR_IA)
    SET_VAR(entry, '*SYSTEM*','$HOSTC_CFG[1].$SERVER_PORT',8000,status)
    WRITE(' VAR status = ',status,CR)
    MSG_CONNECT('C1:',status)
    WRITE(' Connect status = ',status,CR)
    IF status = 1 THEN
     GOTO label_2
    ENDIF
    GOTO label
    label_2::
    
    delay 50 
    
    MSG_PING('C1:',status)
    IF status = 0 THEN
     MSG_DISCO('C1:',status)
     WRITE('Disconnect status=',status,CR)
     GOTO label
    ENDIF
    GOTO label_2
    END kc
    Display More
  • Damek123
    Trophies
    2
    Posts
    13
    • February 24, 2021 at 8:05 AM
    • #14

    PROGRAM kc

    %STACKSIZE = 4000

    %NOLOCKGROUP

    %NOPAUSE=ERROR+COMMAND+TPENABLE

    %ENVIRONMENT uif

    %ENVIRONMENT sysdef

    %ENVIRONMENT kclop

    %ENVIRONMENT bynam

    %ENVIRONMENT fdev

    %ENVIRONMENT flbt

    %INCLUDE klevccdf

    %INCLUDE klevkeys

    %INCLUDE klevkmsk


    VAR

    file_var : FILE

    tmp_int : INTEGER

    tmp_str : STRING[128]

    status : INTEGER

    entry : INTEGER

    loop1 : BOOLEAN

    s : STRING[25]

    BEGIN

    MSG_DISCO('C1:',status)

    label::

    DELAY 100

    SET_FILE_ATR(file_var, ATR_IA)

    SET_VAR(entry, '*SYSTEM*','$HOSTC_CFG[1].$SERVER_PORT',8000,status)

    WRITE(' VAR status = ',status,CR)

    MSG_CONNECT('C1:',status)

    WRITE(' Connect status = ',status,CR)

    DELAY 100

    IF status = 0 THEN

    WRITE(' spojeno',status,CR)

    MSG_DISCO('C1:',status)

    DELAY 100

    WRITE(' Odspojeno',status,CR)

    ENDIF

    DELAY 100

    GOTO label

    END kc

    ---------------------------------------

    Yes, I tried with a few delays but I still get the same behavior.

  • Damek123
    Trophies
    2
    Posts
    13
    • February 24, 2021 at 12:23 PM
    • #15

    Here is the full code. The idea is that the Karel program works in the background and on the Python app demands changes DO and get register values. I tested locally and everything works. The problem is only that when I run simultaneously Karel and TP program (a simple program that moves the robot through few points) the robot in Roboguide starts lagging and moving in big steps. I tried with a few delays but that didn't help. Any other ideas?

    Thank you!

    -----------------------------------------------------

    PROGRAM kc_test

    %STACKSIZE = 4000

    %NOLOCKGROUP

    %NOPAUSE=ERROR+COMMAND+TPENABLE

    %ENVIRONMENT uif

    %ENVIRONMENT sysdef

    %ENVIRONMENT kclop

    %ENVIRONMENT bynam

    %ENVIRONMENT fdev

    %ENVIRONMENT flbt

    %ENVIRONMENT REGOPE

    %INCLUDE klevccdf

    %INCLUDE klevkeys

    %INCLUDE klevkmsk


    VAR

    file_var : FILE

    tmp_int : INTEGER

    tmp_str : STRING[128]

    status : INTEGER

    entry : INTEGER

    loop1 : BOOLEAN

    broj_kom : INTEGER

    status_2 : INTEGER

    broj_kom_str : STRING[128]

    r_val : REAL

    rflag : BOOLEAN

    BEGIN

    MSG_DISCO('C1:',status)

    label::

    DELAY 100

    SET_FILE_ATR(file_var, ATR_IA)

    SET_VAR(entry, '*SYSTEM*','$HOSTC_CFG[1].$SERVER_PORT',8000,status)

    WRITE(' VAR status = ',status,CR)

    MSG_CONNECT('C1:',status)

    WRITE(' Connect status = ',status,CR)

    loop1 = TRUE

    IF status = 0 THEN

    WHILE loop1 = TRUE DO

    DELAY 100

    WRITE('Opening file...',CR)

    OPEN FILE file_var('rw','C1:')

    status = IO_STATUS(file_var)

    IF status = 0 THEN

    WRITE('Waiting to read from server...')

    DELAY 100

    READ file_var(tmp_str::2)

    WRITE('Read: ',tmp_str::2,CR)

    DELAY 100

    IF tmp_str = 'P1' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[5] = ON

    DELAY 500

    ENDIF

    IF tmp_str = 'P2' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[6] = ON

    ENDIF

    IF tmp_str = 'P3' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[7] = ON

    ENDIF

    IF tmp_str = 'P6' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[8] = ON

    ENDIF

    IF tmp_str = 'P9' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[9] = ON

    ENDIF

    IF tmp_str = '12' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[10] = ON

    ENDIF

    IF tmp_str = 'S6' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[11] = ON

    ENDIF

    IF tmp_str = 'S9' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[12] = ON

    ENDIF

    IF tmp_str = '13' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[13] = ON

    ENDIF

    IF tmp_str = '14' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[14] = ON

    ENDIF

    IF tmp_str = 'F6' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[15] = ON

    ENDIF

    IF tmp_str = '15' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[16] = ON

    ENDIF

    IF tmp_str = 'F9' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[17] = ON

    ENDIF

    IF tmp_str = 'CO' THEN

    FOR tmp_int = 1 TO 18 DO

    DOUT[tmp_int] = OFF

    ENDFOR

    DOUT[1] = ON

    DOUT[2] = ON

    ENDIF

    IF tmp_str = '99' THEN

    DOUT[4] = ON

    CLOSE FILE file_var

    MSG_DISCO('C1:',status)

    GOTO label

    ENDIF

    IF tmp_str = 'BR' THEN

    GET_REG(1, rflag, broj_kom, r_val, status_2)

    CNV_INT_STR(broj_kom, 0, 0, broj_kom_str)

    WRITE file_var(broj_kom_str)

    CLOSE FILE file_var

    ENDIF

    IF tmp_str = 'RS' THEN

    SET_REAL_REG(1,0, status_2)

    DELAY 50

    GET_REG(1, rflag, broj_kom, r_val, status_2)

    CNV_INT_STR(broj_kom, 0, 0, broj_kom_str)

    WRITE file_var(broj_kom_str)

    CLOSE FILE file_var

    ENDIF

    CLOSE FILE file_var

    ELSE

    GOTO label

    ENDIF

    ENDWHILE

    ENDIF

    DELAY 200

    GOTO label

    END kc_test

  • jmd2777
    Reactions Received
    34
    Trophies
    4
    Posts
    193
    • February 24, 2021 at 3:44 PM
    • #16

    Its possible that its just the graphics lagging in Roboguide.

  • Damek123
    Trophies
    2
    Posts
    13
    • February 25, 2021 at 6:25 AM
    • #17
    Quote from jmd2777

    Its possible that its just the graphics lagging in Roboguide.

    Yeah, I think so too. I will test it soon on a real robot.

    Thanks!

  • lemon132
    Reactions Received
    2
    Trophies
    2
    Posts
    14
    • July 19, 2021 at 9:42 AM
    • #18

    Hello, may i ask if you tested on a real robot ?

  • echolinq
    Trophies
    2
    Posts
    1
    • January 18, 2022 at 5:07 PM
    • #19

    I don't think there is anyway to do it "out of the box". I think you would have to use the socket messaging option and implement TCP/IP on your own. They way I have done it in the past is use a library that implemented Ethernet/IP messaging and communicated directly to the robot that way. I didn't use python but I have used C# and C++. I'm sure there's probably a python library out there.

    c# implementation:

    https://github.com/rossmann-engineering/EEIP.NET

  • Uli202
    Reactions Received
    1
    Trophies
    1
    Posts
    1
    • June 25, 2025 at 10:27 AM
    • New
    • #20

    Hey,

    I really dont want to seem like advertising FANUC product, but I can highly recommend you to get RMI option from fanuc. RMI (Remote motion interface) is based on TCP/IP, written in python and has everything built in which you are looking for and even more. It is definetly a great add on.

    I believe there is a some also some code examples. Just checkout this source:

    Files · 3270afdd02f1414775b396f532a32e92d4d705ff · Diego Tognelli / fanuc_rmi_ros_node
    ROS node that implements Remote Motion Interface (R912) protocol for communication between ROS and the Fanuc Robot.
    gitlab.cblelectronics.com

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
  • krc5
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • 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
  • krc5
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Similar Threads

  • Running robot from c# app using PCDK

    • G05U
    • November 12, 2018 at 7:12 PM
    • Fanuc Robot Forum
  • Lincoln i400

    • Joshua460
    • September 18, 2018 at 5:14 PM
    • Fanuc Robot Forum

Tags

  • Fanuc
  • karel
  • tp
  • TCP/IP

Users Viewing This Thread

  • 1 Guest
  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