You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
591 B
Python

#!/usr/bin/env python3
"""
A very basic serial client that can unpack a binary 32 int from a message
and print it to the console.
message: b'H<bytes>\r\n'
"""
import serial
PORT = '/dev/cu.usbmodem2667001'
def main():
print('Connecting to serial port: ', PORT)
with serial.Serial(PORT, 9600, timeout=1) as ser:
_ = ser.readline()
print('Connection made')
while True:
msg = ser.readline()
val = int.from_bytes(msg[1:-2], byteorder='little', signed=False)
print('Recieved: ', val)
if __name__ == '__main__':
main()