Browse Source

Fix for Python 2 and unicode.

pyserial_fix
Scott Petersen 8 years ago
parent
commit
5e1d3f5352
1 changed files with 10 additions and 1 deletions
  1. +10
    -1
      alarmdecoder/decoder.py

+ 10
- 1
alarmdecoder/decoder.py View File

@@ -6,6 +6,7 @@ Provides the main AlarmDecoder class.
.. moduleauthor:: Scott Petersen <scott@nutech.com> .. moduleauthor:: Scott Petersen <scott@nutech.com>
""" """


import sys
import time import time
import re import re


@@ -248,7 +249,15 @@ class AlarmDecoder(object):
""" """


if self._device: if self._device:
self._device.write(str.encode(data))
if isinstance(data, str):
data = str.encode(data)

# Hack to support unicode under Python 2.x
if sys.version_info < (3,):
if isinstance(data, unicode):
data = bytes(data)

self._device.write(data)


def get_config(self): def get_config(self):
""" """


Loading…
Cancel
Save