回答編集履歴
1
コメントを受けての追記
answer
CHANGED
@@ -1,3 +1,45 @@
|
|
1
1
|
落ち着いて考えれば分かると思います。
|
2
2
|
|
3
|
-
`other`スレッドは最初に一度`start()`で起動されて終わりで、その後は、GPSスレッドのなかで緯度経度表示の後で呼び出されるだけです。
|
3
|
+
`other`スレッドは最初に一度`start()`で起動されて終わりで、その後は、GPSスレッドのなかで緯度経度表示の後で呼び出されるだけです。
|
4
|
+
|
5
|
+
#コメントを受けて追記
|
6
|
+
> 当方、これが初めてのPythonでして
|
7
|
+
|
8
|
+
おそらく、プログラミングが初めてですよね?
|
9
|
+
・`other`を`rungps`同様に無限ループにする
|
10
|
+
・`rungps`から`other`を呼び出すのをやめる
|
11
|
+
の2箇所を修正します。
|
12
|
+
|
13
|
+
```Python
|
14
|
+
import time, datetime, threading, serial, micropyGPS
|
15
|
+
|
16
|
+
gps = micropyGPS.MicropyGPS(9, 'dd')
|
17
|
+
|
18
|
+
#関数------------------------------------------------------
|
19
|
+
def rungps():
|
20
|
+
s = serial.Serial('/dev/serial0', 9600, timeout=10)
|
21
|
+
s.readline()
|
22
|
+
while True:
|
23
|
+
sentence = s.readline().decode('utf-8')
|
24
|
+
if sentence[0] != '$':
|
25
|
+
continue
|
26
|
+
for x in sentence:
|
27
|
+
gps.update(x)
|
28
|
+
|
29
|
+
if gps.clean_sentences > 20:
|
30
|
+
print('緯度経度: %2.8f, %2.8f' % (gps.latitude[0], gps.longitu$
|
31
|
+
time.sleep(1.0)
|
32
|
+
#----------------------------------------------------------
|
33
|
+
|
34
|
+
def other():
|
35
|
+
while True:
|
36
|
+
print('ok')
|
37
|
+
time.sleep(2.0)
|
38
|
+
#----------------------------------------------------------
|
39
|
+
if __name__ == "__main__":
|
40
|
+
gpsthread = threading.Thread(target=rungps, args=())
|
41
|
+
otherthread = threading.Thread(target=other)
|
42
|
+
#gpsthread.daemon = True
|
43
|
+
gpsthread.start()
|
44
|
+
otherthread.start()
|
45
|
+
```
|