Files
dev/script/epics_camera.py
2021-04-28 09:29:19 +02:00

74 lines
1.9 KiB
Python

import ch.psi.pshell.epics.CAS as CAS
import ch.psi.pshell.device.Register.RegisterArray as RegisterArray
import random
camera = "EPICS_example_1"
IMG_WIDTH = 100
IMG_HEIGHT = 50
EPICS_PV_SUFFIX_STATUS = ":INIT"
EPICS_PV_SUFFIX_WIDTH = ":WIDTH"
EPICS_PV_SUFFIX_HEIGHT = ":HEIGHT"
EPICS_PV_SUFFIX_IMAGE = ":FPICTURE"
class Scalar(RegisterBase):
def __init__(self, name):
RegisterBase.__init__(self, name)
def doRead(self):
return self.val
def doWrite(self, val):
self.val = val
class Waveform(RegisterBase, RegisterArray):
def __init__(self, name):
RegisterBase.__init__(self, name)
def doRead(self):
return self.val
def doWrite(self, val):
self.val = val
def getSize(self):
return len(self.take(-1)) #only reads if cache is None
add_device(Scalar("cam_init"), True)
add_device(Scalar("cam_width"), True)
add_device(Scalar("cam_height"), True)
add_device(Waveform("cam_image"), True)
cam_width.write(IMG_WIDTH)
cam_height.write(IMG_HEIGHT)
cam_init.write("INIT")
def update_image(width = None, height = None):
if width:
cam_width.write(width)
if height:
cam_height.write(height)
img = []
for i in range(cam_width.take() * cam_height.take()):
img.append(int(random.random()*100))
cam_image.write(img)
update_image()
#CAS.setServerPort(1234)
cas1 = CAS(camera + EPICS_PV_SUFFIX_STATUS, cam_init, 'string')
cas2 = CAS(camera + EPICS_PV_SUFFIX_WIDTH, cam_width, 'int')
cas3 = CAS(camera + EPICS_PV_SUFFIX_HEIGHT, cam_height, 'int')
cas4 = CAS(camera + EPICS_PV_SUFFIX_IMAGE, cam_image, 'short')
print caget(camera + EPICS_PV_SUFFIX_STATUS)
print caget(camera + EPICS_PV_SUFFIX_WIDTH)
print caget(camera + EPICS_PV_SUFFIX_HEIGHT)
#print caget(camera + EPICS_PV_SUFFIX_IMAGE).tolist()
while True:
time.sleep(1.0)
update_image()