Skip to content

Attempt to increase reliability for UART #6

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

Merged
merged 1 commit into from
Aug 10, 2020
Merged
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
16 changes: 8 additions & 8 deletions adafruit_pm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ def __init__(self, uart, reset_pin=None):
super().__init__()

def _read_into_buffer(self):
b = self._uart.read(1)
if not b:
raise RuntimeError("Unable to read from PM2.5 UART")
b = b[0]
if b != 0x42:
raise RuntimeError("Unable to read from PM2.5 UART")
self._buffer[0] = b # read one byte
while True:
b = self._uart.read(1)
if not b:
raise RuntimeError("Unable to read from PM2.5 (no start of frame)")
if b[0] == 0x42:
break
self._buffer[0] = b[0] # first byte and start of frame

remain = self._uart.read(31)
if not remain or len(remain) != 31:
raise RuntimeError("Unable to read from PM2.5 UART")
raise RuntimeError("Unable to read from PM2.5 (incomplete frame)")
for i in range(31):
self._buffer[i + 1] = remain[i]
# print([hex(i) for i in self._buffer])