From fbf6112cea0fff14a83f4a653c612a36255c76ac Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 26 Jun 2013 17:45:39 +1000 Subject: [PATCH] Update to show motor position on display screen --- .../TEST_SICS/fakeGalil/SIM_GALIL.py | 61 ++++++++++++++++++- .../TEST_SICS/fakeGalil/SIM_GALIL_taipan.py | 2 - 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL.py b/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL.py index a2255af5..e2d3aec8 100755 --- a/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL.py +++ b/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL.py @@ -12,11 +12,60 @@ import time import inspect from galilfactory import GalilFactory +import curses +from displayscreen import Screen def device_iterator(): now = time.time() +def display_iterator(): + global screen, devices + + 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 + +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 + def main(**kwargs): + global screen, devices parser = argparse.ArgumentParser( description="Generates fake Galil controllers for testing SICS" ) parser.add_argument("instrument", help="The instrument name") args = parser.parse_args() @@ -25,7 +74,8 @@ def main(**kwargs): 'echidna': 62034, 'wombat': 62134, 'kowari': 62230, 'dingo': 62300, 'quokka': 62430, 'platypus': 62530, 'pelican': 62630, 'taipan': 62730, 'lyrebird': 62830, 'kookaburra': 62930, 'bilby': 63030, 'emu': 63130 } - log.startLogging(sys.stdout) + #log.startLogging(sys.stdout) + log.startLogging(open(("/tmp/Fake_Galil_%d.log" % basePort[args.instrument]), "w")) devices = {} for dev in range(0, 6): port = basePort[args.instrument] + dev @@ -33,6 +83,15 @@ def main(**kwargs): factory = GalilFactory(port) devices[controllerName] = factory.device reactor.listenTCP(port, factory) + + stdscr = curses.initscr() + screen = MyScreen(stdscr) + reactor.addReader(screen) + + #lc = LoopingCall(device_iterator) + #lc.start(0.5) + dc = LoopingCall(display_iterator) + dc.start(0.5) reactor.run() if __name__ == '__main__': 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 773dd164..b13ab031 100755 --- a/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py +++ b/site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py @@ -144,8 +144,6 @@ if __name__ == "__main__": stdscr = curses.initscr() screen = MyScreen(stdscr) reactor.addReader(screen) - print "stdscr:", stdscr - print "screen:", screen lc = LoopingCall(device_iterator) lc.start(0.05)