回答編集履歴

1

コメントを受けての追記

2018/11/16 06:20

投稿

otn
otn

スコア84421

test CHANGED
@@ -3,3 +3,87 @@
3
3
 
4
4
 
5
5
  `other`スレッドは最初に一度`start()`で起動されて終わりで、その後は、GPSスレッドのなかで緯度経度表示の後で呼び出されるだけです。
6
+
7
+
8
+
9
+ #コメントを受けて追記
10
+
11
+ > 当方、これが初めてのPythonでして
12
+
13
+
14
+
15
+ おそらく、プログラミングが初めてですよね?
16
+
17
+ ・`other`を`rungps`同様に無限ループにする
18
+
19
+ ・`rungps`から`other`を呼び出すのをやめる
20
+
21
+ の2箇所を修正します。
22
+
23
+
24
+
25
+ ```Python
26
+
27
+ import time, datetime, threading, serial, micropyGPS
28
+
29
+
30
+
31
+ gps = micropyGPS.MicropyGPS(9, 'dd')
32
+
33
+
34
+
35
+ #関数------------------------------------------------------
36
+
37
+ def rungps():
38
+
39
+ s = serial.Serial('/dev/serial0', 9600, timeout=10)
40
+
41
+ s.readline()
42
+
43
+ while True:
44
+
45
+ sentence = s.readline().decode('utf-8')
46
+
47
+ if sentence[0] != '$':
48
+
49
+ continue
50
+
51
+ for x in sentence:
52
+
53
+ gps.update(x)
54
+
55
+
56
+
57
+ if gps.clean_sentences > 20:
58
+
59
+ print('緯度経度: %2.8f, %2.8f' % (gps.latitude[0], gps.longitu$
60
+
61
+ time.sleep(1.0)
62
+
63
+ #----------------------------------------------------------
64
+
65
+
66
+
67
+ def other():
68
+
69
+ while True:
70
+
71
+ print('ok')
72
+
73
+ time.sleep(2.0)
74
+
75
+ #----------------------------------------------------------
76
+
77
+ if __name__ == "__main__":
78
+
79
+ gpsthread = threading.Thread(target=rungps, args=())
80
+
81
+ otherthread = threading.Thread(target=other)
82
+
83
+ #gpsthread.daemon = True
84
+
85
+ gpsthread.start()
86
+
87
+ otherthread.start()
88
+
89
+ ```