76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
import socket
|
||
import time
|
||
|
||
TCP_PORT = 7777
|
||
Buffer = 80
|
||
|
||
class LakeShore336:
|
||
|
||
def __init__(self, ip):
|
||
#establishes connection to device via ethernet.
|
||
try:
|
||
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||
self.s.connect((ip, TCP_PORT))
|
||
self.s.settimeout(1)
|
||
time.sleep(0.2)
|
||
except:
|
||
print(f'could not connect to device with IP: {ip}')
|
||
|
||
def __del__(self):
|
||
self.s.close()
|
||
|
||
def read(self,CH): #reads temperature Data in Kelvin from channels specified in CH. CH is in format ['A','B','C','D']
|
||
for i in CH:
|
||
command = f'KRDG? {i}\r\n'
|
||
self.s.send(command.encode('utf-8'))
|
||
time.sleep(0.2)
|
||
data = str(self.s.recv(Buffer))[2:]
|
||
data = data.split('\\r\\n')
|
||
data = [float(i) for i in data[:-1]]
|
||
return data
|
||
|
||
def set_T(self,out,T):
|
||
#set the temperture setpoint "T" (in preferred units of the control loop sensor) of output "out"
|
||
command = f'SETP {out},{T}\r\n'
|
||
self.s.send(command.encode('utf-8'))
|
||
time.sleep(0.2)
|
||
|
||
def set_Ramp(self,out,ON,ramp):
|
||
#sets temperature rate of output "out", turns it on, if "ON" is not 0 or 'OFF', with ramprate "ramp" in Kelvin per minute.
|
||
#If a ramprate of 0 is entered, the ramprate is turned off
|
||
if ramp == 0:
|
||
ON = 0
|
||
if ON == 0 or ON == 'OFF':
|
||
command = f'RAMP {out},0\r\n'
|
||
else:
|
||
command = f'RAMP {out},{ON},{ramp}\r\n'
|
||
self.s.send(command.encode('utf-8'))
|
||
time.sleep(0.2)
|
||
|
||
def conf_outp(self,out=1,mode=0,inp=1,powup=0):
|
||
#configures putputmode:
|
||
#<out> Specifies which output to configure: 1–4.
|
||
#<mode> Specifies the control mode. Valid entries: 0 = Off, 1 = ClosedLoop PID, 2 = Zone, 3 = Open Loop, 4 = Monitor Out,5 = Warmup Supply
|
||
#<inp> Specifies which input to use for control: 0 = None, 1 = A, 2 = B, 3 = C, 4 = D, 5 = Input D2, 6 = Input D3, 7 = Input D4,8 = Input D5 for 3062 option)
|
||
#<powerup enable> Specifies whether the output remains on or shuts off afterpower cycle. Valid entries: 0 = powerup enable off,1 = powerup enable on.
|
||
command = f'OUTMODE {out},{mode},{inp},{powup}\r\n'
|
||
self.s.send(command.encode('utf-8'))
|
||
time.sleep(0.2)
|
||
|
||
def turn_on_outp(self, out=1, range = 0):
|
||
#turns the heater output on or off by setting the heater range to:
|
||
#For outputs 1 and 2: 0 = Off, 1 = Low, 2 = Medium, 3 = High
|
||
#For outputs 3 and 4: 0 = Off, 1 = On
|
||
command = f'Range {out},{range}\r\n'
|
||
self.s.send(command.encode('utf-8'))
|
||
time.sleep(0.2)
|
||
|
||
def conf_pid(self, out, Pid, pId, piD):
|
||
#sets PID values of output "out"
|
||
# <output> Specifies which output’s control loop to configure: 1 or 2.
|
||
# <P value> The value for output Proportional (gain): 0.1 to 1000.
|
||
# <I value> The value for output Integral (reset): 0.1 to 1000.
|
||
# <D value> The value for output Derivative (rate): 0 to 200.
|
||
command = f'PID {out},{Pid},{pId},{piD}\r\n'
|
||
self.s.send(command.encode('utf-8'))
|
||
time.sleep(0.2) |