实时显示功率和温度曲线

import paramiko
import time
import pandas as pds
import signal
import matplotlib.pyplot as plt

THERMAL_TEST_SHEET={"time":[],"gap":[],"PL":[],"LM75":[],"INA238_SOC":[]}
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.1.2", port=22, username="root", password="root")
WRITER = pds.ExcelWriter("thermal_test.xlsx", engine="xlsxwriter")

def myHandler(signum, frame):
    print("exit detect board sensor")
    write2excel=pds.DataFrame(THERMAL_TEST_SHEET)
    write2excel.to_excel(WRITER,sheet_name='sheet1',index=False)
    write2excel.plot(x='gap',y='PL',kind='line').figure.savefig('pl.png')
    write2excel.plot(x='gap',y='LM75',kind='line').figure.savefig('lm75.png')
    write2excel.plot(x='gap',y='INA238_SOC',kind='line').figure.savefig('ina238.png')
    worksheet = WRITER.sheets['sheet1']
    worksheet.insert_image('H2', 'pl.png')
    worksheet.insert_image('H22', 'lm75.png')
    worksheet.insert_image('H42', 'ina238.png')
    WRITER.close()
    exit(0)
    
signal.signal(signal.SIGINT, myHandler)
gap=0.5
index=0

draw=[plt.subplots() for x in range(0,3)]

while True:
    try:
            time.sleep(0.5)
            timestamp = time.strftime("%H:%M:%S", time.localtime())
            THERMAL_TEST_SHEET['time'].append(timestamp)
            index+=1
            tmp=gap*index
            THERMAL_TEST_SHEET['gap'].append(float(tmp))
            stdin, stdout, stderr = ssh.exec_command("source /etc/profile && /usr/bin/pl_sersor")
            PL = "%s" % (stdout.read().decode("utf-8"))
            PL = PL.strip("\n")
            THERMAL_TEST_SHEET['PL'].append(float(PL))
            print("PL %s"%PL)
            stdin, stdout, stderr = ssh.exec_command("source /etc/profile && /usr/bin/lm75_sersor")
            LM75 = "%s" % (stdout.read().decode("utf-8"))
            LM75 = LM75.strip("\n") 
            THERMAL_TEST_SHEET['LM75'].append(float(LM75)) 
            print("LM75 %s"%LM75)
            stdin, stdout, stderr = ssh.exec_command("source /etc/profile && /usr/bin/pl_pwr.sh")
            INA238_SOC = "%f" % (
                float(stdout.read().decode("utf-8")) / 1e3,
            )
            INA238_SOC.strip("\n")
            print("INA238_SOC %s"%INA238_SOC)
            THERMAL_TEST_SHEET['INA238_SOC'].append(float(INA238_SOC))
            draw[0][1].cla()
            draw[0][1].set_title("thermal test fpga temp plot")
            draw[0][1].grid()
            draw[0][1].plot(THERMAL_TEST_SHEET['gap'],THERMAL_TEST_SHEET['PL'],label='PL temp')
            draw[0][1].legend()

            draw[1][1].cla()
            draw[1][1].set_title("thermal test LM75 temp plot")
            draw[1][1].grid()
            draw[1][1].plot(THERMAL_TEST_SHEET['gap'],THERMAL_TEST_SHEET['LM75'],label='LM75 temp')
            draw[1][1].legend()

            draw[2][1].cla()
            draw[2][1].set_title("thermal test fpga temp plot")
            draw[2][1].grid()
            draw[2][1].plot(THERMAL_TEST_SHEET['gap'],THERMAL_TEST_SHEET['INA238_SOC'],label='INA238 SOC power')
            draw[2][1].legend()
            plt.pause(0.5)
    except ValueError as e:
        myHandler()

ssh.close()

实时显示功率和温度曲线_第1张图片

你可能感兴趣的:(机器学习,人工智能)