Calling program using variable?

  • Greetings, before spending too much time on this topic, I would like to know if it is possible to call a program using a set variable that is declared globally. Using KRC4 controller.


    Ex.)
    note this is done in the cell.



    IF statement:
    userinput[] = "20"
    addstring[] = "A"


    concatsum = StrAdd (userinput[], addstring[])


    CWrite ($CMD, STAT, MODE, "RUN /R1 "concatsum[]")


    ENDIF


    so my question is, can I run the contents of concatsum[]?

    Edited once, last by TickTack ().

  • there is couple of things...


    1. you need to FINISH string manipulation BEFORE trying to use it with CWRITE... also those quotation marks are not even in pairs!? Just get userinput[] and whatever you like then put it all into some variable, such as RunMyProgram[]. Then display content of the variable to ensure it is correct....
    2. when using it in CWRITE, use variable name such as CWRITE($CMD,STAT,MODE,RunMyProgram[]). it is easy when previous step is done.
    3. when using any CWRITE command, it is a really good idea to check for status/completion. Most importantly - make sure it is executed ONCE only. this means you need to add some sort of logic that will ensure one shot execution.
    4. need to check if program is already running, correct mode etc.
    5. if this is done in EXT mode should do handshaking like in CELL...

    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

  • Okay thanks for the good advice, i didn't think about monitoring the status.


    and yes i noticed on my first post I didn't do the STRADD correctly, I called the BOOL and not the actual string.


    Do you think it is just as easy to call it thought the .cell? Of course this would be a even bigger gray area for me, but as long as i know it is "possible" then its worth investigating.

  • not sure what you mean... it is a good idea to split problem into smaller ones (modular programming).
    in this case you can put whatever you want (by hand) into string then start the CWRITE command.
    if it does what you want, all you need to do is massage the string into shape depending on what you want to do (check SWRITE for example).
    note, that there are two main tasks on KRC (unless you have multisubmit), they are identified by letters R and S (robot and submit).
    neither of them can be used to .... start itself. command to start R task must be in another task (Submit).


    CELL.SRC is dead simple to use but it is not meant to launch programs the way want (must be statically linked).

    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

  • Thanks, I don't seem to have a issue with manipulation of the string i want to produce.


    To give you a bigger picture, users will generate "one off"offline programs lets say "program_1". end user must enter the number portion only "1". After handshaking and string manipulation, it should run "program_1"


    Im still trying to figure out if its best to launch programs via .sps or .cell....


    what did you mean my statically linked? :hmmm:

  • and how would you normally call program with such name? (hint sufix)
    did you see manual for CWRITE? (hint, same sufix)

    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

  • if you have program module "program_1", you can call it from other program (in same task) by using line of code:


    Code
    program_1()


    notice round brackets after program module name.


    if you want to execute program using CWRITE (in another task), those brackets are still needed, they must be part of your string:


    "RUN /R1/program_1()"

    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

    Edited once, last by panic mode ().

  • oh wow, it seams so simple now that it was explained. Yes i have the Cwrite manual but it didn't go about of the requirements of variables for program calls.


    So .... if i have a variable called myprogram[]...inside that variable MUST be runprogram(). i think thats where i was messing up not including the ()'s.


    :beerchug:

Advertising from our partners