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)
Esempio n. 2
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 "
Esempio n. 3
0
    def on_update_test_func(
        self, device_name, record_func, conn, always_update
    ):

        builder.SetDeviceName(device_name)

        li = builder.longIn("ON-UPDATE-COUNTER-RECORD", initial_value=0)

        def on_update_func(new_val):
            """Increments li record each time main out record receives caput"""
            li.set(li.get() + 1)

        kwarg = {}
        if record_func is builder.WaveformOut:
            kwarg = {"length": WAVEFORM_LENGTH}  # Must specify when no value

        record_func(
            "ON-UPDATE-RECORD",
            on_update=on_update_func,
            always_update=always_update,
            **kwarg)

        def on_update_done(_):
            conn.send("C")  # "Complete"
        # Put to the action record after we've done all other Puts, so we know
        # all the callbacks have finished processing
        builder.Action("ON-UPDATE-DONE", on_update=on_update_done)

        dispatcher = asyncio_dispatcher.AsyncioDispatcher()
        builder.LoadDatabase()
        softioc.iocInit(dispatcher)

        conn.send("R")  # "Ready"

        log("CHILD: Sent R over Connection to Parent")

        # Keep process alive while main thread runs CAGET
        if conn.poll(TIMEOUT):
            val = conn.recv()
            assert val == "D", "Did not receive expected Done character"

        log("CHILD: Received exit command, child exiting")
Esempio n. 4
0
    def blocking_test_func(self, device_name, conn):

        builder.SetDeviceName(device_name)

        count_rec = builder.longIn("BLOCKING-COUNTER", initial_value=0)

        async def blocking_update_func(new_val):
            """A function that will block for some time"""
            log("CHILD: blocking_update_func starting")
            await asyncio.sleep(0.5)
            log("CHILD: Finished sleep!")
            completed_count = count_rec.get() + 1
            count_rec.set(completed_count)
            log(
                "CHILD: blocking_update_func finished, completed ",
                completed_count
            )

        builder.longOut(
            "BLOCKING-REC",
            on_update=blocking_update_func,
            always_update=True,
            blocking=True
        )


        dispatcher = asyncio_dispatcher.AsyncioDispatcher()
        builder.LoadDatabase()
        softioc.iocInit(dispatcher)

        conn.send("R")  # "Ready"

        log("CHILD: Sent R over Connection to Parent")

        # Keep process alive while main thread runs CAGET
        if conn.poll(TIMEOUT):
            val = conn.recv()
            assert val == "D", "Did not receive expected Done character"

        log("CHILD: Received exit command, child exiting")
Esempio n. 5
0
def test_DISP_can_be_overridden():
    """Test that DISP can be forced off for In records"""

    record = builder.longIn("DISP-OFF", DISP=0)
    # Note: DISP attribute won't exist if field not specified
    assert record.DISP.Value() == 0
Esempio n. 6
0
    def _create_mirror_records(self, mirror_csv):
        """Create all the mirror records from the .csv file at the location
        passed, see create_csv.py for more information.

        Args:
            mirror_csv (string): The filepath to the .csv file to load the
                                    records in accordance with.
        """
        csv_reader = csv.DictReader(open(mirror_csv))
        for line in csv_reader:
            # Parse arguments.
            input_pvs = line["in"].split(", ")
            if (len(input_pvs) > 1) and (line["mirror type"]
                                         in ["basic", "inverse", "refresh"]):
                raise IndexError("Transformation, refresher, and basic mirror "
                                 "types take only one input PV.")
            elif (len(input_pvs) < 2) and (line["mirror type"]
                                           in ["collate", "summate"]):
                raise IndexError("collation and summation mirror types take at"
                                 " least two input PVs.")
            monitor = input_pvs  # need to update to support camonitor multiple
            # Convert input pvs to record objects
            input_records = []
            for pv in input_pvs:
                try:
                    input_records.append(self.all_record_names[pv])
                except KeyError:
                    input_records.append(caget_mask(pv))
            # Create output record.
            prefix, suffix = line["out"].split(":", 1)
            builder.SetDeviceName(prefix)
            if line["mirror type"] == "refresh":
                # Refresh records come first as do not require an output record
                pass
            elif line["output type"] == "caput":
                output_record = caput_mask(line["out"])
            elif line["output type"] == "aIn":
                value = float(line["value"])
                output_record = builder.aIn(suffix,
                                            initial_value=value,
                                            MDEL="-1")
            elif line["output type"] == "longIn":
                value = int(line["value"])
                output_record = builder.longIn(suffix,
                                               initial_value=value,
                                               MDEL="-1")
            elif line["output type"] == "Waveform":
                value = numpy.asarray(line["value"][1:-1].split(", "),
                                      dtype=float)
                output_record = builder.Waveform(suffix, initial_value=value)
            else:
                raise TypeError("{0} isn't a supported mirroring output type;"
                                "please enter 'caput', 'aIn', 'longIn', or "
                                "'Waveform'.".format(line["output type"]))
            # Update the mirror dictionary.
            for pv in monitor:
                if pv not in self._mirrored_records:
                    self._mirrored_records[pv] = []
            if line["mirror type"] == "basic":
                self._mirrored_records[monitor[0]].append(output_record)
            elif line["mirror type"] == "inverse":
                # Other transformation types are not yet supported.
                transformation = transform(numpy.invert, output_record)
                self._mirrored_records[monitor[0]].append(transformation)
            elif line["mirror type"] == "summate":
                summation_object = summate(input_records, output_record)
                for pv in monitor:
                    self._mirrored_records[pv].append(summation_object)
            elif line["mirror type"] == "collate":
                collation_object = collate(input_records, output_record)
                for pv in monitor:
                    self._mirrored_records[pv].append(collation_object)
            elif line["mirror type"] == "refresh":
                refresh_object = refresher(self, line["out"])
                self._mirrored_records[pv].append(refresh_object)
            else:
                raise TypeError("{0} is not a valid mirror type; please enter "
                                "a currently supported type from: 'basic', "
                                "'summate', 'collate', 'inverse', and "
                                "'refresh'.".format(line["mirror type"]))
Esempio n. 7
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)
Esempio n. 8
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)