Universal Robots Forum

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


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():
            modbus_conn = rpc.ModbusHandler.getModbusConnection()
            if(modbus_conn == False):
                popup("Not connected to modbus. Stopping program", warning=True, blocking=False)
   thread_handler_modbus_conn = run thread_modbus_conn()

I have looked on the forum and this is the most accurate representation of what I am aiming for.


Hi @mcp

Welcome to the UR community!

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

Should probably have been like this:

if(modbus_conn == False):

Best Regards

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?

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

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

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():
thread_handler_modbus_conn = run thread_modbus_conn()

This also gives the same compile error.

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

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 :slight_smile:

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