RobotStudio event

Proc with argument

Hello

I have mulitple programs wich are all the same but just changing one number

    PROC MoveToPos1()
        SetDO DoMoveToPosition1,1;
        WaitDI DiPosition1,1;
        SetDO DoMoveToPosition1,0;
    ENDPROC

    PROC MoveToPos2()
        SetDO DoMoveToPosition2,1;
        WaitDI DiPosition2,1;
        SetDO DoMoveToPosition2,0;
    ENDPROC

I want to replace them with a single proc with an argument, something like this:

    PROC MoveToPos(num Position)

        SetDO "DoMoveToPosition"+NumToStr(Position,0);,1;
        WaitDI "DiPosition"+NumToStr(Position,0);,1;
      SetDO "DoMoveToPosition"+NumToStr(Position,0);,0;

    ENDPROC

This doesn't work and gives me a type mismatch error. I've tried also with the StrToVal function, but it doesn't work either.

Is there any way to do this?

Thank you



Comments


  • Try this: 

    PROC MoveToPos(num Position)

    %"SetDO DoMoveToPosition"+ValToStr(Position)+",1"%;
    %"WaitDo DiMoveToPosition"+ValToStr(Position)+",1"%;
    %"SetDO DoMoveToPosition"+ValToStr(Position)+",0"%;

    ENDPROC



    Hope it will work out.

    Best regards,
    blind3rr

    blind3rr2013-03-11 01:46:47
    Benteler Maschinenbau CZ



  • [QUOTE=londoneye]Hello
        PROC MoveToPos(num Position)

            SetDO "DoMoveToPosition"+NumToStr(Position,0);,1;
            WaitDI "DiPosition"+NumToStr(Position,0);,1;
          SetDO "DoMoveToPosition"+NumToStr(Position,0);,0;

        ENDPROC



    [/QUOTE]

    The ; shoudn't be inside the calls - only at the end.

    Try remove them.

     Just looked a bit further into it - you can't give SetDO etc. a string as it expect a type of signalDO.

    Mayby this approach can be used?

        PROC MoveToPos(num Position)

            TEST Position
            CASE 1:
                SetDO DoMoveToPosition1,1;
                WaitDI DiPosition1,1;
                SetDO DoMoveToPosition1,0;
            CASE 2:
                SetDO DoMoveToPosition2,1;
                WaitDI DiPosition2,1;
                SetDO DoMoveToPosition2,0;
            DEFAULT:
                TPWrite " No such position exist";
                Stop;
            ENDTEST
        ENDPROC

    Regards, Lars


    DanLars2013-03-11 10:11:45
    Lars Glud
    Danrob A/S

  • [QUOTE=blind3rr]
    Try this: 

    PROC MoveToPos(num Position)

    %"SetDO DoMoveToPosition"+ValToStr(Position)+",1"%;
    %"WaitDo DiMoveToPosition"+ValToStr(Position)+",1"%;
    %"SetDO DoMoveToPosition"+ValToStr(Position)+",0"%;

    ENDPROC



    Hope it will work out.

    Best regards,
    blind3rr

    [/QUOTE]

    It gives me this error

    40226: Name error
     
    Description
    Task T_ROB1: Procedure name
    SetDO DoMoveToPosition3 1
    is not a RAPID identifier excluding
    reserved words

    Actions
    The procedure name, must be a legal
    RAPID identifier not equal to any of
    the reserved words of the RAPID
    language. Change the name expression.

    What is % supposed to do anyway?. I cannot find it in the manual?


  • [QUOTE=londoneye] 
    What is % supposed to do anyway?. I cannot find it in the manual?
    [/QUOTE]

    A text string encapsulated in % will be called as if it where at PROC. Like this:

    PROC main
    var num path := 1;

    %"path" + NumToStr(path,0);% // Calling path1
    path := 2;

    %"path" + NumToStr(path,0);% // Calling path2
    ENDPROC


    PROC path1
    ...
    ENDPROC

    PROC path2
    ...
    ENDPROC

    As far as I can remember :)

    Regards, Lars
    Lars Glud
    Danrob A/S
  • AlexK
    AlexK ✭✭





    Something that would work is to use GetDataVal, for example:
     
    PROC

    MoveToPos(


    num nIO)



    VAR string strInput;


    VAR string strOutput;



    VAR signaldo ioOutput;


    VAR signaldi ioInput;



    VAR string nuStr;



    nuStr := NumToStr(nIO, 0);



    strOutput := "DoMoveToPosition" + nuStr;


    strInput := "DiPosition" + nuStr;



    GetDataVal strOutput, ioOutput;


    GetDataVal strInput, ioInput;



    Set ioOutput;


    WaitDI ioInput, 1;


    Reset ioOutput;


    ENDPROC

    The call would look something like this:

    PROC main()MoveToPos(1);
    MoveToPos(2);
    MoveToPos(3);
    MoveToPos(4);
    ENDPROC

    AlexK2013-03-12 10:44:42
    Best regards
    Alexander Källberg

  • [QUOTE=AlexK]




    Something that would work is to use GetDataVal, for example:
     
    PROC

    MoveToPos(


    num nIO)



    VAR string strInput;


    VAR string strOutput;



    VAR signaldo ioOutput;


    VAR signaldi ioInput;



    VAR string nuStr;



    nuStr := NumToStr(nIO, 0);



    strOutput := "DoMoveToPosition" + nuStr;


    strInput := "DiPosition" + nuStr;



    GetDataVal strOutput, ioOutput;


    GetDataVal strInput, ioInput;



    Set ioOutput;


    WaitDI ioInput, 1;


    Reset ioOutput;


    ENDPROC

    The call would look something like this:

    PROC main()MoveToPos(1);
    MoveToPos(2);
    MoveToPos(3);
    MoveToPos(4);
    ENDPROC

    [/QUOTE]

    That worked!!!!

    Thak you very much
  • AlexK
    AlexK ✭✭



    Your welcome, glad it worked!AlexK2013-03-18 12:08:48
    Best regards
    Alexander Källberg