herosdevices.core.bus.visa
==========================

.. py:module:: herosdevices.core.bus.visa

.. autoapi-nested-parse::

   Primitive functions and classes representing visa connections.







Module Contents
---------------

.. py:data:: pyvisa
   :value: None


.. py:data:: usb
   :value: None


.. py:class:: VisaConnection(resource: str, keep_alive: bool = True, **kwargs)

   A class to manage VISA communication connections.

   This class provides functionality to handle visa connections including opening/closing connections, reading
   data, and writing data.

   :param resource: The resource name of the visa instrument (e.g. ``TCPIP::my_device_hostname::INSTR``).
   :param keep_alive: Flag indicating whether to keep the connection open between operations.
   :param \*\*kwargs: Keyword arguments passed to :code:`pyvisa.open_resource`


   .. py:attribute:: resource
      :type:  str


   .. py:attribute:: connection
      :type:  pyvisa.resources.MessageBasedResource | None
      :value: None



   .. py:attribute:: keep_alive
      :value: True



   .. py:method:: operation() -> collections.abc.Iterator[None]

      Context manager for handling visa connection operations.

      Ensures the visa connection is open before performing operations and closes it afterward
      if :code:`self.keep_alive` is False.

      :Yields: Yields control back to the caller for performing operations within the context.



   .. py:method:: close() -> None

      Close the visa connection if it is open.

      The connection is reopened automatically on the next read or write operation.



   .. py:method:: goto_local() -> None

      Set the device back to local mode by sending the USB488 GO_TO_LOCAL request.

      pyvisa-py asserts the remote enable line of USBTMC devices when opening a connection but never releases
      it, leaving the device in remote mode (e.g. with a locked front panel) even after the connection is
      closed. Sending this request sets the device back to local mode.

      This is a no-op if the connection is not a pyvisa-py USBTMC connection whose device supports the
      request. Errors are logged instead of raised, as this is a best effort cleanup operation.



   .. py:method:: read() -> str | None

      Do device read query.

      :returns: The decoded data as string, or None if an error occurs.



   .. py:method:: write(message: str, read_echo: bool = False, *args, **kwargs) -> str | None

      Write to the visa connection.

      :param message: The message to be written to the serial connection.
      :param read_echo: If True, reads back the echo after writing. Defaults to False.



