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