some changes, meter reading works so far

This commit is contained in:
2022-11-20 22:39:46 +01:00
parent f30c8e7eb3
commit 3f0c80fd42
10 changed files with 220 additions and 101 deletions

64
src/pv_controller/pvc.py Normal file
View File

@ -0,0 +1,64 @@
from MeterPublish import MeterPublish
# from TestSubscribe import TestSubscribe
from ModbusBase import ModbusHandler
from loguru import logger
import logging
import argparse
import configparser
import threading
l = logging.getLogger()
for h in l.handlers:
l.removeHandler(h)
deathBell = threading.Event()
def exceptHook(args):
global deathBell
logger.error("Exception in thread caught: {}".format(args))
deathBell.set()
logger.error("rang the death bell")
logger.info("pv controller starting")
parser = argparse.ArgumentParser(description="pv controller")
parser.add_argument('--config', '-f',
help='Config file, default is $pwd/config.ini',
required=False,
default='./config.ini')
args = parser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
# testSubscribeThread = TestSubscribe(config)
# testSubscribeThread.start()
# logger.info("testSubscribe started")
modbusHandler = ModbusHandler(config)
meterPublishThread = MeterPublish(config, modbusHandler)
meterPublishThread.start()
logger.info("meterPublishThread started")
threading.excepthook = exceptHook
logger.info("Threading excepthook set")
logger.info("pv controller is running")
deathBell.wait()
logger.error("pv controller is dying")
# testSubscribeThread.stop()
meterPublishThread.stop()
# testSubscribeThread.join()
# logger.error("testSubscribe joined")
meterPublishThread.join()
logger.error("meterPublishThread joined")
logger.error("pv controller is terminated")