Browse Source

Merge pull request #56 from ajschmidt8/dev

Serial read_line fixes
main
Scott Petersen 4 years ago
committed by GitHub
parent
commit
d45be9f538
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions
  1. +3
    -3
      alarmdecoder/devices/serial_device.py
  2. +5
    -5
      alarmdecoder/util.py

+ 3
- 3
alarmdecoder/devices/serial_device.py View File

@@ -189,7 +189,7 @@ class SerialDevice(Device):
except serial.SerialException as err: except serial.SerialException as err:
raise CommError('Error reading from device: {0}'.format(str(err)), err) raise CommError('Error reading from device: {0}'.format(str(err)), err)


return data return data.decode('utf-8')


def read_line(self, timeout=0.0, purge_buffer=False): def read_line(self, timeout=0.0, purge_buffer=False):
""" """
@@ -229,7 +229,7 @@ class SerialDevice(Device):
buf = filter_ad2prot_byte(self._device.read(1)) buf = filter_ad2prot_byte(self._device.read(1))


if buf != b'': if buf != b'':
self._buffer += buf[0] self._buffer += buf


if buf == b"\n": if buf == b"\n":
self._buffer = self._buffer.rstrip(b"\r\n") self._buffer = self._buffer.rstrip(b"\r\n")
@@ -252,7 +252,7 @@ class SerialDevice(Device):
finally: finally:
timer.cancel() timer.cancel()


return ret return ret.decode('utf-8')


def purge(self): def purge(self):
""" """


+ 5
- 5
alarmdecoder/util.py View File

@@ -97,14 +97,14 @@ def filter_ad2prot_byte(buf):
""" """
Return the byte sent in back if valid visible terminal characters or line terminators. Return the byte sent in back if valid visible terminal characters or line terminators.
""" """
c = buf[0]; c = buf[0]


if (c == '\n' or c == '\r'): if (c == 10 or c == 13):
return c return buf
if (c > 31 and c < 127): if (c > 31 and c < 127):
return c return buf
else: else:
return '' return b''


def read_firmware_file(file_path): def read_firmware_file(file_path):
""" """


||||||
x
 
000:0
Loading…
Cancel
Save