def hardware_collection(process, params):

    # Connect to the Control port
    control = PandABoxControl(process, params.hostname, params.port)
    control.start()

    # Create a block updater
    poller = PandABoxPoller(process, control)

    # Get some information about what is available in this PandABox
    blocks_data = control.get_blocks_data()
    blocks = []
    parts = []

    for block_name, block_data in blocks_data.items():
        block_names = []
        if block_data.number == 1:
            block_names.append(block_name)
        else:
            for i in range(block_data.number):
                block_names.append("%s%d" % (block_name, i + 1))
        for bn in block_names:
            mri = "%s-%s" % (params.mriPrefix, bn)
            if block_name == "PCAP" and params.areaDetectorPrefix:
                extra_parts = make_pcap_ad_parts(
                    process, params.areaDetectorPrefix)
            else:
                extra_parts = []
            # Make a block
            block = poller.make_panda_block(
                mri, bn, block_data, extra_parts, params.areaDetectorPrefix)
            blocks.append(block)
            # Make it's corresponding part
            part = make_child_part(process, bn, mri, params.areaDetectorPrefix)
            parts.append(part)

    # Start polling
    poller.start()

    return blocks, parts
示例#2
0
def hardware_collection(process, params):

    # Connect to the Control port
    control = PandABoxControl(process, params.hostname, params.port)
    control.start()

    # Create a block updater
    poller = PandABoxPoller(process, control)

    # Get some information about what is available in this PandABox
    blocks_data = control.get_blocks_data()
    blocks = []
    parts = []

    for block_name, block_data in blocks_data.items():
        block_names = []
        if block_data.number == 1:
            block_names.append(block_name)
        else:
            for i in range(block_data.number):
                block_names.append("%s%d" % (block_name, i + 1))
        for bn in block_names:
            mri = "%s-%s" % (params.mriPrefix, bn)
            if block_name == "PCAP" and params.areaDetectorPrefix:
                extra_parts = make_pcap_ad_parts(process,
                                                 params.areaDetectorPrefix)
            else:
                extra_parts = []
            # Make a block
            block = poller.make_panda_block(mri, bn, block_data, extra_parts,
                                            params.areaDetectorPrefix)
            blocks.append(block)
            # Make it's corresponding part
            part = make_child_part(process, bn, mri, params.areaDetectorPrefix)
            parts.append(part)

    # Start polling
    poller.start()

    return blocks, parts
示例#3
0
 def setUp(self):
     self.process = Mock()
     self.control = Mock()
     self.o = PandABoxPoller(self.process, self.control)
     fields = OrderedDict()
     fields["INP"] = FieldData("pos_mux", "", "Input A", ["ZERO", "COUNTER.OUT"])
     fields["START"] = FieldData("param", "pos", "Start position", [])
     fields["STEP"] = FieldData("param", "relative_pos", "Step position", [])
     fields["OUT"] = FieldData("bit_out", "", "Output", [])
     self.pcomp = self.o.make_panda_block(
         "P:PCOMP", "PCOMP", BlockData(1, "", fields))
     fields = OrderedDict()
     fields["INP"] = FieldData("bit_mux", "", "Input", ["ZERO", "TTLIN.VAL"])
     fields["START"] = FieldData("param", "pos", "Start position", [])
     fields["OUT"] = FieldData("pos_out", "", "Output", ["No", "Capture"])
     self.counter = self.o.make_panda_block(
         "P:COUNTER", "COUNTER", BlockData(1, "", fields))
     fields = OrderedDict()
     fields["VAL"] = FieldData("bit_out", "", "Output", [])
     self.ttlin = self.o.make_panda_block(
         "P:TTLIN", "TTLIN", BlockData(1, "", fields))
     changes = OrderedDict()
     changes["PCOMP.INP"] = "ZERO"
     for field_name in ("START", "STEP"):
         changes["PCOMP.%s" % field_name] = "0"
         changes["PCOMP.%s.SCALE" % field_name] = "1"
         changes["PCOMP.%s.OFFSET" % field_name] = "0"
         changes["PCOMP.%s.UNITS" % field_name] = ""
     changes["PCOMP.OUT"] = "0"
     changes["COUNTER.INP"] = "ZERO"
     changes["COUNTER.INP.DELAY"] = "0"
     changes["COUNTER.OUT"] = "0"
     changes["COUNTER.OUT.SCALE"] = "1"
     changes["COUNTER.OUT.OFFSET"] = "0"
     changes["COUNTER.OUT.UNITS"] = ""
     changes["TTLIN.VAL"] = "0"
     self.o.handle_changes(changes)
     # Once more to let the bit_outs toggle back
     self.o.handle_changes({})
示例#4
0
def PandABox(process, params):

    # Connect to the Control port
    control = PandABoxControl(process, params.hostname, params.port)
    control.start()

    # Create a block updater
    poller = PandABoxPoller(process, control)

    # Get some information about what is available in this PandABox
    blocks_data = control.get_blocks_data()
    parts = OrderedDict()
    ret = []

    for block_name, block_data in blocks_data.items():
        block_names = []
        if block_data.number == 1:
            block_names.append(block_name)
        else:
            for i in range(block_data.number):
                block_names.append("%s%d" % (block_name, i+1))
        for bn in block_names:
            malcolm_name = "%s:%s" % (params.name, bn)
            ret.append(poller.make_panda_block(malcolm_name, bn, block_data))
            part_params = LayoutPart.MethodMeta.prepare_input_map(
                dict(name=bn, child=malcolm_name))
            parts[bn] = LayoutPart(process, part_params)

    # Make a controller
    controller = ManagerController(params.name, process, parts)
    ret.append(controller.block)

    # Start polling
    poller.start()

    return ret
示例#5
0
class PandABoxPollerTest(unittest.TestCase):
    def setUp(self):
        self.process = Mock()
        self.control = Mock()
        self.o = PandABoxPoller(self.process, self.control)
        fields = OrderedDict()
        fields["INP"] = FieldData("pos_mux", "", "Input A", ["ZERO", "COUNTER.OUT"])
        fields["START"] = FieldData("param", "pos", "Start position", [])
        fields["STEP"] = FieldData("param", "relative_pos", "Step position", [])
        fields["OUT"] = FieldData("bit_out", "", "Output", [])
        self.pcomp = self.o.make_panda_block(
            "P:PCOMP", "PCOMP", BlockData(1, "", fields))
        fields = OrderedDict()
        fields["INP"] = FieldData("bit_mux", "", "Input", ["ZERO", "TTLIN.VAL"])
        fields["START"] = FieldData("param", "pos", "Start position", [])
        fields["OUT"] = FieldData("pos_out", "", "Output", ["No", "Capture"])
        self.counter = self.o.make_panda_block(
            "P:COUNTER", "COUNTER", BlockData(1, "", fields))
        fields = OrderedDict()
        fields["VAL"] = FieldData("bit_out", "", "Output", [])
        self.ttlin = self.o.make_panda_block(
            "P:TTLIN", "TTLIN", BlockData(1, "", fields))
        changes = OrderedDict()
        changes["PCOMP.INP"] = "ZERO"
        for field_name in ("START", "STEP"):
            changes["PCOMP.%s" % field_name] = "0"
            changes["PCOMP.%s.SCALE" % field_name] = "1"
            changes["PCOMP.%s.OFFSET" % field_name] = "0"
            changes["PCOMP.%s.UNITS" % field_name] = ""
        changes["PCOMP.OUT"] = "0"
        changes["COUNTER.INP"] = "ZERO"
        changes["COUNTER.INP.DELAY"] = "0"
        changes["COUNTER.OUT"] = "0"
        changes["COUNTER.OUT.SCALE"] = "1"
        changes["COUNTER.OUT.OFFSET"] = "0"
        changes["COUNTER.OUT.UNITS"] = ""
        changes["TTLIN.VAL"] = "0"
        self.o.handle_changes(changes)
        # Once more to let the bit_outs toggle back
        self.o.handle_changes({})

    def test_initial_changes(self):
        pcomp = self.pcomp
        self.assertEqual(pcomp.inp, "ZERO")
        self.assertEqual(pcomp.inpVal, 0.0)
        self.assertEqual(pcomp.start, 0.0)
        self.assertEqual(pcomp.step, 0.0)
        self.assertEqual(pcomp.out, False)
        counter = self.counter
        self.assertEqual(counter.inp, "ZERO")
        self.assertEqual(counter.inpDelay, 0)
        self.assertEqual(counter.inpVal, False)
        self.assertEqual(counter.out, 0.0)
        self.assertEqual(counter.outScale, 1.0)
        self.assertEqual(counter.outOffset, 0.0)
        self.assertEqual(counter.outUnits, "")
        ttlin = self.ttlin
        self.assertEqual(ttlin.val, False)

    def test_rewiring(self):
        pcomp = self.pcomp
        counter = self.counter
        self.o.handle_changes({"COUNTER.OUT": 32.0})
        self.assertEqual(counter.out, 32.0)
        self.o.handle_changes({"PCOMP.INP": "COUNTER.OUT"})
        self.assertEqual(pcomp.inp, "COUNTER.OUT")
        self.assertEqual(pcomp.inpVal, 32.0)
        self.o.handle_changes({"PCOMP.INP": "ZERO"})
        self.assertEqual(pcomp.inp, "ZERO")
        self.assertEqual(pcomp.inpVal, 0.0)

    def test_scale_offset_following(self):
        pcomp = self.pcomp
        self.assertEqual(self.control.send.call_args_list, [
            call('PCOMP.START.SCALE=1\n'),
            call('PCOMP.START.OFFSET=0\n'),
            call('PCOMP.START.UNITS=\n'),
            call('PCOMP.STEP.SCALE=1\n'),
            call('PCOMP.STEP.UNITS=\n'),
            call('COUNTER.START.SCALE=1\n'),
            call('COUNTER.START.OFFSET=0\n'),
            call('COUNTER.START.UNITS=\n'),
        ])
        self.control.send.reset_mock()
        self.o.handle_changes({"PCOMP.INP": "COUNTER.OUT"})
        self.assertEqual(pcomp.inp, "COUNTER.OUT")
        self.assertEqual(pcomp.inpVal, 0.0)
        self.assertEqual(self.control.send.call_args_list, [
            call('PCOMP.START.SCALE=1.0\n'),
            call('PCOMP.START.OFFSET=0.0\n'),
            call('PCOMP.START.UNITS=\n'),
            call('PCOMP.STEP.SCALE=1.0\n'),
            call('PCOMP.STEP.UNITS=\n')
        ])
        self.control.send.reset_mock()
        self.o.handle_changes({"COUNTER.OUT.OFFSET": "5.2"})
        self.assertEqual(self.control.send.call_args_list, [
            call('COUNTER.START.OFFSET=5.2\n'),
            call('PCOMP.START.OFFSET=5.2\n')
        ])
        self.control.send.reset_mock()
        self.o.handle_changes({"COUNTER.OUT.SCALE": "0.2"})
        self.assertEqual(self.control.send.call_args_list, [
            call('COUNTER.START.SCALE=0.2\n'),
            call('PCOMP.START.SCALE=0.2\n'),
            call('PCOMP.STEP.SCALE=0.2\n'),
        ])
        self.control.send.reset_mock()
        self.o.handle_changes({"PCOMP.INP": "ZERO"})
        self.assertEqual(self.control.send.call_args_list, [
            call('PCOMP.START.SCALE=1\n'),
            call('PCOMP.START.OFFSET=0\n'),
            call('PCOMP.START.UNITS=\n'),
            call('PCOMP.STEP.SCALE=1\n'),
            call('PCOMP.STEP.UNITS=\n')
        ])