From 99f18f8798c2230f932e6925a56a36459cfe9e19 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 26 Jun 2013 17:24:47 +1000 Subject: [PATCH] Add a display screen for motor position to taipan fake motors --- .../TEST_SICS/fakeGalil/SIM_GALIL_taipan.py | 133 +++++++++++++----- 1 file changed, 98 insertions(+), 35 deletions(-) diff --git a/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py b/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py index aa5d40d5..773dd164 100755 --- a/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py +++ b/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py @@ -13,12 +13,8 @@ from galilfactory import GalilFactory from counterclient import CounterClientFactory from powdersample import CubicPowderSample -log.startLogging(sys.stdout) - -beam_monitor_counter = None -detector_counter = None -beam_monitor_rate = None -nickel = CubicPowderSample() +import curses +from displayscreen import Screen def stopCallbackM1M2(motor): global nickel @@ -58,34 +54,101 @@ def device_iterator(): m2.doIteration(now) s2.doIteration(now) -basePort = 62034 # Echidna -basePort = 62134 # Wombat -basePort = 62430 # Quokka -basePort = 62730 # Taipan -devices = {} -for dev in range(0, 6): - port = basePort + dev - controllerName = "mc%d" % (dev + 1) - factory = GalilFactory(port) - devices[controllerName] = factory.device - reactor.listenTCP(port, factory) +def display_iterator(): + global screen, devices -s2 = devices["mc2"].motors["F"] -s2.moveCallback = s2.stopCallback = stopCallbackS2 -m1 = devices["mc3"].motors["E"] -m1.moveCallback = m1.stopCallback = stopCallbackM1M2 -m2 = devices["mc1"].motors["F"] -m2.moveCallback = m2.stopCallback = stopCallbackM1M2 -m1.stopCallback(m1) -m2.stopCallback(m2) -s2.stopCallback(s2) + try: + rows, cols = screen.stdscr.getmaxyx() + col = 0 + for idx in sorted(devices.keys()): + line = 0; + col += 1 + screen.stdscr.addstr(line, 13 * (col - 1), idx) + for mtr in sorted(devices[idx].motors.keys()): + line += 1 + screen.stdscr.addstr(line, 13 * (col - 1), "%1s:%8.3f" % (mtr, devices[idx].motors[mtr].getPosition())) + if (devices[idx].motors[mtr].motorState == "OFF"): + screen.stdscr.addstr(line, 13 * (col - 1) + 10, " ") + else: + screen.stdscr.addstr(line, 13 * (col - 1) + 10, "*") + except: + raise + finally: + try: + screen.stdscr.refresh() + except: + pass -beam_monitor_counter = CounterClientFactory() -detector_counter = CounterClientFactory() -connector1 = reactor.connectTCP("localhost", 33001, beam_monitor_counter) -connector2 = reactor.connectTCP("localhost", 33000, detector_counter) -print "Connector1:", connector1.getDestination() -print "Connector2:", connector2.getDestination() -lc = LoopingCall(device_iterator) -lc.start(0.05) -reactor.run() +class MyScreen(Screen): + def __init__(self, stdscr): + Screen.__init__(self, stdscr) + + def sendLine(self, txt): + global devices + dev, cmd = line.split(":") + print "Dev:", dev, "Cmd:", cmd + if dev in devices: + myDev = devices[dev] + myDev.protocol = self + myDev.dataReceived(cmd) + + def write(self, txt): + try: + newLine = self.lines[-1] + " => " + txt + del self.lines[-1] + self.addLine(newLine) + except: + pass + +if __name__ == "__main__": + global screen, devices + + basePort = 62034 # Echidna + basePort = 62134 # Wombat + basePort = 62430 # Quokka + basePort = 62730 # Taipan + + #log.startLogging(sys.stdout) + log.startLogging(open(("/tmp/Fake_Galil_%d.log" % basePort), "w")) + + beam_monitor_counter = None + detector_counter = None + beam_monitor_rate = None + nickel = CubicPowderSample() + + devices = {} + for dev in range(0, 6): + port = basePort + dev + controllerName = "mc%d" % (dev + 1) + factory = GalilFactory(port) + devices[controllerName] = factory.device + reactor.listenTCP(port, factory) + + s2 = devices["mc2"].motors["F"] + s2.moveCallback = s2.stopCallback = stopCallbackS2 + m1 = devices["mc3"].motors["E"] + m1.moveCallback = m1.stopCallback = stopCallbackM1M2 + m2 = devices["mc1"].motors["F"] + m2.moveCallback = m2.stopCallback = stopCallbackM1M2 + m1.stopCallback(m1) + m2.stopCallback(m2) + s2.stopCallback(s2) + + beam_monitor_counter = CounterClientFactory() + detector_counter = CounterClientFactory() + connector1 = reactor.connectTCP("localhost", 33001, beam_monitor_counter) + connector2 = reactor.connectTCP("localhost", 33000, detector_counter) + print "Connector1:", connector1.getDestination() + print "Connector2:", connector2.getDestination() + + stdscr = curses.initscr() + screen = MyScreen(stdscr) + reactor.addReader(screen) + print "stdscr:", stdscr + print "screen:", screen + + lc = LoopingCall(device_iterator) + lc.start(0.05) + dc = LoopingCall(display_iterator) + dc.start(0.5) + reactor.run()