import matplotlib.pyplot as plt import random import voltmeter import amperemeter from numpy import tanh # Значения part = 1, 2 соответствуют режимам считывания с первой и второй пары приборов соответственно, # режимы 3 и 4 являются тестовыми и генерируют значения самостоятельно def start_measure(part): if part == 1: global v1, i1 v1 = voltmeter.AKIP('/dev/usbtmc0') i1 = amperemeter.B7_78('/dev/ttyUSB0') i1.getCurrentDC() elif part == 2: global v2, i2 v2 = voltmeter.AKIP('/dev/usbtmc0') i2 = amperemeter.B7_78('/dev/ttyUSB1') i2.getCurrentDC() elif part == 0: global i ir = amperemeter.B7_78('/dev/ttyUSB0') i = float(ir.getCurrentDC()) * 10 ** 3 i = float(ir.getCurrentDC()) * 10 ** 3 def get_point(part, num): if part == 1: vol[0][num].append(v1.getVoltageDC()) cur[0][num].append(i1.getCurrentDC() * 10 ** 3) elif part == 2: # global i vol[1][num].append(v2.getVoltageDC()) cur[1][num].append(i2.getCurrentDC() * 10 ** 6) # i = amperemeter.B7_78('/dev/ttyUSB0').getCurrentDC() * 10 ** 3 # print(vol[1], cur[1]) elif part == 3: vol[2][num].append(random.random() * 100) cur[2][num].append(random.random() * 100) elif part == 4: vol[3][num].append(random.random() * 50 - 25) if experiment % 3 == 0: cur[3][num].append( (83 * tanh(15.5 / 83 * vol[3][num][-1]) + 1.7 * vol[3][num][-1]) * (0.98 + random.random() / 25)) elif experiment % 3 == 1: cur[3][num].append( (44 * tanh(8.7 / 44 * vol[3][num][-1]) + 0.9 * vol[3][num][-1]) * (0.98 + random.random() / 25)) else: cur[3][num].append( (22 * tanh(4.4 / 22 * vol[3][num][-1]) + 0.5 * vol[3][num][-1]) * (0.98 + random.random() / 25)) def saveplot(part): plt.figure(figsize=(8, 6)) for j in range(len(vol[part - 1])): # print(vol[part - 1][j], cur[part - 1][j]) plt.scatter(vol[part - 1][j], cur[part - 1][j], marker='o') plt.grid() plt.xlabel('Напряжение, В') if part == 1: plt.ylabel('Ток, мА') else: plt.ylabel('Ток, мкА') plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200) plt.close() def empty_plot(part): vol[part - 1] = [[]] cur[part - 1] = [[]] plt.figure(figsize=(8, 6)) plt.scatter(cur[part - 1][0], vol[part - 1][0], marker='o') plt.grid() plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200) plt.close() def plus_plot(part): global experiment vol[part - 1].append([]) cur[part - 1].append([]) experiment += 1 def minus_plot(part): vol[part - 1].pop() cur[part - 1].pop() if len(vol[part - 1]) == 0: vol[part - 1].append([]) cur[part - 1].append([]) i = 0 vol = [[[]], [[]], [[]], [[]]] cur = [[[]], [[]], [[]], [[]]] experiment = 0