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:

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

Hello,
you can code your routine like this:

  PROC routineStd(signalgo goOut, signalgi giIn, num nValue)
    ErrWrite\I,"Starting..",stEmpty;
    SetGO goOut,nValue;
    WaitGI giIn,nValue;
  ENDPROC

Then call it by:

    routineStd goIF_1_Format, giIF_1_Format, 10;
    routineStd goIF_2_Format, giIF_2_Format, 20;
    routineStd goIF_3_Format, giIF_3_Format, 30;

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!

Hello,
you have to use the argument “VAR” if you want to handover signals to a routine

 PROC routineStd(**VAR** signalgo goOut,**VAR** 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

/BR
Micky

Hi Micky,

Thanks for this. I’ll give it a go and keep the forum updated!

Cheers,

Hi Micky,

It works like a charm. Thanks for this!