test_protobuf.py 617 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
from time import sleep
import serial
from interfaces.Protocol.sadapmap_pb2 import MultiChannelReading, ReqMultiChannelReading

with serial.Serial("/dev/ttyUSB0", 115200, timeout=0.1) as ser:
    print("Opened serial")
    while True:
        req = ReqMultiChannelReading()
        req.id.append(0)
        ser.flushInput()
        ser.write(req.SerializeToString())
        reading = MultiChannelReading()
        data = ser.read(128)
        print(data)
        try:
            reading.ParseFromString(data)
        except:
            print("FAILLLLLLLLLLLLLLLLLLLLLLLLL")
        print(reading)
        sleep(0.1)