ems/Swich/modules/modbus.py
2014-01-30 18:42:36 +01:00

41 lines
911 B
Python

'''
Created on 05.12.2013
@author: Philipp Rauch
'''
from pymodbus.client.sync import ModbusTcpClient
PAC01, PAC02, PAC03, PAC04 = None, None, None, None
def setup(conf):
### INITIALIZE ###
PAC01 = ModbusTcpClient('10.2.6.5')
PAC02 = ModbusTcpClient('10.2.6.6')
PAC03 = ModbusTcpClient('10.2.6.7')
PAC04 = ModbusTcpClient('10.2.6.8')
### CONNECT ###
PAC01.connect()
PAC02.connect()
PAC03.connect()
PAC04.connect()
def loop(cursor, item):
# PAC01.write_coil(213, 100,2)
# result = PAC01.read_coils(213,1,unit=2)
ans = PAC01.write_registers(213,(1,0),unit=2)
print "Antwort: %s" % ans
res = PAC01.read_holding_registers(213,4,unit=2)
print "Werte: %s" % res.registers
# print result.bits[0]
def close():
### CLOSE ###
PAC01.close()
PAC02.close()
PAC03.close()
PAC04.close()