Parcourir la source

Querry *OPC? instead of waiting 1 second between commands.

Added logging file, 'OscScreenGrabLAN.py.log'.
RoGeorge il y a 8 ans
Parent
révision
b0030f172f
2 fichiers modifiés avec 10 ajouts et 31 suppressions
  1. 5
    21
      OscScreenGrabLAN.py
  2. 5
    10
      Rigol_functions.py

+ 5
- 21
OscScreenGrabLAN.py Voir le fichier

@@ -44,8 +44,11 @@ __author__ = 'RoGeorge'
44 44
 logging.basicConfig(level=logging.INFO,
45 45
                     format='%(asctime)s - %(levelname)s - %(message)s',
46 46
                     filename=os.path.basename(sys.argv[0]) + '.log')
47
+logging.info("New run started...")
47 48
 logging.info("Log message: INFO level set.")
48 49
 
50
+log_running_Python_versions()
51
+
49 52
 # Update the next lines for your own default settings:
50 53
 path_to_save = "captures/"
51 54
 save_format = "PNG"
@@ -70,7 +73,6 @@ script_name = os.path.basename(sys.argv[0])
70 73
 
71 74
 
72 75
 def print_help():
73
-    # Print usage
74 76
     print
75 77
     print "Usage:"
76 78
     print "    " + "python " + script_name + " png|bmp|csv [oscilloscope_IP [save_path]]"
@@ -100,8 +102,6 @@ if len(sys.argv) <= 1:
100 102
 elif sys.argv[1].lower() not in ["png", "bmp", "csv"]:
101 103
     print_help()
102 104
     print "This file type is not supported: ", sys.argv[1]
103
-    print
104
-    print_running_Python_versions()
105 105
     sys.exit("ERROR")
106 106
 
107 107
 file_format = sys.argv[1].lower()
@@ -132,21 +132,17 @@ instrument_id = command(tn, "*idn?")    # ask for instrument ID
132 132
 
133 133
 # Check if instrument is set to accept LAN commands
134 134
 if instrument_id == "command error":
135
-    print instrument_id
135
+    print "Instrument reply:", instrument_id
136 136
     print "Check the oscilloscope settings."
137 137
     print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
138
-    print
139
-    print_running_Python_versions()
140 138
     sys.exit("ERROR")
141 139
 
142 140
 # Check if instrument is indeed a Rigol DS1000Z series
143 141
 id_fields = instrument_id.split(",")
144 142
 if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
145 143
         (id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
146
-    print
144
+    print "Found instrument model", id_fields[model], "instead of expected model, DS1*Z"
147 145
     print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
148
-    print
149
-    print_running_Python_versions()
150 146
     sys.exit("ERROR")
151 147
 
152 148
 print "Instrument ID:",
@@ -199,8 +195,6 @@ elif file_format == "csv":
199 195
         if response == '1':
200 196
             channel_list += [channel]
201 197
 
202
-    print "Active channels on the display:", channel_list
203
-
204 198
     csv_buff = ""
205 199
     depth = get_memory_depth(tn)
206 200
 
@@ -224,25 +218,15 @@ elif file_format == "csv":
224 218
         # if you get on the oscilloscope screen the error message
225 219
         # "Memory lack in waveform reading!", then decrease max_chunk value
226 220
         max_chunk = 100000      # tested for DS1104Z
227
-        print "max_chunk=", max_chunk
228
-        print "depth=", depth
229
-        print "max_chunk > depth:", max_chunk > depth
230 221
         if max_chunk > depth:
231 222
             max_chunk = depth
232 223
 
233
-        print "max_chunk=", max_chunk
234 224
         n1 = 1
235 225
         n2 = max_chunk
236
-        print "n2=", n2
237 226
         while data_available:
238 227
             display_n1 = n1
239
-            print
240
-            print "n1=", n1
241
-            print "n2=", n2
242 228
             stop_point = is_waveform_from_to(tn, n1, n2)
243
-            print "stop_point=", stop_point
244 229
             if stop_point == 0:
245
-                print_running_Python_versions()
246 230
                 logging.error("ERROR: Stop data point index is Zero while available data is True.")
247 231
                 sys.exit("ERROR")
248 232
             elif stop_point < n1:

+ 5
- 10
Rigol_functions.py Voir le fichier

@@ -6,17 +6,14 @@ import sys
6 6
 import logging
7 7
 
8 8
 
9
-def print_running_Python_versions():
10
-    print "Running Python version:"
11
-    print (sys.version)  # parentheses necessary in python 3.
12
-    print sys.version_info
13
-    print
9
+def log_running_Python_versions():
10
+    logging.info("***** Running Python version:")
11
+    logging.info(str(sys.version) + ", " + str(sys.version_info))         # parentheses required in python 3.
12
+    logging.info(sys.version_info)
14 13
 
15 14
     installed_packages = pip.get_installed_distributions()
16 15
     installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
17
-    print "Installed Python modules:"
18
-    print(installed_packages_list)
19
-    print
16
+    logging.info("Installed Python modules:" + str(installed_packages_list))
20 17
 
21 18
 
22 19
 def command(tn, SCPI):
@@ -75,13 +72,11 @@ def is_waveform_from_to(tn, n1_d, n2_d):
75 72
     elif n2_d < n1_c:
76 73
         # first set n1_d then set n2_d
77 74
 
78
-        print "a ", "n1_d=", n1_d, "n2_d=", n2_d
79 75
         command(tn, "WAV:STAR " + str(n1_d))
80 76
         command(tn, "WAV:STOP " + str(n2_d))
81 77
 
82 78
     else:
83 79
         # first set n2_d then set n1_d
84
-        print "b ", "n2_d", n2_d, "n1_d=", n1_d
85 80
         command(tn, "WAV:STOP " + str(n2_d))
86 81
         command(tn, "WAV:STAR " + str(n1_d))
87 82
 

Chargement…
Annuler
Enregistrer