InterfaceL.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. from idlelib.colorizer import color_config
  2. from logging import disable
  3. from math import acosh
  4. from tkinter import Tk, Label, Entry, Button, Spinbox, StringVar, BOTTOM, LEFT, SOLID, EW, END
  5. from tkinter import ttk
  6. from tkinter import filedialog
  7. from tkinter.ttk import Combobox
  8. from matplotlib.figure import Figure
  9. from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  10. from matplotlib.backends._backend_tk import NavigationToolbar2Tk
  11. from random import choice
  12. import matplotlib.pyplot as plt
  13. import matplotlib
  14. import matplotlib.animation as animation
  15. import numpy as np
  16. import time
  17. import os
  18. from matplotlib.animation import FuncAnimation
  19. import tkinter as tk
  20. class ScrollableFrame(ttk.Frame):
  21. def __init__(self, container, *args, **kwargs):
  22. super().__init__(container, *args, **kwargs)
  23. canvas = tk.Canvas(self, width=1600, height=900)
  24. scrollbar = ttk.Scrollbar(self, orient="vertical", command=canvas.yview)
  25. scrollbar_h = ttk.Scrollbar(self, orient="horizontal", command=canvas.xview)
  26. self.scrollable_frame = ttk.Frame(canvas)
  27. self.scrollable_frame.bind(
  28. "<Configure>",
  29. lambda e: canvas.configure(
  30. scrollregion=canvas.bbox("all")
  31. )
  32. )
  33. canvas.create_window((0, 0), window=self.scrollable_frame, anchor="nw")
  34. canvas.configure(yscrollcommand=scrollbar.set)
  35. canvas.configure(xscrollcommand=scrollbar_h.set)
  36. scrollbar_h.pack(side="bottom", fill="x")
  37. scrollbar.pack(side="right", fill="y")
  38. canvas.pack(side="left", fill="both", expand=True)
  39. class Interface():
  40. window0 = Tk()
  41. windowq = ttk.Frame()
  42. windowq.pack()
  43. window = ScrollableFrame(windowq)
  44. window.pack(side='top', anchor='sw')
  45. def __init__(self):
  46. pass
  47. def create_widgets_S(self):
  48. Interface.window0.title("project_gamma_new_2vi")
  49. Interface.window0.geometry('500x250+100+100')
  50. photo = tk.PhotoImage(file='iconka.png')
  51. Interface.window0.iconphoto(False, photo)
  52. self.f_top = ttk.LabelFrame(Interface.window.scrollable_frame, text="Виртуальный COM порт", relief=SOLID, padding=(8, 10))
  53. self.combo = Combobox(self.f_top)
  54. self.combo['values'] = (1, 2, 3, 4, 5)
  55. self.combo.current(4)
  56. self.f_top.grid(column=0, row=0)
  57. self.combo.pack(side=BOTTOM)
  58. self.f_file = ttk.LabelFrame(Interface.window.scrollable_frame, text="Выбрать файл txt для записи", relief=SOLID,
  59. padding=(8, 10))
  60. self.f_file.grid(column=1, row=0)
  61. self.txt = Entry(self.f_file, width=40)
  62. self.txt.pack(side=LEFT)
  63. self.btn = Button(self.f_file, height=1, text='Файл', bg="gray", fg="red", command=self.clicked_file)
  64. self.btn.pack(side=LEFT)
  65. self.f_start = ttk.Frame(Interface.window.scrollable_frame, relief=SOLID, padding=(8, 10))
  66. self.t1 = Label(self.f_start, text="Состояние работы", fg="black")
  67. self.t2 = Label(self.f_start, text="Начать сбор данных", fg="black")
  68. self.t3 = Label(self.f_start, text="Остановить сбор данных", fg="black")
  69. self.t4 = Label(self.f_start, text="Выключено", fg="white", bg="black")
  70. self.button_start = Button(self.f_start, text="Пуск", bg="lightgray", fg="black", command=self.clicked_start1)
  71. self.button_startoff = Button(self.f_start, text="Стоп", bg="lightgray", fg="red",
  72. command=self.clicked_start2,
  73. state='disabled')
  74. self.f_start1 = ttk.LabelFrame(Interface.window.scrollable_frame, text='Принятые символы', relief=SOLID, padding=(8, 10))
  75. self.t_entry = Entry(self.f_start1, width=40, state=['disable'])
  76. self.f_start.grid(column=2, row=0)
  77. self.f_start1.grid(column=3, row=0)
  78. self.t1.grid(column=0, row=0)
  79. self.t2.grid(column=1, row=0)
  80. self.t3.grid(column=2, row=0)
  81. self.t4.grid(column=0, row=1)
  82. self.t_entry.grid(column=0, row=1)
  83. self.button_start.grid(column=1, row=1)
  84. self.button_startoff.grid(column=2, row=1)
  85. def create_widgets_W(self):
  86. self.f_W = ttk.Frame(Interface.window.scrollable_frame, relief=SOLID, padding=(8, 10))
  87. self.f_W.grid(column=0, row=1)
  88. self.tspin1 = Label(self.f_W, text="Время экспозиции, с", fg="black")
  89. self.tspin2 = Label(self.f_W, text="Макс. время сбора данных, с", fg="black")
  90. self.tspin3 = Label(self.f_W, text="Прошло времени, с", fg="black")
  91. self.spin1 = Spinbox(self.f_W, from_=0, to=100, width=7)
  92. self.spin2 = Spinbox(self.f_W, from_=0, to=10000000, increment=500, width=11)
  93. self.t_entry = Entry(self.f_W, width=20, state='disabled')
  94. self.tspin1.grid(column=0, row=0, ipadx=10)
  95. self.spin1.grid(column=0, row=1, pady=10)
  96. self.tspin2.grid(column=0, row=2, ipadx=10)
  97. self.spin2.grid(column=0, row=3, pady=10)
  98. self.tspin3.grid(column=0, row=4, pady=10)
  99. self.t_entry.grid(column=0, row=5)
  100. self.f_W1 = ttk.Frame(Interface.window.scrollable_frame, relief=SOLID, padding=(8, 10))
  101. self.f_W1.grid(column=0, row=2)
  102. self.tspin_0 = Label(self.f_W1, text="Коэффициент делителя", fg="black")
  103. self.spin_0 = Spinbox(self.f_W1, from_=0, to=100, width=7)
  104. self.tspin_0.grid(column=0, row=0, ipadx=10)
  105. self.spin_0.grid(column=0, row=1, pady=10)
  106. self.f_W2 = ttk.Frame(Interface.window.scrollable_frame, relief=SOLID, padding=(8, 10))
  107. self.f_W2.grid(column=0, row=3)
  108. self.spin1_zap = Spinbox(self.f_W2, from_=0.0, to=50.0, increment=0.1, width=6)
  109. self.spin2_zap = Spinbox(self.f_W2, from_=0, to=100, increment=1, width=6)
  110. self.spin3_zap = Spinbox(self.f_W2, from_=0, to=500, width=6)
  111. self.spin4_zap = Spinbox(self.f_W2, from_=0, to=500, width=6)
  112. self.tspin1_zap = Label(self.f_W2, text="ЦАП канал 1.0...3.29В", fg="black")
  113. self.tspin2_zap = Label(self.f_W2, text="ЦАП канал 2.0...3.29В", fg="black")
  114. self.tspin3_zap = Label(self.f_W2, text="ЦАП канал 3.1...256", fg="black")
  115. self.tspin4_zap = Label(self.f_W2, text="ЦАП канал 4.1...256", fg="black")
  116. self.tbut1_zap = Label(self.f_W2, text='''Обновить значение
  117. каналов DAC''', fg="black")
  118. self.tbut2_zap = Label(self.f_W2, text='''Прочесть текущее
  119. значение каналов DAC''', fg="black")
  120. self.button1_zap = Button(self.f_W2, text="Обновить", bg="lightgray", fg="black")
  121. self.button2_zap = Button(self.f_W2, text="Прочесть", bg="lightgray", fg="black")
  122. self.tspin1_zap.grid(column=0, row=0, ipadx=10)
  123. self.spin1_zap.grid(column=0, row=1, pady=10)
  124. self.tspin2_zap.grid(column=0, row=2, ipadx=10)
  125. self.spin2_zap.grid(column=0, row=3, pady=10)
  126. self.tspin3_zap.grid(column=0, row=4, ipadx=10)
  127. self.spin3_zap.grid(column=0, row=5, pady=10)
  128. self.tspin4_zap.grid(column=0, row=6, ipadx=10)
  129. self.spin4_zap.grid(column=0, row=7, pady=10)
  130. self.tbut1_zap.grid(column=0, row=8)
  131. self.button1_zap.grid(column=0, row=9)
  132. self.tbut2_zap.grid(column=0, row=10)
  133. self.button2_zap.grid(column=0, row=11)
  134. self.f_W3 = ttk.Frame(Interface.window.scrollable_frame, relief=SOLID, padding=(8, 10))
  135. self.txt0_fw3 = Label(self.f_W3, text="Порт В1 напряжения", fg="black")
  136. self.txt1_fw3 = Label(self.f_W3, text=" 0 B ", fg="black", bg="pink")
  137. self.m = ' 0 B '
  138. self.txt2_fw3 = Label(self.f_W3, text='''Выбор напряжения:
  139. 0 В 3.3B''')
  140. self.but_fw3 = Button(self.f_W3, text='<---', command=self.clicked_V)
  141. self.f_W3.grid(column=0, row=4)
  142. self.txt0_fw3.grid(column=0, row=0)
  143. self.txt1_fw3.grid(column=0, row=1, pady=10)
  144. self.txt2_fw3.grid(column=0, row=2)
  145. self.but_fw3.grid(column=0, row=3)
  146. def create_Figure(self):
  147. self.file1 = open('coordinates.txt', 'r')
  148. with self.file1 as f:
  149. self.lines = f.readlines()
  150. self.data = [line.strip().split() for line in self.lines]
  151. self.xdata, self.ydata = zip(*[(float(x), float(y)) for x, y in self.data])
  152. self.f_graf = ttk.LabelFrame(Interface.window.scrollable_frame,
  153. text='Количество импульсов в минуту', relief=SOLID)
  154. self.f_graf.grid(column=1, row=1, columnspan=2, rowspan=2)
  155. self.fig = Figure(figsize=(7, 4), dpi=80)
  156. self.ax = self.fig.add_subplot(111)
  157. self.ax.set_xlabel('Время, с')
  158. self.ax.set_ylabel('Импульсы')
  159. self.ax.grid(color='black', linewidth=1.0)
  160. self.ax.set_xlim(0, 3000)
  161. self.ax.set_ylim(0, 10000)
  162. self.canvas = FigureCanvasTkAgg(self.fig, master=self.f_graf)
  163. self.canvas.draw()
  164. self.canvas.get_tk_widget().grid(column=0, row=0)
  165. self.line, = self.ax.plot([], [], 'ro-')
  166. def init():
  167. self.line.set_data([], [])
  168. return self.line,
  169. def update(frame):
  170. self.line.set_data(self.xdata[:frame], self.ydata[:frame])
  171. return self.line,
  172. self.ani = FuncAnimation(self.fig, update, frames=len(self.xdata),
  173. init_func=init, blit=True, interval=5, repeat=False)
  174. Interface.window.after(100, lambda: None)
  175. self.f_grafbtn = ttk.LabelFrame(self.f_graf, text='Время отоброжения', padding=(8, 10))
  176. self.f_grafbtn.grid(column=1, row=0)
  177. self.tgrafsp = Label(self.f_grafbtn, text="Начало времени, с", fg="black")
  178. self.tgrafsp.grid(column=0, row=0)
  179. self.grafspin = Spinbox(self.f_grafbtn, from_=0, to=1000, increment=100, width=7)
  180. self.grafspin.grid(column=0, row=1)
  181. self.t1grafbtn = Label(self.f_grafbtn, text="Выбор конца времени", fg="black")
  182. self.t1grafbtn.grid(column=0, row=2)
  183. self.button_time1 = Button(self.f_grafbtn, text="Текущее время",
  184. bg="lightgray", fg="black", command=self.clicked_time, state=['disable'])
  185. self.button_time1.grid(column=0, row=3, sticky=EW)
  186. self.tgrafsp1 = Label(self.f_grafbtn, text="Конец времени, с", fg="black")
  187. self.tgrafsp1.grid(column=0, row=4)
  188. self.Time_flag = 'disabled'
  189. self.grafspin1 = Entry(self.f_grafbtn, width=7,state=self.Time_flag)
  190. self.grafspin1.grid(column=0, row=5)
  191. self.spinbox_var1 = StringVar(value=str(0))
  192. self.tgrafspTmin = Label(self.f_grafbtn, text="Нижняя граница, имп/с", fg="black")
  193. self.tgrafspTmin.grid(column=0, row=6)
  194. self.grafspinTmin = Spinbox(self.f_grafbtn, from_=0, to=5000,
  195. textvariable=self.spinbox_var1, increment=500, width=7)
  196. self.grafspinTmin.grid(column=0, row=7)
  197. self.tgrafspTmax = Label(self.f_grafbtn, text="Верхняя граница, имп/с", fg="black")
  198. self.tgrafspTmax.grid(column=0, row=8)
  199. self.spinbox_var2 = StringVar(value=str(10000))
  200. self.grafspinTmax = Spinbox(self.f_grafbtn, from_=5000, to=10000, increment=500,
  201. textvariable=self.spinbox_var2, width=7)
  202. self.grafspinTmax.grid(column=0, row=9)
  203. def ADC_create_Figure(self):
  204. self.ADC_file1 = open('coordinates.txt', 'r')
  205. with self.ADC_file1 as f:
  206. self.ADC_lines = f.readlines()
  207. self.ADC_data = [line.strip().split() for line in self.ADC_lines]
  208. self.ADC_xdata, self.ADC_ydata = zip(*[(float(x), float(y)) for x, y in self.ADC_data])
  209. self.f_graf_ADC = ttk.LabelFrame(Interface.window.scrollable_frame,
  210. text='АЦП канал 1, В', relief=SOLID)
  211. self.f_graf_ADC.grid(column=3, row=1, columnspan=2, rowspan=2)
  212. self.fig_ADC = Figure(figsize=(7, 4), dpi=80)
  213. self.ax_ADC = self.fig_ADC.add_subplot(111)
  214. self.ax_ADC.set_xlabel('Время, с')
  215. self.ax_ADC.set_ylabel('Напряжение, В')
  216. self.ax_ADC.grid(color='black', linewidth=1.0)
  217. self.ax_ADC.set_xlim(0, 3000)
  218. self.ax_ADC.set_ylim(0, 10000)
  219. self.canvas_ADC = FigureCanvasTkAgg(self.fig_ADC, master=self.f_graf_ADC)
  220. self.canvas_ADC.draw()
  221. self.canvas_ADC.get_tk_widget().grid(column=0, row=0)
  222. self.ADC_line, = self.ax_ADC.plot([], [], 'ro-')
  223. def init():
  224. self.ADC_line.set_data([], [])
  225. return self.ADC_line,
  226. def update(frame):
  227. self.ADC_line.set_data(self.ADC_xdata[:frame], self.ADC_ydata[:frame])
  228. return self.ADC_line,
  229. self.ADC_ani = FuncAnimation(self.fig_ADC, update, frames=len(self.ADC_xdata),
  230. init_func=init, blit=True, interval=5, repeat=False)
  231. Interface.window.after(100, lambda: None)
  232. self.f_grafbtnADC = ttk.LabelFrame(self.f_graf_ADC, text='Время отоброжения', padding=(8, 10))
  233. self.f_grafbtnADC.grid(column=1, row=0)
  234. self.tgrafspADC = Label(self.f_grafbtnADC, text="Начало времени, с", fg="black")
  235. self.tgrafspADC.grid(column=0, row=0)
  236. self.grafspinADC = Spinbox(self.f_grafbtnADC, from_=0, to=1000, increment=100, width=7)
  237. self.grafspinADC.grid(column=0, row=1)
  238. self.t1grafbtnADC = Label(self.f_grafbtnADC, text="Выбор конца времени", fg="black")
  239. self.t1grafbtnADC.grid(column=0, row=2)
  240. self.button_time1ADC = Button(self.f_grafbtnADC, text="Текущее время",
  241. bg="lightgray", fg="black", command=self.clicked_timeADC, state=['disable'])
  242. self.button_time1ADC.grid(column=0, row=3, sticky=EW)
  243. self.tgrafsp1ADC = Label(self.f_grafbtnADC, text="Конец времени, с", fg="black")
  244. self.tgrafsp1ADC.grid(column=0, row=4)
  245. self.Time_flagADC = 'disabled'
  246. self.grafspin1ADC = Entry(self.f_grafbtnADC, width=7, state=self.Time_flagADC)
  247. self.grafspin1ADC.grid(column=0, row=5)
  248. self.spinbox_var1ADC = StringVar(value=str(0))
  249. self.tgrafspTminADC = Label(self.f_grafbtnADC, text="Нижняя граница, В", fg="black")
  250. self.tgrafspTminADC.grid(column=0, row=6)
  251. self.grafspinTminADC = Spinbox(self.f_grafbtnADC, from_=0, to=5000,
  252. textvariable=self.spinbox_var1ADC, increment=500, width=7)
  253. self.grafspinTminADC.grid(column=0, row=7)
  254. self.tgrafspTmaxADC = Label(self.f_grafbtnADC, text="Верхняя граница, В", fg="black")
  255. self.tgrafspTmaxADC.grid(column=0, row=8)
  256. self.spinbox_var2ADC = StringVar(value=str(10000))
  257. self.grafspinTmaxADC = Spinbox(self.f_grafbtnADC, from_=5000, to=10000, increment=500,
  258. textvariable=self.spinbox_var2ADC, width=7)
  259. self.grafspinTmaxADC.grid(column=0, row=9)
  260. def TEM_create_Figure(self):
  261. self.TEM_file1 = open('coordinates.txt', 'r')
  262. with self.TEM_file1 as f:
  263. self.TEM_lines = f.readlines()
  264. self.TEM_data = [line.strip().split() for line in self.TEM_lines]
  265. self.TEM_xdata, self.TEM_ydata = zip(*[(float(x), float(y)) for x, y in self.TEM_data])
  266. self.f_graf_TEM = ttk.LabelFrame(Interface.window.scrollable_frame,
  267. text='Температура, С', relief=SOLID)
  268. self.f_graf_TEM.grid(column=1, row=3, columnspan=2, rowspan=2)
  269. self.fig_TEM = Figure(figsize=(7, 4), dpi=80)
  270. self.ax_TEM = self.fig_TEM.add_subplot(111)
  271. self.ax_TEM.set_xlabel('Время, с')
  272. self.ax_TEM.set_ylabel('Температура, С')
  273. self.ax_TEM.grid(color='black', linewidth=1.0)
  274. self.ax_TEM.set_xlim(0, 3000)
  275. self.ax_TEM.set_ylim(0, 10000)
  276. self.canvas_TEM = FigureCanvasTkAgg(self.fig_TEM, master=self.f_graf_TEM)
  277. self.canvas_TEM.draw()
  278. self.canvas_TEM.get_tk_widget().grid(column=0, row=0)
  279. self.TEM_line, = self.ax_TEM.plot([], [], 'ro-')
  280. def init():
  281. self.TEM_line.set_data([], [])
  282. return self.TEM_line,
  283. def update(frame):
  284. self.TEM_line.set_data(self.TEM_xdata[:frame], self.TEM_ydata[:frame])
  285. return self.TEM_line,
  286. self.TEM_ani = FuncAnimation(self.fig_TEM, update, frames=len(self.TEM_xdata),
  287. init_func=init, blit=True, interval=5, repeat=False)
  288. Interface.window.after(100, lambda: None)
  289. self.f_grafbtnTEM = ttk.LabelFrame(self.f_graf_TEM, text='Время отоброжения', padding=(8, 10))
  290. self.f_grafbtnTEM.grid(column=1, row=0)
  291. self.tgrafspTEM = Label(self.f_grafbtnTEM, text="Начало времени, с", fg="black")
  292. self.tgrafspTEM.grid(column=0, row=0)
  293. self.grafspinTEM = Spinbox(self.f_grafbtnTEM, from_=0, to=1000, increment=100, width=7)
  294. self.grafspinTEM.grid(column=0, row=1)
  295. self.t1grafbtnTEM = Label(self.f_grafbtnTEM, text="Выбор конца времени", fg="black")
  296. self.t1grafbtnTEM.grid(column=0, row=2)
  297. self.button_time1TEM = Button(self.f_grafbtnTEM, text="Текущее время",
  298. bg="lightgray", fg="black", command=self.clicked_timeTEM, state=['disable'])
  299. self.button_time1TEM.grid(column=0, row=3, sticky=EW)
  300. self.tgrafsp1TEM = Label(self.f_grafbtnTEM, text="Конец времени, с", fg="black")
  301. self.tgrafsp1TEM.grid(column=0, row=4)
  302. self.Time_flagTEM = 'disabled'
  303. self.grafspin1TEM = Entry(self.f_grafbtnTEM, width=7, state=self.Time_flagTEM)
  304. self.grafspin1TEM.grid(column=0, row=5)
  305. self.spinbox_var1TEM = StringVar(value=str(0))
  306. self.tgrafspTminTEM = Label(self.f_grafbtnTEM, text="Нижняя граница, С", fg="black")
  307. self.tgrafspTminTEM.grid(column=0, row=6)
  308. self.grafspinTminTEM = Spinbox(self.f_grafbtnTEM, from_=0, to=5000,
  309. textvariable=self.spinbox_var1TEM, increment=500, width=7)
  310. self.grafspinTminTEM.grid(column=0, row=7)
  311. self.tgrafspTmaxTEM = Label(self.f_grafbtnTEM, text="Верхняя граница, С", fg="black")
  312. self.tgrafspTmaxTEM.grid(column=0, row=8)
  313. self.spinbox_var2TEM = StringVar(value=str(10000))
  314. self.grafspinTmaxTEM = Spinbox(self.f_grafbtnTEM, from_=5000, to=10000, increment=500,
  315. textvariable=self.spinbox_var2TEM, width=7)
  316. self.grafspinTmaxTEM.grid(column=0, row=9)
  317. def start(self):
  318. self.mennuB()
  319. self.create_widgets_S()
  320. self.create_widgets_W()
  321. self.create_Figure()
  322. self.ADC_create_Figure()
  323. self.TEM_create_Figure()
  324. self.block_control()
  325. Interface.window.mainloop()
  326. def clicked_file(self):
  327. self.file1 = filedialog.askopenfile(filetypes=(("Text files", "*.txt"), ("all files", "*.*")))
  328. assert self.file1 is not None
  329. self.file = os.path.abspath(self.file1.name)
  330. self.txt.delete(0, END)
  331. self.txt.insert(0, self.file)
  332. def clicked_start1(self):
  333. self.button_start.configure(state="disabled")
  334. self.t4.configure(text="Включено", bg="black", fg="green")
  335. self.button_startoff.configure(state="active")
  336. self.seconds1 = time.time()
  337. self.clicked_time()
  338. self.clicked_timeADC()
  339. self.clicked_timeTEM()
  340. def clicked_start2(self):
  341. self.seconds2 = time.time()
  342. self.button_start.configure(state="active")
  343. self.t4.configure(text="Выключено", bg="black", fg="white")
  344. self.button_startoff.configure(state='disabled')
  345. self.grafspin1.configure(state="normal")
  346. self.grafspin1ADC.configure(state="normal")
  347. self.grafspin1TEM.configure(state="normal")
  348. self.IMP_entry.configure(state="normal")
  349. self.ADC_entry.configure(state="normal")
  350. self.TEM_entry.configure(state="normal")
  351. if self.ani is not None:
  352. self.ani.event_source.stop()
  353. self.ani = None
  354. if self.ADC_ani is not None:
  355. self.ADC_ani.event_source.stop()
  356. self.ADC_ani = None
  357. if self.TEM_ani is not None:
  358. self.TEM_ani.event_source.stop()
  359. self.TEM_ani = None
  360. if self.ani1 is not None:
  361. self.ani1.event_source.stop()
  362. self.ani1 = None
  363. if self.ADC_ani1 is not None:
  364. self.ADC_ani1.event_source.stop()
  365. self.ADC_ani1 = None
  366. if self.TEM_ani1 is not None:
  367. self.TEM_ani1.event_source.stop()
  368. self.TEM_ani1 = None
  369. self.indexxx = (self.seconds2 - self.seconds1)
  370. self.grafspin1.delete(0, last=END)
  371. self.grafspin1.insert(0, str(self.xdata[round(self.indexxx * 5)]))
  372. self.grafspin1ADC.delete(0, last=END)
  373. self.grafspin1ADC.insert(0, str(self.ADC_xdata[round(self.indexxx * 5)]))
  374. self.grafspin1TEM.delete(0, last=END)
  375. self.grafspin1TEM.insert(0, str(self.TEM_xdata[round(self.indexxx * 5)]))
  376. self.IMP_entry.delete(0, last=END)
  377. self.IMP_entry.insert(0, str(round(self.ydata[round(self.indexxx * 5)])))
  378. self.ADC_entry.delete(0, last=END)
  379. self.ADC_entry.insert(0, str(round(self.ADC_ydata[round(self.indexxx * 5)])))
  380. self.TEM_entry.delete(0, last=END)
  381. self.TEM_entry.insert(0, str(round(self.TEM_ydata[round(self.indexxx * 5)])))
  382. self.grafspin1.configure(state="disabled")
  383. self.grafspin1ADC.configure(state="disabled")
  384. self.grafspin1TEM.configure(state="disabled")
  385. self.IMP_entry.configure(state="disabled")
  386. self.ADC_entry.configure(state="disabled")
  387. self.TEM_entry.configure(state="disabled")
  388. def clicked_V(self):
  389. if self.m == " 0 B ":
  390. self.m = ' 3.3 B '
  391. self.txt1_fw3.configure(text=' 3.3 B ')
  392. self.but_fw3.configure(text="--->")
  393. else:
  394. self.m = ' 0 B '
  395. self.but_fw3.configure(text='<---')
  396. self.txt1_fw3.configure(text=' 0 B ')
  397. def clicked_time(self):
  398. if self.ani is not None:
  399. self.ani.event_source.stop()
  400. self.ani = None
  401. self.file1 = open(self.file, 'r')
  402. with self.file1 as f:
  403. self.lines = f.readlines()
  404. self.data = [line.strip().split() for line in self.lines]
  405. self.xdata, self.ydata = zip(*[(float(x), float(y) + 100 * (-1) ** (round(float(y)) % 2)) for x, y in self.data])
  406. min_time = self.grafspin.get()
  407. self.xdata = list(filter(lambda x: x >= int(min_time), self.xdata))
  408. self.ax.clear()
  409. self.ax.set_xlabel('Время, с')
  410. self.ax.set_ylabel('Импульсы')
  411. self.ax.grid(color='black', linewidth=1.0)
  412. self.ax.set_xlim(min(self.xdata), 3000)
  413. self.ax.set_ylim(int(self.spinbox_var1.get()),
  414. int(self.spinbox_var2.get()))
  415. self.line, = self.ax.plot([], [], 'ro-')
  416. def init1():
  417. self.line.set_data([], [])
  418. return self.line,
  419. def update1(frame):
  420. self.line.set_data(self.xdata[:frame], self.ydata[:frame])
  421. return self.line,
  422. self.ani1 = FuncAnimation(self.fig, update1, frames=len(self.xdata),
  423. init_func=init1, blit=True, interval=200, repeat=False)
  424. self.canvas.draw()
  425. Interface.window.after(10, lambda: None)
  426. def clicked_timeADC(self):
  427. if self.ADC_ani is not None:
  428. self.ADC_ani.event_source.stop()
  429. self.ADC_ani = None
  430. self.ADC_file1 = open(self.file, 'r')
  431. self.Time_flagADC = 'disabled'
  432. self.grafspin1.configure(state=self.Time_flagADC)
  433. with self.ADC_file1 as f:
  434. self.ADC_lines = f.readlines()
  435. self.ADC_data = [line.strip().split() for line in self.ADC_lines]
  436. self.ADC_xdata, self.ADC_ydata = zip(*[(float(x), float(y)) for x, y in self.ADC_data])
  437. max_time = self.grafspin1ADC.get()
  438. min_time = self.grafspinADC.get()
  439. self.ADC_xdata = list(filter(lambda x: x >= int(min_time), self.ADC_xdata))
  440. self.ax_ADC.clear()
  441. self.ax_ADC.set_xlabel('Время, с')
  442. self.ax_ADC.set_ylabel('Напряжение, В')
  443. self.ax_ADC.grid(color='black', linewidth=1.0)
  444. self.ax_ADC.set_xlim(min(self.ADC_xdata), 3000)
  445. self.ax_ADC.set_ylim(int(self.spinbox_var1ADC.get()),
  446. int(self.spinbox_var2ADC.get()))
  447. self.ADC_line, = self.ax_ADC.plot([], [], 'ro-')
  448. def init1():
  449. self.ADC_line.set_data([], [])
  450. return self.ADC_line,
  451. def update1(frame):
  452. self.ADC_line.set_data(self.ADC_xdata[:frame], self.ADC_ydata[:frame])
  453. return self.ADC_line,
  454. self.ADC_ani1 = FuncAnimation(self.fig_ADC, update1, frames=len(self.ADC_xdata),
  455. init_func=init1, blit=True, interval=200, repeat=False)
  456. self.canvas_ADC.draw()
  457. Interface.window.after(10, lambda: None)
  458. def clicked_timeTEM(self):
  459. if self.TEM_ani is not None:
  460. self.TEM_ani.event_source.stop()
  461. self.TEM_ani = None
  462. self.TEM_file1 = open(self.file, 'r')
  463. self.Time_flagTEM = 'disabled'
  464. self.grafspin1TEM.configure(state=self.Time_flagTEM)
  465. with self.TEM_file1 as f:
  466. self.TEM_lines = f.readlines()
  467. self.TEM_data = [line.strip().split() for line in self.ADC_lines]
  468. self.TEM_xdata, self.TEM_ydata = zip(*[(float(x), float(y)) for x, y in self.TEM_data])
  469. max_time = self.grafspin1TEM.get()
  470. min_time = self.grafspinTEM.get()
  471. self.TEM_xdata = list(filter(lambda x: x >= int(min_time), self.TEM_xdata))
  472. self.ax_TEM.clear()
  473. self.ax_TEM.set_xlabel('Время, с')
  474. self.ax_TEM.set_ylabel('Температура, С')
  475. self.ax_TEM.grid(color='black', linewidth=1.0)
  476. self.ax_TEM.set_xlim(min(self.TEM_xdata), 3000)
  477. self.ax_TEM.set_ylim(int(self.spinbox_var1TEM.get()),
  478. int(self.spinbox_var2TEM.get()))
  479. self.TEM_line, = self.ax_TEM.plot([], [], 'ro-')
  480. def init1():
  481. self.TEM_line.set_data([], [])
  482. return self.TEM_line,
  483. def update1(frame):
  484. self.TEM_line.set_data(self.TEM_xdata[:frame], self.TEM_ydata[:frame])
  485. return self.TEM_line,
  486. self.TEM_ani1 = FuncAnimation(self.fig_TEM, update1, frames=len(self.TEM_xdata),
  487. init_func=init1, blit=True, interval=200, repeat=False)
  488. self.canvas_TEM.draw()
  489. Interface.window.after(10, lambda: None)
  490. def block_control(self):
  491. self.f_BC = ttk.LabelFrame(Interface.window.scrollable_frame, text='Текущее значение данных:', relief=SOLID)
  492. self.f_BC.grid(column=3, row=3, columnspan=2, rowspan=2)
  493. self.text_BC = Label(self.f_BC, text="Кол-во импульсов", fg="black")
  494. self.text_BC.grid(column=0, row=0, pady=10)
  495. self.text_BC_ADC = Label(self.f_BC, text="АЦП канал 1, В", fg="black")
  496. self.text_BC_ADC.grid(column=1, row=0, ipadx=15, pady=10)
  497. self.text_BC_TEM = Label(self.f_BC, text="Температура, С", fg="black")
  498. self.text_BC_TEM.grid(column=2, row=0, ipady=10)
  499. self.impSV = StringVar(value=round(self.ydata[0]))
  500. self.adcSV = StringVar(value=round(self.ADC_ydata[0]))
  501. self.temSV = StringVar(value=round(self.TEM_ydata[0]))
  502. self.IMP_entry = Entry(self.f_BC, width=15, state='disabled', textvariable=self.impSV)
  503. self.IMP_entry.grid(column=0, row=1)
  504. self.ADC_entry = Entry(self.f_BC, width=15, state='disabled', textvariable=self.adcSV)
  505. self.ADC_entry.grid(column=1, row=1, padx=15)
  506. self.TEM_entry = Entry(self.f_BC, width=15, state='disabled', textvariable=self.temSV)
  507. self.TEM_entry.grid(column=2, row=1)
  508. self.bctext = Label(self.f_BC, text="Статус датчика Температуры", fg="black")
  509. self.bctext.grid(column=0, row=2, padx=10, ipady=5)
  510. self.bctext1 = Label(self.f_BC, text="Статус внешнего ЦАП", fg="black")
  511. self.bctext1.grid(column=2, row=2, padx=10, ipady=5)
  512. self.SDT = Label(self.f_BC, text="Работает", fg="black", bg="green")
  513. self.SDT.grid(column=0, row=3, pady=15, padx=10, sticky='NSEW')
  514. self.SVadc = Label(self.f_BC, text="Работает", fg="black", bg="green")
  515. self.SVadc.grid(column=2, row=3, padx=10, pady=15, sticky='NSEW')
  516. self.bctext11 = Label(self.f_BC, text="Проверить статус работы", fg="black")
  517. self.bctext11.grid(column=0, row=4, padx=10, ipady=5)
  518. self.bctext12 = Label(self.f_BC, text="Проинициализировать датчик", fg="black")
  519. self.bctext12.grid(column=2, row=4, padx=10, ipady=5)
  520. self.bcbtn = Button(self.f_BC, text='Проверка')
  521. self.bcbtn.grid(column=0, row=5, padx=10, ipady=5)
  522. self.bcbtn1 = Button(self.f_BC, text='INIT', state=['disable'])
  523. self.bcbtn1.grid(column=2, row=5, padx=10, ipady=5)
  524. self.bctext111 = Label(self.f_BC, text="При запуске exe приложения и сборе данных, проверка датчика температуры автоматическая", fg="black")
  525. self.bctext111.grid(column=0, row=6, columnspan=3, padx=10, ipady=5)
  526. def mennuB(self):
  527. menubar1 = tk.Menu(self.window0)
  528. self.window0.config(menu=menubar1)
  529. setting_menu1 = tk.Menu(menubar1)
  530. setting_menu1.add_command(label='---')
  531. menubar1.add_cascade(label='File', menu=setting_menu1)
  532. setting_menu2 = tk.Menu(menubar1)
  533. setting_menu2.add_command(label='----')
  534. menubar1.add_cascade(label='Edit', menu=setting_menu2)
  535. setting_menu3 = tk.Menu(menubar1)
  536. setting_menu3.add_command(label='---')
  537. menubar1.add_cascade(label='Operate', menu=setting_menu3)
  538. setting_menu4 = tk.Menu(menubar1)
  539. setting_menu4.add_command(label='-----')
  540. menubar1.add_cascade(label='Tools', menu=setting_menu4)
  541. setting_menu5 = tk.Menu(menubar1)
  542. setting_menu5.add_command(label='-----')
  543. menubar1.add_cascade(label='Window', menu=setting_menu5)
  544. setting_menu6 = tk.Menu(menubar1)
  545. setting_menu6.add_command(label='-----')
  546. menubar1.add_cascade(label='Help', menu=setting_menu6)
  547. interface = Interface()
  548. interface.start()