Update to show motor position on display screen
This commit is contained in:
@@ -12,11 +12,60 @@ import time
|
|||||||
import inspect
|
import inspect
|
||||||
from galilfactory import GalilFactory
|
from galilfactory import GalilFactory
|
||||||
|
|
||||||
|
import curses
|
||||||
|
from displayscreen import Screen
|
||||||
|
|
||||||
def device_iterator():
|
def device_iterator():
|
||||||
now = time.time()
|
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):
|
def main(**kwargs):
|
||||||
|
global screen, devices
|
||||||
parser = argparse.ArgumentParser( description="Generates fake Galil controllers for testing SICS" )
|
parser = argparse.ArgumentParser( description="Generates fake Galil controllers for testing SICS" )
|
||||||
parser.add_argument("instrument", help="The instrument name")
|
parser.add_argument("instrument", help="The instrument name")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -25,7 +74,8 @@ def main(**kwargs):
|
|||||||
'echidna': 62034, 'wombat': 62134, 'kowari': 62230, 'dingo': 62300, 'quokka': 62430, 'platypus': 62530,
|
'echidna': 62034, 'wombat': 62134, 'kowari': 62230, 'dingo': 62300, 'quokka': 62430, 'platypus': 62530,
|
||||||
'pelican': 62630, 'taipan': 62730, 'lyrebird': 62830, 'kookaburra': 62930, 'bilby': 63030, 'emu': 63130
|
'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 = {}
|
devices = {}
|
||||||
for dev in range(0, 6):
|
for dev in range(0, 6):
|
||||||
port = basePort[args.instrument] + dev
|
port = basePort[args.instrument] + dev
|
||||||
@@ -33,6 +83,15 @@ def main(**kwargs):
|
|||||||
factory = GalilFactory(port)
|
factory = GalilFactory(port)
|
||||||
devices[controllerName] = factory.device
|
devices[controllerName] = factory.device
|
||||||
reactor.listenTCP(port, factory)
|
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()
|
reactor.run()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -144,8 +144,6 @@ if __name__ == "__main__":
|
|||||||
stdscr = curses.initscr()
|
stdscr = curses.initscr()
|
||||||
screen = MyScreen(stdscr)
|
screen = MyScreen(stdscr)
|
||||||
reactor.addReader(screen)
|
reactor.addReader(screen)
|
||||||
print "stdscr:", stdscr
|
|
||||||
print "screen:", screen
|
|
||||||
|
|
||||||
lc = LoopingCall(device_iterator)
|
lc = LoopingCall(device_iterator)
|
||||||
lc.start(0.05)
|
lc.start(0.05)
|
||||||
|
|||||||
Reference in New Issue
Block a user