added DilSc
This commit is contained in:
67
devices/dilsc.py
Normal file
67
devices/dilsc.py
Normal file
@ -0,0 +1,67 @@
|
||||
""" DilSc prototype
|
||||
|
||||
"""
|
||||
|
||||
from slic.core.adjustable import Adjustable
|
||||
|
||||
from slic.core.device import Device, SimpleDevice
|
||||
|
||||
from frappy.client import SecopClient
|
||||
from frappy import states
|
||||
from frappy.datatypes import StatusType
|
||||
|
||||
|
||||
class DilSc(Device):
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
self.name = 'DilSc'
|
||||
ID = self.name
|
||||
super().__init__(ID, **kwargs)
|
||||
|
||||
self.dilsc = SecopClient('dilsc.psi.ch:5000')
|
||||
self.dilsc.connect()
|
||||
|
||||
self.x = MagnetCoil("Magnet_X", self.dilsc, 'x', limit_low=-0.6, limit_high=0.6)
|
||||
self.y = MagnetCoil("Magnet_Y", self.dilsc, 'y', limit_low=-0.6, limit_high=0.6)
|
||||
self.z = MagnetCoil("Magnet_Z", self.dilsc, 'z', limit_low=-5.2, limit_high=5.2)
|
||||
|
||||
|
||||
|
||||
class MagnetCoil(Adjustable):
|
||||
|
||||
def __init__(self, name, dilsc_connection, direction, limit_low=-0.0001, limit_high=0.0001):
|
||||
# What's with name or ID?
|
||||
|
||||
super().__init__(name, limit_low=-0.0001, limit_high=0.0001)
|
||||
|
||||
self.direction = direction.lower()
|
||||
|
||||
if self.direction not in ["x", "y", "z"]:
|
||||
raise ValueError("Direction must be either x, y or z.")
|
||||
|
||||
self.dilsc = dilsc_connection
|
||||
|
||||
if not self.dilsc.online:
|
||||
raise ConnectionError('No connection to dilsc.')
|
||||
|
||||
|
||||
def get_current_value(self):
|
||||
if self.dilsc.online:
|
||||
return self.dilsc.getParameter(f'mf{self.direction}', 'value',)
|
||||
else:
|
||||
raise ConnectionError('No connection to dilsc.')
|
||||
|
||||
|
||||
|
||||
def set_target_value(self, value):
|
||||
if self.dilsc.online:
|
||||
self.dilsc.setParameter(f'mf{self.direction}', 'target', value)
|
||||
else:
|
||||
raise ConnectionError('No connection to dilsc.')
|
||||
|
||||
|
||||
def is_moving(self):
|
||||
response = self.dilsc.getParameter(f'mf{self.direction}','status', trycache=False)
|
||||
return response[0][0] > StatusType.PREPARED
|
||||
|
||||
|
Reference in New Issue
Block a user