Commit 3cdabf21 authored by Mateus Goto's avatar Mateus Goto

[Tested] Connections

parent 29ab8c8e
import sys
sys.path.insert(0, "..")
from NHR9400series.NHR9410 import NHR9410 from NHR9400series.NHR9410 import NHR9410
from NHR9400series.NHR9430 import NHR9430 from NHR9400series.NHR9430 import NHR9430
from Utility.IPFinder import IPFinder from UtilitiesRei.IPFinder import IPFinder
class controlInterface: class controlInterface:
...@@ -26,13 +24,13 @@ class controlInterface: ...@@ -26,13 +24,13 @@ class controlInterface:
new.locateIp(self.__listIp) new.locateIp(self.__listIp)
usedIp = new.getIp() usedIp = new.getIp()
print(type(usedIp))
try: try:
self.__listIp.remove(usedIp) self.__listIp.remove(usedIp)
self.__listUsedIp.append(usedIp) self.__listUsedIp.append(usedIp)
self.__nhr9430.append(new) self.__nhr9410.append(new)
print("herer")
except: except:
print("Any IP adress matched") print("Any IP address matched")
#create a NHR9430 object #create a NHR9430 object
def newNhr9430(self): def newNhr9430(self):
......
from abc import abstractmethod from abc import abstractmethod
import socket import socket
from Utility.RefineOutput import RefineOutput from UtilitiesRei.refineOutput import refineOutput
class NHR9400: class NHR9400:
...@@ -9,7 +9,7 @@ class NHR9400: ...@@ -9,7 +9,7 @@ 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.__out = RefineOutput self.__out = refineOutput()
self.__ip = "" self.__ip = ""
################################# Configurations ###################################################### ################################# Configurations ######################################################
...@@ -73,15 +73,20 @@ class NHR9400: ...@@ -73,15 +73,20 @@ class NHR9400:
self.__s.send("INST:NAME " + str(num) + "\n") self.__s.send("INST:NAME " + str(num) + "\n")
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): def receiveString(self,recv):
msg = self.__s.recv(1024) print("fail6")
msg = self.__out.byteToString(msg) print("fail8")
return msg recv = bytes(recv)
recv = recv.decode("UTF-8")
recv = recv.rstrip('\n')
recv = recv.rstrip('\x00')
print("sucess")
return recv
#Function that receives messages back and transform it in a float #Function that receives messages back and transform it in a float
def receiveFloat(self): def receiveFloat(self):
msg = self.__s.recv(1024) msg = self.__s.recv(1024)
msg = self.__out.byteToFloat(msg) msg = self.byteToFloat(msg)
return msg return msg
def identify(self): def identify(self):
...@@ -92,6 +97,12 @@ class NHR9400: ...@@ -92,6 +97,12 @@ class NHR9400:
self.__s.send("SYST:ERR?\n") self.__s.send("SYST:ERR?\n")
self.__s.timeout(5) self.__s.timeout(5)
return self.receive() return self.receive()
def close(self):
print(self.__ip)
self.__s.connect((self.__ip,5025))
self.__s.send("SYST:LOC\n".encode())
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)
# 0 OFF - Instrumento desabilitado # 0 OFF - Instrumento desabilitado
# 1 ON - Instrumento habilitado # 1 ON - Instrumento habilitado
......
from NHR9400series.NHR9400 import NHR9400 from NHR9400series.NHR9400 import NHR9400
import socket
class NHR9410(NHR9400): class NHR9410(NHR9400):
def __init__(self): def __init__(self):
super().__init__("NHR9410") super().__init__("NHR9410")
self.__ip = 0
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.settimeout(1)
self.__s.connect((client, 5025)) self.__s.connect((client, 5025))
self.__s.send("SYST:RWL\n") #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") self.__s.send("*IDN?\n".encode())
recv = super().receiveString() msg = self.__s.recv(1024)
recv = self.receiveString(msg)
if recv.find("NH Research,9410-") != -1: #if find this subtring if recv.find("NH Research,9410-") != -1: #if find this subtring
print("o cliente encontrado: " + client)
self.__ip = client self.__ip = client
print(self.__ip)
print("Connection successfully") print("Connection successfully")
return self.__ip return self.__ip
else: else:
...@@ -23,6 +29,9 @@ class NHR9410(NHR9400): ...@@ -23,6 +29,9 @@ class NHR9410(NHR9400):
except: except:
print("Connection failed 2") print("Connection failed 2")
def getIp(self):
return self.__ip
from NHR9400series.NHR9400 import NHR9400 from NHR9400series.NHR9400 import NHR9400
import socket
class NHR9430(NHR9400): class NHR9430(NHR9400):
def __init__(self): def __init__(self):
super().__init__("NHR9410") super().__init__("NHR9430")
self.__ip = 0
#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
...@@ -66,12 +68,17 @@ class NHR9430(NHR9400): ...@@ -66,12 +68,17 @@ class NHR9430(NHR9400):
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.settimeout(1)
self.__s.connect((client, 5025)) self.__s.connect((client, 5025))
self.__s.send("SYST:RWL\n") #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") self.__s.send("*IDN?\n".encode())
recv = super().receiveString() msg = self.__s.recv(1024)
recv = self.receiveString(msg)
if recv.find("NH Research,9430-") != -1: #if find this subtring if recv.find("NH Research,9430-") != -1: #if find this subtring
print("o cliente encontrado: " + client)
self.__ip = client self.__ip = client
print(self.__ip)
print("Connection successfully") print("Connection successfully")
return self.__ip return self.__ip
else: else:
...@@ -79,8 +86,9 @@ class NHR9430(NHR9400): ...@@ -79,8 +86,9 @@ class NHR9430(NHR9400):
self.__s.close() self.__s.close()
except: except:
print("Connection failed 2") print("Connection failed 2")
pass
def getIp(self):
return self.__ip
...@@ -20,7 +20,7 @@ class IPFinder: ...@@ -20,7 +20,7 @@ class IPFinder:
ether = Ether(dst="ff:ff:ff:ff:ff:ff") ether = Ether(dst="ff:ff:ff:ff:ff:ff")
packet = ether/arp packet = ether/arp
result = srp(packet, timeout=3,retry = 1, verbose = 0)[0] result = srp(packet, timeout=1,retry = 1, verbose = 0)[0]
clients = [] clients = []
for sent, received in result: for sent, received in result:
clients.append(received.psrc) clients.append(received.psrc)
......
class RefineOutput: class refineOutput:
def byteToFloat(recv): def byteToFloat(recv):
recv = recv.decode("UTF-8") recv = recv.decode("UTF-8")
...@@ -6,5 +6,10 @@ class RefineOutput: ...@@ -6,5 +6,10 @@ class RefineOutput:
return float(recv) return float(recv)
def byteToString(recv): def byteToString(recv):
print("fail8")
recv = bytes(recv)
recv = recv.decode("UTF-8") recv = recv.decode("UTF-8")
return str(recv) recv = recv.rstrip('\n')
\ No newline at end of file recv = recv.rstrip('\x00')
print("sucess")
return recv
\ No newline at end of file
from Control_Interface.controlInterface import controlInterface from Control_Interface.controlInterface import controlInterface
from Utility.IPFinder import IPFinder
interface = controlInterface() interface = controlInterface()
interface.__init__() interface.__init__()
print(interface.getListIp())
interface.newNhr9410() interface.newNhr9410()
interface.newNhr9430() interface.newNhr9430()
#interface.newNhr9430() #interface.newNhr9430()
...@@ -13,3 +15,9 @@ nhr30 = interface.getNhr9430() ...@@ -13,3 +15,9 @@ nhr30 = interface.getNhr9430()
print(nhr10) print(nhr10)
print(nhr30) print(nhr30)
for elem in nhr10:
print(elem.getIp())
elem.close()
for elem in nhr30:
elem.close()
\ No newline at end of file
(packet, timeout=3,retry = 1, verbose = 0)[0]
\ No newline at end of file
...@@ -10,7 +10,7 @@ def getAllIp(): ...@@ -10,7 +10,7 @@ def getAllIp():
s.connect(("10.255.255.255",1)) s.connect(("10.255.255.255",1))
local_ip = s.getsockname()[0] local_ip = s.getsockname()[0]
print(local_ip) print(local_ip)
local_ip = local_ip[:-2] + "1/24" local_ip = local_ip[:-3] + "1/24"
print(local_ip) print(local_ip)
print(type(local_ip)) print(type(local_ip))
arp = ARP(pdst=local_ip) arp = ARP(pdst=local_ip)
......
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