Program Calls

  • You have several different ways of doing it.


    One way is to put in your dat file of the routine an external call


    EXT Program(Int :IN,REAL :IN )



    Then you can call it from your .Src File



    its been a while since ive played with a KRC1, but On a KRC2 you can just define the program as global



    GLOBAL DEF FOO()
    END


    Then you can just call it from anywhere you want.

  • Here is what I am trying to do. Where would I put GLOBAL DEF FOO() ? I am trying to Call a program called A91118.SRC that has all my weld positions.
    END



    1. INI
    2. LOOP
    3. –
    4. ;Push Station Ready Button
    5. WAIT FOR IN 53 ‘STATION READY’ State=TRUE
    6. –
    7. PTP HOME Vel= 100 % Defualt
    8. -
    9. ;Index Table
    10. INDX_TBL ( )
    11. ;Index Complete
    12. –
    13. ;Weld Side A
    14. ;insert program call here
    15. –
    16. –
    17. ;Index Table
    18. INDX_TBL ( )
    19. ;Index Complete
    20. –
    21. ;Weld Side B
    22. ;insert program call here
    23. –
    24. –
    25. PTP HOME Vel= 100 % Defualt
    26. –
    27. ENDLOOP

  • Greetings.
    I am relatively new to KRC programming, but not new to programming itself.
    I have a program in which there are many calls to the same sub-routine, like below (global sub-routine, src/dat):
    04 PTP …
    05 Routine (1)
    06 LIN …
    07 Routine (2)
    08 PTP …
    09 Routine (3)
    10 LIN …
    11 Routine (4)
    12 PTP HOME
    In all the examples I have, the call for a routine is done with the following syntax “Routine ()”, so my question is, what are the incremental for?


    I appreciate your time and effort in answering my question.
    Kai

    "I was gratified to be able to answer promptly, I said 'I don't know'." Mark Twain

  • When you call a routine or function in KRL, any value(s) or variable(s) inside the parentheses are values or variables that are being sent to the called routine. So in your example, ROUTINE() might look something like this:

    Code
    DEF ROUTINE (VariableName :IN)
      DECL INT VariableName
      SWITCH VariableName
      CASE 1
        ; do 1
      CASE 2
        ; do 2
      ENDSWITCH
    END
  • Just one more thing: can I use an integer variable as pointer for the call of the routine, or must it be a constant?


    Example:
    Straight call: Routine()
    Constant pointer call: Routine (3)
    Variable pointer call: Routine(var)


    Thanks again

    "I was gratified to be able to answer promptly, I said 'I don't know'." Mark Twain

  • Passing arguments to a routine or function in KRL can be done two ways: by value, and by reference. This is controlled by the DEF line for the routine:

    Code
    DEF Routine (IntVariable :IN, RealVariable :OUT)
    DECL INT IntVariable
    DECL REAL RealVariable
    END


    Then you call Routine like so:

    Code
    Routine (Var1, Var2)


    Var1 will be unaffected, regardless of what Routine() does to IntVariable. This is because the DEF line sets up IntVariable to only receive the value of Var1 -- hence the :IN. Var2, however, will be affected by whatever Routine() does to RealVariable, due to the :OUT -- this causes the memory location of Var2 to be "shared" to Routine(), rather like sending pointers in C.

Advertising from our partners