Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
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
20 changes: 6 additions & 14 deletions 20 src/ppk2_api/ppk2_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,18 @@ def _convert_source_voltage(self, mV: int) -> Tuple[int, int]:

def _read_metadata(self) -> str:
"""Read metadata"""
# try to get metadata from device
for _ in range(0, 5):
accumulated = ""
for _ in range(0, 10):
read = self.ser.read(self.ser.in_waiting)
time.sleep(0.1)

if not read:
continue # No data, try again

# Try decoding the data
continue
try:
metadata = read.decode("utf-8")
accumulated += read.decode("utf-8")
except UnicodeDecodeError:
# If decoding fails, try again in next iteration
continue

# Check if the metadata is valid (i.e., contains "END")
if "END" in metadata:
return metadata

# If we exit the loop, it means we couldn't get valid metadata
if "END" in accumulated:
return accumulated
raise ValueError("Could not retrieve valid metadata from the device.")

def _parse_metadata(self, metadata: str) -> None:
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.