Skip to content

[BUG]: untrapped exceptions occur in trigger controller when connection lost #103

Description

@timcnicholls

Describe the bug
When the trigger adapter is running and loses communication with the trigger box, exceptions occur in the Modbus TCP client but are not caught by the trigger controller. The exceptions surface in the Tornado event loop:
causing a traceback. This occurs on each background update:

Connection to (192.168.0.160, 502) failed: timed out
[E 260513 07:47:35 ioloop:949] Exception in callback <bound method TriggerController._get_all_registers of <livex.trigger.controller.TriggerController object at 0x10aa22e40>>
    Traceback (most recent call last):
      File "~/.virtualenvs/livex-3.14/lib/python3.14/site-packages/tornado/ioloop.py", line 945, in _run
        val = self.callback()
      File "~/develop/projects/livex/livex/control/src/livex/trigger/controller.py", line 136, in _get_all_registers
        trigger._get_parameters()
        ~~~~~~~~~~~~~~~~~~~~~~~^^
      File "~/develop/projects/livex/livex/control/src/livex/trigger/trigger.py", line 36, in _get_parameters
        self.running = read_coil(self.client, self.addr['running_coil'])
                       ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "~/develop/projects/livex/livex/control/src/livex/util.py", line 21, in read_coil
        response = client.read_coils(address, count=1, slave=1)
      File "~/.virtualenvs/livex-3.14/lib/python3.14/site-packages/pymodbus/client/mixin.py", line 72, in read_coils
        return self.execute(pdu_bit_read.ReadCoilsRequest(address, count, slave=slave))
               ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "~/.virtualenvs/livex-3.14/lib/python3.14/site-packages/pymodbus/client/base.py", line 236, in execute
        raise ConnectionException(f"Failed to connect[{self!s}]")
    pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.160:502]

To Reproduce
Steps to reproduce the behavior:

  1. Run the trigger adapter in odin-control
  2. Disconnect the trigger box (power off or network disconnect)
  3. See the error and traceback in the odin-control output / log

Expected behavior
The exceptions should be handled cleanly in the controller code, report connection loss and manage state accordingly

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions