瀏覽代碼

Remove hardcoded numbers

RoGeorge 9 年之前
父節點
當前提交
4115e00996
共有 1 個檔案被更改,包括 20 行新增9 行删除
  1. 20
    9
      OscScreenGrabLAN.py

+ 20
- 9
OscScreenGrabLAN.py 查看文件

18
 save_format = "PNG"
18
 save_format = "PNG"
19
 IP_DS1104Z = "192.168.1.3"
19
 IP_DS1104Z = "192.168.1.3"
20
 
20
 
21
-# Port used by Rigol LXI protocol
21
+# Rigol/LXI specific constants
22
 port = 5555
22
 port = 5555
23
 
23
 
24
+expected_len = 1152068
25
+TMC_header_len = 11
26
+terminator_len = 3
27
+
28
+big_wait = 10
29
+small_wait = 1
30
+
31
+company = 0
32
+model = 1
33
+serial = 2
34
+
24
 # Check parameters
35
 # Check parameters
25
 script_name = os.path.basename(sys.argv[0])
36
 script_name = os.path.basename(sys.argv[0])
26
 
37
 
73
 
84
 
74
 # Check if instrument is indeed a Rigol DS1000Z series
85
 # Check if instrument is indeed a Rigol DS1000Z series
75
 id_fields = instrument_id.split(",")
86
 id_fields = instrument_id.split(",")
76
-if (id_fields[0] != "RIGOL TECHNOLOGIES") or \
77
-	((id_fields[1][:3] != "DS1") and (id_fields[1][-1] != "Z")):
87
+if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
88
+	(id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
78
 	print
89
 	print
79
 	print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
90
 	print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
80
 	sys.exit("ERROR")
91
 	sys.exit("ERROR")
84
 
95
 
85
 # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
96
 # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
86
 timestamp = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime())
97
 timestamp = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime())
87
-filename = path_to_save + id_fields[1] + "_" + id_fields[2] + "_" + timestamp
98
+filename = path_to_save + id_fields[model] + "_" + id_fields[serial] + "_" + timestamp
88
 
99
 
89
 # Ask for an oscilloscope display print screen
100
 # Ask for an oscilloscope display print screen
90
 tn.write("display:data?")
101
 tn.write("display:data?")
91
 print "Receiving..."
102
 print "Receiving..."
92
-buff = tn.read_until("\n", 10)
103
+buff = tn.read_until("\n", big_wait)
93
 
104
 
94
 # Just in case the transfer did not complete in 10 seconds
105
 # Just in case the transfer did not complete in 10 seconds
95
-while len(buff) < 1152068:
96
-	tmp = tn.read_until("\n", 1)
106
+while len(buff) < expected_len:
107
+	tmp = tn.read_until("\n", small_wait)
97
 	if len(tmp) == 0:
108
 	if len(tmp) == 0:
98
 		break
109
 		break
99
 	buff += tmp
110
 	buff += tmp
100
 
111
 
101
-# Strip TMC Blockheader and last 3 bytes
102
-buff = buff[11:-3]
112
+# Strip TMC Blockheader and terminator bytes
113
+buff = buff[TMC_header_len:-terminator_len]
103
 
114
 
104
 # Save as PNG
115
 # Save as PNG
105
 im = Image.open(StringIO.StringIO(buff))
116
 im = Image.open(StringIO.StringIO(buff))

Loading…
取消
儲存