Skip to content

Instantly share code, notes, and snippets.

@fabaff
Last active June 20, 2026 23:30
Show Gist options
  • Select an option

  • Save fabaff/461bae72a0558f34eee1e405c76a147a to your computer and use it in GitHub Desktop.

Select an option

Save fabaff/461bae72a0558f34eee1e405c76a147a to your computer and use it in GitHub Desktop.
Reading one number from a PRG320
"Get data from PRG320 and print it as JSON."
import asyncio
import binascii
import json
import serialx
async def main():
"""Get the output of PRG320."""
reader, writer = await serialx.open_serial_connection(
url="/dev/ttyUSB0", baudrate=921600
)
data = await reader.readline()
output = {
"raw": str(repr(data)),
"hex": str(binascii.hexlify(bytearray(data))),
"int": int(bytearray(data).hex(), 16),
}
print(json.dumps(output, sort_keys=True, indent=2))
writer.close()
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment