Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling to async serial. #7

Merged
merged 2 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions dsmr_parser/serial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import serial
import asyncio
import logging

import serial

import serial_asyncio
from dsmr_parser.exceptions import ParseError
from dsmr_parser.parsers import TelegramParser, TelegramParserV2_2

logger = logging.getLogger(__name__)


SERIAL_SETTINGS_V2_2 = {
'baudrate': 9600,
'bytesize': serial.SEVENBITS,
Expand Down Expand Up @@ -44,7 +51,6 @@
}



def is_start_of_telegram(line):
return line.startswith('/')

Expand Down Expand Up @@ -129,6 +135,11 @@ def read(self, queue):
telegram.append(line)

if is_end_of_telegram(line):
# push new parsed telegram onto queue
queue.put_nowait(self.telegram_parser.parse(telegram))
try:
parsed_telegram = self.telegram_parser.parse(telegram)
# push new parsed telegram onto queue
queue.put_nowait(parsed_telegram)
except ParseError:
logger.exception("failed to parse telegram")

telegram = []
9 changes: 5 additions & 4 deletions test/test_parse_v4_2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Test parsing of a DSMR v4.2 telegram."""
import datetime

from decimal import Decimal

import pytz

from dsmr_parser import obis_references as obis
from dsmr_parser import telegram_specifications
from dsmr_parser.objects import CosemObject, MBusObject
from dsmr_parser.parsers import TelegramParser
from dsmr_parser import telegram_specifications
from dsmr_parser import obis_references as obis

TELEGRAM_V4_2 = [
'1-3:0.2.8(42)',
Expand All @@ -22,7 +22,8 @@
'1-0:2.7.0(00.000*kW)',
'0-0:96.7.21(00015)',
'0-0:96.7.9(00007)',
'1-0:99.97.0(3)(0-0:96.7.19)(000103180420W)(0000237126*s)(000101000001W)(2147483647*s)(000101000001W)(2147483647*s)',
('1-0:99.97.0(3)(0-0:96.7.19)(000103180420W)(0000237126*s)'
'(000101000001W)(2147483647*s)(000101000001W)(2147483647*s)'),
'1-0:32.32.0(00000)',
'1-0:52.32.0(00000)',
'1-0:72.32.0(00000)',
Expand Down