Advertisement
silver2row

serial to file

May 9th, 2022
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # coding=utf-8
  3. """TriviaL example using the thread triumvirate
  4.        agps_thread = AGPS3mechanism()
  5.        agps_thread.stream_data()
  6.        agps_thread.run_thread()
  7.    imported from the agps3threaded.py class AGPS3mechanism.  The unordered associative array
  8.    from the gpsd is then exposed as attributes of that 'data_stream'
  9. """
  10. from time import sleep
  11. import serial
  12. import os
  13. from gps3.agps3threaded import AGPS3mechanism
  14.  
  15. __author__ = 'Moe'
  16. __copyright__ = 'Copyright 2016  Moe'
  17. __license__ = 'MIT'
  18. __version__ = '0.2'
  19.  
  20. agps_thread = AGPS3mechanism()  # Instantiate AGPS3 Mechanisms
  21. agps_thread.stream_data()  # From localhost (), or other hosts, by example, (host='gps.ddns.net')
  22. agps_thread.run_thread()  # Throttle time to sleep after an empty lookup, default 0.2 second, default daemon=True
  23.  
  24. host = "/dev/ttyS2"
  25.  
  26. def __init__():
  27.     while True:  # All data is available via instantiated thread data stream attribute.
  28.         # line #140-ff of /usr/local/lib/python3.5/dist-packages/gps3/agps.py
  29.         print('---------------------')
  30.         print(                   agps_thread.data_stream.time)
  31.         print('Lat:{}   '.format(agps_thread.data_stream.lat))
  32.         print('Lon:{}   '.format(agps_thread.data_stream.lon))
  33.         print('Speed:{} '.format(agps_thread.data_stream.speed))
  34.         print('Course:{}'.format(agps_thread.data_stream.track))
  35.         print('---------------------')
  36.         sleep(5)  # Sleep, or do other things for as long as you like.
  37.  
  38. def make():
  39.     while True:
  40.         f = open('GPS/gps.txt', 'w')
  41.         f.write(host)
  42.         try:
  43.             while True:
  44.                 lat = str('Lat:{} '.format(agps_thread.data_stream.lat))
  45.                 lon = str('Lon:{} '.format(agps_thread.data_stream.lon))
  46.                 f.write(',' + lat + ',' + lon)
  47.                 sleep(1)
  48.         except(KeyboardInterrupt, SystemExit):
  49.             print("Done and now exiting!")
  50.             f.close()
  51. __init__()
  52. make()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement