35 lines
794 B
Python
35 lines
794 B
Python
#!/usr/bin/env python
|
|
|
|
import sys
|
|
from pycomm.ab_comm.clx import Driver as ClxDriver
|
|
from readConfigimport readConfig
|
|
|
|
configProperties = readConfig()
|
|
|
|
def main(tagName):
|
|
global configProperties
|
|
c = ClxDriver()
|
|
|
|
def readString(tag):
|
|
read_vals = c.read_array(tag, 82)
|
|
string = filter(lambda b: b != "",map(lambda a: chr(a[1]),read_vals))
|
|
return "".join(string)
|
|
|
|
if c.open(configProperties['PLC_IP_ADDRESS']):
|
|
out = {}
|
|
try:
|
|
result = c.read_tag([tagName])
|
|
if result[0][2] == None:
|
|
raise ValueError('Tag not found')
|
|
out['status'] = "success"
|
|
out['value'] = result[0][1]
|
|
out['type'] = result[0][2]
|
|
except Exception, e:
|
|
out['status'] = "error"
|
|
out['message'] = "Tag not found"
|
|
return out
|
|
|
|
if __name__ == '__main__':
|
|
res = main(sys.argv[1])
|
|
print res
|