Beispiel #1
0
def test_pini_always_on():
    """Test that PINI is always on for in records regardless of initial_value"""
    bi = builder.boolIn("AAA")
    assert bi.PINI.Value() == "YES"

    mbbi = builder.mbbIn("BBB", initial_value=5)
    assert mbbi.PINI.Value() == "YES"
def build_typed_pvs():
    """Build generic PVs"""
    dynamic_pvs = {}

    builder.aOut('AO:STATIC', **ANALOGUE_VALUES)
    builder.aIn('AI:STATIC', **ANALOGUE_VALUES)
    dynamic_pvs.update({
        builder.aOut('AO:DYNAMIC', **ANALOGUE_VALUES):
        lambda pv: increment(pv, 10)})

    builder.longOut('LONGO:STATIC',**LONG_VALUES)
    builder.longIn('LONGI:STATIC',**LONG_VALUES)
    dynamic_pvs.update({
        builder.aOut('LONGO:DYNAMIC', **LONG_VALUES):
        lambda pv: increment(pv, 10)})

    builder.boolOut('BOOLO:STATIC', **BOOLEAN_VALUES)
    builder.boolIn('BOOLI:STATIC', **BOOLEAN_VALUES)
    dynamic_pvs.update({
        builder.boolOut('BOOLO:DYNAMIC', **BOOLEAN_VALUES):
        lambda pv: increment(pv, 1)})

    builder.stringOut('STRINGO:STATIC', initial_value=STRINGS[0])
    builder.stringIn('STRINGI:STATIC', initial_value=STRINGS[0])
    dynamic_pvs.update({
        builder.stringOut('STRINGO:DYNAMIC', initial_value=STRINGS[0]):
        update_string})

    enum_pv = builder.mbbOut('MBBO:STATIC', *STRINGS, initial_value=0)
    enum_pv = builder.mbbIn('MBBI:STATIC', *STRINGS, initial_value=0)
    dynamic_pvs.update({
        builder.mbbOut('MBBO:DYNAMIC', *STRINGS, initial_value=0):
        lambda pv: increment(pv, len(STRINGS) - 1)})
    return lambda: update_pvs(dynamic_pvs)
Beispiel #3
0
def test_enum_length_restriction():
    with pytest.raises(AssertionError):
        builder.mbbIn(
            "ManyLabels",
            "one",
            "two",
            "three",
            "four",
            "five",
            "six",
            "seven",
            "eight",
            "nine",
            "ten",
            "eleven",
            "twelve",
            "thirteen",
            "fourteen",
            "fifteen",
            "sixteen",
            "seventeen",
        )
Beispiel #4
0
    def __init__(self, config):

        #name for the pvs
        host = config["host"].strip()
        ioc = config["ioc"].strip()
        pvnam = host + ":" + ioc

        #status pv
        self.pv_stat = builder.mbbIn(pvnam + ":status", ("OK", 0),
                                     ("NOT_RUNNING", 1),
                                     ("MULTIPLE_INSTANCES", 2),
                                     ("DISCONNECTED", 3), ("UNDEFINED", 4))

        #description pv
        desc = config["description"].strip(" \"'")
        self.pv_desc = builder.stringIn(pvnam + ":description",
                                        initial_value=desc)
Beispiel #5
0
    def _create_feedback_records(self, feedback_csv):
        """Create all the feedback records from the .csv file at the location
        passed, see create_csv.py for more information; records for two edge
        cases are also created.

        Args:
            feedback_csv (string): The filepath to the .csv file to load the
                                    records in accordance with.
        """
        csv_reader = csv.DictReader(open(feedback_csv))
        for line in csv_reader:
            prefix, suffix = line["pv"].split(":", 1)
            builder.SetDeviceName(prefix)
            in_record = builder.aIn(suffix,
                                    initial_value=int(line["value"]),
                                    MDEL="-1")
            self._feedback_records[(int(line["index"]),
                                    line["field"])] = in_record
        # Special case: BPM ID for the x axis of beam position plot, since we
        # cannot currently create Waveform records via CSV.
        bpm_ids = [
            int(pv[2:4]) + 0.1 * int(pv[14:16])
            for pv in self.lattice.get_element_pv_names("BPM", "x", pytac.RB)
        ]
        builder.SetDeviceName("SR-DI-EBPM-01")
        bpm_id_record = builder.Waveform("BPMID",
                                         NELM=len(bpm_ids),
                                         initial_value=bpm_ids)
        self._feedback_records[(0, "bpm_id")] = bpm_id_record
        # Special case: EMIT STATUS for the vertical emittance feedback, since
        # we cannot currently create mbbIn records via CSV.
        builder.SetDeviceName("SR-DI-EMIT-01")
        emit_status_record = builder.mbbIn("STATUS",
                                           initial_value=0,
                                           ZRVL=0,
                                           ZRST="Successful",
                                           PINI="YES")
        self._feedback_records[(0, "emittance_status")] = emit_status_record
Beispiel #6
0
 def __init__(self, ip):
     self.ip = ip
     self.boards = [1, 3, 5, 7]
     self.channels = [0, 1, 2, 3, 4, 5]
     self.lib = ctypes.cdll.LoadLibrary(
         '/home/mtd/CAENHVWrapper-5.82/lib/x64/libcaenhvwrapper.so.5.82')
     self.handle = ctypes.c_int(0)
     #self.result0 = self.lib.CAENHV_InitSystem(2, 0, self.ip, "admin", "admin", ctypes.byref(self.handle)) # for CAEN SY4527
     self.result0 = self.lib.CAENHV_InitSystem(
         0, 0, self.ip, "admin", "admin",
         ctypes.byref(self.handle))  # for CAEN SY1527
     print "MTD is using {0} boards".format(len(self.boards))
     #### Read INITIAL values for self.on and self.standby ####
     try:
         self.values = {}
         with open("init_val.txt", "r") as f:
             for line in f:
                 variable, value = line.split(",")
                 self.values[variable] = value.strip("\n")
     except:
         print "!!! init_val.txt not found, setting default values !!!"
         self.values = {
             "MTD:HV:SectorSwitch": 0,
             "MTD:HV:Standby": 0
         }  # Setting default values
     finally:
         self.init_standby = int(self.values["MTD:HV:Standby"])
         self.init_switch = int(self.values["MTD:HV:SectorSwitch"])
     #### Process Variables creation ####
     self.standby = builder.boolOut("Standby",
                                    on_update=self.Standby,
                                    always_update=True,
                                    ZNAM="FULL",
                                    ONAM="StandBy",
                                    initial_value=self.init_standby)
     self.full = builder.boolOut("full", on_update=self.full, HIGH=0.1)
     #self.off = builder.boolOut('off', on_update=self.turnOff, HIGH=0.1)
     #self.on = builder.boolOut('on', on_update=self.turnOn, HIGH=0.1)
     self.on = builder.boolOut('SectorSwitch',
                               on_update=self.Switch,
                               always_update=True,
                               ZNAM="OFF",
                               ONAM="ON",
                               initial_value=self.init_switch)
     self.boardlist_temp = []  # Board Temperature list
     self.boardlist_stat = []  # Board Status list
     self.chanlist = []
     for i in range(0, len(self.boards)):
         if self.boards[i] == 1 or self.boards[i] == 5:
             base_PV_temp = "Negative:{0}:Temp".format(self.boards[i])
             base_PV_stat = "Negative:{0}:status".format(self.boards[i])
         else:
             base_PV_temp = "Positive:{0}:Temp".format(self.boards[i])
             base_PV_stat = "Positive:{0}:status".format(self.boards[i])
         self.boardlist_temp.append(builder.aIn(base_PV_temp))
         self.boardlist_stat.append(
             builder.mbbIn(base_PV_stat, ("All good", 0),
                           ("Power-failure", 1), ("Firmware error", 2),
                           ("HV calib error", 3), ("Temtp calib error", 4),
                           ("Under temp", 5), ("Over temp", 6)))
         for j in range(0, len(self.channels)):
             self.chanlist.append(
                 Channel(self.boards[i], self.channels[j], self.lib,
                         self.handle))
def create_records(configure_scan_function, start_scan_function, min_x, min_y,
                   min_z, max_x, max_y, max_z):
    """Create the records for the scan interface"""

    # We'll return them in a dict
    records = {}

    # Start the scan
    records["start_scan"] = builder.mbbOut('START',
                                           initial_value=0,
                                           PINI='NO',
                                           NOBT=2,
                                           ZRVL=0,
                                           ZRST='Start',
                                           ONVL=1,
                                           ONST='Starting',
                                           on_update=start_scan_function,
                                           always_update=True)

    records["configure_scan"] = builder.mbbOut(
        'CONFIGURE',
        initial_value=0,
        PINI='NO',
        NOBT=2,
        ZRVL=0,
        ZRST='Configure',
        ONVL=1,
        ONST='Configuring',
        on_update=configure_scan_function,
        always_update=True)

    # Status to say we're sending commands
    records["STATE"] = builder.mbbIn("STATE",
                                     initial_value=0,
                                     PINI='YES',
                                     NOBT=2,
                                     ZRVL=STATE_NOT_CONFIGRED,
                                     ZRST='Not configured',
                                     ZRSV="INVALID",
                                     ONVL=STATE_PREPARING,
                                     ONST='Preparing',
                                     ONSV="MINOR",
                                     TWVL=STATE_ERROR,
                                     TWST='Error',
                                     TWSV="MAJOR",
                                     THVL=STATE_READY,
                                     THST='Ready',
                                     THSV="NO_ALARM",
                                     FRVL=STATE_SCAN_RUNNING,
                                     FRST="Scan running",
                                     FRSV="NO_ALARM")
    # Number of steps in x
    records["NX"] = builder.longOut("NX",
                                    initial_value=30,
                                    PINI='YES',
                                    LOPR=1,
                                    HOPR=1000000)
    # Number of steps in y
    records["NY"] = builder.longOut("NY",
                                    initial_value=30,
                                    PINI='YES',
                                    DRVL=1,
                                    DRVH=1000000)
    # Number of steps in z
    records["NZ"] = builder.longOut("NZ",
                                    initial_value=30,
                                    PINI='YES',
                                    DRVL=1,
                                    DRVH=1000000)
    # x step size / um
    records["DX"] = builder.aOut("DX",
                                 initial_value=0.1,
                                 PINI='YES',
                                 DRVL=0.001,
                                 DRVH=300.0,
                                 EGU="um",
                                 PREC=3)
    # y step size / um
    records["DY"] = builder.aOut("DY",
                                 initial_value=0.1,
                                 PINI='YES',
                                 DRVL=0.001,
                                 DRVH=300.0,
                                 EGU="um",
                                 PREC=3)

    # z step size / um
    records["DZ"] = builder.aOut("DZ",
                                 initial_value=0.1,
                                 PINI='YES',
                                 DRVL=0.001,
                                 DRVH=300.0,
                                 EGU="um",
                                 PREC=3)

    # x centre position / um
    records["X0"] = builder.aOut("X0",
                                 initial_value=150,
                                 PINI='YES',
                                 DRVL=min_x,
                                 DRVH=max_x,
                                 EGU="um",
                                 PREC=3)
    # y centre position / um
    records["Y0"] = builder.aOut("Y0",
                                 initial_value=150,
                                 PINI='YES',
                                 DRVL=min_y,
                                 DRVH=max_y,
                                 EGU="um",
                                 PREC=3)

    # z centre position / um
    records["Z0"] = builder.aOut("Z0",
                                 initial_value=150,
                                 PINI='YES',
                                 DRVL=min_z,
                                 DRVH=max_z,
                                 EGU="um",
                                 PREC=3)

    # Theta rotation about Y / degrees
    records["THETA"] = builder.aOut("THETA",
                                    initial_value=0.0,
                                    PINI='YES',
                                    DRVL=-360,
                                    DRVH=360,
                                    EGU="deg",
                                    PREC=3)

    # EXPOSURE time / ms
    records["EXPOSURE"] = builder.aOut("EXPOSURE",
                                       initial_value=100,
                                       PINI='YES',
                                       DRVL=0.001,
                                       DRVH=300.0,
                                       EGU="ms",
                                       PREC=1)

    # Move time / ms
    records["MOVETIME"] = builder.aOut("MOVETIME",
                                       initial_value=40,
                                       PINI='YES',
                                       DRVL=0.001,
                                       DRVH=300.0,
                                       EGU="ms",
                                       PREC=1)

    return records
Beispiel #8
0
 def __init__(self, bdlist, channel, lib, handle):
     self.bdlist = bdlist
     self.channel = channel
     self.lib = lib
     self.handle = handle
     # Process Variables
     if self.bdlist == 1 or self.bdlist == 5:
         base_PV = "Negative:{0}:{1}:".format(self.bdlist, self.channel)
     else:
         base_PV = "Positive:{0}:{1}:".format(self.bdlist, self.channel)
     self.readVol = builder.aIn(
         base_PV + "vmon",
         LOPR=0,
         HOPR=8000,
         LOW=6200,
         LOLO=6000,
         LLSV="MAJOR",
         LSV="MINOR",
         EGU="V",
     )
     self.readCur = builder.aIn(base_PV + "imon",
                                LOPR=0,
                                HOPR=100,
                                PREC=2,
                                HIHI=20,
                                HIGH=15,
                                HHSV="MAJOR",
                                HSV="MINOR",
                                EGU="muA")
     self.readStatus = builder.mbbIn(
         base_PV + "status", ("Off", 0), ("On", 1), ("Ramping Up", 2),
         ("Ramping Down", 3), ("Over-Current", 4, "MAJOR"),
         ("Over-Voltage", 5, "MAJOR"), ("Under-Voltage", 6, "MAJOR"),
         ("External Trip", 7, "MAJOR"), ("Max V", 8, "MAJOR"),
         ("Ext. Disable", 9, "MAJOR"), ("Internal Trip", 10, "MAJOR"),
         ("Calib. Error", 11, "MINOR"), ("Unplugged", 12, "MINOR"),
         ("reserved forced to 0", 13, "MAJOR"),
         ("OverVoltage Protection", 14, "MAJOR"),
         ("PowerFail", 15, "MAJOR"), ("Temperature Error", 16, "MAJOR"))
     #self.setOn = builder.boolOut(base_PV+'setOn', on_update=self.setOn, HIGH=1, always_update=True)
     #self.setOff = builder.boolOut(base_PV+'setOff', on_update=self.setOff, HIGH=1, always_update=True)
     self.setVol = builder.aOut(
         base_PV + 'v0set',
         LOPR=0,
         HOPR=8000,
         EGU="V",
         initial_value=self.getFloatParameter("V0Set"),
         on_update=self.setV0Set,
         always_update=True)
     self.setMaxVol = builder.aOut(
         base_PV + 'setMaxVol',
         LOPR=0,
         HOPR=8000,
         EGU="V",
         initial_value=self.getFloatParameter("SVMax"),
         on_update=self.setSVMax,
         always_update=True)
     self.setRampUp = builder.aOut(
         base_PV + 'setRampUp',
         LOPR=0,
         HOPR=50,
         EGU="V/s",
         initial_value=self.getFloatParameter("RUp"),
         on_update=self.setRUp,
         always_update=True)
     self.setRampDown = builder.aOut(
         base_PV + 'setRampDown',
         LOPR=0,
         HOPR=50,
         EGU="V/s",
         initial_value=self.getFloatParameter("RDWn"),
         on_update=self.setRDWn,
         always_update=True)
     self.setTripI = builder.aOut(
         base_PV + 'setTripI',
         LOPR=0,
         HOPR=90,
         PREC=2,
         EGU="muA",
         initial_value=self.getFloatParameter("I0Set"),
         on_update=self.setI0Set,
         always_update=True)
     self.setTripTime = builder.aOut(
         base_PV + 'setTripTime',
         LOPR=0,
         HOPR=90,
         PREC=1,
         EGU="s",
         initial_value=self.getFloatParameter("Trip"),
         on_update=self.setTrip,
         always_update=True)
     self.pwOnOff = builder.boolOut(base_PV + "pwonoff",
                                    on_update=self.slideOnOff,
                                    ZNAM="OFF",
                                    ONAM="ON",
                                    always_update=True)