Ejemplo n.º 1
0
    def test_mixed_sources(self):
        config.bs_connection_mode = "pull"
        config.bs_default_host = "localhost"
        config.bs_default_port = 9999

        positions = [[1, 1], [2, 2], [3, 3], [4, 4]]
        positioner = VectorPositioner(positions)

        writables = [
            epics_pv("PYSCAN:TEST:MOTOR1:SET", "PYSCAN:TEST:MOTOR1:GET"),
            epics_pv("PYSCAN:TEST:MOTOR2:SET", "PYSCAN:TEST:MOTOR2:GET")
        ]

        readables = [
            bs_property("CAMERA1:X"),
            bs_property("CAMERA1:Y"),
            epics_pv("PYSCAN:TEST:OBS1")
        ]

        conditions = [
            epics_condition("PYSCAN:TEST:VALID1", 10),
            bs_condition("CAMERA1:VALID", 10)
        ]

        initialization = [
            action_set_epics_pv("PYSCAN:TEST:PRE1:SET", 1,
                                "PYSCAN:TEST:PRE1:GET")
        ]

        finalization = [
            action_set_epics_pv("PYSCAN:TEST:PRE1:SET", 0,
                                "PYSCAN:TEST:PRE1:GET"),
            action_restore(writables)
        ]

        result = scan(positioner=positioner,
                      readables=readables,
                      writables=writables,
                      conditions=conditions,
                      initialization=initialization,
                      finalization=finalization,
                      settings=scan_settings(measurement_interval=0.25,
                                             n_measurements=1))

        self.assertEqual(len(result), len(positions),
                         "Not the expected number of results.")

        # The first 2 attributes are from bs_read, they should be equal to the pulse ID processed.
        self.assertTrue(all(x[0] == x[1] and x[2] == 1 for x in result),
                        "The result is wrong.")
Ejemplo n.º 2
0
    def test_actions(self):
        positions = [[1, 1], [2, 2]]
        positioner = VectorPositioner(positions)

        writables = [
            epics_pv("PYSCAN:TEST:MOTOR1:SET", "PYSCAN:TEST:MOTOR1:GET"),
            epics_pv("PYSCAN:TEST:MOTOR2:SET", "PYSCAN:TEST:MOTOR2:GET")
        ]

        readables = [epics_pv("PYSCAN:TEST:OBS1")]

        # MOTOR1 initial values should be -11, MOTOR2 -22.
        cached_initial_values["PYSCAN:TEST:MOTOR1:SET"] = -11
        cached_initial_values["PYSCAN:TEST:MOTOR2:SET"] = -22
        initialization = [action_set_epics_pv("PYSCAN:TEST:OBS1", -33)]
        finalization = [action_restore(writables)]

        result = scan(positioner=positioner,
                      readables=readables,
                      writables=writables,
                      initialization=initialization,
                      finalization=finalization,
                      settings=scan_settings(measurement_interval=0.25,
                                             n_measurements=1))

        self.assertEqual(pv_cache["PYSCAN:TEST:MOTOR1:SET"][0].value, -11,
                         "Finalization did not restore original value.")
        self.assertEqual(pv_cache["PYSCAN:TEST:MOTOR2:SET"][0].value, -22,
                         "Finalization did not restore original value.")

        self.assertEqual(result[0][0], -33,
                         "Initialization action did not work.")
Ejemplo n.º 3
0
    def test_multiple_conditions(self):
        config.bs_connection_mode = "pull"
        config.bs_default_host = "localhost"
        config.bs_default_port = 9999

        positioner = StaticPositioner(5)

        initialization = [action_set_epics_pv("PYSCAN:TEST:VALID1", 778)]

        readables = [bs_property("CAMERA1:X")]

        conditions = [
            bs_condition("CAMERA1:VALID",
                         10,
                         operation=ConditionComparison.EQUAL),
            bs_condition("CAMERA1:VALID",
                         11,
                         operation=ConditionComparison.LOWER),
            epics_condition("PYSCAN:TEST:VALID1",
                            778,
                            operation=ConditionComparison.LOWER_OR_EQUAL),
            epics_condition("PYSCAN:TEST:VALID1",
                            779,
                            operation=ConditionComparison.LOWER)
        ]

        result = scan(positioner=positioner,
                      readables=readables,
                      conditions=conditions,
                      initialization=initialization,
                      settings=scan_settings(measurement_interval=0.25,
                                             n_measurements=1))

        self.assertTrue(all(x[0] == i + 1 for i, x in enumerate(result)),
                        "The result is wrong.")