Generic code with different I/Os
Hello,
I have a repeated piece of code in a program but I am stuck with making it 'generic' because of different I/O it's using. A simple version of this is below:
I have a repeated piece of code in a program but I am stuck with making it 'generic' because of different I/O it's using. A simple version of this is below:
PROC routine1()
ErrWrite\I,"Starting..",stEmpty;
SetGO goIF_1_Format,10;
WaitGI giIF_1_Format,10;
ENDPROC
PROC routine2()
ErrWrite\I,"Starting..",stEmpty;
SetGO goIF_2_Format,20;
WaitGI giIF_2_Format,20;
ENDPROC
PROC routine3()
ErrWrite\I,"Starting..",stEmpty;
SetGO goIF_3_Format,30;
WaitGI giIF_3_Format,30;
ENDPROC
As you can see these routine are technically the same only dealing with different I/Os. Any chance to make it one routine and just keep calling it with different I/O as parameter or something?
Thanks
As you can see these routine are technically the same only dealing with different I/Os. Any chance to make it one routine and just keep calling it with different I/O as parameter or something?
Thanks
Tagged:
0
Best Answer
-
Hello,you have to use the argument "VAR" if you want to handover signals to a routine
PROC routineStd(<b>VAR </b>signalgo goOut,<b>VAR </b>signalgi giIn, num nValue)
It is also possible that you use the instruction ALIASIO to connect a real signal name to a signal declaration in your program.Example:PROC myRoutine(num Value)
VAR signalgo goFormat;
VAR signalgi giFormat;
VAR string stSignal;
ErrWrite\I,"Starting..",stEmpty;
stSignal:="goIF_"+ValToStr(Value)+"_Format";
AliasIO stSignal,goFormat;
stSignal:="giIF_"+ValToStr(Value)+"_Format";
AliasIO stSignal,giFormat;
SetGO goFormat,20;
WaitGI giFormat,20;
ENDPROC/BRMicky5
Answers
-
Hello,you can code your routine like this:
PROC routineStd(signalgo goOut, signalgi giIn, num nValue)<br> ErrWrite\I,"Starting..",stEmpty;<br> SetGO goOut,nValue;<br> WaitGI giIn,nValue;<br> ENDPROC<br>
Then call it by: routineStd goIF_1_Format, giIF_1_Format, 10;<br> routineStd goIF_2_Format, giIF_2_Format, 20;<br> routineStd goIF_3_Format, giIF_3_Format, 30;<br>
☑️2024 - RobotStudio® User Group0 -
Hi Denis,
I tried this and at first it gave me an error "signalgi not value type". Did some reading and apparently since signalX is a semi-value type, the only way to use them as parameters are if you declare the parameters as VAR. It kinda makes sense really.
Thanks for your help!0 -
Hi Micky,
Thanks for this. I'll give it a go and keep the forum updated!
Cheers,0 -
Hi Micky,
It works like a charm. Thanks for this!0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 800 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings