# testDI function

**URL:** <https://tech-community.robotics.abb.com/t/testdi-function/8635>\
**Category:** RAPID Programming\
**Tags:** testdi\
**Created:** [January 6, 2019, 12:34pm UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635 "2019-01-06T12:34:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sort](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sort](https://tech-community.robotics.abb.com/u/sort)\
**Post date:** [January 6, 2019, 12:34pm UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635/1 "2019-01-06T12:34:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [January 8, 2019, 11:44am UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635/2 "2019-01-08T11:44:06Z")

</div>

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).

 |

---

<div class="post-metadata">

**Author:** ![Micky](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Micky](https://tech-community.robotics.abb.com/u/Micky)\
**Post date:** [January 8, 2019, 2:31pm UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635/3 "2019-01-08T14:31:13Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [January 8, 2019, 3:30pm UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635/4 "2019-01-08T15:30:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [January 9, 2019, 8:49am UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635/5 "2019-01-09T08:49:24Z")

</div>

I take the text from documentation.

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [January 9, 2019, 6:30pm UTC](https://tech-community.robotics.abb.com/t/testdi-function/8635/6 "2019-01-09T18:30:24Z")

</div>

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.
