Skip to content

Commit

Permalink
fix using log before initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Oberdorf committed Apr 28, 2022
1 parent 757653b commit 7c067fa
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/modbus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import FloatToHex
from numpy import little_endian

VERSION='1.0.5'
VERSION='1.0.6'
DEBUG=False
"""
###############################################################################
Expand Down Expand Up @@ -77,6 +77,13 @@ def parse_modbus_result(registers, start_register, big_endian=False):
###############################################################################
"""

# Initialize logger
#FORMAT = ('%(asctime)-15s %(threadName)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
FORMAT = ('%(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.INFO)

# Parsing command line arguments
parser = argparse.ArgumentParser(description='Modbus TCP Client v'+ VERSION)
group = parser.add_argument_group()
Expand Down Expand Up @@ -112,6 +119,9 @@ def parse_modbus_result(registers, start_register, big_endian=False):
sys.exit(1)
if args.debug: DEBUG=True

# change loglevel to DEBUG
if DEBUG: log.setLevel(logging.DEBUG)

# define some values, based on the input
if args.registerType == 1:
register_type = 'Discrete Output Coils'
Expand All @@ -126,16 +136,6 @@ def parse_modbus_result(registers, start_register, big_endian=False):
register_type = 'Analog Input Register'
register_number = 30000 + args.register


# Initialize logger
#FORMAT = ('%(asctime)-15s %(threadName)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
FORMAT = ('%(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()

if DEBUG: log.setLevel(logging.DEBUG)
else: log.setLevel(logging.INFO)

# start the master and connect to slave
if DEBUG:
print('Starting Modbus TCP master client, v' + str(VERSION))
Expand Down

0 comments on commit 7c067fa

Please sign in to comment.