質問編集履歴
1
具体的な情報を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,4 +4,96 @@
|
|
4
4
|
'\xe6\x80\x98\x80\x1e\x0c\xe6\x80\x98\x80'
|
5
5
|
|
6
6
|
このような文字列の処理はどのように考えて対処していけばよいのか,ご教授いただきたいです.
|
7
|
-
よろしくお願いします.
|
7
|
+
よろしくお願いします.
|
8
|
+
|
9
|
+
追記です
|
10
|
+
|
11
|
+
python2.7 コマンドに対して,<CR><LF>OK<CR><LF> または<CR><LF>#<CR><LF>の返答が帰ってくるようです.
|
12
|
+
コマンドはasciiで書き込み,出力は
|
13
|
+
計測が開始されると32bitのリトルエンディアンの形式でデータが受信されるようです.
|
14
|
+
今は以下のコードで動作確認をしているところでした.
|
15
|
+
|
16
|
+
```python
|
17
|
+
import serial
|
18
|
+
import sys, time
|
19
|
+
import os
|
20
|
+
|
21
|
+
def main():
|
22
|
+
|
23
|
+
port = 'COM5'
|
24
|
+
baudrate = 460800
|
25
|
+
ser = serial.Serial(port, baudrate, timeout=3)
|
26
|
+
|
27
|
+
print 'Starting Up Serial Monitor'
|
28
|
+
|
29
|
+
if ser.isOpen():
|
30
|
+
|
31
|
+
try:
|
32
|
+
ser.flushInput() # flush input buffer, discarding all its contents
|
33
|
+
ser.flushOutput() # flush output buffer, aborting current output
|
34
|
+
time.sleep(1)
|
35
|
+
|
36
|
+
ser.write(bytes("ATCONFIG\r\n"))
|
37
|
+
time.sleep(1)
|
38
|
+
print "Send the command to config sensor"
|
39
|
+
|
40
|
+
ser.write(bytes("ATWRDTRG = 2, 00005, 0\r\n"))
|
41
|
+
time.sleep(1)
|
42
|
+
|
43
|
+
|
44
|
+
ser.write(bytes("ATRDDTRG\r\n"))
|
45
|
+
time.sleep(1)
|
46
|
+
|
47
|
+
print "Send the command to read the trigger setting"
|
48
|
+
print ser.portstr
|
49
|
+
r = ser.readline()
|
50
|
+
print r.encode('hex')
|
51
|
+
print r
|
52
|
+
|
53
|
+
ser.write(bytes("ATENDMES\r\n"))
|
54
|
+
time.sleep(1)
|
55
|
+
|
56
|
+
print "Send the command to start Measurement Mode"
|
57
|
+
|
58
|
+
ser.write(bytes("ATMESMD1\r\n"))
|
59
|
+
time.sleep(1)
|
60
|
+
|
61
|
+
print "Send the command to start Measurement Mode"
|
62
|
+
time.sleep(2.5) # Measurement Wait Time is 220[ms]
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
nline = 0
|
67
|
+
while True:
|
68
|
+
ser.write(b"ATRDDFRM\r\n")
|
69
|
+
|
70
|
+
str = ser.readline()
|
71
|
+
print ser.readline()
|
72
|
+
|
73
|
+
ser.write(bytes("ATREQDAT\r\n"))
|
74
|
+
print "Send the command to request Measurement data"
|
75
|
+
|
76
|
+
nline = nline + 1
|
77
|
+
if (nline >= 1000):
|
78
|
+
break
|
79
|
+
|
80
|
+
|
81
|
+
ser.close()
|
82
|
+
|
83
|
+
except Exception as e:
|
84
|
+
print "error communicating...: " + str(e)
|
85
|
+
|
86
|
+
else:
|
87
|
+
print "cannot open serial port "
|
88
|
+
|
89
|
+
|
90
|
+
# Main Process -----------------------------
|
91
|
+
if __name__ == '__main__':
|
92
|
+
try:
|
93
|
+
|
94
|
+
main()
|
95
|
+
|
96
|
+
except Exception as e:
|
97
|
+
print('Error occurred on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e), e)
|
98
|
+
raise e
|
99
|
+
```
|