Commit 60e5851e authored by Mateus Goto's avatar Mateus Goto

[To be fixed]

parent 88cea533
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.
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())
def getCurrentArray(self):
self.__s.send("FETC:ARR:CURR?\n".encode())
value = self.__s.recv(1024)
return self.receiveArray(value)
###################### 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
def byteToArray(self, recv):
recv = bytes(recv)
recv = recv.decode("UTF-8")
recv = recv.rstrip('\n\x00')
recv_array = recv.split(',')
return recv_array
\ No newline at end of file
...@@ -2,17 +2,19 @@ import json ...@@ -2,17 +2,19 @@ import json
from random import randint from random import randint
from asyncio import sleep from asyncio import sleep
from channels.generic.websocket import AsyncWebsocketConsumer from channels.generic.websocket import AsyncWebsocketConsumer
from NHR9400series.NHR9400 import NHR9400 from NHR9400series.NHR9410 import NHR9410
from NHR9400series.NHR9430 import NHR9430 from Control_Interface.controlInterface import controlInterface
interface = controlInterface()
interface.newNhr("9410")
nhr10 = []
nhr10 = interface.getNhr9410()
class GraphConsumer(AsyncWebsocketConsumer): class GraphConsumer(AsyncWebsocketConsumer):
async def connect(self): async def connect(self):
await self.accept() await self.accept()
for i in range(1000): for i in range(1000):
await self.send(json.dumps({'value': NHR9400.getVoltageArray()})) await self.send(json.dumps({'value': randint(0,40)}))
await sleep(0.16) await sleep(1)
var dps = Array(130)
const ctx = document.getElementById('myChart').getContext('2d'); var myChart = new CanvasJS.Chart("chartContainer",{
title: {
var graph_data = { text: "Live Data"
type: 'line',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
tension: 0,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
],
borderWidth: 5
}]
}, },
axisY: {
gridThickness: 0
}
const data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'Looping tension',
data: [65, 59, 80, 81, 26, 55, 40],
tension: 0.5,
fill: false,
borderColor: 'rgb(75, 192, 192)',
}]
};
const config = {
type: 'line',
data: graph_data,
bezierCurve: true,
options: {
animations: {
tension: {
duration: 1000,
easing: 'easeInSine',
loop: true
}
}, },
scales: { data: [{
y: { // defining min and max so hiding the dataset does not change scale range type: "spline",
min: 0, dataPoints: dps
max: 100 }]
} });
} myChart.render();
}
};
const myChart = new Chart(ctx, graph_data, config);
var socket = new WebSocket('ws://localhost:8000/ws/graph/') var socket = new WebSocket('ws://localhost:7000/ws/graph/');
var updateInterval = 500;
socket.onmessage = function(e){ socket.onmessage = function(e){
var djangoData = JSON.parse(e.data); var djangoData = JSON.parse(e.data);
console.log(djangoData); console.log(djangoData.value);
var updatedDps = [];
myChart.options.data[0].dataPoints = [];
var newGraphData = graph_data.data.datasets[0].data; for(var i = 0; i < dps.length; i++)
newGraphData.shift(); updatedDps.push(djangoData.value[i]);
newGraphData.push(djangoData.value); console.log(djangoData.value[i]);
graph_data.data.datasets[0].data = newGraphData; myChart.options.data[0].dataPoints = updatedDps;
myChart.update(); myChart.render();
};
} setInterval(function(e){socket.onmessage()}, updateInterval);
\ No newline at end of file \ No newline at end of file
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<div class="row"> <div class="row">
<div class="col-10 mx-auto mt-5"> <div class="col-10 mx-auto mt-5">
<h1 id="app">{{ text }}</h1> <h1 id="app">{{ text }}</h1>
<canvas id="myChart" width="400" height="200"></canvas> <canvas id="chartContainer" width="400" height="200"></canvas>
</div> </div>
......
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