2023-04-15 18:35:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
# See https://docs.python.org/3/library/configparser.html
|
|
|
|
|
|
|
|
import configparser
|
2023-05-12 06:17:17 +00:00
|
|
|
import sys
|
2023-04-15 18:35:51 +00:00
|
|
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read('pyPlc.ini')
|
|
|
|
|
|
|
|
def getConfigValue(s):
|
2023-05-12 06:17:17 +00:00
|
|
|
try:
|
|
|
|
return config['general'][s]
|
|
|
|
except:
|
|
|
|
print("Error: seems we have a problem with pyPlc.ini.")
|
|
|
|
print("How to fix: Try to use the docs/pyPlc.ini.template,")
|
|
|
|
print(" copy it into the pyPlc's main folder,")
|
|
|
|
print(" rename it to pyPlc.ini, and edit it for your needs.")
|
|
|
|
sys.exit()
|
2023-04-15 18:35:51 +00:00
|
|
|
|
|
|
|
def getConfigValueBool(s):
|
|
|
|
return config.getboolean('general', s)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("Testing configmodule...")
|
|
|
|
print(str(config.sections()))
|
|
|
|
print(config['general']['mode'])
|
|
|
|
for key in config['general']:
|
|
|
|
print(key + " has value " + config['general'][key])
|
|
|
|
print(config.getboolean('general', 'display_via_serial'))
|