Browse Source

Remove hardcoded numbers

RoGeorge 9 years ago
parent
commit
4115e00996
1 changed files with 20 additions and 9 deletions
  1. 20
    9
      OscScreenGrabLAN.py

+ 20
- 9
OscScreenGrabLAN.py View File

@@ -18,9 +18,20 @@ path_to_save = ""
18 18
 save_format = "PNG"
19 19
 IP_DS1104Z = "192.168.1.3"
20 20
 
21
-# Port used by Rigol LXI protocol
21
+# Rigol/LXI specific constants
22 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 35
 # Check parameters
25 36
 script_name = os.path.basename(sys.argv[0])
26 37
 
@@ -73,8 +84,8 @@ if instrument_id == "command error":
73 84
 
74 85
 # Check if instrument is indeed a Rigol DS1000Z series
75 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 89
 	print
79 90
 	print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
80 91
 	sys.exit("ERROR")
@@ -84,22 +95,22 @@ print instrument_id
84 95
 
85 96
 # Prepare filename as C:\MODEL_SERIAL_YYYY-MM-DD_HH.MM.SS
86 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 100
 # Ask for an oscilloscope display print screen
90 101
 tn.write("display:data?")
91 102
 print "Receiving..."
92
-buff = tn.read_until("\n", 10)
103
+buff = tn.read_until("\n", big_wait)
93 104
 
94 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 108
 	if len(tmp) == 0:
98 109
 		break
99 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 115
 # Save as PNG
105 116
 im = Image.open(StringIO.StringIO(buff))

Loading…
Cancel
Save