Commit bcbb0eeb authored by goto01's avatar goto01
parents e3f79f79 f3c8295f
from NHR9400series.NHR9410 import NHR9410
from NHR9400series.NHR9430 import NHR9430
from UtilitiesRei.IPFinder import IPFinder
class controlInterface:
def __init__(self):
self.__listIp = IPFinder().getList()
self.__listUsedIp = []
self.__nhr9410 = []
self.__nhr9430 = []
#refresh the list of ip
def refresh(self):
self.__listIp = IPFinder().getList()
for ip in self.__listUsedIp:
self.__listIp.remove(ip)
#create a NHR object
def newNhr(self, nhr):
if(nhr == "9410"):
new = NHR9410()
elif nhr == "9430":
new = NHR9430()
else:
return -1
new.locateIp(self.__listIp)
new.setS()
usedIp = new.getIp()
try:
self.__listIp.remove(usedIp)
self.__listUsedIp.append(usedIp)
if nhr == "9410":
self.__nhr9410.append(new)
elif nhr == "9430":
self.__nhr9430.append(new)
else:
return -1
except:
print("Any IP address matched")
def getNhr9410(self):
return self.__nhr9410
def getNhr9430(self):
return self.__nhr9430
def getListIp(self):
return self.__listIp
usedIp = new.getIp()
\ No newline at end of file
This diff is collapsed.
Main.jpg

154 KB

This diff is collapsed.
from NHR9400series.NHR9400 import NHR9400
class NHR9410(NHR9400):
def __init__(self):
super().__init__("9410")
def setS(self):
self.__s = self.getS()
from NHR9400series.NHR9400 import NHR9400
class NHR9430(NHR9400):
def __init__(self):
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 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)
# 1 = CR = Constant Resistance (with optional CC limit)
# 2 = RL = Constant series Resistance & Inductance
def instrumentLoad(self, value):
if value < 0 or value > 2:
print("INVALID INPUT")
else:
if value == 0:
self.__s.send("CONF:INST:LOAD:NORM".encode())
if value == 1:
self.__s.send("CONF:INST:LOAD:CR".encode())
if value == 2:
self.__s.send("CONF:INST:LOAD:RL".encode())
self.checkErrors()
#Command enables bi-directional power flow for the 9420 (DC outputs) and 9430 (AC outputs) Query returns if Bi-directional power flow is permitted.
#0 | NO | FALSE | OFF = Bi directional mode is disabled
#1 | YES | TRUE | ON = Bi directional mode is enabled
def instrumentBidirec(self, value):
if value == 0 or value == 1:
self.__s.send(("CONF:INST:BID"+ str(value) + "\n").encode())
else:
print("INVALID INPUT")
self.checkErrors()
#Command sets the standby detection conditions.
#Query returns the configured standby detection conditions for the selected instrument
def instrumentStndy(self):
self.__s.send("CONF: INST:STBY".encode())
self.checkErrors()
#set the current of all phases ** Available only to NHR9430-12
def setCurrent(self, current):
if current < 0:
return -1
self.__s.send(("SOUR:CURR " + str(current) + "\n").encode())
#Functions that sets the limite currents on one phase (A, B or C)
def setCurrentA(self, current):
if current < 0:
return -1
self.__s.send(("SOUR:CURR:APHase " + str(current) + "\n").encode())
def setCurrentB(self, current):
if current < 0:
return -1
self.__s.send(("SOUR:CURR:BPHase " + str(current) + "\n").encode())
def setCurrentC(self, current):
if current < 0:
return -1
self.__s.send(("SOUR:CURR:CPHase " + str(current) + "\n").encode())
###################### Instrument Capabilities #################
#Query returns the minimum and maximum allowable set value for crest factor in NORMal loading mode Refer to CONFigure:LOAD:MODE for information about setting the 9430 in NORmal loading mode.
def instrumentCapCurrentCF(self):
range = []
self.__s.send(("INST:CAP:CURR:CF:MIN?\r\n").encode())
value = self.__s.recv(1024)
range.append(self.receiveFloat(value))
self.__s.send(("INST:CAP:CURR:CF:MAX?\n").encode())
value = self.__s.recv(1024)
range.append(self.receiveFloat(value))
return range
#Query returns the minimum and maximum resistance that can be set in RL loading mode. Refer to CONFigure:LOAD:MODE for information about setting the 9430 in RL loading mode.
def instrumentCapResistenceRL(self):
range = []
self.__s.send(("INST:CAP:RL:RES:MIN?\r\n").encode())
value = self.__s.recv(1024)
range.append(self.receiveFloat(value))
self.__s.send(("INST:CAP:RL:RES:MAX?\n").encode())
value = self.__s.recv(1024)
range.append(self.receiveFloat(value))
return range
#Query returns the minimum and maximum inductance that can be set in RL loading mode.
def instrumentCapInductanceRL(self):
range = []
self.__s.send(("INST:CAP:RL:IND:MIN?\r\n").encode())
value = self.__s.recv(1024)
range.append(self.receiveFloat(value))
self.__s.send(("INST:CAP:RL:IND:MAX?\n").encode())
value = self.__s.recv(1024)
range.append(self.receiveFloat(value))
return range
import socket
from scapy.all import ARP, Ether, srp
class IPFinder:
#uses socket and scapy to scan the entire local network and returns all the IPs adresses of the devices connects in this networok
def __getAllIp(self):
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.connect(("10.255.255.255",1))
local_ip = s.getsockname()[0]
splited = local_ip.split('.')
splited = local_ip.split('.')
splited.pop()
splited.append("1/24")
local_ip = ".".join(splited)
arp = ARP(pdst=local_ip)
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
packet = ether/arp
result = srp(packet, timeout=1,retry = 1, verbose = 0)[0]
clients = []
for sent, received in result:
clients.append(received.psrc)
self.__clients = clients
def deteleIp(self, ip):
self.__clients.remove(ip)
def getList(self):
self.__getAllIp()
return self.__clients
\ No newline at end of file
class refineOutput:
def byteToFloat(self, recv):
recv = bytes(recv)
recv = recv.decode("UTF-8")
recv = recv.rstrip('\n\x00')
return float(recv)
def byteToString(self, recv):
recv = bytes(recv)
recv = recv.decode("UTF-8")
recv = recv.rstrip('\n\x00')
return recv
\ No newline at end of file
import socket
import time
from Control_Interface.controlInterface import controlInterface
def main():
interface = controlInterface()
interface.__init__()
print(interface.getListIp())
interface.newNhr("9410")
#interface.newNhr("9430")
#interface.newNhr("9430")
nhr10 = []
nhr30 = []
nhr10 = interface.getNhr9410()
nhr30 = interface.getNhr9430()
for elem in nhr10:
print("nhr10 watch dog interval: ", elem.systWatchdogInterval(0))
print("nhr10 ip: ",elem.getIp())
print("nhr10 max current: ", elem.instrumentCapCurrent())
print("nhr10 current range: ", elem.instrumentCapCurrentRange())
print("nhr10 freq range: ", elem.instrumentCapFreqRange())
print("nhr10 power range: ", elem.instrumentCapPowerMax())
print("nhr10 voltage range: ", elem.instrumentCapVoltageMaxMin())
for elem in nhr30:
print("nhr30 ip: ",elem.getIp())
print("nhr10 watch dog interval: ", elem.systWatchdogInterval(5))
print("nhr30 max current: ", elem.instrumentCapCurrent())
print("nhr30 current range: ", elem.instrumentCapCurrentRange())
print("nhr30 freq range: ", elem.instrumentCapFreqRange())
print("nhr30 power range: ", elem.instrumentCapPowerMax())
print("nhr30 voltage range: ", elem.instrumentCapVoltageMaxMin())
print("nhr30 range: ", elem.instrumentCapResistenceRL())
time.sleep(3)
for elem in nhr10:
elem.close()
for elem in nhr30:
elem.close()
if __name__ == '__main__':
main()
import mug
class can(mug.mug):
def __init__(self, name):
super().__init__(name)
self.__id = 0
def setId(self, id):
self.__id = id
def getId(self):
return self.__id
def getS(self):
return self.__s
\ No newline at end of file
class dec():
def rewrite(self, recv):
recv = recv + "blablabla"
return recv
\ No newline at end of file
#files to test any problems that was find in the project
#02/08/22: solving the problems with heritage
import can
import mug
can = can.can("caneca")
mug = mug.mug("mug")
can.setId(132)
print(can.getId())
print(can.decode("isso aqui é "))
print("can s: ", can.getS()) #this should be working on the project was well
print(mug.getS())
\ No newline at end of file
import socket
import dec
class mug():
def __init__(self,name):
self.__name: name
self.__s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.__s.settimeout(1)
def decode(self, recv):
recv = dec.dec().rewrite(recv)
return recv
\ No newline at end of file
#Arquivo para teste em geral
import socket
from scapy.all import ARP, Ether, srp, arping
import socket
import time
start = time.time()
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(1)
s.connect(("192.168.0.2",5025))
s.send("SYST:RWL\n".encode()) #Command to activate remote control and locking the touchscreen
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
read = str("192.168.150.5")
splited = read.split('.')
print(splited)
splited.pop()
print(splited)
splited.append("1/24")
read = ".".join(splited)
print(read)
print("INSTrument:NSELect "+ str(2) + "\n")
\ 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