SHARE
TWEET

Untitled

a guest Jan 24th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import serial, time, sys, threading, datetime, shutil
  2.  
  3. def stream_serial():
  4.     #stream data directly from the serial port
  5.     line = ser.readline()
  6.     line_str = str(line)    
  7.     print line_str
  8.  
  9.  
  10. # configure the serial connections
  11. global ser, BAUDRATE
  12. comnum = '/dev/ttyUSB1'
  13. ser = serial.Serial()
  14. ser.baudrate = 4800
  15. ser.port = comnum
  16. ser.timeout = 2
  17. ser.open()
  18. ser.isOpen()
  19.  
  20. #Prints menu and asks for input
  21. global lat_input, long_input
  22.  
  23. while 1:
  24.     line = ser.readline()
  25.     line_str = str(line)
  26.     #print line_str
  27.     if(line_str[4] == 'G'): # $GPGGA
  28.         if(len(line_str) > 20):
  29.             print(line_str)
  30.         # open txt file and log data
  31.             f = open('nmea.txt', 'a')
  32.             try:
  33.                 f.write('{0:}'.format(line_str))
  34.             finally:
  35.                 f.close()
  36.         else:
  37.             stream_serial()
  38.     #time.sleep(0.2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top