Commit 474b2bde authored by Mateus Goto's avatar Mateus Goto

[Fixed] set voltage [Tested] setters and fetchs

parent 5fed8559
...@@ -21,16 +21,15 @@ class controlInterface: ...@@ -21,16 +21,15 @@ class controlInterface:
def newNhr(self, nhr): def newNhr(self, nhr):
if(nhr == "9410"): if(nhr == "9410"):
new = NHR9410() new = NHR9410()
elif nhr == "9430": elif nhr == "9430":
new = NHR9430() new = NHR9430()
else: else:
return -1 return -1
new.locateIp(self.__listIp) new.locateIp(self.__listIp)
print(new.getIp()) new.setS()
print(new.getS())
usedIp = new.getIp() usedIp = new.getIp()
print("usedIP:" + str(usedIp))
try: try:
self.__listIp.remove(usedIp) self.__listIp.remove(usedIp)
self.__listUsedIp.append(usedIp) self.__listUsedIp.append(usedIp)
......
...@@ -12,6 +12,12 @@ class NHR9400(): ...@@ -12,6 +12,12 @@ class NHR9400():
self.__ip = "" self.__ip = ""
################################# Configurations ###################################################### ################################# Configurations ######################################################
#Default start: Enable all instruments and close output relays and starts an aperture measurement on all channels which will run for the time specified by the last received SENSe:SWEep:APERture instrument command
#!!!!!! upgrade this function later
def start(self):
self.__s.send("SOUR:OUTP:ON 1\n".encode())
self.__s.send("INIT\n".encode())
def locateIp(self, clients = []): def locateIp(self, clients = []):
for client in clients: for client in clients:
try: try:
...@@ -23,7 +29,6 @@ class NHR9400(): ...@@ -23,7 +29,6 @@ class NHR9400():
msg = self.__s.recv(1024) msg = self.__s.recv(1024)
recv = self.receiveString(msg) recv = self.receiveString(msg)
id = "NH Research," + str(self.__name) id = "NH Research," + str(self.__name)
self.__s.send("SOUR:VOLT: 110\n".encode())
if recv.find(id) != -1: #if find this subtring if recv.find(id) != -1: #if find this subtring
self.__ip = client self.__ip = client
print(self.__ip) print(self.__ip)
...@@ -36,6 +41,7 @@ class NHR9400(): ...@@ -36,6 +41,7 @@ class NHR9400():
def getIp(self): def getIp(self):
return self.__ip return self.__ip
def getS(self): def getS(self):
return self.__s return self.__s
...@@ -113,6 +119,8 @@ class NHR9400(): ...@@ -113,6 +119,8 @@ class NHR9400():
return self.receiveString(value) return self.receiveString(value)
def close(self): def close(self):
self.__s.send("SOUR:OUTP:ON 0\n".encode())
self.__s.send("ABOR\n".encode())
self.__s.send("SYST:LOC\n".encode()) self.__s.send("SYST:LOC\n".encode())
print(self.checkErrors()) print(self.checkErrors())
self.__s.close() self.__s.close()
...@@ -124,10 +132,12 @@ class NHR9400(): ...@@ -124,10 +132,12 @@ class NHR9400():
self.__s.send(("SOUR:OUTP:ON "+ str(value) + "\n").encode()) self.__s.send(("SOUR:OUTP:ON "+ str(value) + "\n").encode())
else: else:
print("INVALID INPUT") print("INVALID INPUT")
################################# System command #####################################################
#Command places the touch panel (if present) in local control mode. All front panel keys are returned to a functional state.
def systLocal(self):
################################# Setters and Getters ################################################ ################################# Setters and Getters ################################################
#set limit voltage of all phases #set limit voltage of all phases
def setVoltage(self,voltage): def setVoltage(self,voltage):
self.__s.send("INIT\n".encode())
msg = "SOUR:VOLT: 110\n" msg = "SOUR:VOLT: 110\n"
print(msg) print(msg)
print(self.__s) print(self.__s)
...@@ -155,7 +165,12 @@ class NHR9400(): ...@@ -155,7 +165,12 @@ class NHR9400():
self.__s.send(("SOUR:POW:CPHase " + str(pow) + "\n").encode()) self.__s.send(("SOUR:POW:CPHase " + str(pow) + "\n").encode())
#Command establishes the operating frequency for the selected instrument. #Command establishes the operating frequency for the selected instrument.
def setFreq(self, freq): def setFreq(self, freq):
self.__s.send(("SOUR:POW " + str(freq) + "\n").encode()) self.__s.send(("SOUR:FREQ " + str(freq) + "\n").encode())
#!!!! Doesnt work!!!!
def getFreq(self):
self.__s.send("FETC:FREQ\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value)
#Fetch the average voltage of all channels #Fetch the average voltage of all channels
def getVoltage(self): def getVoltage(self):
self.__s.send("FETC:VOLT?\n".encode()) self.__s.send("FETC:VOLT?\n".encode())
......
...@@ -5,6 +5,6 @@ class NHR9410(NHR9400): ...@@ -5,6 +5,6 @@ class NHR9410(NHR9400):
def __init__(self): def __init__(self):
super().__init__("9410") super().__init__("9410")
def getS(self): def setS(self):
return self.__s self.__s = self.getS()
import socket
from NHR9400series.NHR9400 import NHR9400 from NHR9400series.NHR9400 import NHR9400
class NHR9430(NHR9400): class NHR9430(NHR9400):
...@@ -7,11 +6,14 @@ class NHR9430(NHR9400): ...@@ -7,11 +6,14 @@ class NHR9430(NHR9400):
super().__init__("9430") super().__init__("9430")
def setS(self):
self.__s = self.getS()
#Command sets the loading features <loading mode> for a 9430 AC output Query returns the loading features enabled on a 9430 #Command sets the loading features <loading mode> for a 9430 AC output Query returns the loading features enabled on a 9430
#Command is only accepted if the instrument is a 9430, with AC outputs mode, and in an OFF state Other models & modes: This command is invalid #Command is only accepted if the instrument is a 9430, with AC outputs mode, and in an OFF state Other models & modes: This command is invalid
# 0 = NORMal = CC / CP / CVA with modifiers (PF, CF, & IWAVESHAPE) # 0 = NORMal = CC / CP / CVA with modifiers (PF, CF, & IWAVESHAPE)
# 1 = CR = Constant Resistance (with optional CC limit) # 1 = CR = Constant Resistance (with optional CC limit)
# 2 = RL = Constant series Resistance & Inductance # 2 = RL = Constant series Resistance & Inductance
def instrumentLoad(self, value): def instrumentLoad(self, value):
if value < 0 or value > 2: if value < 0 or value > 2:
print("INVALID INPUT") print("INVALID INPUT")
......
...@@ -15,25 +15,31 @@ nhr30 = [] ...@@ -15,25 +15,31 @@ nhr30 = []
nhr10 = interface.getNhr9410() nhr10 = interface.getNhr9410()
nhr30 = interface.getNhr9430() nhr30 = interface.getNhr9430()
print(nhr10)
print(nhr30)
for elem in nhr10: for elem in nhr10:
print("nhr10 ip: ",elem.getIp()) print("nhr10 ip: ",elem.getIp())
elem.setVoltage(220) elem.setVoltage(220)
time.sleep(1) elem.setPower(5)
elem.setPower(0.7) elem.start()
print(elem.checkErrors())
print("voltage:",elem.getVoltage()) print("voltage:",elem.getVoltage())
print("current:", elem.getCurrent()) print("current:", elem.getCurrent())
print("Power:", elem.getPower()) print("Power:", elem.getPower())
elem.close() print(elem.checkErrors())
for elem in nhr30: for elem in nhr30:
print("nhr30 ip: ",elem.getIp()) print("nhr30 ip: ",elem.getIp())
elem.setCurrent(30) elem.setCurrent(30)
elem.start()
print("voltage:",elem.getVoltage()) print("voltage:",elem.getVoltage())
print("current:", elem.getCurrent()) print("current:", elem.getCurrent())
print("Power:", elem.getPower()) print("Power:", elem.getPower())
time.sleep(20)
for elem in nhr10:
elem.close()
for elem in nhr30:
elem.close() elem.close()
\ No newline at end of file
...@@ -11,3 +11,5 @@ class can(mug.mug): ...@@ -11,3 +11,5 @@ class can(mug.mug):
def getId(self): def getId(self):
return self.__id return self.__id
def getS(self):
return self.__s
\ No newline at end of file
...@@ -8,5 +8,5 @@ can.setId(132) ...@@ -8,5 +8,5 @@ can.setId(132)
print(can.getId()) print(can.getId())
print(can.decode("isso aqui é ")) print(can.decode("isso aqui é "))
print(can.getS()) #this should be working on the project was well print("can s: ", can.getS()) #this should be working on the project was well
print(mug.getS()) print(mug.getS())
\ No newline at end of file
...@@ -11,5 +11,4 @@ class mug(): ...@@ -11,5 +11,4 @@ class mug():
recv = dec.dec().rewrite(recv) recv = dec.dec().rewrite(recv)
return recv return recv
def getS(self):
return self.__s \ No newline at end of file
\ No newline at end of file
...@@ -5,31 +5,29 @@ import socket ...@@ -5,31 +5,29 @@ import socket
import time import time
start = time.time() start = time.time()
def getAllIp():
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(("10.255.255.255",1))
local_ip = s.getsockname()[0]
print(local_ip)
local_ip = local_ip[:-3] + "1/24"
print(local_ip)
print(type(local_ip))
arp = ARP(pdst=local_ip)
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
packet = ether/arp
result= srp(packet, timeout=3,retry = 1, verbose = 0)[0]
clients = []
for sent, received in result:
clients.append(received.psrc)
for client in clients:
print(client)
getAllIp()
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(1) s.settimeout(1)
try:
s.connect(("192.168.15.10", 5025)) s.connect(("192.168.0.2",5025))
except:
print("conexão falhou") s.send("SYST:RWL\n".encode()) #Command to activate remote control and locking the touchscreen
print (time.time() - start) s.send("*IDN?\r\n".encode())
msg = s.recv(1024)
print(msg)
s.send("SOUR:OUTP:ON 1\n".encode())
s.send("INIT\n".encode())
s.send("SOUR:VOLT: 110\r\n".encode())
s.send("SYST:ERR?\n".encode())
msg = s.recv(1024)
print(msg)
time.sleep(5)
s.send("SOUR:OUTP:ON 0\n".encode())
s.send("SYST:LOC\n".encode())
s.close()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment