add logics
This commit is contained in:
parent
a7155a4a6f
commit
f0449a472b
@ -30,9 +30,6 @@ class Start:
|
|||||||
self.draw()
|
self.draw()
|
||||||
self.app.exec()
|
self.app.exec()
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
print('destruct')
|
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ class ThreadData(QtCore.QThread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
self.running = True
|
self.running = True
|
||||||
while self.running:
|
while self.running:
|
||||||
self.parent.take_data()
|
self.parent.no_data()
|
||||||
self.sleep(2)
|
self.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
class MainExperimentDataWindow(AbstractWindow):
|
class MainExperimentDataWindow(AbstractWindow):
|
||||||
@ -45,27 +45,19 @@ class MainExperimentDataWindow(AbstractWindow):
|
|||||||
|
|
||||||
self.setWindowTitle('Основной эксперимент. Получение данных')
|
self.setWindowTitle('Основной эксперимент. Получение данных')
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
# self.add_ser()
|
||||||
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'))
|
|
||||||
self.data_thread = ThreadData(self)
|
self.data_thread = ThreadData(self)
|
||||||
self.resize(1400, 800)
|
self.resize(1400, 800)
|
||||||
|
self.number_iteration = 1
|
||||||
|
self.start_time = 0
|
||||||
|
self.volt = 0
|
||||||
|
|
||||||
# make masthead
|
# make masthead
|
||||||
self.parent.dataname = 'data.csv'
|
self.parent.dataname = 'data.csv'
|
||||||
head_1 = 'I_0,mA'
|
heads = ['U_34,mV', 'I_M,mA', 'U_0,mV', 'I_0,mA', 'E, mV', 'N', 't,ms']
|
||||||
head_2 = 'U_34,mV'
|
|
||||||
head_3 = 't,ms'
|
|
||||||
with open(os.path.join(self.parent.folder, self.parent.dataname), 'w') as file:
|
with open(os.path.join(self.parent.folder, self.parent.dataname), 'w') as file:
|
||||||
wr = csv.writer(file)
|
wr = csv.writer(file)
|
||||||
wr.writerow([head_1, head_2, head_3])
|
wr.writerow(heads)
|
||||||
|
|
||||||
self.centralwidget = QWidget()
|
self.centralwidget = QWidget()
|
||||||
self.setCentralWidget(self.centralwidget)
|
self.setCentralWidget(self.centralwidget)
|
||||||
@ -79,89 +71,114 @@ class MainExperimentDataWindow(AbstractWindow):
|
|||||||
self.stop.clicked.connect(self.stop_clicked)
|
self.stop.clicked.connect(self.stop_clicked)
|
||||||
self.stop.setEnabled(False)
|
self.stop.setEnabled(False)
|
||||||
|
|
||||||
self.next = QPushButton(self)
|
self.new = QPushButton('Новый ток')
|
||||||
self.next.setIcon(QIcon('arrow.png'))
|
self.new.clicked.connect(self.new_clicked)
|
||||||
self.next.setEnabled(False)
|
self.new.setEnabled(False)
|
||||||
self.next.clicked.connect(self.next_clicked)
|
|
||||||
|
|
||||||
self.lineEdit = QLineEdit(placeholderText='Введите что-то')
|
self.chart = QPushButton('График')
|
||||||
self.lineEdit.returnPressed.connect(self.enter_smth)
|
self.chart.setEnabled(False)
|
||||||
|
self.chart.clicked.connect(self.chart_clicked)
|
||||||
|
|
||||||
|
self.lineEdit = QLineEdit(placeholderText='Введите a, мм')
|
||||||
|
self.lineEdit.returnPressed.connect(self.enter_a)
|
||||||
|
|
||||||
# make table
|
# make table
|
||||||
self.table = QTableWidget(self)
|
self.table = QTableWidget(self)
|
||||||
self.table.setColumnCount(3)
|
self.table.setColumnCount(len(heads))
|
||||||
self.table.setRowCount(0)
|
self.table.setRowCount(0)
|
||||||
self.table.setHorizontalHeaderLabels([head_1, head_2, head_3])
|
self.table.setHorizontalHeaderLabels(heads)
|
||||||
header = self.table.horizontalHeader()
|
header = self.table.horizontalHeader()
|
||||||
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
|
for i in range(len(heads)):
|
||||||
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
|
header.setSectionResizeMode(i, QHeaderView.ResizeMode.Stretch)
|
||||||
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Stretch)
|
|
||||||
self.table.resizeColumnsToContents()
|
self.table.resizeColumnsToContents()
|
||||||
|
|
||||||
# Adding the table to the grid
|
# Adding the table to the grid
|
||||||
self.grid_layout.addWidget(self.table, 0, 0, -1, 1)
|
self.grid_layout.addWidget(self.table, 0, 0, -1, 1)
|
||||||
self.grid_layout.addWidget(self.lineEdit, 0, 2, -1, -1)
|
self.grid_layout.addWidget(self.lineEdit, 0, 2, 1, -1)
|
||||||
self.grid_layout.addWidget(self.next, 2, 2, -1, -1)
|
|
||||||
self.grid_layout.addWidget(self.start, 1, 2)
|
self.grid_layout.addWidget(self.start, 1, 2)
|
||||||
self.grid_layout.addWidget(self.stop, 1, 3)
|
self.grid_layout.addWidget(self.stop, 1, 3)
|
||||||
|
self.grid_layout.addWidget(self.new, 2, 2, 1, -1)
|
||||||
|
self.grid_layout.addWidget(self.chart, 3, 2, 1, -1)
|
||||||
|
|
||||||
def enter_smth(self):
|
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):
|
||||||
# TODO
|
# TODO
|
||||||
self.parent.smth = self.lineEdit.text()
|
self.parent.a = self.lineEdit.text()
|
||||||
self.start.setEnabled(True)
|
self.start.setEnabled(True)
|
||||||
self.lineEdit.setReadOnly(True)
|
self.lineEdit.setReadOnly(True)
|
||||||
|
|
||||||
def start_clicked(self):
|
def start_clicked(self):
|
||||||
self.stop.setEnabled(True)
|
self.stop.setEnabled(True)
|
||||||
|
if self.start_time == 0:
|
||||||
self.start_time = round(time.time()*1000)
|
self.start_time = round(time.time()*1000)
|
||||||
self.start.setEnabled(False)
|
self.start.setEnabled(False)
|
||||||
if not self.data_thread.isRunning():
|
self.new.setEnabled(True)
|
||||||
|
if not self.data_thread.running:
|
||||||
self.data_thread.start()
|
self.data_thread.start()
|
||||||
|
|
||||||
def stop_clicked(self):
|
def stop_clicked(self):
|
||||||
self.data_thread.running = False
|
self.data_thread.running = False
|
||||||
self.stop.setEnabled(False)
|
self.stop.setEnabled(False)
|
||||||
self.next.setEnabled(True)
|
self.start.setEnabled(True)
|
||||||
|
self.chart.setEnabled(True)
|
||||||
|
|
||||||
def next_clicked(self):
|
def new_clicked(self):
|
||||||
|
self.number_iteration += 1
|
||||||
|
self.volt = 0
|
||||||
|
if not self.data_thread.running:
|
||||||
|
self.data_thread.start()
|
||||||
|
self.start.setEnabled(False)
|
||||||
|
self.new.setEnabled(True)
|
||||||
|
self.stop.setEnabled(True)
|
||||||
|
|
||||||
|
def chart_clicked(self):
|
||||||
self.parent.number = 21
|
self.parent.number = 21
|
||||||
self.parent.change_number()
|
self.parent.change_number()
|
||||||
|
|
||||||
def no_data(self):
|
def no_data(self):
|
||||||
current_time = round(time.time()*1000)
|
current_time = round(time.time()*1000)
|
||||||
v = str((current_time-self.start_time)/60)
|
v = str((current_time-self.start_time)/60)
|
||||||
a = v
|
|
||||||
t = str(current_time-self.start_time)
|
t = str(current_time-self.start_time)
|
||||||
self.save_data(v, a, t)
|
if float(self.volt) <= 0.1:
|
||||||
|
self.u_0 = v
|
||||||
|
a = str(float(v)/100)
|
||||||
|
I_M = v
|
||||||
|
self.save_data([v, I_M, self.u_0, a, self.volt,
|
||||||
|
self.number_iteration, t])
|
||||||
|
self.volt = str(float(self.volt)+5)
|
||||||
|
if float(a) > 1:
|
||||||
|
self.stop_clicked()
|
||||||
|
|
||||||
def save_data(self, v, a, t):
|
def save_data(self, data):
|
||||||
with open(os.path.join(self.parent.folder, self.parent.dataname), 'a') as file:
|
with open(os.path.join(self.parent.folder, self.parent.dataname), 'a') as file:
|
||||||
wr = csv.writer(file)
|
wr = csv.writer(file)
|
||||||
wr.writerow([v, a, t])
|
wr.writerow(data)
|
||||||
v = str(v)
|
|
||||||
a = str(a)
|
|
||||||
t = str(t)
|
|
||||||
self.table.insertRow(self.table.rowCount())
|
self.table.insertRow(self.table.rowCount())
|
||||||
self.table.setItem(self.table.rowCount()-1, 0, QTableWidgetItem(v))
|
for i in range(len(data)):
|
||||||
self.table.setItem(self.table.rowCount()-1, 1, QTableWidgetItem(a))
|
self.table.setItem(self.table.rowCount()-1, i,
|
||||||
self.table.setItem(self.table.rowCount()-1, 2, QTableWidgetItem(t))
|
QTableWidgetItem(str(data[i])))
|
||||||
|
|
||||||
def take_data(self):
|
def take_data(self):
|
||||||
# measure voltage and current
|
# measure voltage and current
|
||||||
volt = 1.5 * (1+(time.time()-self.start_time/1000)/20)
|
msg = 'VOLTage '+str(self.volt)+'\n'
|
||||||
|
|
||||||
# print(volt)
|
|
||||||
msg = 'VOLTage '+str(volt)+'\n'
|
|
||||||
self.parent.ser.write(msg.encode('ascii'))
|
self.parent.ser.write(msg.encode('ascii'))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
msg = 'MEASure:VOLTage?\n'
|
msg = 'MEASure:Current?\n'
|
||||||
|
|
||||||
self.parent.ser.write(msg.encode('ascii'))
|
self.parent.ser.write(msg.encode('ascii'))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
bytesToRead = self.parent.ser.inWaiting()
|
bytesToRead = self.parent.ser.inWaiting()
|
||||||
data = self.parent.ser.read(bytesToRead)
|
I_M = self.parent.ser.read(bytesToRead)
|
||||||
print(float(data))
|
self.volt += 5
|
||||||
|
|
||||||
volt_name = os.path.join('/dev', 'usbtmc0')
|
volt_name = os.path.join('/dev', 'usbtmc0')
|
||||||
f_volt = open(volt_name, 'w')
|
f_volt = open(volt_name, 'w')
|
||||||
@ -174,14 +191,23 @@ class MainExperimentDataWindow(AbstractWindow):
|
|||||||
|
|
||||||
f_volt = open(volt_name, 'r')
|
f_volt = open(volt_name, 'r')
|
||||||
v = '{:.9f}'.format(float(f_volt.read(15))*10**3)
|
v = '{:.9f}'.format(float(f_volt.read(15))*10**3)
|
||||||
|
if self.volt == 0:
|
||||||
|
self.u_0 = v
|
||||||
f_amp = open(amp_name, 'r')
|
f_amp = open(amp_name, 'r')
|
||||||
a = '{:.9f}'.format(float(f_amp.read(15))*10**3)
|
a = '{:.9f}'.format(float(f_amp.read(15))*10**3)
|
||||||
|
print(a)
|
||||||
|
# protect of errors:
|
||||||
|
if a > 1:
|
||||||
|
self.stop_clicked()
|
||||||
|
|
||||||
f_volt.close()
|
f_volt.close()
|
||||||
f_amp.close()
|
f_amp.close()
|
||||||
|
|
||||||
current_time = round(time.time()*1000)
|
current_time = round(time.time()*1000)
|
||||||
t = str(current_time-self.start_time)
|
t = str(current_time-self.start_time)
|
||||||
self.save_data(v, a, t)
|
|
||||||
|
self.save_data([v, I_M, self.u_0, a, self.volt,
|
||||||
|
self.number_iteration, t])
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
self.data_thread.running = False
|
self.data_thread.running = False
|
||||||
@ -210,13 +236,13 @@ class MainExperimentChartWindow(AbstractWindow):
|
|||||||
pixmap = QPixmap(os.path.join(
|
pixmap = QPixmap(os.path.join(
|
||||||
self.parent.folder, self.parent.chartname))
|
self.parent.folder, self.parent.chartname))
|
||||||
self.label = QLabel(self)
|
self.label = QLabel(self)
|
||||||
pixmap.scaled(0.5, 0.3)
|
self.label.setScaledContents(True)
|
||||||
self.label.setPixmap(pixmap)
|
self.label.setPixmap(pixmap)
|
||||||
|
self.label.setFixedSize(0.7*self.width(), self.height())
|
||||||
|
|
||||||
self.text = QTextBrowser()
|
self.text = QTextBrowser()
|
||||||
self.text.setText('text')
|
self.text.setText('text')
|
||||||
|
|
||||||
self.resize(1400, 800)
|
|
||||||
self.hbox_layout = QGridLayout(self.centralwidget)
|
self.hbox_layout = QGridLayout(self.centralwidget)
|
||||||
self.hbox_layout.addWidget(self.label, 0, 0)
|
self.hbox_layout.addWidget(self.label, 0, 0)
|
||||||
self.hbox_layout.addWidget(self.text, 0, 1)
|
self.hbox_layout.addWidget(self.text, 0, 1)
|
||||||
|
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
,anna,anna-HP-Laptop-15-bw0xx,08.11.2022 18:47,file:///home/anna/.config/libreoffice/4;
|
|
Binary file not shown.
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 80 KiB |
@ -1,4 +1,13 @@
|
|||||||
"I_0,mA","U_34,mV","t,ms"
|
"U_34,mV","I_M,mA","U_0,mV","I_0,mA","E, mV",N,"t,ms"
|
||||||
5.721514880,-0.000002069,3963
|
0.016666666666666666,0.016666666666666666,0.016666666666666666,0.00016666666666666666,0,1,1
|
||||||
4.002560960,0.000000000,9913
|
16.7,16.7,0.016666666666666666,0.16699999999999998,5.0,1,1002
|
||||||
-88.817369600,-0.000000886,15850
|
33.38333333333333,33.38333333333333,0.016666666666666666,0.3338333333333333,10.0,1,2003
|
||||||
|
50.06666666666667,50.06666666666667,0.016666666666666666,0.5006666666666667,15.0,1,3004
|
||||||
|
66.75,66.75,0.016666666666666666,0.6675,20.0,1,4005
|
||||||
|
83.43333333333334,83.43333333333334,0.016666666666666666,0.8343333333333334,25.0,1,5006
|
||||||
|
100.11666666666666,100.11666666666666,0.016666666666666666,1.0011666666666665,30.0,1,6007
|
||||||
|
142.81666666666666,142.81666666666666,142.81666666666666,1.4281666666666666,0,2,8569
|
||||||
|
172.68333333333334,172.68333333333334,172.68333333333334,1.7268333333333334,0,3,10361
|
||||||
|
212.01666666666668,212.01666666666668,212.01666666666668,2.120166666666667,0,5,12721
|
||||||
|
235.11666666666667,235.11666666666667,235.11666666666667,2.351166666666667,0,6,14107
|
||||||
|
256.65,256.65,256.65,2.5664999999999996,0,7,15399
|
||||||
|
|
Loading…
Reference in New Issue
Block a user