Kaynağa Gözat

Ported for Linux - tested on Debian 7.7.0

Python 2.7.3 and PIL were already included in Debian
RoGeorge 9 yıl önce
ebeveyn
işleme
58e3bbc377
1 değiştirilmiş dosya ile 24 ekleme ve 20 silme
  1. 24
    20
      OscScreenGrabLAN.py

+ 24
- 20
OscScreenGrabLAN.py Dosyayı Görüntüle

1
 __author__ = 'RoGeorge'
1
 __author__ = 'RoGeorge'
2
 #
2
 #
3
-# TODO: Port for Linux
4
 # TODO: Add command line parameters for IP, file path and file format
3
 # TODO: Add command line parameters for IP, file path and file format
5
 # TODO: Add GUI
4
 # TODO: Add GUI
6
 # TODO: Add browse and custom filename selection
5
 # TODO: Add browse and custom filename selection
12
 import StringIO
11
 import StringIO
13
 import sys
12
 import sys
14
 import os
13
 import os
14
+import platform
15
 
15
 
16
 # Update the next lines for your own default settings:
16
 # Update the next lines for your own default settings:
17
 path_to_save = ""
17
 path_to_save = ""
38
 # Print usage
38
 # Print usage
39
 print
39
 print
40
 print "Usage:"
40
 print "Usage:"
41
-print "    " + script_name + " [oscilloscope_IP [save_path [PNG | BMP]]]"
41
+print "    " + script_name + " [oscilloscope_IP [save_path [png | bmp]]]"
42
 print
42
 print
43
 print "Usage examples:"
43
 print "Usage examples:"
44
 print "    " + script_name
44
 print "    " + script_name
61
 
61
 
62
 
62
 
63
 # Check network response (ping)
63
 # Check network response (ping)
64
-response = os.system("ping -n 1 " + IP_DS1104Z + " > nul")
64
+if platform.system() == "Windows":
65
+    response = os.system("ping -n 1 " + IP_DS1104Z + " > nul")
66
+else:
67
+    response = os.system("ping -c 1 " + IP_DS1104Z + " > /dev/null")
68
+
65
 if response != 0:
69
 if response != 0:
66
-	print
67
-	print "No response pinging " + IP_DS1104Z
68
-	print "Check network cables and settings."
69
-	print "You should be able to ping the oscilloscope."
70
+    print
71
+    print "No response pinging " + IP_DS1104Z
72
+    print "Check network cables and settings."
73
+    print "You should be able to ping the oscilloscope."
70
 
74
 
71
 # Open a modified telnet session
75
 # Open a modified telnet session
72
 # The default telnetlib drops 0x00 characters,
76
 # The default telnetlib drops 0x00 characters,
73
 #   so a modified library 'telnetlib_receive_all' is used instead
77
 #   so a modified library 'telnetlib_receive_all' is used instead
74
 tn = telnetlib_receive_all.Telnet(IP_DS1104Z, port)
78
 tn = telnetlib_receive_all.Telnet(IP_DS1104Z, port)
75
-tn.write("*idn?")                       # ask for instrument ID
79
+tn.write("*idn?")  # ask for instrument ID
76
 instrument_id = tn.read_until("\n", 1)
80
 instrument_id = tn.read_until("\n", 1)
77
 
81
 
78
 # Check if instrument is set to accept LAN commands
82
 # Check if instrument is set to accept LAN commands
79
 if instrument_id == "command error":
83
 if instrument_id == "command error":
80
-	print instrument_id
81
-	print "Check the oscilloscope settings."
82
-	print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
83
-	sys.exit("ERROR")
84
+    print instrument_id
85
+    print "Check the oscilloscope settings."
86
+    print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
87
+    sys.exit("ERROR")
84
 
88
 
85
 # Check if instrument is indeed a Rigol DS1000Z series
89
 # Check if instrument is indeed a Rigol DS1000Z series
86
 id_fields = instrument_id.split(",")
90
 id_fields = instrument_id.split(",")
87
 if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
91
 if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
88
-	(id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
89
-	print
90
-	print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
91
-	sys.exit("ERROR")
92
+        (id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
93
+    print
94
+    print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
95
+    sys.exit("ERROR")
92
 
96
 
93
 print "Instrument ID:"
97
 print "Instrument ID:"
94
 print instrument_id
98
 print instrument_id
104
 
108
 
105
 # Just in case the transfer did not complete in the expected time
109
 # Just in case the transfer did not complete in the expected time
106
 while len(buff) < expected_len:
110
 while len(buff) < expected_len:
107
-	tmp = tn.read_until("\n", small_wait)
108
-	if len(tmp) == 0:
109
-		break
110
-	buff += tmp
111
+    tmp = tn.read_until("\n", small_wait)
112
+    if len(tmp) == 0:
113
+        break
114
+    buff += tmp
111
 
115
 
112
 # Strip TMC Blockheader and terminator bytes
116
 # Strip TMC Blockheader and terminator bytes
113
 buff = buff[TMC_header_len:-terminator_len]
117
 buff = buff[TMC_header_len:-terminator_len]

Loading…
İptal
Kaydet