Commit 81a61642 authored by vertighel's avatar vertighel
Browse files

mercury: connection error handling, version/status; init.html stage section



- mercury.py: catch OSError (errno 111/113) in _check_connection; null-check
  pidevice in get, put, wait, init, abort, Stage.is_moving; add version
  property (qIDN) and status property (bool reachability check)
- init.html: mirror stage section with connection/power/init widgets and
  stage-status/stage-position telemetry; layout column reflow

Co-Authored-By: default avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent adf7d4cf
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -31,12 +31,12 @@ node = STX
[teccam2]
module = mako
class = Guider
node = MAKO2
node = MAKO111

[teccam3]
module = mako
class = Guider
node = MAKO
node = MAKO115

######################################

+40 −11
Original line number Diff line number Diff line
@@ -78,20 +78,21 @@ class Mercury(BaseDevice):

        Returns
        -------
        GCSCommands
            The active PI GCS commands instance.
        GCSCommands or None
            The active PI GCS commands instance, or None if the connection failed.
        """

        if self.pidevice is None:
            # Open Gateway (Socket)
            try:
                self._gateway = PISocket(host=self.host, port=self.port)
                self._gateway.__enter__()
            except OSError as e:
                self.error.append(str(e))
                return None

            messages = GCSMessages(self._gateway)

            # 3. Creation and opening of GCSCommands
            self.pidevice = GCSCommands(messages)
            self.pidevice.__enter__() # Second context manager
            self.pidevice.__enter__()

        return self.pidevice

@@ -115,6 +116,24 @@ class Mercury(BaseDevice):
                pass


    @property
    def version(self):
        """str or None: Device identification string from qIDN()."""
        pidevice = self._check_connection()
        if pidevice is None:
            return None
        try:
            return pidevice.qIDN()
        except GCSError as e:
            log.error(f"qIDN error: {e}")
            self.error.append(str(e))
            return None

    @property
    def status(self):
        """bool: True if the device responds to identification query."""
        return self.version is not None

    def get(self, command):
        """
        Get information from the controller using GCS query commands.
@@ -126,6 +145,8 @@ class Mercury(BaseDevice):
        """

        pidevice = self._check_connection()
        if pidevice is None:
            return None
        method = getattr(pidevice, f"q{command.upper()}")
        try:
            if (command == "ERR"):
@@ -151,6 +172,8 @@ class Mercury(BaseDevice):
        """

        pidevice = self._check_connection()
        if pidevice is None:
            return None
        method = getattr(pidevice, command.upper())
        try:
            return method(self.axis, *args)
@@ -167,13 +190,14 @@ class Mercury(BaseDevice):
        """

        pidevice = self._check_connection()
        if pidevice is None:
            return

        time.sleep(0.2)

        moving = True
        while moving:
            try:
                # log.debug(pidevice.qPOS())
                status_dict = pidevice.IsMoving(self.axis)
                moving = status_dict[self.axis]
            except GCSError as e:
@@ -182,7 +206,6 @@ class Mercury(BaseDevice):
            err = pidevice.qERR()
            if err != 0:
                log.warning(err)
                pass

            time.sleep(0.2)

@@ -192,6 +215,8 @@ class Mercury(BaseDevice):
        """

        pidevice = self._check_connection()
        if pidevice is None:
            return

        # Clear any previous errors
        pidevice.qERR()
@@ -212,6 +237,8 @@ class Mercury(BaseDevice):
        """

        pidevice = self._check_connection()
        if pidevice is None:
            return

        # Clear any previous errors
        pidevice.qERR()
@@ -252,6 +279,8 @@ class Stage(Mercury):
        """

        pidevice = self._check_connection()
        if pidevice is None:
            return None
        return pidevice.IsMoving(self.axis)[self.axis]


+12 −4
Original line number Diff line number Diff line
@@ -96,9 +96,9 @@
              })
            }}
        </div>
    </section>
    <!-- </section> -->

    <section class="col-xl-6 p-3">
    <!-- <section class="col-xl-6 p-3"> -->
        <div class="bg-dark p-4 rounded shadow mb-4">
            <h5 class="pb-2 mb-4">Dome</h5>
            
@@ -217,6 +217,11 @@

        </div>

    </section>

    <section class="col-xl-6 p-3">


        <div class="bg-dark p-4 rounded shadow mb-4">
            <h5 class="pb-2 mb-4">Mirror Stage</h5>

@@ -249,13 +254,16 @@
                "buttons": [
                    {"label": "Initialize", "endpoint": "/stage/status", "method": "POST"}
                ],
                "info_list": [
                    {"label": "init", "status": "stage-status"},
                    {"label": "pos",  "status": "stage-position"}
                ],
              })
            }}

        </div>
    </section>

    <section class="col-xl-6 p-3">
      
        <div class="bg-dark p-4 rounded shadow mb-4">
            <h5 class="pb-2 mb-4">Dome Webcam</h5>