#START AS: pshell console -dev -v -k -b -g -t test_camserver,1,5 -r false (-cl FINE)(--debug -y) import ch.psi.pshell.screenpanel.CamServerViewer as CamServerViewer import traceback SHOW_RENDERER=False CAMERA="simulation" CHANNEL_IMG = "TEST:FPICTURE" CHANNEL_WIDTH = "TEST:WIDTH" CHANNEL_HEIGHT = "TEST:HEIGHT" INTERVAL = 1.0 SHOW_PROFILE = False SHOW_FIT = True #IMAGE_TYPE = PV.Type.SHORT IMAGE_TYPE = PV.Type.BYTE #IMAGE_SIZE = Dimension(500,500) #IMAGE_SIZE = Dimension(255,255) IMAGE_SIZE = Dimension(300,218) MAX_IMAGE_SIZE = 65500 if PV.Type.BYTE else 65500/2 DEBUG = (not Setup.isServerMode()) or Setup.isDebug() PLOT = DEBUG img = PV.waveform(CHANNEL_IMG, IMAGE_TYPE, MAX_IMAGE_SIZE) width = PV.scalar(CHANNEL_WIDTH, PV.Type.INT) height = PV.scalar(CHANNEL_HEIGHT, PV.Type.INT) viewer = CamServerViewer() viewer.applyOptions(); viewer.initialize(CamServerViewer.SourceSelecionMode.Single); viewer.setStream(CAMERA) viewer.camera.config.colormap=Colormap.Flame viewer.camera.config.colormapAutomatic = True viewer.setShowProfile(SHOW_PROFILE) viewer.setShowFit(SHOW_FIT) r=viewer.renderer r.setPenProfile(Pen(Color.GRAY, 0)) viewer.setPenFit(Pen(Color.WHITE, 0)) viewer.setPenCross(Pen(Color.WHITE, 0)) if SHOW_RENDERER: f=SwingUtils.showFrame(App.getMainFrame(), "CamServerViewer", Dimension(450,250), r) f.setAlwaysOnTop(True) else: r.device.addListener(r) p=None try: r.waitImage(10000) while True: i=r.getImage(True, IMAGE_SIZE) i=ImagingUtils.grayscale(i) d = Data(i) a = d.array if IMAGE_TYPE != PV.Type.BYTE: a=Convert.toUnsigned(a) img.write(a) width.write(d.width) height.write(d.height) if PLOT: matrix = Convert.reshape(a, d.height, d.width) if IMAGE_TYPE == PV.Type.BYTE: matrix=Convert.toUnsigned(matrix) #p=plot(matrix)[0] if p is None or (s.numberOfBinsX!=d.width) []or (s.numberOfBinsY!=d.height): p=plot(matrix)[0] p.setColormap(Colormap.Grayscale) p.getAxis(p.AxisId.Y).inverted=True s=p.getSeries(0) else: s.setData(Convert.toDouble(matrix)) if INTERVAL: time.sleep(INTERVAL) r.waitNext(10000) #If stops receiving, tries restarting except: width.write(0) height.write(0) if DEBUG: print "Camera image processing exception:" print sys.exc_info()[1] traceback.print_exc() finally: viewer.setStream(None)