forked from AFMD/sEQE-Setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockin.py
182 lines (139 loc) · 7.33 KB
/
lockin.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import io
import itertools
import math
import os
import re
import sys
import time
import logging
import warnings
import platform
import pathlib
import GUI_template
import serial
import zhinst.utils
import zhinst.ziPython
import pandas as pd
import serial
import codecs
class LockIn():
def __init__(self,device):
self.zurich_device = device
self.channel = 1
self.c = str(self.channel-1)
self.c6 = str(6)
self.connected = False
def connect(self):
"""Function to establish connection to Lockin.
Returns
-------
tuple
Zurich Instruments localhost name, device details and True if device is connected
"""
# Find device via Device Discovery and open connection to ziServer
d = zhinst.ziPython.ziDiscovery()
props = d.get(d.find(self.zurich_device))
daq = zhinst.ziPython.ziDAQServer(props['serveraddress'],
props['serverport'],
props['apilevel'])
daq.connectDevice(self.zurich_device,
props['interfaces'][0])
self.daq = daq
# Detect device
self.device = zhinst.utils.autoDetect(daq)
logging.info('Connection to Lock-In Established')
self.connected = True
return self.daq, self.device, self.connected
def setParameters(self,diff_2, diff,imp50,imp50_2,ac,Range,lowpass,rate,tc,c_2,amplification):
"""Function to set default Lockin parameters.
Parameters
----------
diff : int, required
Boolean representation to turn differentiale mode on and off: default: 1
imp50 : int, required
Boolean representation to turn 50 Ohm impedance(?) on or off, default: 0
imp50_2 : int,required
Boolean representation to turn on 50 Ohm on channel 2 to attenuate signal from chopper controller as reference signal, default: 1
ac : int, required
Boolean representation to turn AC voltage on or off, default: 0
Range : int, required
Voltage range for measurement, default: 2V
lowpass : int, required
low pass filter order
rate : int, required
data transfer rate
tc : int, required
time constant for measurement
c_2 : str, required
Channel 2, with value 1, for the reference input
amplification : int, required
Lock-in amplification of the signal
Returns
-------
None
"""
try:
self.diff = diff
self.diff_2 = diff_2
self.imp50 = imp50
self.imp50_2 = imp50_2
self.ac = ac
self.range = Range
self.lowpass = lowpass
self.rate = rate
self.tc = tc
self.c_2 = c_2
self.amplification = amplification
# Disable all outputs and all demods
general_setting = [
[['/', self.device, '/demods/0/trigger'], 0],
[['/', self.device, '/demods/1/trigger'], 0],
[['/', self.device, '/demods/2/trigger'], 0],
[['/', self.device, '/demods/3/trigger'], 0],
[['/', self.device, '/demods/4/trigger'], 0],
[['/', self.device, '/demods/5/trigger'], 0],
[['/', self.device, '/sigouts/0/enables/*'], 0],
[['/', self.device, '/sigouts/1/enables/*'], 0]
]
self.daq.set(general_setting)
# Set test settings
t1_sigOutIn_setting = [
# Diff Button (Enable for differential mode to measure the difference between +In and -In.)
[['/', self.device, '/sigins/',self.c,'/diff'], self.diff],
# 50 Ohm Button (Enable to switch input impedance between low (50 Ohm) and high (approx 1 MOhm).
[['/', self.device, '/sigins/',self.c,'/imp50'], self.imp50], # Select for signal frequencies of > 10 MHz.)
# AC Button (Enable for AC coupling to remove DC signal. Cutoff frequency = 1kHz)
[['/', self.device, '/sigins/',self.c,'/ac'], self.ac],
[['/', self.device, '/sigins/',self.c,'/range'], self.range], # Input Range
[['/', self.device, '/demods/',self.c,'/order'], self.lowpass], # Low-Pass Filter Order
[['/', self.device, '/demods/',self.c,'/timeconstant'], self.tc], # Time Constant
[['/', self.device, '/demods/',self.c,'/rate'], self.rate], # Data Transfer Rate
[['/', self.device, '/demods/',self.c,'/oscselect'], self.channel-1], # Oscillators
[['/', self.device, '/demods/',self.c,'/harmonic'], 1], # Harmonicss
[['/', self.device, '/demods/',self.c,'/phaseshift'], 0], # Phase Shift
[['/', self.device, '/zctrls/',self.c,'/tamp/0/currentgain'], self.amplification], # Amplifier Setting for wire 1
[['/', self.device, '/zctrls/',self.c,'/tamp/1/currentgain'], self.amplification], # Amplifier Setting for wire 2
[['/', self.device, '/demods/',self.c,'/adcselect'], self.channel-1], # ???
# For locked reference signal
# 50 Ohm Button (Enable to switch input impedance between low (50 Ohm) and high (approx 1 MOhm).
# Select for signal frequencies of > 10 MHz.)
[['/', self.device, '/sigins/', self.c_2,'/imp50'], self.imp50_2],
[['/', self.device, '/sigins/',self.c_2,'/diff'], self.diff_2],
[['/', self.device, '/plls/',self.c,'/enable'], 1], # Manual [0], External Reference [1]
[['/', self.device, '/plls/',self.c,'/adcselect'], 1], # ???
# For manual reference signal - The frequency tab is currently not implemented in the GUI
# [['/', self.device, '/plls/',self.c,'/enable'], 0], # Manual [0], External Reference [1]
# [['/', self.device, '/oscs/',self.c,'/freq'], self.frequency], # Demodulation Frequency
# Additional settings ?
# [['/', self.device, '/sigouts/',self.c,'/add'], -179.8390], # Output Add Button (Adds signal from "Add" connection)
# [['/', self.device, '/sigouts/',self.c,'/on'], 1], # Turn on Output Channel
# [['/', self.device, '/sigouts/',self.c,'/enables/',c6], 1], # Enable Output Channel
# [['/', self.device, '/sigouts/',self.c,'/range'], 1], # Output Range
# [['/', self.device, '/sigouts/',self.c,'/amplitudes/',c6], amplitude], # Output Amplitude
# [['/', self.device, '/sigouts/',self.c,'/offset'], 0], # Output Offset
]
self.daq.set(t1_sigOutIn_setting);
time.sleep(1) # wait 1s to get a settled lowpass filter
self.daq.flush() # clean queue
except Exception as err:
logging.exception("Unexpected error during execution of setParameters function:")