from pyModbusTCP.client import ModbusClient # Modbus TCP Client
import time
# TCP auto connect on modbus request, close after it
ModbusBMS = ModbusClient(host="192.168.1.100", port=502, unit_id=1, auto_open=True, auto_close=False)
#
bits_addr=1
def ModbusTCP():
global bits_addr
bits_value=ModbusBMS.read_discrete_inputs(bits_addr,1)
print("Bit:",bits_addr,"=","%s" %bits_value)
if __name__ == '__main__':
while True:
ModbusTCP()
time.sleep(2)
bits_addr=bits_addr+1
if bits_addr==16:
bits_addr=0