small changes

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

80
Main.py
View File

@ -31,7 +31,6 @@ from PyQt6.QtWidgets import (QHBoxLayout,
)
class AbstractWindow(QMainWindow):
def __init__(self):
super().__init__()
@ -68,12 +67,10 @@ class AbstractWindow(QMainWindow):
# TODO
class Start:
def __init__(self):
self.number = 0
self.filename = ''
self.foldername = ''
if not QApplication.instance():
self.app = QApplication(sys.argv)
else:
@ -131,7 +128,7 @@ class StartWindow(AbstractWindow):
self.parent.change_number()
def enter_name(self):
self.parent.filename = self.lineEdit.text()
self.parent.foldername = self.lineEdit.text()
self.flow.setEnabled(True)
self.main.setEnabled(True)
self.lineEdit.setReadOnly(True)
@ -142,40 +139,49 @@ class MainExperiment1Window(AbstractWindow):
super().__init__()
self.setWindowTitle('Основной эксперимент')
self.start_time = 0
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.resize(1400, 800)
self.setCentralWidget(self.centralwidget)
self.but = QPushButton('Измерение')
self.but.clicked.connect(self.but_click)
# self.but.clicked.connect(self.but_click)
self.setCentralWidget(self.but)
grid_layout = QGridLayout(self) # Create QGridLayout
self.centralwidget.setLayout(grid_layout) # Set this layout in central widget
# grid_layout = QGridLayout(self) # Create QGridLayout
# self.centralwidget.setLayout(grid_layout) # Set this layout in central widget
table = QTableWidget(self) # Create a table
table.setColumnCount(3) #Set three columns
table.setRowCount(1) # and one row
# table = QTableWidget(self) # Create a table
# table.setColumnCount(3) #Set three columns
# table.setRowCount(1) # and one row
# Set the table headers
table.setHorizontalHeaderLabels(["Header 1", "Header 2", "Header 3"])
# # Set the table headers
# table.setHorizontalHeaderLabels(["Header 1", "Header 2", "Header 3"])
#Set the tooltips to headings
table.horizontalHeaderItem(0).setToolTip("Column 1 ")
table.horizontalHeaderItem(1).setToolTip("Column 2 ")
table.horizontalHeaderItem(2).setToolTip("Column 3 ")
table.setItem(0, 0, QTableWidgetItem("Text in column 1"))
table.setItem(0, 1, QTableWidgetItem("Text in column 2"))
table.setItem(0, 2, QTableWidgetItem("Text in column 3"))
# #Set the tooltips to headings
# table.horizontalHeaderItem(0).setToolTip("Column 1 ")
# table.horizontalHeaderItem(1).setToolTip("Column 2 ")
# table.horizontalHeaderItem(2).setToolTip("Column 3 ")
# table.setItem(0, 0, QTableWidgetItem("Text in column 1"))
# table.setItem(0, 1, QTableWidgetItem("Text in column 2"))
# table.setItem(0, 2, QTableWidgetItem("Text in column 3"))
# Do the resize of the columns by content
table.resizeColumnsToContents()
# # Do the resize of the columns by content
# 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):
# measure voltage and current
volt_name = os.path.join('/dev', 'usbtmc1')
f_volt = open(volt_name, 'w')
f_volt.write('Measure:Voltage:DC?\n')
@ -191,8 +197,9 @@ class MainExperiment1Window(AbstractWindow):
a = f_amp.read(15)
f_volt.close()
f_amp.close()
s = v +' V '+a+' A '+'\n'
out = open(self.parent.filename, 'a')
current_time = round(time.time()*1000)
s = v + a + str(current_time - self.start_time)
out = open(os(self.parent.foldername, self.dataname), 'a')
out.write(s)
out.close()
@ -204,7 +211,6 @@ class MainExperiment1Window(AbstractWindow):
import time
import serial
# configure the serial connections (the parameters differs on the device you are connecting to)
ser=serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
@ -214,7 +220,6 @@ ser.isOpen()
msg='SYSTem:REMote\n'
ser.write(msg.encode('ascii'))
# Reading the data from the serial port. This will be running in an infinite loop.
while 1:
@ -225,22 +230,3 @@ while 1 :
bytesToRead=ser.inWaiting()
data=ser.read(bytesToRead)
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()
# =============================================================================