我正在寻找使用python获取PLC的数据,以便用它做很多工作。我只需要得到" 0"和" 1"值。我发现这个python库pycomm(https://pypi.python.org/pypi/pycomm/1.0.7)这个片段也在哪里:
from pycomm.ab_comm.slc import Driver as SlcDriver
if __name__ == '__main__':
c = SlcDriver(True, 'delete_slc.log')
if c.open('172.16.2.160'):
print c.read_tag('S:1/5')
print c.read_tag('S:60', 2)
print c.write_tag('N7:0', [-30, 32767, -32767])
print c.write_tag('N7:0', 21)
print c.read_tag('N7:0', 10)
print c.write_tag('F8:0', [3.1, 4.95, -32.89])
print c.write_tag('F8:0', 21)
print c.read_tag('F8:0', 3)
print c.write_tag('B3:100', [23, -1, 4, 9])
print c.write_tag('B3:100', 21)
print c.read_tag('B3:100', 4)
print c.write_tag('T4:3.PRE', 431)
print c.read_tag('T4:3.PRE')
print c.write_tag('C5:0.PRE', 501)
print c.read_tag('C5:0.PRE')
print c.write_tag('T4:3.ACC', 432)
print c.read_tag('T4:3.ACC')
print c.write_tag('C5:0.ACC', 502)
print c.read_tag('C5:0.ACC')
c.write_tag('T4:2.EN', 0)
c.write_tag('T4:2.TT', 0)
c.write_tag('T4:2.DN', 0)
print c.read_tag('T4:2.EN', 1)
print c.read_tag('T4:2.TT', 1)
print c.read_tag('T4:2.DN',)
c.write_tag('C5:0.CU', 1)
c.write_tag('C5:0.CD', 0)
c.write_tag('C5:0.DN', 1)
c.write_tag('C5:0.OV', 0)
c.write_tag('C5:0.UN', 1)
c.write_tag('C5:0.UA', 0)
print c.read_tag('C5:0.CU')
print c.read_tag('C5:0.CD')
print c.read_tag('C5:0.DN')
print c.read_tag('C5:0.OV')
print c.read_tag('C5:0.UN')
print c.read_tag('C5:0.UA')
c.write_tag('B3:100', 1)
print c.read_tag('B3:100')
c.write_tag('B3/3955', 1)
print c.read_tag('B3/3955')
c.write_tag('N7:0/2', 1)
print c.read_tag('N7:0/2')
print c.write_tag('O:0.0/4', 1)
print c.read_tag('O:0.0/4')
c.close()
请原谅我的未知,但唯一能让我知道的是否应该知道"改变" (172.16.2.160)ip链接到PLC,对吧?
"并选择正确的标签"
感谢您对未来的帮助,并对此感到抱歉"罕见问题"我现在不能用PLC测试代码。 (也许在几个星期内)所以我不能成功地尝试这部分代码。我需要开始在另一部分工作。(只是为了确保我能用python获取数据。如果你知道python中的另一个库请告诉我那个选项)
答案 0 :(得分:0)
更改IP地址就足够了。