spirack 0.2.18__tar.gz → 0.2.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {spirack-0.2.18 → spirack-0.2.19}/PKG-INFO +1 -1
  2. {spirack-0.2.18 → spirack-0.2.19}/spirack/M2p_module.py +138 -114
  3. spirack-0.2.19/spirack/version.py +1 -0
  4. {spirack-0.2.18 → spirack-0.2.19}/spirack.egg-info/PKG-INFO +1 -1
  5. spirack-0.2.18/spirack/version.py +0 -1
  6. {spirack-0.2.18 → spirack-0.2.19}/LICENSE +0 -0
  7. {spirack-0.2.18 → spirack-0.2.19}/README.md +0 -0
  8. {spirack-0.2.18 → spirack-0.2.19}/setup.cfg +0 -0
  9. {spirack-0.2.18 → spirack-0.2.19}/setup.py +0 -0
  10. {spirack-0.2.18 → spirack-0.2.19}/spirack/B1b_module.py +0 -0
  11. {spirack-0.2.18 → spirack-0.2.19}/spirack/B2b_module.py +0 -0
  12. {spirack-0.2.18 → spirack-0.2.19}/spirack/D4_module.py +0 -0
  13. {spirack-0.2.18 → spirack-0.2.19}/spirack/D4a_module.py +0 -0
  14. {spirack-0.2.18 → spirack-0.2.19}/spirack/D4b_module.py +0 -0
  15. {spirack-0.2.18 → spirack-0.2.19}/spirack/D5a_module.py +0 -0
  16. {spirack-0.2.18 → spirack-0.2.19}/spirack/D5b_module.py +0 -0
  17. {spirack-0.2.18 → spirack-0.2.19}/spirack/F1d_module.py +0 -0
  18. {spirack-0.2.18 → spirack-0.2.19}/spirack/M2j_module.py +0 -0
  19. {spirack-0.2.18 → spirack-0.2.19}/spirack/P2d_module.py +0 -0
  20. {spirack-0.2.18 → spirack-0.2.19}/spirack/S4g_module.py +0 -0
  21. {spirack-0.2.18 → spirack-0.2.19}/spirack/S5i_module.py +0 -0
  22. {spirack-0.2.18 → spirack-0.2.19}/spirack/S5k_module.py +0 -0
  23. {spirack-0.2.18 → spirack-0.2.19}/spirack/S5l_module.py +0 -0
  24. {spirack-0.2.18 → spirack-0.2.19}/spirack/U1c_module.py +0 -0
  25. {spirack-0.2.18 → spirack-0.2.19}/spirack/U2_module.py +0 -0
  26. {spirack-0.2.18 → spirack-0.2.19}/spirack/__init__.py +0 -0
  27. {spirack-0.2.18 → spirack-0.2.19}/spirack/chip_mode.py +0 -0
  28. {spirack-0.2.18 → spirack-0.2.19}/spirack/spi_rack.py +0 -0
  29. {spirack-0.2.18 → spirack-0.2.19}/spirack.egg-info/SOURCES.txt +0 -0
  30. {spirack-0.2.18 → spirack-0.2.19}/spirack.egg-info/dependency_links.txt +0 -0
  31. {spirack-0.2.18 → spirack-0.2.19}/spirack.egg-info/requires.txt +0 -0
  32. {spirack-0.2.18 → spirack-0.2.19}/spirack.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spirack
3
- Version: 0.2.18
3
+ Version: 0.2.19
4
4
  Summary: Drivers for the QuTech SPI-rack
5
5
  Home-page: https://github.com/qutechdev/SPI-rack
6
6
  Author: QuTech Electronics Team
@@ -1,10 +1,6 @@
1
1
  import numpy as np
2
- from spi_rack import *
3
- from chip_mode import BICPINS_MODE, BICPINS_SPEED
4
- from time import sleep
2
+ from .chip_mode import BICPINS_MODE, BICPINS_SPEED
5
3
 
6
- #global values
7
- gainlist = [1,10,100,1000,10000]
8
4
 
9
5
  class M2p_module(object):
10
6
  """M2p module interface class
@@ -22,9 +18,20 @@ class M2p_module(object):
22
18
  remote_settings: contains a byte with the remote settigns (IQ gain and filter)
23
19
  """
24
20
 
21
+ #allowed gain values
22
+ gainlist = [1,10,100,1000,10000]
23
+
24
+
25
25
  def __init__(self, spi_rack, module):
26
26
  self.module = module
27
27
  self.spi_rack = spi_rack
28
+
29
+ # Upon start-up copy the existing local settings
30
+ # and set module to local operation
31
+ initial_gain = self.get_gain_local()
32
+ initial_coupling = self.get_coupling_local()
33
+ self.remote_set_gain_and_coupling(gain = initial_gain, coupling = initial_coupling)
34
+ self.set_local()
28
35
 
29
36
  def set_remote(self):
30
37
  """
@@ -35,29 +42,33 @@ class M2p_module(object):
35
42
  # check if module is already in remote mode, if so do nothing
36
43
  set_mode = self.get_operating_mode()
37
44
  if (set_mode == 1):
38
- print("Already in remotemode, no mode change made" )
45
+ print("Already in remote mode. No mode change made" )
39
46
  return #exit do nothing
40
47
 
41
- # Get gainswitch and coupleswitcht setting
42
- gain = self.get_gainswitch()
43
- couple = self.get_couple_switchsetting()
44
- self.set_gain(gain,couple)
48
+ # Get the local gain and coupling settings (from the front panel) ...
49
+ gain = self.get_gain_local()
50
+ couple = self.get_coupling_local()
51
+ # ... and use them initially when switching to remote mode
52
+ self.remote_set_gain_and_coupling(gain,couple)
45
53
 
46
54
  dummy_data = bytearray([0,0])
47
55
  r_data = bytearray([0,0])
48
56
  r_data = self.spi_rack.read_data(self.module, 6, BICPINS_MODE, BICPINS_SPEED, dummy_data)
49
57
 
50
- #set remote bit keep the others
51
- commandlow = r_data[0]|0b10000000
52
- commandhigh = r_data[1]|0b10000000
53
- s_data = bytearray([commandhigh, commandlow,])
54
- self.spi_rack.write_data(self.module, 5, BICPINS_MODE, BICPINS_SPEED, s_data)
55
- self.set_gain(gain,couple)
58
+ #set remote bit to 1 (keeping other setings)
59
+ high_byte = r_data[0]|0b10000000
60
+ #low_byte = r_data[1]|0b10000000
61
+ low_byte = r_data[1]
62
+
63
+ #write new settings (with high remote bit)
64
+ w_data = bytearray([high_byte,low_byte])
65
+ self.spi_rack.write_data(self.module, 5, BICPINS_MODE, BICPINS_SPEED, w_data)
66
+ self.remote_set_gain_and_coupling(gain,couple)
56
67
 
57
68
  def set_local(self):
58
69
  """
59
- Set the module to local mode. The gain- and coupling settings reverts to the frontpanel switch setting.
60
- If the remotely set gain is different from the front panel setting there migh be a jump in output due to a differnce in gain.
70
+ Set the module to local mode. The gain- and coupling settings revert to the front-panel switch setting.
71
+ If the remotely set gain is different from the front panel setting there might be a jump in output due to a differnce in gain.
61
72
  """
62
73
 
63
74
  # read last high and low byte setting
@@ -65,209 +76,222 @@ class M2p_module(object):
65
76
  r_data = bytearray([0,0])
66
77
  r_data = self.spi_rack.read_data(self.module, 6, BICPINS_MODE, BICPINS_SPEED, dummy_data)
67
78
 
68
- #reset remote bit keep the others
69
- commandlow = r_data[0] & 0b01111111
70
- commandhigh = r_data[1] & 0b01111111
79
+ #reset remote bit to 0 (keeping other setings)
80
+ high_byte = r_data[0] & 0b01111111
81
+ #low_byte = r_data[1] & 0b01111111
82
+ low_byte = r_data[1]
71
83
 
72
- #write settings with reset remote bit
73
- s_data = bytearray([commandlow,commandhigh])
74
- self.spi_rack.write_data(self.module, 5, BICPINS_MODE, BICPINS_SPEED, s_data)
84
+ #write new settings (with 0-set remote bit)
85
+ w_data = bytearray([high_byte,low_byte])
86
+ self.spi_rack.write_data(self.module, 5, BICPINS_MODE, BICPINS_SPEED, w_data)
75
87
 
76
- def set_gain(self, gainlevel, couplemode):
88
+ def remote_set_gain_and_coupling(self, gain, coupling):
77
89
  """
78
90
  Set gain and coupling mode
79
91
  Posible gain settings : 1, 10, 100, 1000, 10.000
80
- Coupling DC=0 AC=1
92
+ Coupling 'DC'=1 'AC'=0
93
+
81
94
  gainlevel and couplemode parameters are checked for valid values.
82
95
  When one of the parameters is out of range or otherwise invalid no change in settings will be made
83
- The remote/local setting will not ne changed, so if current setting is local NO CHANGE in gain or coupling will happen.
96
+
97
+ The remote/local selection is maintained, so under a 'local' setting NO CHANGE in gain or coupling will happen.
84
98
  But the last written values can be readback
85
99
  """
86
100
 
87
- # check for valid gain and couple values
88
- if self.gainvalid(gainlevel) == False or self.couplemodevalid(couplemode) == False:
89
- print("Invalid gain or couplemode, no settings changed" )
101
+ # check for valid gain and coupling values
102
+ if self._is_gain_valid(gain) == False or self._is_couplemode_valid(coupling) == False:
103
+ print("Invalid gain or coupling, no settings changed" )
90
104
  return
91
105
 
92
- # read high byte for remote bit and couple bit
106
+ # read to preserve the value of the high byte for the upcoming 'write'
93
107
  dummy_data = bytearray([0,0])
94
108
  r_data = bytearray([0,0])
95
109
  r_data = self.spi_rack.read_data(self.module, 6, BICPINS_MODE, BICPINS_SPEED, dummy_data)
96
- commandhigh = r_data[1]
110
+ high_byte = r_data[0]
97
111
 
98
- #commandhigh = 0b10000001
99
- # set gain bits
100
- if gainlevel == 1:
101
- commandlow = 0b10010000
102
- if gainlevel == 10:
103
- commandlow = 0b10010001
104
- if gainlevel == 100:
105
- commandlow = 0b10010010
106
- if gainlevel == 1000:
107
- commandlow = 0b10010110
108
- if gainlevel == 10000:
109
- commandlow = 0b10011010
112
+ # config gain bits
113
+ if gain == 1:
114
+ low_byte = 0b10010000
115
+ elif gain == 10:
116
+ low_byte = 0b10010001
117
+ elif gain == 100:
118
+ low_byte = 0b10010010
119
+ elif gain == 1000:
120
+ low_byte = 0b10010110
121
+ else:
122
+ # gain == 10000:
123
+ low_byte = 0b10011010
110
124
 
111
- # (re)setcouple bit while keeping remote bit setting
112
- if couplemode == 0:
113
- commandlow = commandlow | 0b00010000 # DC
125
+ # config coupling bit (while keeping other settings)
126
+ if coupling == 'DC':
127
+ low_byte = low_byte | 0b00010000 # For DC, set control bit to 1
114
128
  else:
115
- commandlow = commandlow & 0b11101111 # AC
129
+ low_byte = low_byte & 0b11101111 # For AC, set control bit to 0
116
130
 
117
- s_data = bytearray([commandhigh,commandlow])
118
- self.spi_rack.write_data(self.module, 5, BICPINS_MODE, BICPINS_SPEED, s_data)
131
+ w_data = bytearray([high_byte,low_byte])
132
+ self.spi_rack.write_data(self.module, 5, BICPINS_MODE, BICPINS_SPEED, w_data)
119
133
 
120
- def gainvalid(self, gain):
134
+ def _is_gain_valid(self, gain):
121
135
  # Check gain parameter for valid values
122
136
  # return True (valid) or False (invalid)
123
- if gain in gainlist:
137
+ if gain in self.gainlist:
124
138
  return True
125
139
  else:
126
140
  return False
127
141
 
128
- def couplemodevalid(self, couplemode):
142
+ def _is_couplemode_valid(self, couplemode):
129
143
  # Check couple parameter for valid values
130
144
  # return True (valid) or False (invalid)
131
- if couplemode <0 or couplemode>1:
132
- return False
133
- else:
145
+ if couplemode in ['AC','DC']:
134
146
  return True
147
+ else:
148
+ return False
135
149
 
136
150
  def get_operating_mode(self):
137
151
  """
138
152
  read the operating status of the module.
139
- Either 1 = Remote mode or 0 = local mode
153
+ Modes can be 'remote' or 'local'
140
154
  """
141
155
 
142
- mode = 0
156
+ mode = ''
143
157
  dummy_data = bytearray([0,0])
144
158
  r_data = bytearray([0,0])
145
159
  r_data = self.spi_rack.read_data(self.module, 6, BICPINS_MODE, BICPINS_SPEED, dummy_data)
146
160
 
147
161
  if r_data[0] & 0b10000000:
148
- mode = 1
162
+ mode = 'remote'
149
163
  else:
150
- mode = 0
164
+ mode = 'local'
151
165
 
152
166
  return(mode)
153
167
 
154
- def get_lastgainset(self):
168
+ def get_gain_setting(self):
155
169
  """
156
170
  Get lastgain switch setting command.
157
171
  This in NOT the same as the gain settings of the switch panel!
158
172
  This is the last gain set in remote mode.
159
- posible results: 1, 10, 100, 1000, 10000
173
+ Posible results: 1, 10, 100, 1000, 10000
160
174
  """
161
- commandhigh = 0b00000000
162
- commandlow = 0b00000000
163
- s_data = bytearray([commandhigh, commandlow])
175
+ if self.get_operating_mode()=='local':
176
+ return self.get_gain_local()
177
+ else:
178
+ return self.get_gain_remote()
179
+
180
+ def get_gain_remote(self):
181
+ s_data = bytearray([0, 0])
164
182
  r_data = self.spi_rack.read_data(self.module, 6, BICPINS_MODE, BICPINS_SPEED, s_data)
165
183
  gain = -1
166
184
  if r_data[1] & 0b00001111 == 0:
167
185
  gain = 1
168
- if r_data[1] & 0b00000001 == 0b00000001:
186
+ if r_data[1] & 0b00001111 == 0b00000001:
169
187
  gain = 10
170
- if r_data[1] & 0b00000010 == 0b00000010 :
188
+ if r_data[1] & 0b00001111 == 0b00000010:
171
189
  gain = 100
172
- if r_data[1] & 0b00000110 == 0b00000110:
190
+ if r_data[1] & 0b00001111 == 0b00000110:
173
191
  gain = 1000
174
- if r_data[1] & 0b00001010 == 0b00001010:
192
+ if r_data[1] & 0b00001111 == 0b00001010:
175
193
  gain = 10000
176
194
  return (gain)
177
195
 
178
196
 
179
- def get_gainswitch(self):
197
+ def get_gain_local(self):
180
198
  """
181
- Get the frontpanel gain switch setting.
182
- posible results: 1, 10, 100, 1000, 10000
199
+ Get the front-panel gain switch setting.
200
+ Posible results: 1, 10, 100, 1000, 10000
183
201
  """
184
- commandhigh = 0b00000000
185
- commandlow = 0b00000000
186
- s_data = bytearray([commandhigh, commandlow])
202
+ s_data = bytearray([0,0])
187
203
  r_data = self.spi_rack.read_data(self.module, 4, BICPINS_MODE, BICPINS_SPEED, s_data)
188
204
 
189
205
  gain = -1
190
206
  if r_data[1] & 0b00001111 == 0:
191
207
  gain = 1
192
- if r_data[1] & 0b00000001 == 0b00000001:
208
+ elif r_data[1] & 0b00001111 == 0b00000001:
193
209
  gain = 10
194
- if r_data[1] & 0b00000010 == 0b00000010 :
210
+ elif r_data[1] & 0b00001111 == 0b00000010:
195
211
  gain = 100
196
- if r_data[1] & 0b00000110 == 0b00000110:
212
+ elif r_data[1] & 0b00001111 == 0b00000110:
197
213
  gain = 1000
198
- if r_data[1] & 0b00001010 == 0b00001010:
214
+ elif r_data[1] & 0b00001111 == 0b00001010:
199
215
  gain = 10000
200
216
 
201
217
  return (gain)
202
218
 
203
- def get_lastcouple_switchsetting(self):
219
+ def get_coupling_setting(self):
204
220
  """
205
221
  Get the last frontpanel couple mode (AC/DC) switch setting command.
206
222
  This in NOT the same as the couple mode settings on the front panel!
207
- posible results: 0 = DC 1=AC
223
+ posible results: 'DC'=1 AC='0'
208
224
  """
225
+ if self.get_operating_mode()=='local':
226
+ return self.get_coupling_local()
227
+ else:
228
+ return self.get_coupling_remote()
229
+
230
+ def get_coupling_remote(self):
209
231
  dummy_data = bytearray([0,0])
210
232
  r_data = self.spi_rack.read_data(self.module, 6, BICPINS_MODE, BICPINS_SPEED, dummy_data)
211
233
  mode = -1
212
234
  if r_data[1] & 0b00010000:
213
- mode = 1
235
+ mode = 'DC'
214
236
  else:
215
- mode = 0
237
+ mode = 'AC'
216
238
  return (mode)
217
239
 
218
- def get_couple_switchsetting(self):
240
+ def get_coupling_local(self):
219
241
  """
220
242
  Get the frontpanel couple mode (AC/DC) switch setting.
221
- posible results: 0 = DC 1=AC
243
+ posible results: 'DC'=1 AC='0'
222
244
  """
223
245
  dummy_data = bytearray([0,0])
224
246
  r_data = self.spi_rack.read_data(self.module, 4, BICPINS_MODE, BICPINS_SPEED, dummy_data)
225
247
  mode = -1
226
248
  if r_data[1] & 0b00010000:
227
- mode = 1
249
+ mode = 'DC'
228
250
  else:
229
- mode = 0
251
+ mode = 'AC'
230
252
  return (mode)
231
-
232
- def get_clipped_latched(self):
233
- # Return:
234
- # 0 if none clipped
235
- # 1 if pos clipped
236
- # 2 if neg clipped
237
- # 3 if pos and neg clipped (is posible when clipped is latched)
238
- clipped = -1
239
- dummy_data = bytearray([0,0])
240
- r_data = self.spi_rack.read_data(self.module, 7, BICPINS_MODE, BICPINS_SPEED, dummy_data)
241
-
242
- if (((r_data[0] & 0b01000000) == 0) & ((r_data[0] & 0b10000000) == 0)):
243
- clipped = 0
244
- elif (r_data[0] & 0b11000000 == 0b11000000):
245
- clipped = 3
246
- elif (r_data[0] & 0b01000000):
247
- clipped = 2
248
- elif (r_data[0] & 0b10000000):
249
- clipped = 1
250
-
251
- return (clipped)
252
253
 
253
254
  def get_clipped_unlatched(self):
255
+ # Inverted polarity
254
256
  # Return:
255
257
  # 0 if none clipped
256
258
  # 1 if pos clipped
257
259
  # 2 if neg clipped
258
260
  # 3 if pos and neg clipped (is posible when clipped is latched)
259
261
 
260
- clipped = -1
262
+ clipped = ''
261
263
  dummy_data = bytearray([0,0])
262
- r_data = self.spi_rack.read_data(self.module, 7, BICPINS_MODE, BICPINS_SPEED, dummy_data)
264
+ r_data = self.spi_rack.read_data(self.module, 3, BICPINS_MODE, BICPINS_SPEED, dummy_data)
263
265
 
264
266
  if (r_data[0] & 0b00110000) == 0b00110000:
265
- clipped = 0
267
+ clipped = 'not clipped'
266
268
  elif (((r_data[0] & 0b00010000) == 0) & ((r_data[0] & 0b00100000) == 0)):
267
- clipped = 3
269
+ clipped = 'pos and neg clipped'
268
270
  elif (r_data[0] & 0b00010000) == 0:
269
- clipped = 1
271
+ clipped = 'pos clipped'
270
272
  elif (r_data[0] & 0b00100000) == 0:
271
- clipped = 2
273
+ clipped = 'neg clipped'
274
+
275
+ return (clipped)
276
+
277
+ def get_clipped_latched(self):
278
+ # Regular polarity (non-inverted)
279
+ # Return:
280
+ # 0 if none clipped
281
+ # 1 if pos clipped
282
+ # 2 if neg clipped
283
+ # 3 if pos and neg clipped (is posible when clipped is latched)
284
+ clipped = ''
285
+ dummy_data = bytearray([0,0])
286
+ r_data = self.spi_rack.read_data(self.module, 4, BICPINS_MODE, BICPINS_SPEED, dummy_data)
287
+
288
+ if (((r_data[0] & 0b01000000) == 0) & ((r_data[0] & 0b10000000) == 0)):
289
+ clipped = 'not clipped'
290
+ elif (r_data[0] & 0b11000000 == 0b11000000):
291
+ clipped = 'pos and neg clipped'
292
+ elif (r_data[0] & 0b01000000):
293
+ clipped = 'neg clipped'
294
+ elif (r_data[0] & 0b10000000):
295
+ clipped = 'pos clipped'
272
296
 
273
297
  return (clipped)
@@ -0,0 +1 @@
1
+ __version__ = '0.2.19'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spirack
3
- Version: 0.2.18
3
+ Version: 0.2.19
4
4
  Summary: Drivers for the QuTech SPI-rack
5
5
  Home-page: https://github.com/qutechdev/SPI-rack
6
6
  Author: QuTech Electronics Team
@@ -1 +0,0 @@
1
- __version__ = '0.2.18'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes