XML RPC

Warning

This is an advanced example and relies on so-called private functionality that may change without notice.

This is a more advanced example that shows how to control ADS through XML RPC. It uses some private functionality to ensure that any functions that are exposed are executing on the main thread again. Executing Design Environment functionality from another thread is not supported. This example is shared without warranty.

Server

# Copyright Keysight Technologies 2023 - 2023
import socketserver
import threading
from xmlrpc.server import DocXMLRPCServer


class SimpleThreadedXMLRPCServer(socketserver.ThreadingMixIn, DocXMLRPCServer):
    pass


def get_all_views_wrapper() -> None:
    unused = get_all_views()
    assert unused is not None


def get_all_views() -> list[str]:
    import keysight.ads.de as de

    wrk = de.active_workspace()
    all_views = []
    for lib_name in wrk.writable_library_names:
        lib = wrk.open_library(lib_name)
        for cell in lib.cells:
            for view in cell.views:
                all_views.append(str(view.lcv_name))
    return all_views


def zoom_to_all() -> None:
    from keysight.ads import ael

    ael.call.de_view_all()


def eimt_get_all_views() -> None:
    import _pde_app

    _pde_app.ui.execute_in_main_thread(get_all_views_wrapper)


def eimt_zoom_to_all() -> None:
    import _pde_app

    _pde_app.ui.execute_in_main_thread(zoom_to_all)


class ServerThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.localServer = SimpleThreadedXMLRPCServer(("0.0.0.0", 8080), logRequests=True, allow_none=True)
        self.localServer.register_function(eimt_get_all_views)
        self.localServer.register_function(eimt_zoom_to_all)

    def empty(self) -> None:
        pass

    def run(self) -> None:
        self.localServer.serve_forever()


def run_server() -> None:
    server = ServerThread()
    server.start()

Client

# Copyright Keysight Technologies 2023 - 2023
import xmlrpc.client


def run_client() -> None:
    with xmlrpc.client.ServerProxy("http://localhost:8080/") as proxy:
        print(proxy.eimt_zoom_to_all())
On this page