# Compile error: An expression was found which produces a result that is not used

**URL:** <https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226>\
**Category:** URScript\
**Created:** [May 10, 2021, 7:55am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226 "2021-05-10T07:55:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon44063908](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon44063908](https://forum.universal-robots.com/u/anon44063908)\
**Post date:** [May 10, 2021, 7:55am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/1 "2021-05-10T07:55:02Z")

</div>

Hi,

I am trying to define a function in which I have a thread that is checking whether a modbus connection is connected or not. When using the function in my program node I get the following error message: Compile error: An expression was found which produces a result that is not used

```
def my_function():
    global modbus_conn = False
    thread thread_modbus_conn():
        while(True):
            modbus_conn = rpc.ModbusHandler.getModbusConnection()
            if(modbus_conn == False):
                popup("Not connected to modbus. Stopping program", warning=True, blocking=False)
                halt
            end
       sleep(1)
       end
   end
   thread_handler_modbus_conn = run thread_modbus_conn()
end

```

I have looked on the forum and [this](https://forum.universal-robots.com/t/stop-program-when-ur-has-no-connection-to-modbus-server/3470/2) is the most accurate representation of what I am aiming for.

Thanks

---

<div class="post-metadata">

**Author:** ![Ebbe](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ebbe/32/1413_2.png) [@Ebbe](https://forum.universal-robots.com/u/Ebbe)\
**Post date:** [May 10, 2021, 8:44am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/2 "2021-05-10T08:44:49Z")

</div>

Hi @anon44063908

Welcome to the UR community!

I am not sure if it is your only issue. But your line:

> [@anon44063908](#):
>
> ` if(modbus_conn = False):`

Should probably have been like this:

` if(modbus_conn == False):`

Best Regards  
Ebbe

---

<div class="post-metadata">

**Author:** ![anon44063908](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon44063908](https://forum.universal-robots.com/u/anon44063908)\
**Post date:** [May 10, 2021, 8:57am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/3 "2021-05-10T08:57:22Z")

</div>

It is == in my code. Edited here so it is aswell. Yet that is not the problem I am trying to solve. Do you have any idea about the compile error?

---

<div class="post-metadata">

**Author:** ![anon44063908](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon44063908](https://forum.universal-robots.com/u/anon44063908)\
**Post date:** [May 10, 2021, 8:58am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/4 "2021-05-10T08:58:33Z")

</div>

The compile error is referencing to the line where the thread is defined by the way

---

<div class="post-metadata">

**Author:** ![Ebbe](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ebbe/32/1413_2.png) [@Ebbe](https://forum.universal-robots.com/u/Ebbe)\
**Post date:** [May 10, 2021, 9:29am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/5 "2021-05-10T09:29:01Z")

</div>

Thank you for the details!

I just tested a similar construction with another function call instead of your RPC call. that worked just fine. Can you elaborate on your rpc server, is your method called “ModbusHandler.getModbusConnection”? And does your code work if you substitute the call with general purpose URScript code?

another thing to note is that your sample differs from the sample you refer to in the sense that your will run ones, while the other will continue to evaluate the connection

---

<div class="post-metadata">

**Author:** ![anon44063908](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon44063908](https://forum.universal-robots.com/u/anon44063908)\
**Post date:** [May 10, 2021, 9:52am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/6 "2021-05-10T09:52:31Z")

</div>

The RPC method is called “MosbusHandler.getModbusConnection()” and returns a boolean. The code works with RPC call if I remove the thread and popup pops up as expected when there is no connection and does not pop up, when there is a connection to the modbus server.

I have edited the code to loop.

I have also tried to remove all content in the thread, so all that is run is:

```
thread thread_modbus_conn():
end
thread_handler_modbus_conn = run thread_modbus_conn()

```

This also gives the same compile error.

---

<div class="post-metadata">

**Author:** ![Ebbe](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/ebbe/32/1413_2.png) [@Ebbe](https://forum.universal-robots.com/u/Ebbe)\
**Post date:** [May 10, 2021, 10:08am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/7 "2021-05-10T10:08:36Z")

</div>

Can you share your program with just this content, that is failing?

> [@anon44063908](#):
>
> ```auto
> thread thread_modbus_conn():
> end
> thread_handler_modbus_conn = run thread_modbus_conn()
> 
> ```

---

<div class="post-metadata">

**Author:** ![anon44063908](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon44063908](https://forum.universal-robots.com/u/anon44063908)\
**Post date:** [May 10, 2021, 11:43am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/8 "2021-05-10T11:43:43Z")

</div>

I have defined a new function with the same funcitonality and now the function is working. I don’t know what the problem was, but it seems fixed now. Thank you for the help 🙂

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/system/32/1_2.png) [@system](https://forum.universal-robots.com/u/system)\
**Post date:** [May 12, 2021, 11:44am UTC](https://forum.universal-robots.com/t/compile-error-an-expression-was-found-which-produces-a-result-that-is-not-used/14226/9 "2021-05-12T11:44:27Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
