0

(python 2.7.9 on raspbian on raspberry hardware) Reading GPS data from a serial port, I find no way to defeat input buffering. This makes my data come in big blurbs with far too much time in between. I searched this site, and others, and applied "buffering" in various forms (buffering=0, buffering=-1, buffering=5, ... ) on the open statement, all to no avail.

INPORT='/dev/ttyAMA0'
with open(INPORT,'rb',buffering=-1) as infile:
 for INLIN in INFILE:
  INFIELD=INLIN.split(",")
   if INFIELD[0][0:1] == "$":
    print datetime.datetime.now(),INFIELD[0]

sample of output:

2016-04-17 11:59:20.469383 $GNGSA
2016-04-17 11:59:20.471004 $GPGSV
2016-04-17 11:59:20.472660 $GPGSV
2016-04-17 11:59:20.475128 $GPGSV
2016-04-17 11:59:20.475743 $GPGSV
2016-04-17 11:59:20.477228 $GLGSV
2016-04-17 11:59:20.478902 $GLGSV
2016-04-17 11:59:20.480494 $GLGSV
2016-04-17 11:59:20.481994 $GNGLL
2016-04-17 11:59:20.483569 $GNRMC
2016-04-17 11:59:20.484283 $GNVTG
2016-04-17 11:59:33.681551 $GNGGA
2016-04-17 11:59:33.682010 $GNGSA
2016-04-17 11:59:33.682357 $GNGSA
2016-04-17 11:59:33.682693 $GPGSV
2016-04-17 11:59:33.683025 $GPGSV
2016-04-17 11:59:33.683359 $GPGSV
2016-04-17 11:59:33.683680 $GPGSV
2016-04-17 11:59:33.684017 $GLGSV
2016-04-17 11:59:33.684467 $GLGSV
5
  • You can try for INLIN iter(infile.readline,"") Commented Apr 17, 2016 at 12:05
  • Sorry, Padraic, no good: for INLIN iter(infile.readline,""): ^ SyntaxError: invalid syntax Commented Apr 17, 2016 at 12:18
  • Sorry was missing the in for INLIN in iter(infile.readline,"") Commented Apr 17, 2016 at 12:42
  • All clear, Padraig, I must admit I could have found that out by myself if I were less lazy. Many thanks! Commented Apr 17, 2016 at 13:04
  • No worries, it is not an obvious solution. Commented Apr 17, 2016 at 13:07

1 Answer 1

1
with open(INPORT,'rb',buffering=-1) as infile:
 for INLIN in iter(infile.readline,""):
  INFIELD=INLIN.split(",")
  if INFIELD[0] == "$GPRMC" or INFIELD[0] == "$GNRMC":
   print datetime.datetime.now(),INLIN

(as suggested) does the trick perfectly - many thanks to Padraig!

2016-04-17 12:59:23.119878 $GNRMC,125923.00,A,5058.48999,N,00437.42029,E,0.050,,170416,,,D*65
2016-04-17 12:59:24.119874 $GNRMC,125924.00,A,5058.48998,N,00437.42032,E,0.066,,170416,,,D*6C
2016-04-17 12:59:25.119593 $GNRMC,125925.00,A,5058.48999,N,00437.42034,E,0.070,,170416,,,D*6D
2016-04-17 12:59:26.121776 $GNRMC,125926.00,A,5058.49001,N,00437.42033,E,0.082,,170416,,,D*6D
2016-04-17 12:59:27.119076 $GNRMC,125927.00,A,5058.49002,N,00437.42033,E,0.025,,170416,,,D*62
2016-04-17 12:59:28.119765 $GNRMC,125928.00,A,5058.49003,N,00437.42035,E,0.113,,170416,,,D*6E
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.