Created
February 15, 2022 11:48
-
-
Save maxim75/f879cf78b4173d2a116be68587179c1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import datetime | |
ser = serial.Serial("/dev/cu.usbserial-0001", baudrate=9600) | |
ser.flushInput() | |
ser.flushOutput() | |
idx = 0 | |
nmea_data = b"" | |
# skip first line, since it could be incomplete | |
ser.readline() | |
while True: | |
idx += 1 | |
nmea_sentence = ser.readline() | |
nmea_data += nmea_sentence | |
if idx % 100 == 0: | |
print(f"idx: {idx}") | |
if idx % 2000 == 0: | |
# save to file after 2000 sentences added | |
filename = datetime.datetime.utcnow().strftime("data/gps_data_%Y%m%d-%H%M%S.nmea") | |
f = open(filename, "ab") | |
f.write(nmea_data) | |
f.close() | |
nmea_data = b"" |
Author
maxim75
commented
Mar 18, 2023
via email
Try replacing "ab" with "wb". "ab" appends to file and throws error if file
does not exist
…On Sun, 19 Mar 2023 at 00:15, Bi4xe ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
https://prnt.sc/JwD9MHF2F94G Hi sir. I am getting an error like in the
picture, what should I do?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/f879cf78b4173d2a116be68587179c1d#gistcomment-4507544>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGBN6TMJVQYQBNCOVG32NDW4WYOZBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCNBXGM3DMMZQU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment