| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2024 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
|
| 25 |
import pytest |
| 26 |
|
| 27 |
from pymeasure.test import expected_protocol |
| 28 |
|
| 29 |
from pymeasure.instruments.attocube import ANC300Controller |
| 30 |
|
| 31 |
# Note: This communication does not contain the first several device |
| 32 |
# responses, as they are ignored due to `adapter.flush_read_buffer()`. |
| 33 |
passwd = "passwd" |
| 34 |
init_comm = [ |
| 35 |
(passwd, "*" * len(passwd)), |
| 36 |
(None, "Authorization success"), |
| 37 |
("echo off", "> echo off"), |
| 38 |
(None, "OK"), |
| 39 |
] |
| 40 |
|
| 41 |
|
| 42 |
def test_stepu(): |
| 43 |
"""Test a setting.""" |
| 44 |
with expected_protocol( |
| 45 |
ANC300Controller, |
| 46 |
init_comm + [("setm 1 stp", "OK"), ("stepu 1 15", "OK"), ], |
| 47 |
axisnames=["a", "b", "c"], |
| 48 |
passwd=passwd, |
| 49 |
) as instr: |
| 50 |
instr.a.mode = "stp" |
| 51 |
with pytest.warns(FutureWarning): |
| 52 |
instr.a.stepu = 15 |
| 53 |
|
| 54 |
|
| 55 |
def test_continuous_move(): |
| 56 |
"""Test a continuous move setting.""" |
| 57 |
with expected_protocol( |
| 58 |
ANC300Controller, |
| 59 |
init_comm + [("setm 3 stp", "OK"), ("stepd 3 c", "OK"), ], |
| 60 |
axisnames=["a", "b", "c"], |
| 61 |
passwd=passwd, |
| 62 |
) as instr: |
| 63 |
instr.c.mode = "stp" |
| 64 |
instr.c.move_raw(float('-inf')) |
| 65 |
|
| 66 |
|
| 67 |
def test_capacity(): |
| 68 |
"""Test a float measurement.""" |
| 69 |
with expected_protocol( |
| 70 |
ANC300Controller, |
| 71 |
init_comm + [("getc 1", "capacitance = 998.901733 nF"), (None, "OK")], |
| 72 |
axisnames=["a", "b", "c"], |
| 73 |
passwd=passwd, |
| 74 |
) as instr: |
| 75 |
assert instr.a.capacity == 998.901733 |
| 76 |
|
| 77 |
|
| 78 |
def test_frequency(): |
| 79 |
"""Test an integer measurement.""" |
| 80 |
with expected_protocol( |
| 81 |
ANC300Controller, |
| 82 |
# the \n in the following is indeed included in the return msg! |
| 83 |
init_comm + [("getf 1", "frequency = 111 Hz\n"), (None, "OK")], |
| 84 |
axisnames=["a", "b", "c"], |
| 85 |
passwd=passwd, |
| 86 |
) as instr: |
| 87 |
assert instr.a.frequency == 111 |
| 88 |
|
| 89 |
|
| 90 |
def test_measure_capacity(): |
| 91 |
"""Test triggering a capacity measurement.""" |
| 92 |
with expected_protocol( |
| 93 |
ANC300Controller, |
| 94 |
init_comm + [ |
| 95 |
("setm 1 cap", "OK"), |
| 96 |
("capw 1", "capacitance = 0.000000 nF"), |
| 97 |
(None, "OK"), |
| 98 |
("getc 1", "capacitance = 1020.173401 nF"), |
| 99 |
(None, "OK"), |
| 100 |
], |
| 101 |
axisnames=["a", "b", "c"], |
| 102 |
passwd=passwd, |
| 103 |
) as instr: |
| 104 |
assert instr.a.measure_capacity() == 1020.173401 |
| 105 |
|
| 106 |
|
| 107 |
def test_move_raw(): |
| 108 |
"""Test a raw movement.""" |
| 109 |
with expected_protocol( |
| 110 |
ANC300Controller, |
| 111 |
init_comm + [ |
| 112 |
("stepd 2 18", "OK"), |
| 113 |
], |
| 114 |
axisnames=["a", "b", "c"], |
| 115 |
passwd=passwd, |
| 116 |
) as instr: |
| 117 |
instr.b.move_raw(-18) |
| 118 |
|
| 119 |
|
| 120 |
def test_move(): |
| 121 |
"""Test a movement.""" |
| 122 |
with expected_protocol( |
| 123 |
ANC300Controller, |
| 124 |
init_comm + [ |
| 125 |
("setm 3 stp", "OK"), |
| 126 |
("stepd 3 20", "OK"), |
| 127 |
("getf 3", "frequency = 111 Hz\n"), |
| 128 |
(None, "OK"), |
| 129 |
("stepw 3", "OK"), |
| 130 |
], |
| 131 |
axisnames=["a", "b", "c"], |
| 132 |
passwd=passwd, |
| 133 |
) as instr: |
| 134 |
instr.c.move(-20, gnd=False) |
| 135 |
|
| 136 |
|
| 137 |
def test_ground_all(): |
| 138 |
"""Test grounding of all axis""" |
| 139 |
with expected_protocol( |
| 140 |
ANC300Controller, |
| 141 |
init_comm + [ |
| 142 |
("setm 1 gnd", "OK"), |
| 143 |
("setm 2 gnd", "OK"), |
| 144 |
("setm 3 gnd", "OK"), |
| 145 |
], |
| 146 |
axisnames=["a", "b", "c"], |
| 147 |
passwd=passwd, |
| 148 |
) as instr: |
| 149 |
instr.ground_all() |