Reading unpredictable input from serial port

Hello,

I want to read data from serial port in vision. I have experimented with system.serial but there seems to be no way to read unpredictable inputs. I cannot use readBytesAsString since I dont know how many bytes will be on the input. I cannot use readUntil since I dont know what the last char will be. And reading whole line doesnt work either.

Is there a way to read char by char from the serial port with some delay and if in the time of the delay there is no new char on the input I simply stop reading? Or is there some other way to solve this?

Thanks

Yes, use system.serial.readBytes() with a short timeout.

When waiting for a new message, consider using it with a longer timeout and numberOfBytes set to one. Followed by the long read with short timeout.

1 Like