Converted to take hosts on command line.

This commit is contained in:
Brock Tice 2014-05-11 11:00:22 -06:00
parent b6d56ce312
commit aa52d6b717

View File

@ -8,6 +8,14 @@
import time import time
counter = 0 counter = 0
import sys
if len(sys.argv) <= 1:
print "Usage: read_registers.py <ip address 1> [ip address 2] ..."
exit(1)
hosts = sys.argv[1:]
# import the server implementation # import the server implementation
from pymodbus.client.sync import ModbusTcpClient as ModbusClient from pymodbus.client.sync import ModbusTcpClient as ModbusClient
@ -17,8 +25,6 @@ logging.basicConfig()
log = logging.getLogger('./modbus.error') log = logging.getLogger('./modbus.error')
log.setLevel(logging.ERROR) log.setLevel(logging.ERROR)
hosts = ['192.168.1.2']
for host in hosts: for host in hosts:
print "Host %s" % host print "Host %s" % host
client = ModbusClient(host,502) client = ModbusClient(host,502)