File: test_anc300.py

package info (click to toggle)
python-pymeasure 0.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,788 kB
  • sloc: python: 47,201; makefile: 155
file content (149 lines) | stat: -rw-r--r-- 4,482 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

import pytest

from pymeasure.test import expected_protocol

from pymeasure.instruments.attocube import ANC300Controller

# Note: This communication does not contain the first several device
# responses, as they are ignored due to `adapter.flush_read_buffer()`.
passwd = "passwd"
init_comm = [
    (passwd, "*" * len(passwd)),
    (None, "Authorization success"),
    ("echo off", "> echo off"),
    (None, "OK"),
]


def test_stepu():
    """Test a setting."""
    with expected_protocol(
        ANC300Controller,
        init_comm + [("setm 1 stp", "OK"), ("stepu 1 15", "OK"), ],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        instr.a.mode = "stp"
        with pytest.warns(FutureWarning):
            instr.a.stepu = 15


def test_continuous_move():
    """Test a continuous move setting."""
    with expected_protocol(
        ANC300Controller,
        init_comm + [("setm 3 stp", "OK"), ("stepd 3 c", "OK"), ],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        instr.c.mode = "stp"
        instr.c.move_raw(float('-inf'))


def test_capacity():
    """Test a float measurement."""
    with expected_protocol(
        ANC300Controller,
        init_comm + [("getc 1", "capacitance = 998.901733 nF"), (None, "OK")],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        assert instr.a.capacity == 998.901733


def test_frequency():
    """Test an integer measurement."""
    with expected_protocol(
        ANC300Controller,
        # the \n in the following is indeed included in the return msg!
        init_comm + [("getf 1", "frequency = 111 Hz\n"), (None, "OK")],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        assert instr.a.frequency == 111


def test_measure_capacity():
    """Test triggering a capacity measurement."""
    with expected_protocol(
        ANC300Controller,
        init_comm + [
            ("setm 1 cap", "OK"),
            ("capw 1", "capacitance = 0.000000 nF"),
            (None, "OK"),
            ("getc 1", "capacitance = 1020.173401 nF"),
            (None, "OK"),
        ],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        assert instr.a.measure_capacity() == 1020.173401


def test_move_raw():
    """Test a raw movement."""
    with expected_protocol(
        ANC300Controller,
        init_comm + [
            ("stepd 2 18", "OK"),
        ],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        instr.b.move_raw(-18)


def test_move():
    """Test a movement."""
    with expected_protocol(
        ANC300Controller,
        init_comm + [
            ("setm 3 stp", "OK"),
            ("stepd 3 20", "OK"),
            ("getf 3", "frequency = 111 Hz\n"),
            (None, "OK"),
            ("stepw 3", "OK"),
        ],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        instr.c.move(-20, gnd=False)


def test_ground_all():
    """Test grounding of all axis"""
    with expected_protocol(
        ANC300Controller,
        init_comm + [
            ("setm 1 gnd", "OK"),
            ("setm 2 gnd", "OK"),
            ("setm 3 gnd", "OK"),
        ],
        axisnames=["a", "b", "c"],
        passwd=passwd,
    ) as instr:
        instr.ground_all()