71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
|
|
|
|
import csv
|
|
from datetime import datetime
|
|
import os
|
|
import sys
|
|
from random import randint
|
|
from time import sleep
|
|
from readConfig import readConfig
|
|
from pycomm.ab_comm.clx import Driver as ClxDriver
|
|
|
|
def readTag(addr, tag):
|
|
time.sleep(0.01)
|
|
c = ClxDriver()
|
|
if c.open(addr):
|
|
try:
|
|
v = c.read_tag(tag)
|
|
# print(v)
|
|
return v
|
|
except Exception:
|
|
print("ERROR RETRIEVING TAG: {}".format(tag))
|
|
c.close()
|
|
print traceback.print_exc()
|
|
pass
|
|
c.close()
|
|
|
|
def writeTag(addr, tag, val, dtype):
|
|
time.sleep(0.01)
|
|
c = ClxDriver()
|
|
if c.open(addr):
|
|
try:
|
|
v = c.write_tag(tag, val, dtype)
|
|
# print(v)
|
|
return v
|
|
except Exception:
|
|
print("ERROR WRITING TAG: {}".format(tag))
|
|
c.close()
|
|
print traceback.print_exc()
|
|
pass
|
|
c.close()
|
|
|
|
def main(fullfilepath):
|
|
configProperties = readConfig()
|
|
errors = []
|
|
with open(fullfilepath, 'rb') as myfile:
|
|
wr = csv.reader(myfile)
|
|
for row in wr:
|
|
if len(row) == 3:
|
|
(tag, value, tagType) = row
|
|
writeTag(configProperties['PLC_IP_ADDRESS'], tag, value, tagType)
|
|
actual = readTag(configProperties['PLC_IP_ADDRESS'], tag)
|
|
verify = False
|
|
if tagType == "REAL":
|
|
verify = actual == float(value)
|
|
elif tagType[-3:] == "INT":
|
|
verify = actual == int(value)
|
|
elif tagType == "BOOL":
|
|
verify = actual == int(value)
|
|
if not verify:
|
|
errors.append( "Validation Error:", tag, "does not equal", value, "(actual value:", actual,")")
|
|
print "Restore Complete with", len(errors), "errors."
|
|
if len(errors) > 0:
|
|
print "-------------------------"
|
|
print "-- ERRORS --"
|
|
print "-------------------------"
|
|
for i in range(0,len(errors)):
|
|
print i+1,"-",errors[i]
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1])
|