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. KUKA 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

CAST_ functions buffer declaration

  • lmonari
  • October 12, 2020 at 9:30 AM
  • Thread is Unresolved
  • lmonari
    Reactions Received
    1
    Trophies
    3
    Posts
    12
    • October 12, 2020 at 9:30 AM
    • #1

    From my experience on KSS 8.3, the buffer array of the CAST_ functions must be locally declared.

    So, for example, this code will result in a compiler error:

    Code
    DEF ExampleError( notLocalBuffer :IN )
        DECL CHAR notLocaBuffer[]
        DECL INT offset, aInt
    
        offset = 0
        CAST_FROM( notLocalBuffer[], offset, aInt )
    END

    while, this will give no error

    Code
    DEF ExampleOk( notLocalBuffer :IN )
        DECL CHAR notLocaBuffer[], localBuffer[4]
        DECL INT offset, aInt
        DECL BOOL res
    
        res = strCopy(localBuffer[], notLocalBuffer[])
        offset = 0
        CAST_FROM( localBuffer[], offset, aInt )
    END

    The same happens with CAST_TO.

    Nothing changes if the buffer is declared as a global variable or if the buffer is passed by reference ( :OUT ).


    Does anyone know why?

    Are there other ways to use the CAST_ functions with not locally defined arrays?


    Thank you for the help

  • dexterv
    Reactions Received
    15
    Trophies
    3
    Posts
    110
    • October 12, 2020 at 12:06 PM
    • #2

    FYI there is a typo, you have notLocaBuffer[] and notLocalBuffer[]

  • Online
    SkyeFire
    Reactions Received
    1,039
    Trophies
    12
    Posts
    9,380
    • October 12, 2020 at 2:50 PM
    • #3
    Quote from lmonari

    this code will result in a compiler error:

    What compiler error, specifically? At which line? Details matter.

  • lmonari
    Reactions Received
    1
    Trophies
    3
    Posts
    12
    • October 12, 2020 at 3:42 PM
    • #4
    Quote from dexterv

    FYI there is a typo, you have notLocaBuffer[] and notLocalBuffer[]

    Yes, sorry for the typo


    Quote from SkyeFire

    What compiler error, specifically? At which line? Details matter.

    At the line with the CAST_ command, the error is "Array index exceeds array limits".

    I attach a screenshot with the code and the error as displayed on the pendant.

    Images

    • Cast_1.PNG
      • 104.46 kB
      • 651 × 578
      • 21
  • Online
    SkyeFire
    Reactions Received
    1,039
    Trophies
    12
    Posts
    9,380
    • October 12, 2020 at 4:08 PM
    • #5

    DEF ExampleError( notLocalBuffer[] :IN )

  • panic mode
    Reactions Received
    1,267
    Trophies
    11
    Posts
    13,033
    • October 12, 2020 at 4:11 PM
    • #6

    so how about those details...? how and where is everything declared and initialized?

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • lmonari
    Reactions Received
    1
    Trophies
    3
    Posts
    12
    • October 12, 2020 at 6:08 PM
    • #7
    Quote from SkyeFire

    DEF ExampleError( notLocalBuffer[] :IN )

    The brackets in the definition of the input array do not affect the problem. The same error persist even with the brackets. as you can see in the attacched image (left side).


    Quote from panic mode

    so how about those details...? how and where is everything declared and initialized?

    My goal is to have a procedure that takes in input a char array of variable lenght and perform a CAST_TO or a CAST_FROM using this array as buffer.

    The example i reported is defined in a file .src with the same name of the procedure, located in a subfolder of KRC:\R1.

    In this particular case the procedure I am showing in the snaps is named "test_cast" and is written in the file "test_cast.src", located in "KRC:\R1\test" folder.


    I also tryed to declare a function instead of a procedure, as shown in the image (right side), but the error persist.

    Thank you for your help

    Images

    • Cast_forum_2.PNG
      • 308.26 kB
      • 1,663 × 779
      • 19
  • panic mode
    Reactions Received
    1,267
    Trophies
    11
    Posts
    13,033
    • October 12, 2020 at 6:40 PM
    • #8

    you are still showing same thing (inside of your sub or function) where runtime variable is declared but ... not answering the question....

    you have not shown how and where external variables are declared and initialized... i am talking about variables PASSED TO your sub or function when your sub or function are called.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • lmonari
    Reactions Received
    1
    Trophies
    3
    Posts
    12
    • October 12, 2020 at 7:14 PM
    • #9
    Quote from panic mode

    [...] i am talking about variables PASSED TO your sub or function when your sub or function are called.

    Here I hope to give you a better example, also with external variable initialized.

    Code
    DEF test_module ( )
    DECL CHAR myBuffer[12]
    DECL INT myInt1, myInt2, myInt3
    DECL INT offset
    
    
    ; Initialize ints
    myInt1 = 10
    myInt2 = 20
    myInt3 = -30
    
    
    ; Cast to myBuffer
    offset = 0
    CAST_TO(myBuffer[], offset, myInt1, myInt2, myInt3) ; this works as the buffer array is defined locally
    
    
    ; Cast from buffer using a subprogram
    castFromInSubprogram(myBuffer[])
    
    
    END
    
    
    DEF castFromInSubprogram( aBuffer[]:IN )
    DECL CHAR aBuffer[]
    DECL INT aInt1, aInt2, aInt3
    DECL INT offset
    
    
    offset = 0
    CAST_FROM(aBuffer[],offset, aInt1, aInt2, aInt3) ; this does not work. Error: "Array index exceeds array limits"
    
    END
    Display More

    All the code above is contained in one single module.

    The error persist if I move the declaration of the char array "myBuffer" in the .dat file of the module.


    Thank you again for your time

  • panic mode
    Reactions Received
    1,267
    Trophies
    11
    Posts
    13,033
    • October 12, 2020 at 8:10 PM
    • #10

    i have tried it on KSS8.5.8 and can see the same behavior.

    passing array is done correctly and works for pretty much all other purposes but clearly CAST_FROM() cannot handle it.

    buffer array CAN be declared in a local DAT for example... but then there is no need to pass it as parameter, it can be used directly.

    problem seem to be only when passing buffer as a as parameter. perhaps has issue with dereferencing.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • lmonari
    Reactions Received
    1
    Trophies
    3
    Posts
    12
    • October 13, 2020 at 9:45 AM
    • #11
    Quote from panic mode

    [...] but clearly CAST_FROM() cannot handle it.

    The same applies to CAST_TO().


    Quote from panic mode

    [...] problem seem to be only when passing buffer as a as parameter. [...]

    Yes. Not only, as you suggesteded, the problem can be avoided declaring the buffer in the local DAT file but also if you declare the buffer as a GLOBAL variable and then using it directly in any subprogram, still without passing it as a parameter.


    Thank you very much for the help

  • panic mode
    Reactions Received
    1,267
    Trophies
    11
    Posts
    13,033
    • October 13, 2020 at 1:47 PM
    • #12

    you are welcome

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

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

Tags

  • KUKA
  • KRL
  • declaration
  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