-
Notifications
You must be signed in to change notification settings - Fork 3
/
modbusClient.py
43 lines (33 loc) · 1.38 KB
/
modbusClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from random import random
from pyModbusTCP.client import ModbusClient
import csv
from time import sleep
import numpy as np
import joblib
import pandas as pd
model = joblib.load('bruno.joblib')
client = ModbusClient('localhost',port = 502)
data = pd.read_csv('dataset1.csv')
df = pd.DataFrame(data)
print(df)
df.columns = ['address','function','length','setpoint','gain','reset rate','deadband','cycle time','rate','system mode','control scheme','pump','solenoid','pressure measurement','crc rate','command response','time','binary result','categorized result','specific result']
df = df.replace('?',-1)
df = df.drop(columns = ['time','binary result','categorized result','specific result'])
for row in range(0,df.size):
#print(df.iloc[row])
r = pd.DataFrame([df.iloc[row]])
print(r)
pred = model.predict(r)
if pred!=[1]:
print(pred)
sleep(.1)
try:
rt =client.write_single_register(row,int(df.iloc[row]))
# print(rt)
except:
pass
str = ['address','function','length','setpoint','gain','reset rate','deadband','cycle time','rate','system mode','control scheme','pump','solenoid','pressure measurement','crc rate']
str1 = str[random*10]
else:
print(f"\n 127.0.0.1:502 {r} behaviour deviation detected \n......... Major deviation detected at {str1} ")
sleep(2)