diff --git a/Automation/Analisis_data.py b/Automation/Analisis_data.py index f54960c..a69636b 100644 --- a/Automation/Analisis_data.py +++ b/Automation/Analisis_data.py @@ -119,7 +119,7 @@ class Data: linestyle='-', color=self.color[1]) def make_grafic(self, named_by_points=True): - plt.figure(dpi=500, figsize=(8, 5)) + plt.figure(dpi=500, figsize=(4, 3)) self.make_errors() if named_by_points: self.cap_point = self.caption diff --git a/Automation/Chart.png b/Automation/Chart.png new file mode 100644 index 0000000..63a0afa Binary files /dev/null and b/Automation/Chart.png differ diff --git a/Automation/Main.py b/Automation/Main.py index c046f3c..6b3bffc 100644 --- a/Automation/Main.py +++ b/Automation/Main.py @@ -1,5 +1,6 @@ import os import sys +import serial import csv import time from PyQt6.QtGui import QIcon @@ -103,6 +104,7 @@ class FlowWindow(AbstractWindow): self.setWindowTitle('Градуировка электромагнита') self.parent = parent + # make csv file self.parent.flow_dataname = 'Induction_data.csv' head_1 = 'B,mTl' @@ -165,6 +167,13 @@ class FlowWindow(AbstractWindow): self.lineEdit.setReadOnly(False) def get_data(self): + + + + # bytesToRead=ser.inWaiting() + # data=ser.read(bytesToRead) + # print(data) + current_time = round(time.time()*1000) b = self.lineEdit.text() u = str((current_time-self.start_time)/60) @@ -181,28 +190,30 @@ class FlowWindow(AbstractWindow): start = Start() -# ============================================================================= # import time # import serial -# + # ser=serial.Serial( -# port='/dev/ttyUSB0', +# port='/dev/ttyUSB2', # baudrate=9600, # timeout=1 # ) # ser.isOpen() -# -# msg='SYSTem:REMote\n' +# msg='Output on\n' + # ser.write(msg.encode('ascii')) -# + + +# msg='VOLTage 1\n' +# ser.write(msg.encode('ascii')) + # while 1: -# -# msg='Read?\n' + +# msg='READ?\n' # ser.write(msg.encode('ascii')) # time.sleep(1) -# + # bytesToRead=ser.inWaiting() # data=ser.read(bytesToRead) # print(data) -# -# ============================================================================= + diff --git a/Automation/Main_experiment_window.py b/Automation/Main_experiment_window.py index bb63cca..e0a1c65 100644 --- a/Automation/Main_experiment_window.py +++ b/Automation/Main_experiment_window.py @@ -7,6 +7,7 @@ Created on Fri Nov 11 20:00:45 2022 """ import os import csv +import serial import time from PyQt6 import QtCore from PyQt6.QtGui import QIcon, QPixmap @@ -34,8 +35,8 @@ class ThreadData(QtCore.QThread): def run(self): self.running = True while self.running: - self.parent.no_data() - self.sleep(1) + self.parent.take_data() + self.sleep(2) class MainExperimentDataWindow(AbstractWindow): @@ -44,6 +45,16 @@ class MainExperimentDataWindow(AbstractWindow): self.setWindowTitle('Основной эксперимент. Получение данных') self.parent = parent + + 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.resize(1400, 800) @@ -127,6 +138,9 @@ class MainExperimentDataWindow(AbstractWindow): with open(os.path.join(self.parent.folder, self.parent.dataname), 'a') as file: wr = csv.writer(file) wr.writerow([v, a, t]) + v = str(v) + a = str(a) + t = str(t) self.table.insertRow(self.table.rowCount()) self.table.setItem(self.table.rowCount()-1, 0, QTableWidgetItem(v)) self.table.setItem(self.table.rowCount()-1, 1, QTableWidgetItem(a)) @@ -134,19 +148,34 @@ class MainExperimentDataWindow(AbstractWindow): def take_data(self): # measure voltage and current - volt_name = os.path.join('/dev', 'usbtmc1') + volt = 1.5 * (1+(time.time()-self.start_time/1000)/20) + + # print(volt) + msg = 'VOLTage '+str(volt)+'\n' + self.parent.ser.write(msg.encode('ascii')) + time.sleep(1) + + msg = 'MEASure:VOLTage?\n' + + self.parent.ser.write(msg.encode('ascii')) + time.sleep(1) + bytesToRead = self.parent.ser.inWaiting() + data = self.parent.ser.read(bytesToRead) + print(float(data)) + + volt_name = os.path.join('/dev', 'usbtmc0') f_volt = open(volt_name, 'w') f_volt.write('Measure:Voltage:DC?\n') f_volt.close() - amp_name = os.path.join('/dev', 'usbtmc2') + amp_name = os.path.join('/dev', 'usbtmc1') f_amp = open(amp_name, 'w') f_amp.write('Measure:Current:DC?\n') f_amp.close() f_volt = open(volt_name, 'r') - v = f_volt.read(15) + v = '{:.9f}'.format(float(f_volt.read(15))*10**3) f_amp = open(amp_name, 'r') - a = f_amp.read(15) + a = '{:.9f}'.format(float(f_amp.read(15))*10**3) f_volt.close() f_amp.close() @@ -154,6 +183,9 @@ class MainExperimentDataWindow(AbstractWindow): t = str(current_time-self.start_time) self.save_data(v, a, t) + def closeEvent(self, event): + self.data_thread.running = False + class MainExperimentChartWindow(AbstractWindow): def __init__(self, parent): @@ -178,12 +210,13 @@ class MainExperimentChartWindow(AbstractWindow): pixmap = QPixmap(os.path.join( self.parent.folder, self.parent.chartname)) self.label = QLabel(self) + pixmap.scaled(0.5, 0.3) self.label.setPixmap(pixmap) - self.label.resize(pixmap.width(), pixmap.height()) self.text = QTextBrowser() self.text.setText('text') + self.resize(1400, 800) self.hbox_layout = QGridLayout(self.centralwidget) self.hbox_layout.addWidget(self.label, 0, 0) self.hbox_layout.addWidget(self.text, 0, 1) diff --git a/Automation/__pycache__/Analisis_data.cpython-39.pyc b/Automation/__pycache__/Analisis_data.cpython-39.pyc index 5c8f757..f687c90 100644 Binary files a/Automation/__pycache__/Analisis_data.cpython-39.pyc and b/Automation/__pycache__/Analisis_data.cpython-39.pyc differ diff --git a/Automation/__pycache__/Main_experiment_window.cpython-39.pyc b/Automation/__pycache__/Main_experiment_window.cpython-39.pyc index dee3633..4f560cf 100644 Binary files a/Automation/__pycache__/Main_experiment_window.cpython-39.pyc and b/Automation/__pycache__/Main_experiment_window.cpython-39.pyc differ diff --git a/Automation/data.csv b/Automation/data.csv new file mode 100644 index 0000000..2640df7 --- /dev/null +++ b/Automation/data.csv @@ -0,0 +1,5 @@ +"I_0,mA","U_34,mV","t,ms" +-118.631224000,-0.000002364,3961 +-13.393977600,-0.000002660,9926 +-12.964528800,-0.000002364,15875 +-119.215280000,-0.000002069,21888 diff --git a/Automation/j/Chart.png b/Automation/j/Chart.png index a6d3d93..1048c2e 100644 Binary files a/Automation/j/Chart.png and b/Automation/j/Chart.png differ diff --git a/Automation/j/data.csv b/Automation/j/data.csv index a995eb2..d69dafd 100644 --- a/Automation/j/data.csv +++ b/Automation/j/data.csv @@ -1,2 +1,4 @@ "I_0,mA","U_34,mV","t,ms" -0.0,0.0,0 +5.721514880,-0.000002069,3963 +4.002560960,0.000000000,9913 +-88.817369600,-0.000000886,15850