testDI function

Hello all I would like to know what is the real difference between these two lines
IF DI_mySignal THEN

and the same using IF TesetDI(DI_mySignal) THEN

Both are working but what is the real differenece?

Thank you

Hello,
You can write it like this too:
IF DI_mysignal=1 THEN
or
IF DI_mysignal=high THEN

But if you define badly DI_mysignal nothing happens in syntax check.
TestDI have a signaldi parameter, so it have to be defined as this.
And TestDI handles errors:

The following recoverable errors are generated and can be handled in an error handler. The system variable ERRNO will be set to:

Error handling

Name

Cause of error

ERR_NO_ALIASIO_DEF

The signal variable is a variable declared in RAPID. It has not been connected to an I/O signal defined in the I/O configuration with instruction AliasIO.

ERR_NORUNUNIT

There is no contact with the I/O device.

ERR_SIG_NOT_VALID

The I/O signal cannot be accessed. The reasons can be that the I/O device is not running or an error in the configuration (only valid for ICI field bus).

Hello,

the difference is that function “TESTDI” returns a boolean value (True or False) instead of “high” and “low”.
I think there is no additional error check inside this function.

The function will probably look like this:

FUNC bool TESTDI(VAR signaldi Signal)
  RETURN Signal = high;
ERROR
  RAISE;
ENDFUNC

I think if you use an “IF” statement in your code, it will be faster than calling the TESTDI function.

BR
Micky

I found this code in an older mediapool for S4 generation controllers:

! Test Digital Input
FUNC bool TestDI(VAR signaldi Signal)
IF Signal = 1 THEN
RETURN TRUE;
ELSE
RETURN FALSE;
ENDIF
ENDFUNC

I take the text from documentation.

I see, Denis. Makes me curious if the error is generated in the routine that calls the function or if the function has its error handler which RAISES the error.