일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Struts
- PHP
- Eclipse
- sencha touch
- MFC
- iBATIS
- rowspan
- node.js
- dock
- Spring
- JSON
- MySQL
- Google Map
- ibsheet
- JDOM
- appspresso
- PLSQL
- WebLogic
- tomcat
- Ajax
- GPS
- Android
- 가우스
- 전자정부프레임워크
- oracle
- jsr 296
- phonegap
- 선택적조인
- swingx
- jQuery
Archives
- Today
- Total
Where The Streets Have No Name
GPS 데이터 가져오기 본문
출처 : http://leewoosung.egloos.com/986759
# -*- coding: EUC-KR -*-
import serial #시리얼 포트를 열기위해서 : serial.Serial(..)
import time #시간을 알아내기 위해서 : time.ctime(time.time())
#현재 시리얼 포트를 엽니다.
s_com4 = serial.Serial(port = 3, baudrate = 4800, timeout = 1)
#데이터를 저장할 파일입니다.
dst_file = "c:\\gps_message.txt"
try: #파일에 추가로 열기를 시도해봅니다.
save_file = open(dst_file, 'a')
except: #기존에 파일이 없었다면 쓰기로 엽니다. (새로 하나 만듭니다.)
save_file = open(dst_file, 'w')
while (1): #무한반복입니다.
#현재 시간을 [요일 월 일 시:분:초 연]의 형식으로 알아냅니다.
current_time = time.ctime(time.time())
#시리얼포트로부터의 메시지를 하나씩 받아들입니다.
strgps = s_com4.readline()
#현재 시간과 GPS 메시지를 합칩니다.
save_str = current_time + ' ' + strgps
#합쳐진 메시지를 파일에 저장합니다.
save_file.write(save_str)