Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 58 additions & 16 deletions APSERa Codes/ACI Webapp/cryotel_f.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,59 @@
import time
import json

import tkinter as tk
from tkinter import simpledialog

def get_usb_paths():
# Create the main Tkinter window
root = tk.Tk()
root.withdraw() # Hide the root window

# Create a custom dialog for multiple inputs
def submit():
global cryo_usb, lakeshore_usb, power_usb, iia_usb
cryo_usb = cryo_entry.get()
lakeshore_usb = lakeshore_entry.get()
power_usb = power_entry.get()
iia_usb = iia_entry.get()
dialog.destroy() # Close the dialog box

dialog = tk.Toplevel()
dialog.title("Enter USB Paths")

# Labels and entry fields
tk.Label(dialog, text="Cryo USB:").grid(row=0, column=0, padx=10, pady=5, sticky="e")
cryo_entry = tk.Entry(dialog, width=30)
cryo_entry.insert(0, "/dev/ttyUSB1")
cryo_entry.grid(row=0, column=1, padx=10, pady=5)

tk.Label(dialog, text="Lakeshore USB:").grid(row=1, column=0, padx=10, pady=5, sticky="e")
lakeshore_entry = tk.Entry(dialog, width=30)
lakeshore_entry.insert(0, "/dev/ttyUSB2")
lakeshore_entry.grid(row=1, column=1, padx=10, pady=5)

tk.Label(dialog, text="Power USB:").grid(row=2, column=0, padx=10, pady=5, sticky="e")
power_entry = tk.Entry(dialog, width=30)
power_entry.insert(0, "/dev/ttyUSB5")
power_entry.grid(row=2, column=1, padx=10, pady=5)

tk.Label(dialog, text="IIA USB:").grid(row=3, column=0, padx=10, pady=5, sticky="e")
iia_entry = tk.Entry(dialog, width=30)
iia_entry.insert(0, "/dev/ttyUSB3")
iia_entry.grid(row=3, column=1, padx=10, pady=5)

# Submit button
tk.Button(dialog, text="Submit", command=submit).grid(row=4, column=0, columnspan=2, pady=10)

dialog.wait_window() # Wait until the dialog box is closed

return cryo_usb, lakeshore_usb, power_usb, iia_usb

# Get user inputs
cryo_usb, lakeshore_usb, power_usb, iia_usb = get_usb_paths()



app = Flask(__name__)

#===========================================================================================
Expand All @@ -22,7 +75,7 @@
# Functions for serial connection of cryo controller
def initialize_serial_connection():
global ser_connection_fail, ser
port = "/dev/ttyUSB1" # or "COM3" for Windows
port = cryo_usb # or "COM3" for Windows
baudrate = 9600

try:
Expand Down Expand Up @@ -254,7 +307,7 @@ def initialize_serial_lakeshore(port, baudrate):
# Setup serial connection
def setup_serial_lakeshore():
global ser_lakeshore
port = "/dev/ttyUSB2" # Replace this with actual port input
port = lakeshore_usb # Replace this with actual port input
baudrate = 9600 # Replace this with actual baudrate input
ser_lakeshore = initialize_serial_lakeshore(port, baudrate)
return ser_lakeshore
Expand Down Expand Up @@ -336,17 +389,6 @@ def plot_temperatures():
terminator_power = '\r\n'
read_timeout_power = 2

# Power Supply Functions
def initialize_serial_power():
try:
serial_power = serial.Serial(port='/dev/ttyUSB6', baudrate=9600, timeout=read_timeout_power)
status = remote_on_power()

return serial_power

except Exception as e:
print(f"Failed to initialize serial port: {e}")
return None

def read_response_power(serial_port, timeout_period, terminator_power):
start_time = time.time()
Expand Down Expand Up @@ -501,7 +543,7 @@ def get_data_iia():

# Initialize the serial connection
try:
ser_iia = serial.Serial('/dev/ttyUSB3', 9600, timeout=1)
ser_iia = serial.Serial(iia_usb, 9600, timeout=1)
except Exception as e:
print(f"Error opening serial port: {e}")
exit()
Expand All @@ -511,7 +553,7 @@ def get_data_iia():


try:
ser_power = serial.Serial(port='/dev/ttyUSB6', baudrate=9600, timeout=read_timeout_power)
ser_power = serial.Serial(port=power_usb, baudrate=9600, timeout=read_timeout_power)
remote_on_power()
except Exception as e:
print(f"Error opening serial port: {e}")
Expand All @@ -522,4 +564,4 @@ def get_data_iia():
initialize_serial_connection()


app.run(debug=False, host='172.16.101.78', port=5002)
app.run(debug=False, host='172.16.101.78', port=5001)
180 changes: 157 additions & 23 deletions APSERa Codes/ACI Webapp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ <h3>AccZ: <span id="accz">--</span></h3>
<div id="outVoltagePlot" style="width: 100%; height: 400px;"></div>
<div id="outCurrentPlot" style="width: 100%; height: 400px;"></div>
</div>

<div class="plots-container">
<div id="accXPlot" class="plot-container"></div>
<div id="accYPlot" class="plot-container"></div>
<div id="accZPlot" class="plot-container"></div>
</div>


<div class="info-container_lakeshore lakeshore_css">
Expand Down Expand Up @@ -346,10 +352,22 @@ <h2>Lakeshore Monitor</h2>

let outVoltageData = [];
let outCurrentData = [];
let accXData = [];
let accYData = [];
let accZData = [];
let timeData = [];

let accXValues = [];
let accYValues = [];
let accZValues = [];
let timeSeries = [];

let timeCounter = 0; // Initialize a counter for time tracking


// To track the current time in seconds
let currentTime = 0;

function formatTime(seconds) {
const date = new Date(0);
date.setSeconds(seconds);
Expand Down Expand Up @@ -644,12 +662,7 @@ <h2>Lakeshore Monitor</h2>

// Call this function to initialize the dummy plot
function plotDummy() {
const trace = {
x: Array.from({ length: 60 }, (_, i) => i + 1),
y: Array.from({ length: 60 }, () => Math.random() * 100), // Dummy data
mode: 'lines',
name: 'Dummy Data',
};


const layout = {
title: 'Dummy Plot',
Expand Down Expand Up @@ -711,6 +724,8 @@ <h2>Lakeshore Monitor</h2>
Plotly.newPlot('outCurrentPlot', [trace], layout);
}



function setVoltage() {
const voltage = prompt("Enter the voltage value:");
if (voltage !== null) {
Expand Down Expand Up @@ -757,35 +772,154 @@ <h2>Lakeshore Monitor</h2>
}
}

async function fetchData_iia() {
const response = await fetch('/get_data_iia');
const data = await response.json();
document.getElementById('temperature').innerText = data.temperature[data.temperature.length - 1] + ' °C';
document.getElementById('humidity').innerText = data.humidity[data.humidity.length - 1] + ' %';
document.getElementById('accx').innerText = data.accx[data.accx.length - 1];
document.getElementById('accy').innerText = data.accy[data.accy.length - 1];
document.getElementById('accz').innerText = data.accz[data.accz.length - 1];
function initPlots() {

const layout = {
title: '',
xaxis: {
title: 'Time (seconds)',
showticklabels: true,
ticks: 'outside'
},
yaxis: { title: 'Acceleration (m/s²)' },
plot_bgcolor: '#121212',
paper_bgcolor: '#121212',
font: { color: '#ffffff' },
};

Plotly.newPlot('accXPlot', [], layout);
Plotly.newPlot('accYPlot', [], layout);
Plotly.newPlot('accZPlot', [], layout);
}

// Function to fetch real acceleration data from an API or sensor
async function fetchAccelerationData() {
try {
const response = await fetch('/get_data_iia'); // Your actual API endpoint here
const data = await response.json();

// Fetch the latest acceleration values for each axis
const accX = data.accx[data.accx.length - 1];
const accY = data.accy[data.accy.length - 1];
const accZ = data.accz[data.accz.length - 1];

// Increment the time by 1 second
timeCounter++;

// Add the new data points to the arrays
timeSeries.push(timeCounter);
accXValues.push(accX);
accYValues.push(accY);
accZValues.push(accZ);

// Limit data to the last 60 seconds
if (timeSeries.length > 60) {
timeSeries.shift();
accXValues.shift();
accYValues.shift();
accZValues.shift();
}

// Update the plots
plotAccX();
plotAccY();
plotAccZ();

} catch (error) {
console.error('Error fetching acceleration data:', error);
}
}



function plotAccX() {
const trace = {
x: timeSeries,
y: accXValues,
mode: 'lines',
name: 'Acceleration X',
};

setInterval(fetchData_iia, 1000);
const layout = {
title: 'Acceleration X (m/s²)',
xaxis: {
title: 'Time (seconds)',
showticklabels: false, // Hides the tick labels
ticks: '' // Hides the ticks
},
yaxis: { title: 'Acceleration (m/s²)' },
plot_bgcolor: '#121212',
paper_bgcolor: '#121212',
font: { color: '#ffffff' },
};

Plotly.newPlot('accXPlot', [trace], layout);
}

function plotAccY() {
const trace = {
x: timeSeries,
y: accYValues,
mode: 'lines',
name: 'Acceleration Y',
};

const layout = {
title: 'Acceleration Y (m/s²)',
xaxis: {
title: 'Time (seconds)',
showticklabels: false, // Hides the tick labels
ticks: '' // Hides the ticks
},
yaxis: { title: 'Acceleration (m/s²)' },
plot_bgcolor: '#121212',
paper_bgcolor: '#121212',
font: { color: '#ffffff' },
};

Plotly.newPlot('accYPlot', [trace], layout);
}

function plotAccZ() {
const trace = {
x: timeSeries,
y: accZValues,
mode: 'lines',
name: 'Acceleration Z',
};

const layout = {
title: 'Acceleration Z (m/s²)',
xaxis: {
title: 'Time (seconds)',
showticklabels: false, // Hides the tick labels
ticks: '' // Hides the ticks
},
yaxis: { title: 'Acceleration (m/s²)' },
plot_bgcolor: '#121212',
paper_bgcolor: '#121212',
font: { color: '#ffffff' },
};

Plotly.newPlot('accZPlot', [trace], layout);
}

// Initialize plots on page load
initPlots();

// Update the voltage and current values every second
setInterval(updateVoltageCurrent, 1000);

setInterval(updateVoltageCurrent, 2000);
// Other intervals remain the same
setInterval(updateTemperatures, 2000); // Update every 2 seconds
setInterval(updateLakeshoreTemperatures, 1000); // Update every 1 second
initPlot();
setInterval(fetchCurrentTemperature, 8000); // Update temperature every 8 seconds


plotAccX();
plotAccY();
plotAccZ();
// Initial plot setup
plotDummy();
// Update every second
setInterval(updateVoltageCurrent, 1000);
setInterval(updateVoltageCurrent, 2000);
setInterval(fetchAccelerationData, 1000); // Fetch data every 1000ms (1 second)


</script>
</body>
Expand Down