예제 #1
0
    def __process_loop(self):
        print("process loop")
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        self.conn = Connection()
        self.conn.login(self.usr, self.pwd)

        self.conf = Config()
        self.conf.load(self.conn)

        self.wamp = WampBase(self.conn)
        self.wamp.connect(self.conf.get_wamp_url(), self.conf.get_wamp_realm())

        s = time.time()
        while not self.wamp.session.is_attached():
            if time.time() - s > 5:
                raise RuntimeError("Cannot attach to WAMP session")
            time.sleep(0.1)

        print("session attached")
        f = open(self.path, "wb", buffering=2048)
        print("file opened")
        coro = self.wamp.loop.connect_write_pipe(UnixProtocol, f)
        print("created coro")
        fut = asyncio.run_coroutine_threadsafe(coro, self.wamp.loop)
        print("prima fut")
        (_, self.outpipe) = fut.result()

        self.wamp.subscribe(self.recv, self.conf.get_wamp_pol(self.pol))
        self.wamp.th.join()
예제 #2
0
class Worker(object):
    def __init__(self, conn, pol, path):

        self.pol = pol
        self.path = path
        self.usr = conn.user
        self.pwd = conn.password

    def start(self):
        print("start worker")
        self.p = mp.Process(target=self.__process_loop)
        self.p.start()
        # self.__process_loop()

    def stop(self):
        self.p.terminate()

    def __process_loop(self):
        print("process loop")
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        self.conn = Connection()
        self.conn.login(self.usr, self.pwd)

        self.conf = Config()
        self.conf.load(self.conn)

        self.wamp = WampBase(self.conn)
        self.wamp.connect(self.conf.get_wamp_url(), self.conf.get_wamp_realm())

        s = time.time()
        while not self.wamp.session.is_attached():
            if time.time() - s > 5:
                raise RuntimeError("Cannot attach to WAMP session")
            time.sleep(0.1)

        print("session attached")
        f = open(self.path, "wb", buffering=2048)
        print("file opened")
        coro = self.wamp.loop.connect_write_pipe(UnixProtocol, f)
        print("created coro")
        fut = asyncio.run_coroutine_threadsafe(coro, self.wamp.loop)
        print("prima fut")
        (_, self.outpipe) = fut.result()

        self.wamp.subscribe(self.recv, self.conf.get_wamp_pol(self.pol))
        self.wamp.th.join()

    def recv(self, *args, **pkt):
        self.outpipe.write(json.dumps(pkt).encode())
예제 #3
0
        ):
            board_setup.log(f"Disabling electronics for {self.horn}…")
            board_setup.disable_electronics(polarimeter=self.horn)
            board_setup.log("The electronics has been disabled")

        board_setup.log(f"Turnoff procedure for {self.horn} completed")


if __name__ == "__main__":

    if len(sys.argv) != 2:
        print("usage: python ", sys.argv[0], "MODULE_ID")
        sys.exit(-1)

    board_calibration = read_board_xlsx(sys.argv[1])

    con = Connection()
    con.login()

    sb = SetupBoard(con, board_calibration)

    sb.board_on()
    sb.pols_on()

    sb.setup_VD(0)
    sb.setup_VG(1)
    sb.setup_VPIN(1)
    sb.setup_IPIN(1)

    sb.pols_off()
loop = None


def th_loop():
    global loop
    if loop:
        loop.run_forever()


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    th = Thread(target=th_loop)
    th.start()

    conn = Connection()
    if conn.has_login():
        conn.login()
    else:
        app = QtWidgets.QApplication(sys.argv)
        dialog = LoginWidget()
        dialog.exec_()
        conn.login(dialog.user, dialog.password)

    conf = Config()
    conf.load(conn)

    gui = sp.Popen(
        [
            "program_polview/bin/program_polview", "-u", conn.user, "-p",
            conn.password
예제 #5
0
    def __init__(self):
        """initializes the ui and polulates the housekeeping table"""
        super(ApplicationWindow, self).__init__()

        self.conn = Connection()
        if self.conn.has_login():
            self.conn.login()
        else:
            dialog = LoginWidget()
            dialog.exec_()
            self.conn.login(dialog.user, dialog.password)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        conf = Config()
        conf.load(self.conn)
        self.callbacks = []

        t = self.ui.hk_table
        t.setRowCount(
            sum([
                len(conf.board_addr[x]) for x in conf.board_addr
                if x.endswith("POL")
            ]))
        t.setColumnCount(3)
        i = 0
        #        for s in SCI:
        #            cb = QtWidgets.QCheckBox(t)
        #            cb.setText(s)
        #            cb.setCheckState(2)
        #            callb = CheckBoxCallBack(self.ui.plot,s)
        #            cb.stateChanged.connect(callb.callback)
        #            self.callbacks.append((cb,callb))
        #            t.setCellWidget(i,0,cb)
        #            i += 1

        for table in conf.board_addr:
            if not table.endswith("POL"):
                continue
            for hk in conf.board_addr[table]:
                cb = QtWidgets.QCheckBox(t)
                # cb.setText(hk['name'])
                callb = CheckBoxCallBack(self.ui.plot, table, hk["name"])
                cb.stateChanged.connect(callb.callback)
                self.callbacks.append((cb, callb))

                item_table = QtWidgets.QTableWidgetItem()
                item_table.setText(table)
                t.setItem(i, 1, item_table)

                item_hk = QtWidgets.QTableWidgetItem()
                item_hk.setText(hk["name"])
                t.setItem(i, 2, item_hk)

                t.setCellWidget(i, 0, cb)
                i += 1

        for b in conf.boards:
            for p in b["pols"]:
                self.ui.polList.addItem(p)

        self.ui.polList.currentIndexChanged.connect(self.polChanged)

        self.ui.plot.start(self.conn, self.ui.polList.currentText())
예제 #6
0
class ApplicationWindow(QtWidgets.QMainWindow):
    """Main window class"""
    def __init__(self):
        """initializes the ui and polulates the housekeeping table"""
        super(ApplicationWindow, self).__init__()

        self.conn = Connection()
        if self.conn.has_login():
            self.conn.login()
        else:
            dialog = LoginWidget()
            dialog.exec_()
            self.conn.login(dialog.user, dialog.password)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        conf = Config()
        conf.load(self.conn)
        self.callbacks = []

        t = self.ui.hk_table
        t.setRowCount(
            sum([
                len(conf.board_addr[x]) for x in conf.board_addr
                if x.endswith("POL")
            ]))
        t.setColumnCount(3)
        i = 0
        #        for s in SCI:
        #            cb = QtWidgets.QCheckBox(t)
        #            cb.setText(s)
        #            cb.setCheckState(2)
        #            callb = CheckBoxCallBack(self.ui.plot,s)
        #            cb.stateChanged.connect(callb.callback)
        #            self.callbacks.append((cb,callb))
        #            t.setCellWidget(i,0,cb)
        #            i += 1

        for table in conf.board_addr:
            if not table.endswith("POL"):
                continue
            for hk in conf.board_addr[table]:
                cb = QtWidgets.QCheckBox(t)
                # cb.setText(hk['name'])
                callb = CheckBoxCallBack(self.ui.plot, table, hk["name"])
                cb.stateChanged.connect(callb.callback)
                self.callbacks.append((cb, callb))

                item_table = QtWidgets.QTableWidgetItem()
                item_table.setText(table)
                t.setItem(i, 1, item_table)

                item_hk = QtWidgets.QTableWidgetItem()
                item_hk.setText(hk["name"])
                t.setItem(i, 2, item_hk)

                t.setCellWidget(i, 0, cb)
                i += 1

        for b in conf.boards:
            for p in b["pols"]:
                self.ui.polList.addItem(p)

        self.ui.polList.currentIndexChanged.connect(self.polChanged)

        self.ui.plot.start(self.conn, self.ui.polList.currentText())

    def polChanged(self, i):
        """callback for polarimer change on the dropdown list.
        stops the current polatimeter streaming and starts a new streaming
        for the selected polarimeter.
        """
        pol = self.ui.polList.currentText()
        hkdict = {}
        for cb, call in self.callbacks:
            if cb.checkState() == 2:
                if hkdict.get(call.table) is None:
                    hkdict[call.table] = set()
                hkdict[call.table].add(call.hk)

        print(hkdict)

        self.ui.plot.stop()
        self.ui.plot.start(self.conn, pol, items=hkdict)

    def stop(self):
        self.ui.plot.stop()