コード例 #1
0
class lan(object):
    def __init__(self, lan_ip, lan_port):
        try:
            self.lan_port = lan_port
            self.lan_ip = lan_ip
            self.tn = Telnet(lan_ip, lan_port)
        except:
            print('lan error')
            sys.exit("ERROR")

    def read(self, command):
        wait = 1
        response = ""
        while response != "1\n":
            self.tn.write("*OPC?\n")
            response = self.tn.read_until("\n", wait)

        self.tn.write(command + "\n")
        return self.tn.read_until("\n", wait)

    def write(self, command):
        self.tn.write(command + "\n")

    def ping(self):
        return os.system("ping -c 1 " + osc_ip + " > /dev/null")

    def close(self):
        self.tn.close()
コード例 #2
0
 def __init__(self, lan_ip, lan_port):
     try:
         self.lan_port = lan_port
         self.lan_ip = lan_ip
         self.tn = Telnet(lan_ip, lan_port)
     except:
         print('lan error')
         sys.exit("ERROR")
コード例 #3
0
# Check network response (ping)
if platform.system() == "Windows":
    response = os.system("ping -n 1 " + IP_DS1104Z + " > nul")
else:
    response = os.system("ping -c 1 " + IP_DS1104Z + " > /dev/null")

if response != 0:
    print
    print "WARNING! No response pinging " + IP_DS1104Z
    print "Check network cables and settings."
    print "You should be able to ping the oscilloscope."

# Open a modified telnet session
# The default telnetlib drops 0x00 characters,
#   so a modified library 'telnetlib_receive_all' is used instead
tn = Telnet(IP_DS1104Z, port)
instrument_id = command(tn, "*IDN?")  # ask for instrument ID

# Check if instrument is set to accept LAN commands
if instrument_id == "command error":
    print "Instrument reply:", instrument_id
    print "Check the oscilloscope settings."
    print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
    sys.exit("ERROR")

# Check if instrument is indeed a Rigol DS1000Z series
id_fields = instrument_id.split(",")
if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
        (id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
    print "Found instrument model", "'" + id_fields[
        model] + "'", "from", "'" + id_fields[company] + "'"
コード例 #4
0
# Check network response (ping)
if platform.system() == "Windows":
    response = os.system("ping -n 1 " + IP_DS1104Z + " > nul")
else:
    response = os.system("ping -c 1 " + IP_DS1104Z + " > /dev/null")

if response != 0:
    print
    print "No response pinging " + IP_DS1104Z
    print "Check network cables and settings."
    print "You should be able to ping the oscilloscope."

# Open a modified telnet session
# The default telnetlib drops 0x00 characters,
#   so a modified library 'telnetlib_receive_all' is used instead
tn = Telnet(IP_DS1104Z, port)
tn.write("*idn?")  # ask for instrument ID
instrument_id = tn.read_until("\n", 1)

# Check if instrument is set to accept LAN commands
if instrument_id == "command error":
    print instrument_id
    print "Check the oscilloscope settings."
    print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
    sys.exit("ERROR")

# Check if instrument is indeed a Rigol DS1000Z series
id_fields = instrument_id.split(",")
if (id_fields[company] != "RIGOL TECHNOLOGIES") or (id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
    print
    print "ERROR: No Rigol from series DS1000Z found at ", IP_DS1104Z
コード例 #5
0
def main(
    hostname,
    output_filename,
    note,
    label1,
    label2,
    label3,
    label4,
    enable_raw,
    enable_debug,
    save_as_csv,
):
    """Take screen captures from DS1000Z-series oscilloscopes.

    \b
    OUTPUT_FILENAME: Name of output file to save.
        - If not supplied then a filename will be auto-generated using the current date/time.
        - If not supplied, and a note was supplied, and capturing a screenshot, then the
          filename will be auto-generated from the note.  If the target filename exists, then
          then the suffix "_n" (with increasing values of n) will be appended.

    Passing the --csv flag will save the capture samples as a CSV file.
    If the --csv flag is NOT passed, then a screenshot (.png) will be saved.
    """

    # -----------------------------
    # Initialize Logging
    # -----------------------------
    # Users may call this app from a different directory, so we will figure out the
    # absolute path to the log file in this module's directory.
    module_path = Path(__file__).parent
    log_path = module_path / Path(os.path.basename(sys.argv[0]) + '.log')
    logging.basicConfig(
        level=logging.DEBUG if enable_debug else logging.INFO,
        format='%(asctime)s - %(levelname)s - %(message)s',
        filename=log_path,
        filemode='w',
    )
    logging.info("***** New run started...")
    logging.info("OS Platform: " + str(platform.uname()))
    log_running_python_versions()

    # -----------------------------
    # Wrangle command line arguments
    # -----------------------------
    extension_validation = (
        (True, '.csv', 'csv data'),
        (False, '.png', 'screenshot'),
    )
    for expect_save_as_csv, expect_suffix, capture_description in extension_validation:
        if (save_as_csv == expect_save_as_csv and output_filename
                and Path(output_filename).suffix != expect_suffix):
            print(
                f'ERROR: Output filename "{output_filename}" should have {expect_suffix}'
                f' suffix when capturing {capture_description}')
            sys.exit()

    with open(module_path / Path(CONFIG_FILENAME), 'r') as file:
        config = json.load(file)
    if hostname is None:
        hostname = config['default_hostname']

    output_dir_path = None
    if output_filename:
        output_dir_path, output_filename = extract_parent(output_filename)
    if output_dir_path is None:
        output_dir_path = (Path.cwd() if config['default_save_path'] == '$cwd'
                           else Path(config['default_save_path']))
    logging.debug(
        f'Preliminary output target: {output_dir_path=}, {output_filename=}')

    # -----------------------------
    # Connect to scope
    # -----------------------------
    if not test_ping(hostname):
        sys.exit()

    # Open a modified telnet session
    # The default telnetlib drops 0x00 characters,
    #   so a modified library 'telnetlib_receive_all' is used instead
    telnet = Telnet(hostname, RIGOL_TELNET_PORT)
    instrument_id = command(telnet, '*IDN?').decode()  # ask for instrument ID

    # Check if instrument is set to accept LAN commands
    if instrument_id == "command error":
        print(f'Instrument reply: {instrument_id}')
        print('Check the oscilloscope settings.')
        print('Utility -> IO Setting -> RemoteIO -> LAN must be ON.')
        sys.exit('ERROR')

    # Check if instrument is indeed a Rigol DS1000Z series
    id_fields = instrument_id.split(",")
    if ((id_fields[INDEX_COMPANY] != "RIGOL TECHNOLOGIES")
            or (id_fields[INDEX_MODEL][:3] != "DS1")
            or (id_fields[INDEX_MODEL][-1] != "Z")):
        print(
            f'Found instrument model "{id_fields[INDEX_MODEL]}" from "{id_fields[INDEX_COMPANY]}"'
        )
        print(f'WARNING: No Rigol from series DS1000Z found at {hostname}\n')
        typed = raw_input('ARE YOU SURE YOU WANT TO CONTINUE? (No/Yes):')
        if typed != 'Yes':
            sys.exit('Nothing done. Bye!')

    print(f'Instrument ID: "{instrument_id.strip()}".')

    # -----------------------------
    # Determine output filename
    # -----------------------------
    timestamp_time = time.localtime()
    if output_filename is None:
        suffix = 'csv' if save_as_csv else 'png'
        output_filename = build_save_filename(timestamp_time,
                                              id_fields[INDEX_MODEL], suffix,
                                              note)
    output_path = output_dir_path / Path(output_filename)
    logging.debug(f'Final output target: {output_path}')

    # -----------------------------
    # Capture
    # -----------------------------
    if save_as_csv:
        capture_csv_data(output_path, telnet)
    else:
        capture_screenshot(output_path, telnet)
        if not enable_raw:
            annotate(output_path, timestamp_time, note, label1, label2, label3,
                     label4)
    telnet.close()
コード例 #6
0
# Check network response (ping)
if platform.system() == "Windows":
    response = os.system("ping -n 1 " + IP_DS1104Z + " > nul")
else:
    response = os.system("ping -c 1 " + IP_DS1104Z + " > /dev/null")

if response != 0:
    print
    print "WARNING! No response pinging " + IP_DS1104Z
    print "Check network cables and settings."
    print "You should be able to ping the oscilloscope."

# Open a modified telnet session
# The default telnetlib drops 0x00 characters,
#   so a modified library 'telnetlib_receive_all' is used instead
tn = Telnet(IP_DS1104Z, port)
instrument_id = command(tn, "*IDN?")    # ask for instrument ID

# Check if instrument is set to accept LAN commands
if instrument_id == "command error":
    print "Instrument reply:", instrument_id
    print "Check the oscilloscope settings."
    print "Utility -> IO Setting -> RemoteIO -> LAN must be ON"
    sys.exit("ERROR")

# Check if instrument is indeed a Rigol DS1000Z series
id_fields = instrument_id.split(",")
if (id_fields[company] != "RIGOL TECHNOLOGIES") or \
        (id_fields[model][:3] != "DS1") or (id_fields[model][-1] != "Z"):
    print "Found instrument model", "'" + id_fields[model] + "'", "from", "'" + id_fields[company] + "'"
    print "WARNING: No Rigol from series DS1000Z found at", IP_DS1104Z