small changes

This commit is contained in:
anna 2022-10-31 18:29:30 +03:00
parent 23ea76a395
commit bdbaae9730

172
Main.py
View File

@ -27,9 +27,8 @@ from PyQt6.QtWidgets import (QHBoxLayout,
QGridLayout, QGridLayout,
QMenu, QMenu,
QTableWidgetItem, QTableWidgetItem,
)
)
class AbstractWindow(QMainWindow): class AbstractWindow(QMainWindow):
@ -37,7 +36,7 @@ class AbstractWindow(QMainWindow):
super().__init__() super().__init__()
self.create_actions() self.create_actions()
self.create_menuBar() self.create_menuBar()
def create_menuBar(self): def create_menuBar(self):
menuBar = self.menuBar() menuBar = self.menuBar()
self.fileMenu = QMenu("&Файл", self) self.fileMenu = QMenu("&Файл", self)
@ -47,7 +46,7 @@ class AbstractWindow(QMainWindow):
self.fileMenu.addAction(self.exitAction) self.fileMenu.addAction(self.exitAction)
self.helpMenu.addAction(self.helpContentAction) self.helpMenu.addAction(self.helpContentAction)
self.helpMenu.addAction(self.aboutAction) self.helpMenu.addAction(self.aboutAction)
def create_actions(self): def create_actions(self):
self.exitAction = QAction("&Выход", self) self.exitAction = QAction("&Выход", self)
self.exitAction.triggered.connect(self.exit_click) self.exitAction.triggered.connect(self.exit_click)
@ -58,22 +57,20 @@ class AbstractWindow(QMainWindow):
def exit_click(self): def exit_click(self):
self.close() self.close()
def help_click(self): def help_click(self):
print('Help') print('Help')
# TODO # TODO
def about_click(self): def about_click(self):
print('About') print('About')
# TODO # TODO
class Start: class Start:
def __init__(self): def __init__(self):
self.number = 0 self.number = 0
self.filename = '' self.foldername = ''
if not QApplication.instance(): if not QApplication.instance():
self.app = QApplication(sys.argv) self.app = QApplication(sys.argv)
else: else:
@ -81,26 +78,26 @@ class Start:
self.window = StartWindow(self) self.window = StartWindow(self)
self.draw() self.draw()
self.app.exec() self.app.exec()
def __del__(self): def __del__(self):
print('destruct') print('destruct')
def draw(self): def draw(self):
self.window.show() self.window.show()
def change_number(self): def change_number(self):
if self.number==2: if self.number == 2:
self.window.close() self.window.close()
self.window = MainExperiment1Window(self) self.window = MainExperiment1Window(self)
if self.number == 1: if self.number == 1:
pass pass
self.draw() self.draw()
class StartWindow(AbstractWindow): class StartWindow(AbstractWindow):
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
self.setWindowTitle('Эффект Холла в полупроводниках') self.setWindowTitle('Эффект Холла в полупроводниках')
self.parent = parent self.parent = parent
self.centralwidget = QWidget() self.centralwidget = QWidget()
@ -108,91 +105,101 @@ class StartWindow(AbstractWindow):
self.setCentralWidget(self.centralwidget) self.setCentralWidget(self.centralwidget)
self.lineEdit = QLineEdit(placeholderText='Введите фамилию') self.lineEdit = QLineEdit(placeholderText='Введите фамилию')
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) self.flow.setEnabled(False)
self.main = QPushButton('основной эксперимент') self.main = QPushButton('основной эксперимент')
self.main.clicked.connect(self.main_click) self.main.clicked.connect(self.main_click)
self.main.setEnabled(False) self.main.setEnabled(False)
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.main, 2, 1) self.hbox_layout.addWidget(self.main, 2, 1)
def flow_click(self): def flow_click(self):
self.parent.number=1 self.parent.number = 1
self.parent.change_number() self.parent.change_number()
def main_click(self): def main_click(self):
self.parent.number=2 self.parent.number = 2
self.parent.change_number() self.parent.change_number()
def enter_name(self): def enter_name(self):
self.parent.filename = self.lineEdit.text() self.parent.foldername = self.lineEdit.text()
self.flow.setEnabled(True) self.flow.setEnabled(True)
self.main.setEnabled(True) self.main.setEnabled(True)
self.lineEdit.setReadOnly(True) self.lineEdit.setReadOnly(True)
class MainExperiment1Window(AbstractWindow): class MainExperiment1Window(AbstractWindow):
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
self.setWindowTitle('Основной эксперимент') self.setWindowTitle('Основной эксперимент')
self.start_time = 0
self.parent = parent self.parent = parent
# make masthead
self.dataname = 'data.txt'
file = open(os(self.parent.foldername, self.dataname), 'w')
file.write('I_0, mA U_34, mV t, s')
file.close()
self.centralwidget = QWidget() self.centralwidget = QWidget()
self.resize(1400, 800) self.resize(1400, 800)
self.setCentralWidget(self.centralwidget) self.setCentralWidget(self.centralwidget)
self.but = QPushButton('Измерение') self.but = QPushButton('Измерение')
self.but.clicked.connect(self.but_click) # self.but.clicked.connect(self.but_click)
self.setCentralWidget(self.but) self.setCentralWidget(self.but)
grid_layout = QGridLayout(self) # Create QGridLayout
# grid_layout = QGridLayout(self) # Create QGridLayout self.centralwidget.setLayout(grid_layout) # Set this layout in central widget
# self.centralwidget.setLayout(grid_layout) # Set this layout in central widget
table = QTableWidget(self) # Create a table
# table = QTableWidget(self) # Create a table table.setColumnCount(3) #Set three columns
# table.setColumnCount(3) #Set three columns table.setRowCount(1) # and one row
# table.setRowCount(1) # and one row
# Set the table headers
# # Set the table headers table.setHorizontalHeaderLabels(["Header 1", "Header 2", "Header 3"])
# table.setHorizontalHeaderLabels(["Header 1", "Header 2", "Header 3"])
#Set the tooltips to headings
# #Set the tooltips to headings table.horizontalHeaderItem(0).setToolTip("Column 1 ")
# table.horizontalHeaderItem(0).setToolTip("Column 1 ") table.horizontalHeaderItem(1).setToolTip("Column 2 ")
# table.horizontalHeaderItem(1).setToolTip("Column 2 ") table.horizontalHeaderItem(2).setToolTip("Column 3 ")
# table.horizontalHeaderItem(2).setToolTip("Column 3 ") table.setItem(0, 0, QTableWidgetItem("Text in column 1"))
# table.setItem(0, 0, QTableWidgetItem("Text in column 1")) table.setItem(0, 1, QTableWidgetItem("Text in column 2"))
# table.setItem(0, 1, QTableWidgetItem("Text in column 2")) table.setItem(0, 2, QTableWidgetItem("Text in column 3"))
# table.setItem(0, 2, QTableWidgetItem("Text in column 3"))
# Do the resize of the columns by content
# # Do the resize of the columns by content table.resizeColumnsToContents()
# table.resizeColumnsToContents()
grid_layout.addWidget(table, 0, 0) # Adding the table to the grid
# grid_layout.addWidget(table, 0, 0) # Adding the table to the grid grid_layout.addWidget(self.but, 0, 3)
def but_click(self): def but_click(self):
# measure voltage and current
volt_name = os.path.join('/dev', 'usbtmc1') volt_name = os.path.join('/dev', 'usbtmc1')
f_volt = open (volt_name, 'w') f_volt = open(volt_name, 'w')
f_volt.write('Measure:Voltage:DC?\n') f_volt.write('Measure:Voltage:DC?\n')
f_volt.close() f_volt.close()
amp_name = os.path.join('/dev', 'usbtmc2') amp_name = os.path.join('/dev', 'usbtmc2')
f_amp = open (amp_name, 'w') f_amp = open(amp_name, 'w')
f_amp.write('Measure:Current:DC?\n') f_amp.write('Measure:Current:DC?\n')
f_amp.close() f_amp.close()
f_volt = open (volt_name, 'r') f_volt = open(volt_name, 'r')
v = f_volt.read(15) v = f_volt.read(15)
f_amp = open (amp_name, 'r') f_amp = open(amp_name, 'r')
a = f_amp.read(15) a = f_amp.read(15)
f_volt.close() f_volt.close()
f_amp.close() f_amp.close()
s = v +' V '+a+' A '+'\n' current_time = round(time.time()*1000)
out = open(self.parent.filename, 'a') s = v + a + str(current_time - self.start_time)
out = open(os(self.parent.foldername, self.dataname), 'a')
out.write(s) out.write(s)
out.close() out.close()
@ -204,43 +211,22 @@ class MainExperiment1Window(AbstractWindow):
import time import time
import serial import serial
# configure the serial connections (the parameters differs on the device you are connecting to) ser=serial.Serial(
ser = serial.Serial(
port='/dev/ttyUSB0', port='/dev/ttyUSB0',
baudrate=9600, baudrate=9600,
timeout=1 timeout=1
) )
ser.isOpen() ser.isOpen()
msg = 'SYSTem:REMote\n' msg='SYSTem:REMote\n'
ser.write(msg.encode('ascii')) ser.write(msg.encode('ascii'))
# Reading the data from the serial port. This will be running in an infinite loop.
while 1 : while 1:
msg = 'Read?\n' msg='Read?\n'
ser.write(msg.encode('ascii')) ser.write(msg.encode('ascii'))
time.sleep(1) time.sleep(1)
bytesToRead = ser.inWaiting() bytesToRead=ser.inWaiting()
data = ser.read(bytesToRead) data=ser.read(bytesToRead)
print(data) print(data)
# =============================================================================
# f = open (os.path.join('/dev', 'usbtmc1'), 'w')
# f.write('Measure:Voltage:DC?\n')
# f.close()
# f = open (os.path.join('/dev', 'usbtmc1'), 'r')
# a = f.read(15)
# print(a)
# f.close()
#
# f = open (os.path.join('/dev', 'usbtmc2'), 'w')
# f.write('Measure:Current:DC?\n')
# f.close()
# f = open (os.path.join('/dev', 'usbtmc2'), 'r')
# a = f.read(15)
# print(a)
# f.close()
# =============================================================================