Last active
June 20, 2026 23:30
-
-
Save fabaff/461bae72a0558f34eee1e405c76a147a to your computer and use it in GitHub Desktop.
Reading one number from a PRG320
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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