ソースを参照

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

Added logging file, 'OscScreenGrabLAN.py.log'.
RoGeorge 7年前
コミット
b0030f172f
2個のファイルの変更10行の追加31行の削除
  1. 5
    21
      OscScreenGrabLAN.py
  2. 5
    10
      Rigol_functions.py

+ 5
- 21
OscScreenGrabLAN.py ファイルの表示

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

+ 5
- 10
Rigol_functions.py ファイルの表示

6
 import logging
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
     installed_packages = pip.get_installed_distributions()
14
     installed_packages = pip.get_installed_distributions()
16
     installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
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
 def command(tn, SCPI):
19
 def command(tn, SCPI):
75
     elif n2_d < n1_c:
72
     elif n2_d < n1_c:
76
         # first set n1_d then set n2_d
73
         # first set n1_d then set n2_d
77
 
74
 
78
-        print "a ", "n1_d=", n1_d, "n2_d=", n2_d
79
         command(tn, "WAV:STAR " + str(n1_d))
75
         command(tn, "WAV:STAR " + str(n1_d))
80
         command(tn, "WAV:STOP " + str(n2_d))
76
         command(tn, "WAV:STOP " + str(n2_d))
81
 
77
 
82
     else:
78
     else:
83
         # first set n2_d then set n1_d
79
         # first set n2_d then set n1_d
84
-        print "b ", "n2_d", n2_d, "n1_d=", n1_d
85
         command(tn, "WAV:STOP " + str(n2_d))
80
         command(tn, "WAV:STOP " + str(n2_d))
86
         command(tn, "WAV:STAR " + str(n1_d))
81
         command(tn, "WAV:STAR " + str(n1_d))
87
 
82
 

読み込み中…
キャンセル
保存