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)
Ejemplo n.º 2
0
 def __init__(self, chanID, BoardID, relay):
     self.chanID = chanID
     self.BoardID = BoardID
     self.relay = relay
     #print "Hi, I am channel",self.chanID, "and board",self.BoardID
     pvname = '{0:02d}:{1:02d}:'.format(self.BoardID, self.chanID)
     self.pv_vmon = builder.aIn(pvname + "vmon")
     self.pv_vmon.PREC = 2
     self.pv_vmon.LOPR = 0
     self.pv_vmon.HOPR = 2100
     self.pv_current = builder.aIn(pvname + "current")
     self.pv_vset = builder.aOut(pvname + "vset",
                                 on_update=self.write_voltage)
     self.pv_vset.PREC = 2
     self.pv_vset.HOPR = 3000
     self.pv_vset.LOPR = 0
     self.calc = builder.records.calc(pvname + 'calc', CALC='ABS(A-B)')
     self.calc.INPA = self.pv_vset.name
     self.calc.INPB = self.pv_vmon.name + " MS"
     self.pv_vmon.FLNK = builder.PP(self.calc)
     self.pv_vset.FLNK = builder.PP(self.calc)
     self.hihi = 30
     self.high = 25
     self.calc.HIHI = self.hihi
     self.calc.HIGH = self.high
     self.calc.HHSV = "MAJOR"
     self.calc.HSV = "MINOR"
     self.ramprate = builder.aOut(pvname + "ramprate",
                                  on_update=self.set_ramp,
                                  initial_value=100)
     #print self.calc.name
     self.calc_high = epics.PV(self.calc.name + ".HIGH")
     self.calc_hihi = epics.PV(self.calc.name + ".HIHI")
Ejemplo n.º 3
0
 def _create_records(self, pvs):
     start = time.time()
     for pv in pvs:
         builder.SetDeviceName(pv)
         builder.aIn('I', initial_value=0.1)
         builder.aOut('SETI', initial_value=0.1)
     print("    Time per pv: {0}".format((time.time() - start) / len(pvs)))
Ejemplo n.º 4
0
    def test_blocking_creates_attributes(self):
        """Test that setting the blocking flag on record creation creates the
        expected attributes"""
        ao1 = builder.aOut("OUTREC1", blocking=True)
        self.check_record_blocking_attributes(ao1)

        ao2 = builder.aOut("OUTREC2", blocking=False)
        assert ao2._blocking is False
Ejemplo n.º 5
0
    def __init__(self, ip):
        self.readData = builder.boolOut('readData',
                                        on_update=self.place_voltages,
                                        HIGH=0.1)
        self.on = builder.boolOut('on', on_update=self.turnOn, HIGH=0.1)
        self.off = builder.boolOut('off', on_update=self.turnOff, HIGH=0.1)
        self.avrgVolt = builder.aIn('avrgVolt')
        self.avrgTemp = builder.longIn('avrgTemp')
        self.avrgVoltInner = builder.aIn('avrgVoltInner')
        self.avrgVoltOuter = builder.aIn('avrgVoltOuter')
        self.marker = builder.longIn('marker')
        self.setVoltInner_pv = builder.aOut("setVoltInner",
                                            on_update=self.setVoltInner)
        self.setVoltOuter_pv = builder.aOut("setVoltOuter",
                                            on_update=self.setVoltOuter)
        self.write_voltages_pv = builder.boolOut("write_voltages",
                                                 on_update=self.write_voltages,
                                                 HIGH=0.1)
        self.datacsv = "data.csv"
        self.reset = builder.boolOut("reset", on_update=self.Reset, HIGH=0.1)
        self.adj_current_pv = builder.boolOut("adj_current",
                                              on_update=self.adj_current,
                                              HIGH=0.1)
        self.adj_msg = "Last done: "
        self.adj_stat_pv = builder.stringIn("adj_stat",
                                            initial_value=self.adj_msg +
                                            "none")

        self.chlist = []
        self.wboard, self.wch = 0, 0
        self.ip = ip
        self.dictWiener, self.dictTPC = {}, {}

        #snmp 5.8 for user defined precision in current readings, compiled according to
        # http://file.wiener-d.com/software/net-snmp/net-snmp-CompileForExtendedPrecision-2015-03-06.txt
        self.snmpwalk = "/usr/local/Net-SNMP_5-8/code/apps/snmpwalk"
        self.snmpset = "/usr/local/Net-SNMP_5-8/code/apps/snmpset -v 2c -c seCrET " + self.ip + " WIENER-CRATE-MIB::"

        file = open("file.txt", "w")
        file.write(
            "TPC sector \t TPC channel \t WIENER board \t WIENER channel \n")
        for self.i in xrange(1, 25):  # sector
            for self.j in xrange(2):  # channel
                a = '{0} \t\t {1} \t\t {2} \t\t {3} \n'.format(
                    self.i, self.j, self.wboard, self.wch)
                file.write(a)
                self.chlist.append(
                    Channel(self.i, self.j, self.wboard, self.wch,
                            self.snmpset))
                self.dictWiener[(self.wboard, self.wch)] = self.chlist[-1]
                self.dictTPC[(self.i, self.j)] = self.chlist[-1]
                self.wch += 1
                if (self.wch > 15):
                    self.wboard += 1
                    self.wch = 0
        file.close()
        print "Before start, you have to Load Voltage from file through Load Voltage button "
Ejemplo n.º 6
0
def test_hlopr_dvrhl_different_values():
    """Test you can set H/LOPR and DRVH/L to different values"""
    ao = builder.aOut("DEF", DRVL=1, LOPR=2, HOPR=3, DRVH=4)

    assert ao.DRVL.Value() == 1
    assert ao.LOPR.Value() == 2
    assert ao.HOPR.Value() == 3
    assert ao.DRVH.Value() == 4
Ejemplo n.º 7
0
def main():
    if "-v" in sys.argv:
        logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
        sys.argv.remove("-v")
    else:
        logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

    # Determine the ring mode
    if sys.argv[1:]:
        ring_mode = sys.argv[1]
    else:
        try:
            ring_mode = str(os.environ["RINGMODE"])
        except KeyError:
            try:
                value = caget("SR-CS-RING-01:MODE", format=2)
                ring_mode = value.enums[int(value)]
            except ca_nothing:
                ring_mode = "DIAD"

    # Create PVs.
    server = atip_server.ATIPServer(
        ring_mode,
        DATADIR / "limits.csv",
        DATADIR / "feedback.csv",
        DATADIR / "mirrored.csv",
        DATADIR / "tunefb.csv",
    )

    # Add special case out record for SOFB to write to.
    builder.SetDeviceName("CS-CS-MSTAT-01")
    builder.aOut("FBHEART", initial_value=10)

    # Start the IOC.
    builder.LoadDatabase()
    softioc.iocInit()
    server.monitor_mirrored_pvs()
    server.setup_tune_feedback()

    softioc.interactive_ioc(globals())
Ejemplo n.º 8
0
 def __init__(self, ibd, ichan, bdofs, com):
     #telnet to lecroy
     self.com = com
     #id of board
     self.ibd = ibd
     #id of this channel
     self.ichan = ichan
     #offset in board numbering
     self.bdofs = bdofs
     #PVs for the channel
     pvnam = "{0:02d}:{1:02d}:".format(self.ibd + self.bdofs, self.ichan)
     self.mc_pv = builder.aIn(pvnam + "mc", PREC=3)
     self.mv_pv = builder.aIn(pvnam + "mv",
                              PREC=1,
                              LLSV="MAJOR",
                              HHSV="MAJOR",
                              LOPR=-200.,
                              HOPR=0.)
     self.dv_pv = builder.aOut(pvnam + "dv", on_update=self.put_dv)
Ejemplo n.º 9
0
def test_drvhl_hlopr_defaults():
    """Test the DRVH/L and H/LOPR default settings"""
    # DRVH/L doesn't exist on In records
    ai = builder.aIn("FOO")
    # KeyError as fields with no value are simply not present in
    # epicsdbbuilder's dictionary of fields
    with pytest.raises(KeyError):
        assert ai.LOPR.Value() is None
    with pytest.raises(KeyError):
        assert ai.HOPR.Value() is None

    ao = builder.aOut("BAR")
    with pytest.raises(KeyError):
        assert ao.LOPR.Value() is None
    with pytest.raises(KeyError):
        assert ao.HOPR.Value() is None
    with pytest.raises(KeyError):
        assert ao.DRVH.Value() is None
    with pytest.raises(KeyError):
        assert ao.DRVL.Value() is None
Ejemplo n.º 10
0
 def __init__(self, boardList, relay):
     self.relay = relay
     self.boardList = boardList
     self.bdbegin = 0
     self.bdend = 15
     self.cnbegin = 0
     self.cnend = 15
     #these pvs were created because the user can pick from a range of boards and channels to
     #change their limits
     self.ACboardb = builder.longOut("ACBbegin", initial_value=self.bdbegin)
     self.ACboarde = builder.longOut("ACBend", initial_value=self.bdend)
     self.ACchanb = builder.longOut("ACCbegin", initial_value=self.cnbegin)
     self.ACchane = builder.longOut("ACCend", initial_value=self.cnend)
     #this pv holds the new value for the limit
     self.actrip = builder.aOut("ac_tripval", initial_value=10)
     #this pv will be a button that the user can press to confirm their changes
     self.setactrip = builder.boolOut("setactrip",
                                      ZNAM=0,
                                      ONAM=1,
                                      HIGH=0.1,
                                      on_update=self.set_limits)
Ejemplo n.º 11
0
# Import the basic framework components.
from softioc import softioc, builder, asyncio_dispatcher
import asyncio

# Create an asyncio dispatcher, the event loop is now running
dispatcher = asyncio_dispatcher.AsyncioDispatcher()

# Set the record prefix
builder.SetDeviceName("MY-DEVICE-PREFIX")

# Create some records
ai = builder.aIn('AI', initial_value=5)
ao = builder.aOut('AO', initial_value=12.45, always_update=True,
                  on_update=lambda v: ai.set(v))

# Boilerplate get the IOC started
builder.LoadDatabase()
softioc.iocInit(dispatcher)

# Start processes required to be run after iocInit
async def update():
    while True:
        ai.set(ai.get() + 1)
        await asyncio.sleep(1)

asyncio.run_coroutine_threadsafe(update(), dispatcher.loop)

# Finally leave the IOC running with an interactive shell.
softioc.interactive_ioc(globals())
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
    def _create_records(self, limits_csv):
        """Create all the standard records from both lattice and element Pytac
        fields. Several assumptions have been made for simplicity and
        efficiency, these are:
            - That bend elements all share a single PV, and are the only
               element family to do so.
            - That every field that has an out type record (SP) will also have
               an in type record (RB).
            - That all lattice fields are never setpoint and so only in records
               need to be created for them.

        Args:
            limits_csv (string): The filepath to the .csv file from which to
                                    load the pv limits.
        """
        limits_dict = {}
        if limits_csv is not None:
            csv_reader = csv.DictReader(open(limits_csv))
            for line in csv_reader:
                limits_dict[line["pv"]] = (
                    float(line["upper"]),
                    float(line["lower"]),
                    int(line["precision"]),
                )
        bend_in_record = None
        for element in self.lattice:
            if element.type_ == "BEND":
                # Create bends only once as they all share a single PV.
                if bend_in_record is None:
                    value = element.get_value("b0",
                                              units=pytac.ENG,
                                              data_source=pytac.SIM)
                    get_pv = element.get_pv_name("b0", pytac.RB)
                    upper, lower, precision = limits_dict.get(
                        get_pv, (None, None, None))
                    builder.SetDeviceName(get_pv.split(":", 1)[0])
                    in_record = builder.aIn(
                        get_pv.split(":", 1)[1],
                        LOPR=lower,
                        HOPR=upper,
                        PREC=precision,
                        MDEL="-1",
                        initial_value=value,
                    )
                    set_pv = element.get_pv_name("b0", pytac.SP)
                    upper, lower, precision = limits_dict.get(
                        set_pv, (None, None, None))
                    builder.SetDeviceName(set_pv.split(":", 1)[0])
                    out_record = builder.aOut(
                        set_pv.split(":", 1)[1],
                        LOPR=lower,
                        HOPR=upper,
                        PREC=precision,
                        initial_value=value,
                        on_update_name=self._on_update,
                        always_update=True,
                    )
                    self._in_records[in_record] = ([element.index], "b0")
                    self._out_records[out_record] = in_record
                    bend_in_record = in_record
                else:
                    self._in_records[bend_in_record][0].append(element.index)
            else:
                # Create records for all other families.
                for field in element.get_fields()[pytac.SIM]:
                    value = element.get_value(field,
                                              units=pytac.ENG,
                                              data_source=pytac.SIM)
                    get_pv = element.get_pv_name(field, pytac.RB)
                    upper, lower, precision = limits_dict.get(
                        get_pv, (None, None, None))
                    builder.SetDeviceName(get_pv.split(":", 1)[0])
                    in_record = builder.aIn(
                        get_pv.split(":", 1)[1],
                        LOPR=lower,
                        HOPR=upper,
                        PREC=precision,
                        MDEL="-1",
                        initial_value=value,
                    )
                    self._in_records[in_record] = (element.index, field)
                    try:
                        set_pv = element.get_pv_name(field, pytac.SP)
                    except HandleException:
                        self._rb_only_records.append(in_record)
                    else:
                        upper, lower, precision = limits_dict.get(
                            set_pv, (None, None, None))
                        builder.SetDeviceName(set_pv.split(":", 1)[0])
                        out_record = builder.aOut(
                            set_pv.split(":", 1)[1],
                            LOPR=lower,
                            HOPR=upper,
                            PREC=precision,
                            initial_value=value,
                            on_update_name=self._on_update,
                            always_update=True,
                        )
                        self._out_records[out_record] = in_record
        # Now for lattice fields.
        lat_fields = self.lattice.get_fields()
        for field in set(lat_fields[pytac.LIVE]) & set(lat_fields[pytac.SIM]):
            # Ignore basic devices as they do not have PVs.
            if not isinstance(self.lattice.get_device(field), BasicDevice):
                get_pv = self.lattice.get_pv_name(field, pytac.RB)
                value = self.lattice.get_value(field,
                                               units=pytac.ENG,
                                               data_source=pytac.SIM)
                builder.SetDeviceName(get_pv.split(":", 1)[0])
                in_record = builder.aIn(get_pv.split(":", 1)[1],
                                        PREC=4,
                                        initial_value=value,
                                        MDEL="-1")
                self._in_records[in_record] = (0, field)
                self._rb_only_records.append(in_record)
        print("~*~*Woah, we're halfway there, Wo-oah...*~*~")
Ejemplo n.º 14
0
            # Set the ao value, which will trigger on_update for it
            sim_records.t_ao.set(value)
            print("async update %s (%s)" % (value, sim_records.t_ai.get()))
            # Make sure it goes as epicsExit will not flush this for us
            sys.stdout.flush()
            # Set the ai alarm, but keep the value
            sim_records.t_ai.set_alarm(int(value) % 4, alarm.STATE_ALARM)
            # Must give the t_ai record time to process
            await asyncio.sleep(1)
            conn.send("C")  # "Complete"

        # Set a different initial value
        sim_records.t_ai.set(23.45)

        # Create a record to set the alarm
        t_ao = builder.aOut('ALARM', on_update=callback)

        async def on_update_name_callback(value, name):
            print(name, "value", value)

        builder.longOut(
            "NAME-CALLBACK",
            initial_value = 3,
            always_update=True,
            on_update_name=on_update_name_callback,
            blocking=True
        )

        # Run the IOC
        builder.LoadDatabase()
        softioc.iocInit(asyncio_dispatcher.AsyncioDispatcher())
import sys
import os

from pkg_resources import require
require('cothread==2.13')
require('numpy==1.11.1')
require('epicsdbbuilder==1.0')

from softioc import softioc, builder
from epicsdbbuilder import records  #, MS, CP, ImportRecord

##############################################

builder.SetDeviceName('BL04I-EA-XBPM-01')

x1sigcurr = builder.aOut('SumAll:MeanValue_RBV', initial_value=5)
x1r = builder.mbbOut('DRV:Range', initial_value=0)
x1psy = builder.mbbOut('DRV:PositionScaleY', initial_value=790)
x1psx = builder.mbbOut('DRV:PositionScaleX', initial_value=1200)

##############################################

builder.SetDeviceName('BL04I-EA-XBPM-02')

x2sigcurr = builder.aOut('SumAll:MeanValue_RBV', initial_value=7)
x2r = builder.aOut('DRV:Range', initial_value=0)
x2psy = builder.aOut('DRV:PositionScaleY', initial_value=247)
x2psx = builder.aOut('DRV:PositionScaleX', initial_value=1200)

##############################################
import os

from pkg_resources import require
require('cothread==2.13')
require('numpy==1.11.1')
require('epicsdbbuilder==1.0')

from softioc import softioc, builder
from epicsdbbuilder import records  #, MS, CP, ImportRecord
"""#builder.SetDeviceName('IOC-TEST')
builder.SetDeviceName('SFX44126-PY-IOC-01')
"""

builder.SetDeviceName('BL03I-EA-XBPM-01')

x1sigcurr = builder.aOut('SumAll:MeanValue_RBV', initial_value=30e-09)
x1r = builder.mbbOut('DRV:Range', initial_value=0)
x1psy = builder.mbbOut('DRV:PositionScaleY', initial_value=1)
x1psx = builder.mbbOut('DRV:PositionScaleX', initial_value=1)

builder.SetDeviceName('BL03I-EA-XBPM-02')

x2sigcurr = builder.aOut('SumAll:MeanValue_RBV', initial_value=1.02991e-06)
x2r = builder.mbbOut('DRV:Range', initial_value=0)
x2psy = builder.mbbOut('DRV:PositionScaleY', initial_value=1)
x2psx = builder.mbbOut('DRV:PositionScaleX', initial_value=1)

builder.SetDeviceName('BL03I-MO-DCM-01')

A = 1
x1SF = builder.aOut('ENERGY', initial_value=12.658)
def build_interactive_sin():
    """
    Set up an interactive sine wave that has controls attached to PVs.
    Two output waves our generated, one which samples the sine function
    at a fixed update rate, and the other which outputs a single cycle
    of a sine wave in a waveform PV.

    This returns a function that is intended to be passed to Cothread's
    Spawn function to provide the updates of the travelling wave.
    """

    class Sin(object):
        """
        Holds the state required to simulate a sine wave with external
        PV controls.
        """
        NUM_POINTS = 200
        def __init__(self):
            self.amp = 1
            self.phase = 0
            self.wf_pv = None
            self.travel_pv = None
            self.x = numpy.linspace(0, 2*numpy.pi, self.NUM_POINTS)
            self._update_waveform()
        def set_phase(self, phase):
            self.phase = phase
            self._update_waveform()
        def set_amp(self, amp):
            self.amp = amp
            self._update_waveform()
        def register_waveform_pv(self, pv):
            self.wf_pv = pv
        def register_travelling_pv(self, pv):
            self.travel_pv = pv
        def get_travelling_update_function(self):
            UPDATE_RATE = 10
            TICK_DELTA = numpy.pi / UPDATE_RATE
            X = 0
            def run_sin_wave():
                x = X
                while True:
                    cothread.Sleep(1./UPDATE_RATE)
                    x += TICK_DELTA
                    value = self.amp * numpy.sin(x + self.phase)
                    if self.travel_pv:
                        self.travel_pv._RecordWrapper__device.set(value)
            return run_sin_wave
        def _update_waveform(self):
            self.wf = self.amp * numpy.sin(self.x + self.phase)
            if self.wf_pv:
                self.wf_pv._RecordWrapper__device.set(self.wf)

    sin = Sin()
    builder.WaveformOut('SINE:X', sin.x)
    builder.aOut(
            'SINE:AMP', on_update=lambda x: sin.set_amp(x),
            LOPR=0, HOPR=2, PREC=2, initial_value=sin.amp)
    builder.aOut(
            'SINE:PHASE', on_update=lambda x: sin.set_phase(x),
            LOPR=0, HOPR=numpy.pi*2, PREC=2, initial_value=sin.phase)
    sin.register_travelling_pv(
            builder.aOut('SINE:TRAVEL', PREC=2, initial_value=0))
    sin.register_waveform_pv(builder.WaveformOut('SINE:WF', sin.wf))

    return sin.get_travelling_update_function()
Ejemplo n.º 18
0
from softioc import builder, softioc
from softioc.builder import records

builder.SetDeviceName("XX-XX-XX-01")

py_record = builder.aOut("VAL1", initial_value=5, on_update=print)
soft_record = records.ao("VAL2", VAL=10)

calc = records.calc("CALC", CALC="A*B", INPA=builder.CP(py_record), B=1)

soft_record.OUT = builder.PP(calc.B)

builder.LoadDatabase()
softioc.iocInit()

softioc.interactive_ioc(globals())
Ejemplo n.º 19
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)
import os

from pkg_resources import require

require('cothread==2.13')
require('numpy==1.11.1')
require('epicsdbbuilder==1.0')

from softioc import softioc, builder
from epicsdbbuilder import records  #, MS, CP, ImportRecord

##############################################

builder.SetDeviceName('BL24I-EA-XBPM-01')

x1sigcurr = builder.aOut('SumAll:MeanValue_RBV', initial_value=5)
x1r = builder.mbbOut('DRV:Range', initial_value=0)
x1psy = builder.mbbOut('DRV:PositionScaleY', initial_value=1)
x1psx = builder.mbbOut('DRV:PositionScaleX', initial_value=1)

##############################################

builder.SetDeviceName('BL24I-OP-DCM-01')

A = 1
x1SF = builder.aOut('ENERGY', initial_value=11.882)
pitch = builder.aOut('FPITCH:FB1', initial_value=0.554)
roll = builder.aOut('FPITCH:FB2', initial_value=0.0261)

##############################################
Ejemplo n.º 21
0
 def __init__(self, boardList):
     self.boardList = boardList
     self.ramprate = builder.aOut("placeramprate",
                                  on_update=self.set_ramp,
                                  initial_value=100)
Ejemplo n.º 22
0
 def __init__(self, bdlist, channel, lib, handle):
     self.bdlist = bdlist
     self.channel = channel
     self.lib = lib
     self.handle = handle
     # Process Variables
     base_PV = "{0}:{1}:".format(self.bdlist, self.channel)
     self.readVol = builder.aIn(base_PV + "vmon",
                                LOPR=0,
                                HOPR=2000,
                                EGU="V")
     self.readCur = builder.aIn(base_PV + "imon",
                                LOPR=0,
                                HOPR=3,
                                PREC=2,
                                HIHI=2,
                                HIGH=1.5,
                                HHSV="MAJOR",
                                HSV="MINOR",
                                EGU="muA")
     self.readStatus = builder.longIn(base_PV + "status")
     self.setOn = builder.boolOut(base_PV + 'setOn',
                                  on_update=self.setOn,
                                  HIGH=1)
     self.setOff = builder.boolOut(base_PV + 'setOff',
                                   on_update=self.setOff,
                                   HIGH=1)
     self.setVol = builder.aOut(
         base_PV + 'setVol',
         LOPR=0,
         HOPR=2000,
         EGU="V",
         initial_value=self.getFloatParameter("V0Set"),
         on_update=self.setV0Set)
     self.setMaxVol = builder.aOut(
         base_PV + 'setMaxVol',
         LOPR=0,
         HOPR=2000,
         EGU="V",
         initial_value=self.getFloatParameter("SVMax"),
         on_update=self.setSVMax)
     self.setRampUp = builder.aOut(
         base_PV + 'setRampUp',
         LOPR=0,
         HOPR=50,
         EGU="V/s",
         initial_value=self.getFloatParameter("RUp"),
         on_update=self.setRUp)
     self.setRampDown = builder.aOut(
         base_PV + 'setRampDown',
         LOPR=0,
         HOPR=50,
         EGU="V/s",
         initial_value=self.getFloatParameter("RDWn"),
         on_update=self.setRDWn)
     self.setTripI = builder.aOut(
         base_PV + 'setTripI',
         LOPR=0,
         HOPR=90,
         PREC=2,
         EGU="muA",
         initial_value=self.getFloatParameter("I0Set"),
         on_update=self.setI0Set)
     self.setTripTime = builder.aOut(
         base_PV + 'setTripTime',
         LOPR=0,
         HOPR=90,
         PREC=1,
         EGU="s",
         initial_value=self.getFloatParameter("Trip"),
         on_update=self.setTrip)
Ejemplo n.º 23
0
def get_temp_max():
  return elist[0][0][0].limits.temp_max

#_____________________________________________________________________________
def put_limit(key, val):
  #put limit value to file
  lframe[key][0] = val
  lframe.to_csv(csvlim, index=False)

#PVs to set alarm limits
#_____________________________________________________________________________
def set_imon_max(val):
  elist[0][0][0].limits.imon_max = val
  put_limit('imon_max', val)

imon_max_pv = builder.aOut("imon_max", on_update=set_imon_max, initial_value=get_imon_max(), PREC=2)

#_____________________________________________________________________________
def set_rmon_min(val):
  elist[0][0][0].limits.rmon_min = val
  put_limit('rmon_min', val)

rmon_min_pv = builder.aOut("rmon_min", on_update=set_rmon_min, initial_value=get_rmon_min(), PREC=1)

#_____________________________________________________________________________
def set_rmon_max(val):
  elist[0][0][0].limits.rmon_max = val
  put_limit('rmon_max', val)

rmon_max_pv = builder.aOut("rmon_max", on_update=set_rmon_max, initial_value=get_rmon_max(), PREC=1)
Ejemplo n.º 24
0
    def __init__(self, sect_num, chann_num, wboard, wch, snmpset):
        self.sect_num = sect_num
        self.chann_num = chann_num
        self.wboard = wboard
        self.wch = wch
        self.cmdtemplate = snmpset
        base_PV = '{0:02d}:{1:d}:'.format(self.sect_num, self.chann_num)

        # Features of the channels
        self.volt = builder.aOut(base_PV + 'setVoltage',
                                 on_update=self.setVoltage)
        self.curt = builder.aOut(base_PV + 'setCurrent',
                                 on_update=self.setCurrent)
        self.wboardpv = builder.longIn(base_PV + 'wboardpv',
                                       initial_value=self.wboard)
        self.wchpv = builder.longIn(base_PV + 'wchpv', initial_value=self.wch)
        self.setOn = builder.boolOut(base_PV + 'setOn',
                                     on_update=self.setOn,
                                     HIGH=0.1)
        self.setOff = builder.boolOut(base_PV + 'setOff',
                                      on_update=self.setOff,
                                      HIGH=0.1)
        self.readVol = builder.aIn(base_PV + 'readVol', PREC=1)
        if (self.chann_num == 0):
            self.readVol.LOPR = 100
            self.readVol.HOPR = 130
            self.readVol.HIHI = 125
            self.readVol.HIGH = 120
            self.readVol.LOW = 110
            self.readVol.LOLO = 105
            self.readVol.LSV = "MINOR"
            self.readVol.LLSV = "MAJOR"
            self.readVol.HSV = "MINOR"
            self.readVol.HHSV = "MAJOR"
        if (self.chann_num == 1):
            self.readVol.LOPR = 400
            self.readVol.HOPR = 500
            self.readVol.HIHI = 470
            self.readVol.HIGH = 460
            self.readVol.LOW = 440
            self.readVol.LOLO = 430
            self.readVol.LSV = "MINOR"
            self.readVol.LLSV = "MAJOR"
            self.readVol.HSV = "MINOR"
            self.readVol.HHSV = "MAJOR"
        self.readTem = builder.longIn(base_PV + 'readTem')
        self.imon_read = 0.  # measured current from ISEG
        self.imon_adj = 0.  # adjustment to the measured current
        self.readCurr = builder.aIn(base_PV + 'readCurr', PREC=3)
        self.status = builder.longIn(base_PV + 'status')
        self.setReset = builder.boolOut(base_PV + 'setReset',
                                        on_update=self.setReset,
                                        HIGH=0.1)

        if (self.wboard == 0):
            self.a = str(self.wch)
        else:
            if (self.wboard != 0 and self.wch > 9):
                self.a = str(self.wboard) + str(self.wch)
            else:
                self.a = str(self.wboard) + '0' + str(self.wch)
Ejemplo n.º 25
0
#_____________________________________________________________________________
def put_limit(key, val):
    #put limit value to file
    lframe[key][0] = val
    lframe.to_csv(csvlim, index=False)


#PVs to set alarm limits
#_____________________________________________________________________________
def set_imon_max(val):
    elist[0][0][0].limits.imon_max = val
    put_limit('imon_max', val)


imon_max_pv = builder.aOut("imon_max",
                           on_update=set_imon_max,
                           initial_value=get_imon_max(),
                           PREC=2)


#_____________________________________________________________________________
def set_rmon_min(val):
    elist[0][0][0].limits.rmon_min = val
    put_limit('rmon_min', val)


rmon_min_pv = builder.aOut("rmon_min",
                           on_update=set_rmon_min,
                           initial_value=get_rmon_min(),
                           PREC=1)

Ejemplo n.º 26
0
# Determine the ring mode
if sys.argv[1:]:
    ring_mode = sys.argv[1]
else:
    try:
        ring_mode = str(os.environ['RINGMODE'])
    except KeyError:
        try:
            value = caget('SR-CS-RING-01:MODE', format=2)
            ring_mode = value.enums[int(value)]
        except ca_nothing:
            ring_mode = 'DIAD'

# Create PVs.
server = atip_server.ATIPServer(ring_mode, os.path.join(here, 'limits.csv'),
                                os.path.join(here, 'feedback.csv'),
                                os.path.join(here, 'mirrored.csv'),
                                os.path.join(here, 'tunefb.csv'))

# Add special case out record for SOFB to write to.
builder.SetDeviceName('CS-CS-MSTAT-01')
builder.aOut('FBHEART', initial_value=10)

# Start the IOC.
builder.LoadDatabase()
softioc.iocInit()
server.monitor_mirrored_pvs()

softioc.interactive_ioc(globals())