質問編集履歴

1

プログラムの追加

2020/02/17 00:45

投稿

neko3378
neko3378

スコア8

test CHANGED
File without changes
test CHANGED
@@ -50,6 +50,100 @@
50
50
 
51
51
  サイトの3のところにあるプログラムがうまく実行されないのかファイルが作成されません。
52
52
 
53
+ ```
54
+
55
+ #!/usr/bin/env python3
56
+
57
+
58
+
59
+ import serial
60
+
61
+
62
+
63
+ str=[""] * 10
64
+
65
+
66
+
67
+ con=serial.Serial('/dev/ttyAMA0', 115200, timeout=30)
68
+
69
+ print (con.portstr)
70
+
71
+
72
+
73
+ t15 = 0
74
+
75
+ while 1:
76
+
77
+ s=con.readline()
78
+
79
+ if s == b'':
80
+
81
+ if t15 < 40:
82
+
83
+ t15 += 1
84
+
85
+ print("Failure %3d[s]" % (t15 * 15))
86
+
87
+ else:
88
+
89
+ t15 = 0
90
+
91
+ f = open("/home/pi/web/cgi-bin/env_dat.txt", "w", encoding="utf-8")
92
+
93
+ f.write("")
94
+
95
+ f.close()
96
+
97
+ continue
98
+
99
+
100
+
101
+ cs = s.decode('utf-8')
102
+
103
+ try:
104
+
105
+ n = int(cs)
106
+
107
+ except:
108
+
109
+ continue
110
+
111
+
112
+
113
+ i = 0
114
+
115
+ while i < n:
116
+
117
+ s=con.readline()
118
+
119
+ # print (s)
120
+
121
+ cs = s.decode('utf-8')
122
+
123
+ str[i] = cs
124
+
125
+ i += 1
126
+
127
+
128
+
129
+ f = open("/home/pi/web/cgi-bin/env_dat.txt", "w", encoding="utf-8")
130
+
131
+ i = 0
132
+
133
+ while i < n:
134
+
135
+ f.write(str[i])
136
+
137
+ i += 1
138
+
139
+ f.close()
140
+
141
+ ```
142
+
143
+ ### 試したこと
144
+
145
+ 全角スペースの削除やインデントの整理?はしました
146
+
53
147
 
54
148
 
55
149
  ### 発生している問題・エラーメッセージ