Commit 866934c1 authored by Mateus Goto's avatar Mateus Goto

[TESTED] ouput, conections, fetch v

parent b0e5c791
...@@ -17,31 +17,29 @@ class controlInterface: ...@@ -17,31 +17,29 @@ class controlInterface:
for ip in self.__listUsedIp: for ip in self.__listUsedIp:
self.__listIp.remove(ip) self.__listIp.remove(ip)
#create a NHR9410 object #create a NHR object
def newNhr9410(self): def newNhr(self, nhr):
new = NHR9410() if(nhr == "9410"):
new = NHR9410()
elif nhr == "9430":
new = NHR9430()
else:
return -1
new.locateIp(self.__listIp) new.locateIp(self.__listIp)
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)
self.__nhr9410.append(new) if(nhr == "9410"):
print("herer") self.__nhr9410.append(new)
elif nhr == "9430":
self.__nhr9430.append(new)
else:
return -1
except: except:
print("Any IP address matched") print("Any IP address matched")
#create a NHR9430 object
def newNhr9430(self):
new = NHR9430()
usedIp = new.locateIp(self.__listIp)
#print(usedIp)
try:
self.__listIp.remove(usedIp)
self.__listUsedIp.append(usedIp)
self.__nhr9430.append(new)
except:
print("Any IP adress matched")
def getNhr9410(self): def getNhr9410(self):
return self.__nhr9410 return self.__nhr9410
......
...@@ -9,29 +9,33 @@ class NHR9400: ...@@ -9,29 +9,33 @@ class NHR9400:
self.__name = name self.__name = name
self.__s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.__s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.__s.settimeout(1) self.__s.settimeout(1)
self.__ip = ""
################################# Configurations ###################################################### ################################# Configurations ######################################################
def locateIp(self, clients = []): def locateIp(self, clients = []):
for client in clients: for client in clients:
try: try:
self.__s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.__s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.__s.settimeout(1)
self.__s.connect((client, 5025)) self.__s.connect((client, 5025))
self.__s.send("SYST:RWL\n".encode()) #Command to activate remote control and locking the touchscreen self.__s.send("SYST:RWL\n".encode()) #Command to activate remote control and locking the touchscreen
self.__s.send("*IDN?\n".encode()) self.__s.send("*IDN?\n".encode())
msg = self.__s.recv(1024) msg = self.__s.recv(1024)
recv = self.receiveString(msg) recv = self.receiveString(msg)
if recv.find("NH Research," + self.__name) != -1: #if find this subtring id = "NH Research," + str(self.__name)
print("o cliente encontrado: " + client) if recv.find(id) != -1: #if find this subtring
self.__ip = client self.__ip = client
print(self.__ip) print(self.__ip)
print("Connection successfully") print("Connection successfully")
break break
else: else:
print("Connection failed 1")
self.__s.close() self.__s.close()
except: except:
print("Connection failed 2") print("Connection failed 2")
def getIp(self):
return self.__ip
#chose a mode with the instrument will run, check the manual to see all modes. #chose a mode with the instrument will run, check the manual to see all modes.
def configMode(self, mode): def configMode(self, mode):
if mode < 0 and mode > 16: if mode < 0 and mode > 16:
...@@ -88,13 +92,7 @@ class NHR9400: ...@@ -88,13 +92,7 @@ class NHR9400:
self.checkErrors() self.checkErrors()
#Function that receives messages back and transform it in a string #Function that receives messages back and transform it in a string
def receiveString(self,recv): def receiveString(self,recv):
print("fail6") recv = refineOutput().byteToString(recv)
print("fail8")
recv = bytes(recv)
recv = recv.decode("UTF-8")
recv = recv.rstrip('\n')
recv = recv.rstrip('\x00')
print("sucess")
return recv return recv
#Function that receives messages back and transform it in a float #Function that receives messages back and transform it in a float
...@@ -112,8 +110,6 @@ class NHR9400: ...@@ -112,8 +110,6 @@ class NHR9400:
return self.receive() return self.receive()
def close(self): def close(self):
print(self.__ip)
self.__s.connect((self.__ip,5025))
self.__s.send("SYST:LOC\n".encode()) self.__s.send("SYST:LOC\n".encode())
self.__s.close() self.__s.close()
# Controle do relé de saída do hardware (LIGAR OU DESLIGAR) # Controle do relé de saída do hardware (LIGAR OU DESLIGAR)
...@@ -153,30 +149,39 @@ class NHR9400: ...@@ -153,30 +149,39 @@ class NHR9400:
self.__s.send(("SOUR:POW " + str(freq) + "\n").encode()) self.__s.send(("SOUR:POW " + str(freq) + "\n").encode())
#Fetch the average voltage of all channels #Fetch the average voltage of all channels
def getVoltage(self): def getVoltage(self):
value = self.__s.send("FETC:VOLT?\n".encode()) self.__s.send("FETC:VOLT?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
#fetch individual value of voltage of one channel #fetch individual value of voltage of one channel
def getVoltageA(self): def getVoltageA(self):
value = self.__s.send("FETC:VOLT:APHase?\n".encode()) self.__s.send("FETC:VOLT:APHase?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
def getVoltageB(self): def getVoltageB(self):
value = self.__s.send("FETC:VOLT:BPHase?\n".encode()) self.__s.send("FETC:VOLT:BPHase?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
def getVoltageC(self): def getVoltageC(self):
value = self.__s.send("FETC:VOLT:CPHase?\n".encode()) self.__s.send("FETC:VOLT:CPHase?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
#Fetch the average power of all channels #Fetch the average power of all channels
def getPower(self): def getPower(self):
value = self.__s.send("FETC:POW?\n".encode()) self.__s.send("FETC:POW?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
#fetch individual value of Power of one channel #fetch individual value of Power of one channel
def getPowerA(self): def getPowerA(self):
value = self.__s.send("FETC:POW:APHase?\n".encode()) self.__s.send("FETC:POW:APHase?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
def getPowerB(self): def getPowerB(self):
value = self.__s.send("FETC:POW:BPHase?\n".encode()) self.__s.send("FETC:POW:BPHase?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
def getPowerC(self): def getPowerC(self):
value = self.__s.send("FETC:POW:CPHase?\n".encode()) self.__s.send("FETC:POW:CPHase?\n".encode())
value = self.__s.recv(1024)
return self.receiveFloat(value) return self.receiveFloat(value)
...@@ -3,12 +3,7 @@ from NHR9400series.NHR9400 import NHR9400 ...@@ -3,12 +3,7 @@ from NHR9400series.NHR9400 import NHR9400
class NHR9410(NHR9400): class NHR9410(NHR9400):
def __init__(self): def __init__(self):
super().__init__("NHR9410") super().__init__("9410")
self.__ip = ""
def getIp(self):
return self.__ip
...@@ -3,8 +3,8 @@ from NHR9400series.NHR9400 import NHR9400 ...@@ -3,8 +3,8 @@ from NHR9400series.NHR9400 import NHR9400
class NHR9430(NHR9400): class NHR9430(NHR9400):
def __init__(self): def __init__(self):
super().__init__("NHR9430") super().__init__("9430")
self.__ip = ""
#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
...@@ -64,8 +64,6 @@ class NHR9430(NHR9400): ...@@ -64,8 +64,6 @@ class NHR9430(NHR9400):
value = self.__s.send("FETC:CURR:CPHase?\n".encode()) value = self.__s.send("FETC:CURR:CPHase?\n".encode())
return self.receiveFloat(value) return self.receiveFloat(value)
def getIp(self):
return self.__ip
class refineOutput: class refineOutput:
def byteToFloat(self, recv): def byteToFloat(self, recv):
print("recv:",recv)
recv = bytes(recv)
recv = recv.decode("UTF-8") recv = recv.decode("UTF-8")
recv = recv.rstrip("\n\x00") recv = recv.rstrip('\n\x00')
return float(recv) return float(recv)
def byteToString(self, recv): def byteToString(self, recv):
print("fail8")
recv = bytes(recv) recv = bytes(recv)
recv = recv.decode("UTF-8") recv = recv.decode("UTF-8")
recv = recv.rstrip('\n') recv = recv.rstrip('\n\x00')
recv = recv.rstrip('\x00')
print("sucess")
return recv return recv
\ No newline at end of file
...@@ -5,9 +5,10 @@ interface = controlInterface() ...@@ -5,9 +5,10 @@ interface = controlInterface()
interface.__init__() interface.__init__()
print(interface.getListIp()) print(interface.getListIp())
interface.newNhr9410() interface.newNhr("9410")
interface.newNhr9430() interface.newNhr("9430")
#interface.newNhr9430() interface.newNhr("9430")
nhr10 = [] nhr10 = []
nhr30 = [] nhr30 = []
nhr10 = interface.getNhr9410() nhr10 = interface.getNhr9410()
...@@ -17,7 +18,11 @@ print(nhr10) ...@@ -17,7 +18,11 @@ print(nhr10)
print(nhr30) print(nhr30)
for elem in nhr10: for elem in nhr10:
print(elem.getIp()) print("nhr10 ip: ",elem.getIp())
print("voltage:",elem.getVoltage())
elem.close() elem.close()
for elem in nhr30: for elem in nhr30:
print("nhr30 ip: ",elem.getIp())
print("voltage:",elem.getVoltage())
elem.close() elem.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