Ejemplo n.º 1
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
Ejemplo n.º 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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def setUp(self, mock_socket):
     self.p = Process("process", SyncFactory("sf"))
     self.c = PandABoxControl(self.p, "h", "p")
Ejemplo n.º 5
0
class PandABoxControlTest(unittest.TestCase):
    @patch("malcolm.parts.pandabox.pandaboxcontrol.socket")
    def setUp(self, mock_socket):
        self.p = Process("process", SyncFactory("sf"))
        self.c = PandABoxControl(self.p, "h", "p")

    def tearDown(self):
        del self.p.sync_factory

    def test_multiline_response_good(self):
        messages = ["!TTLIN 6\n", "!OUTENC 4\n!CAL", "C 2\n.\nblah"]
        self.c.socket.recv.side_effect = messages
        self.c.start()
        resp = list(self.c.send_recv(""))
        self.c.stop()
        self.c.wait()
        expected = ["TTLIN 6", "OUTENC 4", "CALC 2"]
        self.assertEqual(resp, expected)

    def test_two_resp(self):
        messages = ["OK =mm\n", "OK =232\n"]
        self.c.socket.recv.side_effect = messages
        self.c.start()
        self.assertEqual(self.c.send_recv(""), "OK =mm")
        self.assertEqual(self.c.send_recv(""), "OK =232")
        self.c.stop()
        self.c.wait()

    def test_bad_good(self):
        messages = ["ERR Invalid bit value\n", "OK =232\n"]
        self.c.socket.recv.side_effect = messages
        self.c.start()
        self.assertRaises(ValueError, self.c.send_recv, "")
        self.assertEqual(self.c.send_recv(""), "OK =232")
        self.c.stop()
        self.c.wait()

    def test_block_data(self):
        self.c.socket.recv.side_effect = [
            "!TTLIN 6\n!TTLOUT 10\n.\n",
            "OK =TTL input\n",
            "OK =TTL output\n",
            "!VAL 1 pos_out\n!TERM 0 param enum\n.\n",
            "!VAL 0 bit_mux\n.\n",
            "OK =TTL termination\n",
            "OK =TTL input value\n",
            "!High-Z\n!50-Ohm\n.\n",
            "!Average\n!No\n.\n",
            "OK =TTL output value\n",
            "!ZERO\n!TTLIN1.VAL\n!TTLIN2.VAL\n.\n",
        ]
        self.c.start()
        block_data = self.c.get_blocks_data()
        self.c.stop()
        self.c.wait()
        self.assertEqual(self.c.socket.send.call_args_list, [
            call("*BLOCKS?\n"),
            call("*DESC.TTLIN?\n"),
            call("*DESC.TTLOUT?\n"),
            call("TTLIN.*?\n"),
            call("TTLOUT.*?\n"),
            call("*DESC.TTLIN.TERM?\n"),
            call("*DESC.TTLIN.VAL?\n"),
            call("*ENUMS.TTLIN.TERM?\n"),
            call("*ENUMS.TTLIN.VAL.CAPTURE?\n"),
            call("*DESC.TTLOUT.VAL?\n"),
            call("*ENUMS.TTLOUT.VAL?\n"),
        ])
        self.assertEqual(list(block_data), ["TTLIN", "TTLOUT"])
        in_fields = OrderedDict()
        in_fields["TERM"] = FieldData("param", "enum", "TTL termination",
                                      ["High-Z", "50-Ohm"])
        in_fields["VAL"] = FieldData("pos_out", "", "TTL input value",
                                     ["Average", "No"])
        self.assertEqual(block_data["TTLIN"],
                         BlockData(6, "TTL input", in_fields))
        out_fields = OrderedDict()
        out_fields["VAL"] = FieldData("bit_mux", "", "TTL output value",
                                      ["ZERO", "TTLIN1.VAL", "TTLIN2.VAL"])
        self.assertEqual(block_data["TTLOUT"],
                         BlockData(10, "TTL output", out_fields))

    def test_changes(self):
        self.c.socket.recv.side_effect = [
            """!PULSE0.WIDTH=1.43166e+09
!PULSE1.WIDTH=1.43166e+09
!PULSE2.WIDTH=1.43166e+09
!PULSE3.WIDTH=1.43166e+09
!SEQ1.TABLE<
!PULSE0.INP (error)
!PULSE1.INP (error)
!PULSE2.INP (error)
!PULSE3.INP (error)
.
""", """!1
!2
!3
.
"""
        ]
        self.c.start()
        changes = self.c.get_changes()
        self.c.stop()
        self.c.wait()
        self.assertEqual(
            self.c.socket.send.call_args_list,
            [call("*CHANGES?\n"), call("SEQ1.TABLE?\n")])
        expected = OrderedDict()
        expected["PULSE0.WIDTH"] = "1.43166e+09"
        expected["PULSE1.WIDTH"] = "1.43166e+09"
        expected["PULSE2.WIDTH"] = "1.43166e+09"
        expected["PULSE3.WIDTH"] = "1.43166e+09"
        expected["SEQ1.TABLE"] = ["1", "2", "3"]
        expected["PULSE0.INP"] = Exception
        expected["PULSE1.INP"] = Exception
        expected["PULSE2.INP"] = Exception
        expected["PULSE3.INP"] = Exception
        self.assertEqual(changes, expected)

    def test_set_field(self):
        self.c.socket.recv.return_value = "OK\n"
        self.c.start()
        self.c.set_field("PULSE0", "WIDTH", 0)
        self.c.stop()
        self.c.wait()
        self.c.socket.send.assert_called_once_with("PULSE0.WIDTH=0\n")

    def test_set_table(self):
        self.c.socket.recv.return_value = "OK\n"
        self.c.start()
        self.c.set_table("SEQ1", "TABLE", [1, 2, 3])
        self.c.stop()
        self.c.wait()
        self.c.socket.send.assert_called_once_with("""SEQ1.TABLE<
1
2
3

""")

    def test_table_fields(self):
        self.c.socket.recv.return_value = """!31:0    REPEATS
!32:32   USE_INPA
!64:54   STUFF
!37:37   INPB
.
"""
        self.c.start()
        fields = self.c.get_table_fields("SEQ1", "TABLE")
        self.c.stop()
        self.c.wait()
        self.c.socket.send.assert_called_once_with("SEQ1.TABLE.FIELDS?\n")
        expected = OrderedDict()
        expected["REPEATS"] = (31, 0)
        expected["USE_INPA"] = (32, 32)
        expected["STUFF"] = (64, 54)
        expected["INPB"] = (37, 37)
        self.assertEqual(fields, expected)
Ejemplo n.º 6
0
 def setUp(self, mock_socket):
     self.p = Process("process", SyncFactory("sf"))
     self.c = PandABoxControl(self.p, "h", "p")
Ejemplo n.º 7
0
class PandABoxControlTest(unittest.TestCase):
    @patch("malcolm.parts.pandabox.pandaboxcontrol.socket")
    def setUp(self, mock_socket):
        self.p = Process("process", SyncFactory("sf"))
        self.c = PandABoxControl(self.p, "h", "p")

    def tearDown(self):
        del self.p.sync_factory

    def test_multiline_response_good(self):
        messages = ["!TTLIN 6\n", "!OUTENC 4\n!CAL", "C 2\n.\nblah"]
        self.c.socket.recv.side_effect = messages
        self.c.start()
        resp = list(self.c.send_recv(""))
        self.c.stop()
        self.c.wait()
        expected = ["TTLIN 6", "OUTENC 4", "CALC 2"]
        self.assertEqual(resp, expected)

    def test_two_resp(self):
        messages = ["OK =mm\n", "OK =232\n"]
        self.c.socket.recv.side_effect = messages
        self.c.start()
        self.assertEqual(self.c.send_recv(""), "OK =mm")
        self.assertEqual(self.c.send_recv(""), "OK =232")
        self.c.stop()
        self.c.wait()

    def test_bad_good(self):
        messages = ["ERR Invalid bit value\n", "OK =232\n"]
        self.c.socket.recv.side_effect = messages
        self.c.start()
        self.assertRaises(ValueError, self.c.send_recv, "")
        self.assertEqual(self.c.send_recv(""), "OK =232")
        self.c.stop()
        self.c.wait()

    def test_block_data(self):
        self.c.socket.recv.side_effect = [
            "!TTLIN 6\n!TTLOUT 10\n.\n",
            "OK =TTL input\n",
            "OK =TTL output\n",
            "!VAL 1 pos_out\n!TERM 0 param enum\n.\n",
            "!VAL 0 bit_mux\n.\n",
            "OK =TTL termination\n",
            "OK =TTL input value\n",
            "!High-Z\n!50-Ohm\n.\n",
            "!Average\n!No\n.\n",
            "OK =TTL output value\n",
            "!ZERO\n!TTLIN1.VAL\n!TTLIN2.VAL\n.\n",
        ]
        self.c.start()
        block_data = self.c.get_blocks_data()
        self.c.stop()
        self.c.wait()
        self.assertEqual(self.c.socket.send.call_args_list, [
            call("*BLOCKS?\n"),
            call("*DESC.TTLIN?\n"),
            call("*DESC.TTLOUT?\n"),
            call("TTLIN.*?\n"),
            call("TTLOUT.*?\n"),
            call("*DESC.TTLIN.TERM?\n"),
            call("*DESC.TTLIN.VAL?\n"),
            call("*ENUMS.TTLIN.TERM?\n"),
            call("*ENUMS.TTLIN.VAL.CAPTURE?\n"),
            call("*DESC.TTLOUT.VAL?\n"),
            call("*ENUMS.TTLOUT.VAL?\n"),
        ])
        self.assertEqual(list(block_data), ["TTLIN", "TTLOUT"])
        in_fields = OrderedDict()
        in_fields["TERM"] = FieldData("param", "enum", "TTL termination",
                                      ["High-Z", "50-Ohm"])
        in_fields["VAL"] = FieldData("pos_out", "", "TTL input value",
                                     ["Average", "No"])
        self.assertEqual(block_data["TTLIN"],
                         BlockData(6, "TTL input", in_fields))
        out_fields = OrderedDict()
        out_fields["VAL"] = FieldData("bit_mux", "", "TTL output value", [
            "ZERO", "TTLIN1.VAL", "TTLIN2.VAL"])
        self.assertEqual(block_data["TTLOUT"],
                         BlockData(10, "TTL output", out_fields))

    def test_changes(self):
        self.c.socket.recv.side_effect = ["""!PULSE0.WIDTH=1.43166e+09
!PULSE1.WIDTH=1.43166e+09
!PULSE2.WIDTH=1.43166e+09
!PULSE3.WIDTH=1.43166e+09
!SEQ1.TABLE<
!PULSE0.INP (error)
!PULSE1.INP (error)
!PULSE2.INP (error)
!PULSE3.INP (error)
.
""","""!1
!2
!3
.
"""]
        self.c.start()
        changes = self.c.get_changes()
        self.c.stop()
        self.c.wait()
        self.assertEqual(self.c.socket.send.call_args_list, [
            call("*CHANGES?\n"), call("SEQ1.TABLE?\n")])
        expected = OrderedDict()
        expected["PULSE0.WIDTH"] = "1.43166e+09"
        expected["PULSE1.WIDTH"] = "1.43166e+09"
        expected["PULSE2.WIDTH"] = "1.43166e+09"
        expected["PULSE3.WIDTH"] = "1.43166e+09"
        expected["SEQ1.TABLE"] = ["1", "2", "3"]
        expected["PULSE0.INP"] = Exception
        expected["PULSE1.INP"] = Exception
        expected["PULSE2.INP"] = Exception
        expected["PULSE3.INP"] = Exception
        self.assertEqual(changes, expected)

    def test_set_field(self):
        self.c.socket.recv.return_value = "OK\n"
        self.c.start()
        self.c.set_field("PULSE0", "WIDTH", 0)
        self.c.stop()
        self.c.wait()
        self.c.socket.send.assert_called_once_with("PULSE0.WIDTH=0\n")

    def test_set_table(self):
        self.c.socket.recv.return_value = "OK\n"
        self.c.start()
        self.c.set_table("SEQ1", "TABLE", [1, 2, 3])
        self.c.stop()
        self.c.wait()
        self.c.socket.send.assert_called_once_with("""SEQ1.TABLE<
1
2
3

""")

    def test_table_fields(self):
        self.c.socket.recv.return_value = """!31:0    REPEATS
!32:32   USE_INPA
!64:54   STUFF
!37:37   INPB
.
"""
        self.c.start()
        fields = self.c.get_table_fields("SEQ1", "TABLE")
        self.c.stop()
        self.c.wait()
        self.c.socket.send.assert_called_once_with("SEQ1.TABLE.FIELDS?\n")
        expected = OrderedDict()
        expected["REPEATS"] = (31, 0)
        expected["USE_INPA"] = (32, 32)
        expected["STUFF"] = (64, 54)
        expected["INPB"] = (37, 37)
        self.assertEqual(fields, expected)