从 PLC (micrologix 1100) 获取数据到 python

Get data from PLC (micrologix 1100) to python

I"m looking for get data of a PLC with python to make a lot of work with it.I only need get the "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()

请原谅我的未知数,但我唯一需要知道的是 "Change" (172.16.2.160) ip 到 link 到 PLC,对吗?

"And select the correct tags"

感谢您以后的帮助,对此深表歉意"rare question"我现在不能用 PLC 测试代码。(可能几周后)所以我不能成功地尝试这部分代码。我需要开始在另一部分工作。(只是为了确定我可以用 python 获取数据。如果你知道 python 中的另一个库,请告诉我那个选项)

更改IP地址即可。