test_ct2_card.py 4.2 KB
Newer Older
1 2
# -*- coding: utf-8 -*-
#
3
# This file is part of the bliss project
4
#
5 6
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
7

Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
8 9
import unittest

Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
10
from bliss.controllers.ct2 import card
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
11

12

Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
13 14
class TestP201(unittest.TestCase):
    def setUp(self):
Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
15
        self.p201 = card.P201Card()
16
        self.p201.set_interrupts()
17 18 19 20
        self.p201.reset()
        self.p201.software_reset()

    def tearDown(self):
21
        self.p201.set_interrupts()
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
22 23 24 25
        self.p201.reset()
        self.p201.software_reset()

    def test_clock(self):
Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
26
        self.p201.set_clock(card.Clock.CLK_DISABLE)
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
27
        clock = self.p201.get_clock()
Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
28
        self.assertEqual(clock, card.Clock.CLK_DISABLE)
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
29

Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
30
        self.p201.set_clock(card.Clock.CLK_66_66_MHz)
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
31
        clock = self.p201.get_clock()
Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
32
        self.assertEqual(clock, card.Clock.CLK_66_66_MHz)
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
33

34
    def test_output_level(self):
35 36 37 38 39 40 41
        for c in (
            {9: card.Level.DISABLE, 10: card.Level.DISABLE},
            {9: card.Level.TTL, 10: card.Level.NIM},
            {9: card.Level.NIM, 10: card.Level.TTL},
            {9: card.Level.TTL, 10: card.Level.TTL},
            {9: card.Level.NIM, 10: card.Level.NIM},
        ):
42 43
            self.p201.set_output_channels_level(c)
            r = self.p201.get_output_channels_level()
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
44
            self.assertEqual(c, r)
45

Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
46
    def test_output_channels_level(self):
47
        for c in ({9: 0, 10: 0}, {9: 1, 10: 0}, {9: 0, 10: 1}, {9: 1, 10: 1}):
48 49
            self.p201.set_output_channels_software_enable(c)
            r = self.p201.get_output_channels_software_enable()
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
50 51 52
            self.assertEqual(c, r)

    def test_output_channels_source(self):
53 54 55 56 57
        srcs = (
            {9: card.OutputSrc.CLK_1_MHz, 10: card.OutputSrc.DISABLE},
            {9: card.OutputSrc.DISABLE, 10: card.OutputSrc.CH_1_RISING_FALLING},
            {9: card.OutputSrc.CT_6_START_STOP, 10: card.OutputSrc.CT_8_SWITCH},
        )
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
58 59 60 61 62 63
        for src in srcs:
            self.p201.set_output_channels_source(src)
            result = self.p201.get_output_channels_source()
            self.assertEqual(src, result)

    def test_output_channels_filter(self):
64 65 66 67 68 69 70 71 72 73
        filters = (
            {
                9: card.FilterOutput(
                    clock=card.FilterClock.CLK_12_5_MHz, enable=True, polarity=0
                ),
                10: card.FilterOutput(
                    clock=card.FilterClock.CLK_10_KHz, enable=False, polarity=1
                ),
            },
        )
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
74 75 76 77 78
        for filter in filters:
            self.p201.set_output_channels_filter(filter)
            result = self.p201.get_output_channels_filter()
            self.assertEqual(filter, result)

79
    def test_channels_interrupts(self):
80 81 82 83 84 85
        triggers = {
            1: card.TriggerInterrupt(rising=True),
            5: card.TriggerInterrupt(falling=True),
            10: card.TriggerInterrupt(rising=True, falling=True),
        }

86
        self.p201.set_channels_interrupts(triggers)
87
        for ch in (2, 3, 4, 6, 7, 8, 9):
Jose Tiago Coutinho Macara's avatar
Jose Tiago Coutinho Macara committed
88
            triggers[ch] = card.TriggerInterrupt()
89
        result = self.p201.get_channels_interrupts()
90

Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
91 92 93 94 95 96 97
        self.assertEqual(triggers, result)

    def test_50ohm_adapter(self):
        # enable odd channels; disable even ones
        channels = {}
        for i in range(1, 11):
            channels[i] = i % 2 != 0
98

99
        self.p201.set_input_channels_50ohm_adapter(channels)
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
100

101
        result = self.p201.get_input_channels_50ohm_adapter()
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
102 103 104
        self.assertEqual(result, channels)

    def test_p201_counters_latch_sources(self):
105 106
        input = {1: set((10,)), 2: set((3, 4, 5)), 5: set((5, 6, 7))}

Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
107
        expected_ret = {
108 109
            "A": (1 << (10 - 1))
            | ((1 << (3 - 1) | 1 << (4 - 1) | 1 << (5 - 1)) << 16),  # counter 2
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
110
            "B": 0,
111
            "C": 1 << (5 - 1) | 1 << (6 - 1) | 1 << (7 - 1),
Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125
            "D": 0,
            "E": 0,
            "F": 0,
        }

        ret = self.p201.set_counters_latch_sources(input)
        self.assertEqual(ret, expected_ret)

        expected_output = dict(input)
        for i in [3, 4] + range(6, 13):
            expected_output[i] = set()

        output = self.p201.get_counters_latch_sources()
        self.assertEqual(output, expected_output)
126 127


Jose Tiago Macara Coutinho's avatar
Jose Tiago Macara Coutinho committed
128 129
if __name__ == "__main__":
    unittest.main()