Created
March 19, 2014 12:58
-
-
Save jtornero/9641105 to your computer and use it in GitHub Desktop.
Small script to get NMEA/other data with python
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
#CAPTURA DE DATOS DESDE NMEA | |
import sys | |
import threading | |
import win32gui | |
import serial | |
import signal | |
from socket import socket,AF_INET,SOCK_DGRAM | |
try: | |
fichero,filtro,entero=win32gui.GetSaveFileNameW(Title='Fichero para captura de datos NMEA') | |
puerto_sonda=0 | |
archivo=open(fichero,'w') | |
serie1=serial.Serial() | |
serie1.close() | |
serie1.port=puerto_sonda | |
serie1.baudrate=4800 | |
serie1.databits=8 | |
serie1.parity='N' | |
serie1.stopbits=1 | |
serie1.open() | |
udp=socket(AF_INET,SOCK_DGRAM) | |
puerto_udp=3000 | |
udp.bind(("",puerto_udp)) | |
udp2=socket(AF_INET,SOCK_DGRAM) | |
puerto_udp2=3100 | |
udp2.bind(("",puerto_udp2)) | |
def lee_serie(): | |
while 1: | |
try: | |
datos_sonda=serie1.readline() | |
print "Sonda capturada" | |
archivo.write(datos_sonda) | |
except KeyboardInterrupt: | |
serie1.close() | |
udp2.close() | |
udp.close() | |
archivo.close() | |
sys.exit() | |
def lee_udp_navega(): | |
while 1: | |
try: | |
datos_navegacion,addr=udp.recvfrom(1024) | |
print "Navegacion capturada" | |
archivo.write(datos_navegacion) | |
except KeyboardInterrupt: | |
serie1.close() | |
udp2.close() | |
udp.close() | |
archivo.close() | |
sys.exit() | |
def lee_udp_meteo(): | |
while 1: | |
try: | |
datos_meteo,addr=udp2.recvfrom(1024) | |
print "Meteo Capturado" | |
archivo.write(datos_meteo) | |
except KeyboardInterrupt: | |
serie1.close() | |
udp.close() | |
udp2.close() | |
archivo.close() | |
sys.exit() | |
lectura_sonda = threading.Thread(target=lee_serie) | |
lectura_sonda.start() | |
lectura_navega= threading.Thread(target=lee_udp_navega) | |
lectura_navega.start() | |
lectura_meteo= threading.Thread(target=lee_udp_navega) | |
lectura_meteo.start() | |
except KeyboardInterrupt: | |
serie1.close() | |
udp.close() | |
udp2.close() | |
archivo.close() | |
sys.exit("---------------CAPTURA DE DATOS FINALIZADA--------------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment