-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMU_m1k.py
More file actions
125 lines (111 loc) · 3.59 KB
/
Copy pathSMU_m1k.py
File metadata and controls
125 lines (111 loc) · 3.59 KB
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
import time
import os
from io import open
import pysmu
from pysmu import Mode
import serial
'''SMU Voltage Range Settings 'from low to hi" USER can set in range from -5V to +5V'''
lowVolt = -5
hiVolt = 5
precision = .1
''' 1.0, 0.10 or 0.01 the number of decimal placees--will affect number of samples'''
''' Setup serial USB to Fluke 289 DMM'''
DMM = serial.Serial()
DMM.port = '/dev/cu.usbserial-AC00FZQJ' # Serial port; change to suit your USB
# Serial port setup and open for FLUKE 289 (don't change)
DMM.baudrate = 115200
DMM.bytesize = serial.EIGHTBITS
DMM.parity = serial.PARITY_NONE
DMM.stopbits = serial.STOPBITS_ONE
DMM.xonxoff = False
DMM.rtscts = False
DMM.dsrdtr = False
DMM.timeout = 0.1 # seconds
try:
DMM.open()
except:
print("Cannot open serial port...")
exit()
'''Setup output file for data, this will be from your PC path'''
output_filename = 'dmm_out.csv'
output_directory = "/Users/donal/documents/" #''' MacOS; PC users will know what to do'''
os.chdir(output_directory)
file = open(output_filename, 'w', newline='')
file.write('Volt,Amps,V_a,I_a,V_b,I_b \n') #''' for the column headings (can be changed)'''
''' this function will get current reading from DMM set on mAmp or uAmp as needed'''
def QM():
DMM.write(('qm' + '\r').encode('utf-8'))
if DMM.read():
data = (DMM.read(32).decode('utf-8'))
return ((data.split(','))[0][1:]) # dont change this
''' convert volt range for greater precision'''
lowVolt = int((lowVolt)/precision)
hiVolt = int((hiVolt)/precision+1)
session = pysmu.Session(ignore_dataflow=True)
#print (session) debug
smu = session.devices[0]
#smu = list_devices(session,0) more debug
#print (smu.serial)
#print (smu.fwver)
''' Set both channels to SMU mode. (different settings, just FYI'''
chan_a = smu.channels['A']
chan_b = smu.channels['B']
# CHAN_A source
#chan_a.mode = Mode.HI_Z
chan_a.mode = Mode.SVMI
#chan_a.mode = Mode.SVMI_SPLIT
#chan_a.mode = Mode.SIMV
# CHAN_B source
#chan_b.mode = Mode.HI_Z
chan_b.mode = Mode.SVMI
#chan_b.mode = Mode.SIMV
#chan_b.mode = Mode.SIMV_SPLIT
'''this sends settings to ADALM1000'''
def out_file(v_a,v_b):
#print (volt)
session.start(0)
chan_a.constant(v_a)
chan_b.constant(v_b)
time.sleep(.1)
amps = QM()
volt = v_a - v_b
data = ()
for x in smu.read(1):
out_data = ((format(x[0][0],'E')), (format(x[0][1],'E')), (format(x[1][0],'E')), (format(x[1][1],'E')))
data = (str(out_data).replace('(',''))
data = (data.replace(')',''))
data = (data.replace('\'',''))
print (str(round(volt,2)) + ', ' + (amps)+', '+ ((data)))
file.write(str(round(volt,2)) +', ' + (amps) +', ' + (data) +'\n')
# deal with negative voltage
if lowVolt < 0 and hiVolt > 0:
for vb in range(abs(lowVolt),0,-1):
v_a = 0.0
v_b = float(vb*precision)
out_file(v_a,v_b)
for va in range(0,hiVolt):
v_a = float(va*precision)
v_b = 0.0
out_file(v_a,v_b)
else:
for va in range(lowVolt,hiVolt): # when both lowVolt and hiVolt > 0
v_a = float(va*precision)
v_b = 0.0
out_file(v_a,v_b)
# deal with both lowVolt and hiVolt negative voltage
if lowVolt < 0 and hiVolt < 0:
for vb in range((lowVolt),abs(hiVolt),-1):
v_a = 0.0
v_b = float(vb*precision)
out_file(v_a,v_b)
for va in range((hiVolt),(lowVolt)):
v_a = float(va*precision)
v_b = 0.0
out_file(v_a,v_b)
'''DONE, tidy up'''
file.close()
chan_a.mode = Mode.HI_Z
chan_b.mode = Mode.HI_Z
chan_a.constant(0)
chan_b.constant(0)
#print (All finished")