add new window

This commit is contained in:
nazarchuk.as 2022-11-14 21:00:20 +03:00
parent 15339b98e7
commit bf75188f82
7 changed files with 209 additions and 113 deletions

View File

@ -0,0 +1,115 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 14 20:18:17 2022
@author: anna
"""
import os
import csv
import time
from PyQt6.QtWidgets import (QLineEdit,
QPushButton,
QWidget,
QTableWidget,
QGridLayout,
QTableWidgetItem,
QHeaderView,
)
from Abstract_window import AbstractWindow
class GraduationWindow(AbstractWindow):
def __init__(self, parent):
super().__init__()
self.setWindowTitle('Градуировка электромагнита')
self.parent = parent
self.volt = 0
# make csv file
self.parent.flow_dataname = 'Induction_data.csv'
self.heads = ['B,mTl', 'E,mV', 'I_M,mA','t,ms']
with open(os.path.join(self.parent.folder, self.parent.flow_dataname), 'w') as file:
wr = csv.writer(file)
wr.writerow(self.heads)
self.centralwidget = QWidget()
self.resize(1400, 800)
self.setCentralWidget(self.centralwidget)
self.grid_layout = QGridLayout(self.centralwidget)
self.start = QPushButton('Старт')
self.start.clicked.connect(self.start_clicked)
self.start.setEnabled(True)
self.menu = QPushButton('Меню')
self.menu.setEnabled(False)
self.menu.clicked.connect(self.menu_clicked)
self.lineEdit = QLineEdit(placeholderText='Индукция B, мТл')
self.lineEdit.returnPressed.connect(self.enter_value)
self.lineEdit.setReadOnly(True)
self.table = QTableWidget(self) # Create a self.table
self.table.setColumnCount(len(self.heads)) # Set three columns
self.table.setRowCount(0)
self.table.setHorizontalHeaderLabels(self.heads)
header = self.table.horizontalHeader()
for i in range(len(self.heads)):
header.setSectionResizeMode(i, QHeaderView.ResizeMode.Stretch)
self.table.resizeColumnsToContents()
self.grid_layout.addWidget(self.start, 0, 0)
self.grid_layout.addWidget(self.lineEdit, 1, 0)
self.grid_layout.addWidget(self.table, 0, 3, -1, 1)
self.grid_layout.addWidget(self.menu, 2, 0)
def menu_clicked(self):
self.parent.number = 0
self.parent.change_number()
def start_clicked(self):
self.start.setEnabled(False)
self.start_time = round(time.time()*1000)
self.lineEdit.setReadOnly(False)
self.menu.setEnabled(True)
def enter_value(self):
self.lineEdit.setReadOnly(True)
self.no_data()
self.lineEdit.clear()
self.lineEdit.setReadOnly(False)
def no_data(self):
current_time = round(time.time()*1000)
b = self.lineEdit.text()
u = str((current_time-self.start_time)/60)
i = str((current_time-self.start_time)/60/2)
t = str(current_time-self.start_time)
self.save_data([b, u, i, t])
def save_data(self, data):
with open(os.path.join(self.parent.folder, self.parent.flow_dataname), 'a') as file:
wr = csv.writer(file)
wr.writerow(data)
self.table.insertRow(self.table.rowCount())
for i in range(len(data)):
self.table.setItem(self.table.rowCount()-1, i,
QTableWidgetItem(str(data[i])))
def take_data(self):
t = (round(time.time()*1000)-self.start_time)
b = self.lineEdit.text()
msg = 'VOLTage '+str(self.volt)+'\n'
self.parent.ser.write(msg.encode('ascii'))
time.sleep(1)
msg = 'MEASure:Current?\n'
self.parent.ser.write(msg.encode('ascii'))
time.sleep(1)
bytesToRead = self.parent.ser.inWaiting()
I_M = self.parent.ser.read(bytesToRead)
self.volt += 5
self.save_data([b, self.volt, I_M, t])

View File

@ -8,25 +8,27 @@ from PyQt6.QtWidgets import (QApplication,
QLineEdit, QLineEdit,
QPushButton, QPushButton,
QWidget, QWidget,
QTableWidget,
QGridLayout, QGridLayout,
QTableWidgetItem, QTableWidgetItem,
QHeaderView, QHeaderView,
QLabel
) )
from Abstract_window import AbstractWindow from Abstract_window import AbstractWindow
from Main_experiment_window import (MainExperimentDataWindow, from Main_experiment_window import (MainExperimentDataWindow,
MainExperimentChartWindow) MainExperimentChartWindow)
from GraduationWindow import GraduationWindow
class Start: class Start:
def __init__(self): def __init__(self):
self.number = 0 self.number = 0
self.foldername = '' self.foldername = None
if not QApplication.instance(): if not QApplication.instance():
self.app = QApplication(sys.argv) self.app = QApplication(sys.argv)
else: else:
self.app = QApplication.instance() self.app = QApplication.instance()
self.window = StartWindow(self) self.window = StartWindow(self)
# self.add_ser()
self.draw() self.draw()
self.app.exec() self.app.exec()
@ -34,19 +36,32 @@ class Start:
self.window.show() self.window.show()
def change_number(self): def change_number(self):
if self.number == 0:
self.window.close()
self.window = StartWindow(self)
if self.number == 10:
self.window.close()
self.window = GraduationWindow(self)
if self.number == 20: if self.number == 20:
self.window.close() self.window.close()
self.window = MainExperimentDataWindow(self) self.window = MainExperimentDataWindow(self)
if self.number == 21: if self.number == 21:
self.window.close() self.window.close()
self.window = MainExperimentChartWindow(self) self.window = MainExperimentChartWindow(self)
if self.number == 10: if self.number == 30:
self.window.close() self.window.close()
self.window = FlowWindow(self) self.window = SignWindow(self)
if self.number == 0:
self.window.close()
self.window = StartWindow(self)
self.draw() self.draw()
def add_ser(self):
self.ser = serial.Serial(
port='/dev/ttyUSB2',
baudrate=9600,
timeout=1
)
self.ser.isOpen()
msg = 'OUTput on\n'
self.ser.write(msg.encode('ascii'))
class StartWindow(AbstractWindow): class StartWindow(AbstractWindow):
@ -58,20 +73,34 @@ class StartWindow(AbstractWindow):
self.centralwidget = QWidget() self.centralwidget = QWidget()
self.resize(1400, 800) self.resize(1400, 800)
self.setCentralWidget(self.centralwidget) self.setCentralWidget(self.centralwidget)
self.lineEdit = QLineEdit(placeholderText='Введите фамилию') if not self.parent.foldername:
self.lineEdit = QLineEdit(placeholderText='Введите фамилию')
else:
self.lineEdit = QLineEdit(placeholderText=self.parent.foldername)
self.lineEdit.returnPressed.connect(self.enter_name) self.lineEdit.returnPressed.connect(self.enter_name)
self.flow = QPushButton('градуировка электромагнита') self.flow = QPushButton('Градуировка электромагнита')
self.flow.clicked.connect(self.flow_click) self.flow.clicked.connect(self.flow_click)
self.flow.setEnabled(False) if not self.parent.foldername:
self.main = QPushButton('основной эксперимент') self.flow.setEnabled(False)
self.sign = QPushButton('Знак носителей')
self.sign.clicked.connect(self.sign_click)
if not self.parent.foldername:
self.sign.setEnabled(False)
self.main = QPushButton('Основной эксперимент')
self.main.clicked.connect(self.main_click) self.main.clicked.connect(self.main_click)
self.main.setEnabled(False) if not self.parent.foldername:
self.main.setEnabled(False)
if self.parent.foldername:
self.lineEdit.setReadOnly(True)
self.hbox_layout = QGridLayout(self.centralwidget) self.hbox_layout = QGridLayout(self.centralwidget)
self.hbox_layout.setRowStretch(1, 1) self.hbox_layout.setRowStretch(1, 1)
self.hbox_layout.addWidget(self.lineEdit, 1, 0, 1, 2) self.hbox_layout.addWidget(self.lineEdit, 1, 0, 1, 2)
self.hbox_layout.addWidget(self.flow, 2, 0) self.hbox_layout.addWidget(self.flow, 2, 0)
self.hbox_layout.addWidget(self.sign, 3, 0)
self.hbox_layout.addWidget(self.main, 2, 1) self.hbox_layout.addWidget(self.main, 2, 1)
def flow_click(self): def flow_click(self):
@ -81,6 +110,10 @@ class StartWindow(AbstractWindow):
def main_click(self): def main_click(self):
self.parent.number = 20 self.parent.number = 20
self.parent.change_number() self.parent.change_number()
def sign_click(self):
self.parent.number = 30
self.parent.change_number()
def enter_name(self): def enter_name(self):
# make folder # make folder
@ -91,97 +124,71 @@ class StartWindow(AbstractWindow):
self.flow.setEnabled(True) self.flow.setEnabled(True)
self.main.setEnabled(True) self.main.setEnabled(True)
self.sign.setEnabled(True)
self.lineEdit.setReadOnly(True) self.lineEdit.setReadOnly(True)
class SignWindow(AbstractWindow):
class FlowWindow(AbstractWindow):
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
self.setWindowTitle('Градуировка электромагнита') self.setWindowTitle('Определение знака носителей')
self.parent = parent self.parent = parent
self.start = QPushButton('Старт')
self.start.clicked.connect(self.start_clicked)
self.start.setEnabled(True)
self.menu = QPushButton('Меню')
self.menu.setEnabled(False)
self.menu.clicked.connect(self.menu_clicked)
# make csv file self.with_field = QLabel('С полем: ', self)
self.parent.flow_dataname = 'Induction_data.csv' self.without_field = QLabel('С полем: ', self)
head_1 = 'B,mTl' self.with_field_value = QLabel(self)
head_2 = 'U,mV' self.without_field_value = QLabel(self)
head_3 = 't,ms'
with open(os.path.join(self.parent.folder, self.parent.flow_dataname), 'w') as file:
wr = csv.writer(file)
wr.writerow([head_1, head_2, head_3])
self.centralwidget = QWidget() self.centralwidget = QWidget()
self.resize(1400, 800) self.resize(1400, 800)
self.setCentralWidget(self.centralwidget) self.setCentralWidget(self.centralwidget)
self.grid_layout = QGridLayout(self.centralwidget) self.grid_layout = QGridLayout(self.centralwidget)
self.start = QPushButton('Старт')
self.start.clicked.connect(self.start_clicked)
self.start.setEnabled(True)
self.next = QPushButton(self) self.grid_layout.addWidget(self.start, 0, 0, 1, -1)
self.next.setIcon(QIcon('arrow.png')) self.grid_layout.addWidget(self.with_field, 1, 0)
self.next.setEnabled(False) self.grid_layout.addWidget(self.with_field_value, 1, 1)
self.next.clicked.connect(self.next_clicked) self.grid_layout.addWidget(self.without_field, 2, 0)
self.grid_layout.addWidget(self.without_field_value, 2, 1)
self.lineEdit = QLineEdit(placeholderText='Индукция B, мТл') self.grid_layout.addWidget(self.menu, 3, 0, 1, -1)
self.lineEdit.returnPressed.connect(self.enter_value)
self.lineEdit.setReadOnly(True)
self.table = QTableWidget(self) # Create a self.table
self.table.setColumnCount(3) # Set three columns
self.table.setRowCount(0)
self.table.setHorizontalHeaderLabels([head_1, head_2, head_3])
header = self.table.horizontalHeader()
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
self.table.setItem(0, 0, QTableWidgetItem("Text in column 1"))
self.table.setItem(0, 1, QTableWidgetItem("Text in column 2"))
self.table.setItem(0, 2, QTableWidgetItem("Text in column 3"))
self.table.resizeColumnsToContents()
self.grid_layout.addWidget(self.start, 0, 0) def menu_clicked(self):
self.grid_layout.addWidget(self.lineEdit, 1, 0) self.parent.number = 0
self.grid_layout.addWidget(self.table, 1, 3)
self.grid_layout.addWidget(self.next, 2, 0)
def next_clicked(self):
self.parent.number = 20
self.parent.change_number() self.parent.change_number()
def start_clicked(self): def start_clicked(self):
self.start.setEnabled(False) self.start.setEnabled(False)
self.start_time = round(time.time()*1000) with_field=10
self.lineEdit.setReadOnly(False) without_field=15
self.next.setEnabled(True) # without_field, with_field = self.get_values()
self.with_field_value.setText(str(with_field)+', mV')
def enter_value(self): self.without_field_value.setText(str(without_field)+', mV')
self.lineEdit.setReadOnly(True) self.menu.setEnabled(True)
self.get_data()
self.lineEdit.clear()
self.lineEdit.setReadOnly(False)
def get_data(self):
def measure(self, volt):
msg = 'VOLTage '+str(volt)+'\n'
# bytesToRead=ser.inWaiting() self.parent.ser.write(msg.encode('ascii'))
# data=ser.read(bytesToRead) time.sleep(1)
# print(data) volt_name = os.path.join('/dev', 'usbtmc0')
f_volt = open(volt_name, 'w')
current_time = round(time.time()*1000) f_volt.write('Measure:Voltage:DC?\n')
b = self.lineEdit.text() f_volt.close()
u = str((current_time-self.start_time)/60) f_volt = open(volt_name, 'r')
t = str(current_time-self.start_time) v = '{:.9f}'.format(float(f_volt.read(15))*10**3)
with open(os.path.join(self.parent.folder, self.parent.flow_dataname), 'a') as file: f_volt.close()
wr = csv.writer(file) return v
wr.writerow([b, u, str(t)])
self.table.insertRow(self.table.rowCount()) def get_values(self):
self.table.setItem(self.table.rowCount()-1, 0, QTableWidgetItem(b)) without_field = self.measure(0)
self.table.setItem(self.table.rowCount()-1, 1, QTableWidgetItem(u)) with_field = self.measure(10)
self.table.setItem(self.table.rowCount()-1, 2, QTableWidgetItem(t)) return without_field, with_field
@ -213,4 +220,3 @@ start = Start()
# bytesToRead=ser.inWaiting() # bytesToRead=ser.inWaiting()
# data=ser.read(bytesToRead) # data=ser.read(bytesToRead)
# print(data) # print(data)

View File

@ -46,7 +46,6 @@ class MainExperimentDataWindow(AbstractWindow):
self.setWindowTitle('Основной эксперимент. Получение данных') self.setWindowTitle('Основной эксперимент. Получение данных')
self.parent = parent self.parent = parent
# self.add_ser()
self.data_thread = ThreadData(self) self.data_thread = ThreadData(self)
self.resize(1400, 800) self.resize(1400, 800)
self.number_iteration = 1 self.number_iteration = 1
@ -101,16 +100,6 @@ class MainExperimentDataWindow(AbstractWindow):
self.grid_layout.addWidget(self.new, 2, 2, 1, -1) self.grid_layout.addWidget(self.new, 2, 2, 1, -1)
self.grid_layout.addWidget(self.chart, 3, 2, 1, -1) self.grid_layout.addWidget(self.chart, 3, 2, 1, -1)
def add_ser(self):
self.parent.ser = serial.Serial(
port='/dev/ttyUSB2',
baudrate=9600,
timeout=1
)
self.parent.ser.isOpen()
msg = 'OUTput on\n'
self.parent.ser.write(msg.encode('ascii'))
def enter_a(self): def enter_a(self):
# TODO # TODO
self.parent.a = self.lineEdit.text() self.parent.a = self.lineEdit.text()

Binary file not shown.

View File

@ -1,11 +1 @@
"B,mTl","U,mV","t,ms" "B,mTl","E,mV","I_M,mA","t,ms"
80,45.18333333333333,2711
90,70.75,4245
90,85.66666666666667,5140
90,99.33333333333333,5960
90,111.96666666666667,6718
90,124.51666666666667,7471
90,136.53333333333333,8192
90,148.96666666666667,8938
90,164.7,9882
90,177.73333333333332,10664

1 B,mTl U,mV E,mV I_M,mA t,ms
80 45.18333333333333 2711
90 70.75 4245
90 85.66666666666667 5140
90 99.33333333333333 5960
90 111.96666666666667 6718
90 124.51666666666667 7471
90 136.53333333333333 8192
90 148.96666666666667 8938
90 164.7 9882
90 177.73333333333332 10664

View File

@ -1,5 +1 @@
"U_34,mV","I_M,mA","U_0,mV","I_0,mA","E, mV",N,"t,ms" "U_34,mV","I_M,mA","U_0,mV","I_0,mA","E, mV",N,"t,ms"
0.016666666666666666,0.016666666666666666,0.016666666666666666,0.00016666666666666666,0,1,1
16.7,16.7,0.016666666666666666,0.16699999999999998,5.0,1,1002
33.38333333333333,33.38333333333333,0.016666666666666666,0.3338333333333333,10.0,1,2003
50.06666666666667,50.06666666666667,0.016666666666666666,0.5006666666666667,15.0,1,3004

1 U_34,mV I_M,mA U_0,mV I_0,mA E, mV N t,ms
0.016666666666666666 0.016666666666666666 0.016666666666666666 0.00016666666666666666 0 1 1
16.7 16.7 0.016666666666666666 0.16699999999999998 5.0 1 1002
33.38333333333333 33.38333333333333 0.016666666666666666 0.3338333333333333 10.0 1 2003
50.06666666666667 50.06666666666667 0.016666666666666666 0.5006666666666667 15.0 1 3004