Add V2.2 telegram implementation and console read.

This commit is contained in:
Johan Bloemberg
2016-11-06 20:40:01 +01:00
parent 6343bce2ee
commit 90eb6fb3fe
5 changed files with 71 additions and 1 deletions

35
dsmr_parser/__main__.py Normal file
View File

@@ -0,0 +1,35 @@
import argparse
from dsmr_parser.serial import SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, SerialReader
from dsmr_parser import telegram_specifications
from dsmr_parser.obis_references import P1_MESSAGE_TIMESTAMP
def console():
"""Output DSMR data to console."""
parser = argparse.ArgumentParser(description=console.__doc__)
parser.add_argument('--device', default='/dev/ttyUSB0',
help='port to read DSMR data from')
parser.add_argument('--version', default='2.2', choices=['2.2', '4'],
help='DSMR version (2.2, 4)')
args = parser.parse_args()
version = 'V' + args.version.replace('.', '_')
settings = {
'2.2': (SERIAL_SETTINGS_V2_2, telegram_specifications.V2_2),
'4': (SERIAL_SETTINGS_V4, telegram_specifications.V4),
}
serial_reader = SerialReader(
device=args.device,
serial_settings=settings[args.version][0],
telegram_specification=settings[args.version][1],
)
for telegram in serial_reader.read():
for obiref, obj in telegram.items():
if obj:
print(obj.value, obj.unit)
print()