1

I am working on a BP sensor serial and am using serial readline() to read the output provided by the port, when I initiate the port as serial.Serial('/dev/ttyUSB2',115200,timeout=1) and print the date read using readline() in a loop as follows

for I in range(1,10)
  print('integration')
  print(ser.readline())

the readline() seems to into infinite loop as the program prints integration once and then goes infinite however when I try the same with timeout=0 the program prints integration 9 times with blank space after each line. Need to know what I am doing wrong as the same code seems to work fine with other sensors like laser distance sensor etc. Already referred to Reference1 Reference2 and a few more.

OshoParth
  • 1,402
  • 2
  • 17
  • 38

1 Answers1

0

ser.readline() expects to find a \n character so it keeps reading data until it finds it.

You need to make sure your sensor is sending this default EOL character. If that is not the case, you can specify a different character.

There used to be a simple way to do that but apparently, it's not working anymore. The workaround is to use TextIOWrapper, see here. Pay attention to the first answer to that question to make sure you change the default buffer size.

Marcos G.
  • 2,626
  • 2
  • 5
  • 13