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
Everywhere
  • Everywhere
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Members
  3. Shubham_23

Posts by Shubham_23

  • TCP/IP Communication Python and Fanuc

    • Shubham_23
    • March 27, 2024 at 4:31 PM

    Do you mean I should use Big Endian?
    Little_Endian False here means the message is decode in Big_endian only.

  • TCP/IP Communication Python and Fanuc

    • Shubham_23
    • March 26, 2024 at 11:36 PM

    Hello Robot -Forum Fanuc Community, After referring to multiple solution and not being able to solve the issue I am posting my doubt here.

    I am trying to send data from a Python client to move a Fanuc Robot Server in Roboguide. I have the Karel and Socket Programming packages installed on the Roboguide.

    The Data I am sending it in the form of one integer and 6 real values which represents Joint values.

    Here is the Python Client to send the Data. " I can't share the full python code but the The OpenFanucClient constructor sets the IP and Port Message and fanuc_client.process_msg uses Struct to unpack the data and also checks Little Endian. NOTE: Little Endian is False always

    Code
    import socket
    
    
    #Socket Params
    server_ip='127.0.0.1'
    server_port = 12345
    socket_timeout_s = 4
    
    #Sample Message
    test_id  = 1
    test_params = [46.0,16.0,-13.7,100.1,-45.2,-69.5]
    
    
    log = logging.getLogger(__name__) 
    log.addHandler(logging.NullHandler())
    
    # fanuc = OpenFanuc(host=server_ip,port=server_port)
    fanuc_client = OpenFanucClient(server_ip,server_port)
    try:
        #Connect to the server
        fanuc_client.connect()
    
        #Send and receive message
        try:
            fanuc_client.process_msg(OpenFanucMsg(id=test_id,params=test_params))
        except Exception as e:
             print('Failed to process message',e)
    except socket.timeout:
            print("Socket timeout occurred. Connection timed out.")
    except Exception as e:
        print("Error:", e)
    finally:
         fanuc_client.disconnect()
    
    ------------------------------
        packed_data = struct.pack(
                    OpenFanucMsg.packed_data_format(), self.id, *self.default_params
                )
    
        def packed_data_format(cls) -> str:
            """
            Returns the format string that describe the
            data layout when packing and unpacking data.
            """
            fmt = "<" if cls.little_endian else ">"
            fmt += "i" + str(cls.params_len) + "f" #>i6f
            return fmt
    Display More
    Code
    The problem seems to be with Karel Server, as I am not very familiar with the bytes and communication nuances for Fanuc. So, apologies for any naive questions or missing details.
    
    Below is my Karel Code: I have written 4 different cases that I have tried and the error I encountered
    
    
    PROGRAM Claude
    -- translator directive
    %NOPAUSESHFT
    %DEFGROUP  = 1
    %COMMENT = '2023.09.19'
    %STACKSIZE = 4000
    %NOLOCKGROUP
    %NOPAUSE=ERROR+COMMAND+TPENABLE
    -- Missing Environment Groups
    %ENVIRONMENT uif
    %ENVIRONMENT sysdef
    %ENVIRONMENT memo
    %ENVIRONMENT kclop
    %ENVIRONMENT bynam
    %ENVIRONMENT fdev
    %ENVIRONMENT flbt
    %ENVIRONMENT regope
    %INCLUDE klevccdf
    %INCLUDE klevkeys
    %INCLUDE klevkmsk
    -- const declarations
    CONST
        oRunningOk      = 705
        oError          = 706
        timeoutVal      = 60000
        myTim           = 5             -- Timer used as timeout
        myTimeout       = 40000         -- 40 seconds
        myTimOff        = 10000         -- TODO - Check the proper Value
        rPosRet         = 50            -- Position calculated by procedures
        rSelMov         = 150           -- 1 Linear 2 PTP (Point-to-Point)
        rIniRet         = 151           -- Various return registers
    -- program vars
    VAR
        -- file group
        ServerFile      : FILE
        -- integer group
        temp_int        : INTEGER
        stato           : INTEGER       -- status
        recByte         : INTEGER
        codiceErr       : INTEGER       -- Error Code
        entry           : INTEGER
        Ret             : BOOLEAN
        i               : INTEGER       -- Unknown
        porta           : INTEGER       -- port
        faseMain        : INTEGER       -- Main Phase
        fase            : INTEGER       -- Phase
        portaHW         : STRING[20]
        portaSW         : STRING[20]
        ipHMI           : STRING[15]
        temp_str        : STRING[254]
        msg_id          : REAL        -- 'id' written in a message
        msg_params      : ARRAY [9] OF REAL -- 'parameters' written in a message    
        -- Boolean Group
        debug           : BOOLEAN
        -- Array of positions
        aPosizioni      : ARRAY [100] OF XYZWPR -- Similar to temp position
        -- Shared data for receiving and sending data
        bEndFound       : BOOLEAN       -- Unused
        nPezzo          : INTEGER
        I1              : INTEGER
        R1              : REAL
        R2              : REAL
        R3              : REAL
        R4              : REAL
        R5              : REAL
        R6              : REAL
        R7              : REAL
        R8              : REAL
        R9              : REAL    
        PosAttuale      : XYZWPR        -- Current Position
        Counter         : INTEGER       -- Unused
        c               : INTEGER       -- Unused
        CounterRet      : INTEGER       -- Unused
        pzz             : INTEGER       -- Unused
        PhaseOK         : BOOLEAN       -- Unused
        indicePos       : INTEGER
    -- Initialization Server
    ROUTINE IniEth
    VAR
        i : INTEGER
    BEGIN
        faseMain = 0
        fase = 0
        portaSW = '12345'
        portaHW = 'S3:'
        stato = 0
        debug = true
        -- Initialize 'ipHMI' if it is uninitialized
        IF UNINIT(ipHMI) THEN
            ipHMI = '192.168.1.110'
        ENDIF
    END IniEth
    ROUTINE wait_fr_data(neededBytes: INTEGER) : INTEGER
    VAR
        numBytes : INTEGER
    BEGIN
        numBytes = 0 -- Initialize variable to enter the loop
        WHILE (numBytes < neededBytes) DO
            BYTES_AHEAD(ServerFile, numBytes, stato) -- Count bytes received
            Write('Number of Bytes',numBytes,cr)
            IF stato <> 0 THEN
                -- Connection error
                faseMain = 0
                fase = 0
                RETURN(-1)
            ENDIF
            IF (numBytes >= neededBytes) THEN
                RETURN(0)
            ENDIF
            DELAY 1
        ENDWHILE
        RETURN(-1)
    END wait_fr_data
    ROUTINE TestTCP
    VAR
        rit         : INTEGER
        loop1       : BOOLEAN
        posGiunti   : JOINTPOS
        tmp_int     : INTEGER
        io_stato    : INTEGER
        temp_real   : Array[256] of Real
        stri        : String[4]
        i           : INTEGER
    BEGIN
        -- Initialize 'port' if it is uninitialized
        IF UNINIT(porta) THEN
            porta = 12345
        ENDIF
        WHILE TRUE DO
            -- Wait for incoming connections
            MSG_DISCO('S3:', stato)
            CLOSE FILE ServerFile
            -- Initialize Server
            SET_FILE_ATR(ServerFile, ATR_IA)
            -- SET_FILE_ATR(ServerFile,ATR_READAHD)
            MSG_CONNECT('S3:', stato)
            IF stato = 0 THEN
                WRITE('New connection accepted. state=', stato, CR)
                CLR_IO_STAT(ServerFile)
                OPEN FILE ServerFile('rw', 'S3:')
                -- While connection is alive process incoming messages
                io_stato = IO_STATUS(ServerFile)
                WHILE io_stato = 0 DO
                    WRITE('Opening File', CR)
                    -- Case 1: Using Wait_fr_data function 
                    -- IF wait_fr_data(28) < 0 THEN
                        -- Connection error, disconnect from Client and wait for new connection
                        -- TODO: Add error handling and exit
                    -- ELSE
                        DELAY 100
                        Write('Post Delay',cr)
                        --Case 2.0 -- Commenting the Wait_fr_data call : Error Waits at Line 175
                        -- For I = 1 to 9 DO
                        -- WRITE('In Loop',cr)
                        -- Read ServerFile(msg_params[i])
                        -- ENDFOR
                        -- -- CASE 3 -- Error Prints String and some value as shown in the picture RobotForum: Only using 4 bytes
                        -- READ ServerFile(temp_str::4)
                        -- WRITE('String',temp_str::4)
                        --Case 4-- Tried converting those strings to REAL Values resulted in the Syntax error
                        -- CNV_STR_REAL((temp_str::4),I1)
                        -- WRITE('[DEBUG] msg-in:',I1,cr)
    ----------------------------------------------------------------------
    --                      181                     CNV_STR_REAL((temp_str::4),I1) 
    --                                                ^ ERROR
    -- ")" expected.
    --  181                     CNV_STR_REAL((temp_str::4),I1) 
    --                                                ^ ERROR
    -- "," or ")" expected.
    --  181                     CNV_STR_REAL((temp_str::4),I1) 
    --                                                    ^ ERROR
    -- Invalid statement. ";" or new line expected.
    -------------------------------------------------------------------------------
                    -- ENDIF
                    io_stato = IO_STATUS(ServerFile)
                ENDWHILE
                -- Connection with the Client was closed
                WRITE('Connection closed', CR)
            ELSE
                WRITE('Error in accepting new connection. state=', stato, CR)
            ENDIF
        ENDWHILE
        WRITE TPPROMPT('Disconnecting..', CR)
        MSG_DISCO('S3:', stato)
        CLOSE FILE ServerFile
        WRITE TPPROMPT('Done', CR)
    END TestTCP
    -- Main Function
    BEGIN
        IniEth
        TestTCP
    END Claude
    Display More

    Image: Case 3
    Thanks
    Shubham

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics
  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