質問編集履歴

1

具体的な情報を追記

2017/08/14 04:41

投稿

umechan47
umechan47

スコア17

test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,187 @@
11
11
  このような文字列の処理はどのように考えて対処していけばよいのか,ご教授いただきたいです.
12
12
 
13
13
  よろしくお願いします.
14
+
15
+
16
+
17
+ 追記です
18
+
19
+
20
+
21
+ python2.7 コマンドに対して,<CR><LF>OK<CR><LF> または<CR><LF>#<CR><LF>の返答が帰ってくるようです.
22
+
23
+ コマンドはasciiで書き込み,出力は
24
+
25
+ 計測が開始されると32bitのリトルエンディアンの形式でデータが受信されるようです.
26
+
27
+ 今は以下のコードで動作確認をしているところでした.
28
+
29
+
30
+
31
+ ```python
32
+
33
+ import serial
34
+
35
+ import sys, time
36
+
37
+ import os
38
+
39
+
40
+
41
+ def main():
42
+
43
+
44
+
45
+ port = 'COM5'
46
+
47
+ baudrate = 460800
48
+
49
+ ser = serial.Serial(port, baudrate, timeout=3)
50
+
51
+
52
+
53
+ print 'Starting Up Serial Monitor'
54
+
55
+
56
+
57
+ if ser.isOpen():
58
+
59
+
60
+
61
+ try:
62
+
63
+ ser.flushInput() # flush input buffer, discarding all its contents
64
+
65
+ ser.flushOutput() # flush output buffer, aborting current output
66
+
67
+ time.sleep(1)
68
+
69
+
70
+
71
+ ser.write(bytes("ATCONFIG\r\n"))
72
+
73
+ time.sleep(1)
74
+
75
+ print "Send the command to config sensor"
76
+
77
+
78
+
79
+ ser.write(bytes("ATWRDTRG = 2, 00005, 0\r\n"))
80
+
81
+ time.sleep(1)
82
+
83
+
84
+
85
+
86
+
87
+ ser.write(bytes("ATRDDTRG\r\n"))
88
+
89
+ time.sleep(1)
90
+
91
+
92
+
93
+ print "Send the command to read the trigger setting"
94
+
95
+ print ser.portstr
96
+
97
+ r = ser.readline()
98
+
99
+ print r.encode('hex')
100
+
101
+ print r
102
+
103
+
104
+
105
+ ser.write(bytes("ATENDMES\r\n"))
106
+
107
+ time.sleep(1)
108
+
109
+
110
+
111
+ print "Send the command to start Measurement Mode"
112
+
113
+
114
+
115
+ ser.write(bytes("ATMESMD1\r\n"))
116
+
117
+ time.sleep(1)
118
+
119
+
120
+
121
+ print "Send the command to start Measurement Mode"
122
+
123
+ time.sleep(2.5) # Measurement Wait Time is 220[ms]
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ nline = 0
132
+
133
+ while True:
134
+
135
+ ser.write(b"ATRDDFRM\r\n")
136
+
137
+
138
+
139
+ str = ser.readline()
140
+
141
+ print ser.readline()
142
+
143
+
144
+
145
+ ser.write(bytes("ATREQDAT\r\n"))
146
+
147
+ print "Send the command to request Measurement data"
148
+
149
+
150
+
151
+ nline = nline + 1
152
+
153
+ if (nline >= 1000):
154
+
155
+ break
156
+
157
+
158
+
159
+
160
+
161
+ ser.close()
162
+
163
+
164
+
165
+ except Exception as e:
166
+
167
+ print "error communicating...: " + str(e)
168
+
169
+
170
+
171
+ else:
172
+
173
+ print "cannot open serial port "
174
+
175
+
176
+
177
+
178
+
179
+ # Main Process -----------------------------
180
+
181
+ if __name__ == '__main__':
182
+
183
+ try:
184
+
185
+
186
+
187
+ main()
188
+
189
+
190
+
191
+ except Exception as e:
192
+
193
+ print('Error occurred on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e), e)
194
+
195
+ raise e
196
+
197
+ ```