Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
0
Indexable
Never
from pymodbus.client.sync import ModbusTcpClient
from matplotlib.animation import FuncAnimation
import matplotlib.animation as animation
from matplotlib import pyplot as plt
import matplotlib.dates as mdates
from matplotlib import style 
import csv
import time
from datetime import datetime
import tkinter as tk
import pandas as pd 

csvfile= "temp_145.csv"
#connect to modnet-----------------------------------------------------------------------------------
client = ModbusTcpClient('127.0.0.1',502)
print(client.connect())

client.read_holding_registers(0,3)
result=client.read_holding_registers(0,3)
  
    #reg1.registers[0]
    #print("Reg1 :" + str(result.registers[0]))
    #print("Reg2 :" + str(result.registers[1]))
    #print("Reg3 :" + str(result.registers[2]))
timeC= time.strftime("%I")+':' +time.strftime("%M")+':'+time.strftime("%S")
temprature = (result.registers[0])
     #print(temprature)
data=[temprature, timeC]
with open (csvfile,"a") as output:
        writer = csv.writer(output, delimiter=",",lineterminator='\n')
        writer.writerow(data)
        time.sleep(10)


x_vals=[]
y_vals=[]

def animate(i):
    #fig= Figure(figsize = (10,10),dpi = 100)
    df=pd.read_csv('temp_145.csv', header=None)
    df.head

    x_vals=df[0]
    y_vals=df[1]
    
    plt.cla()
    plt.plot(y_vals,x_vals, label='Channel 1')
    plt.legend(loc='upper left')
    plt.tight_layout()
ani = FuncAnimation(plt.gcf(),animate, interval = 1000)   
plt.tight_layout()
plt.show()