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
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=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
[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
AlexK
March 12, 2013, 10:33am
6
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=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
March 18, 2013, 12:08pm
8
Your welcome, glad it worked!