コード例 #1
0
def discover(config, ip_address, bus_addresses, port):
    """Connect to the target IP address and log the weather station output for the given bus addresses
       Do not write a log entry"""

    start_time = time.time()

    # Make sure its at least debug level 1
    if config.verbosity == 0:
        config.verbosity = 1

    for weather_addr in ap.parse_address_list(bus_addresses):
        attempts = 3
        while attempts > 0:
            # Try 3 times to make sure a successfull read
            retval = read_weather(ip_address, port, str(weather_addr), False,
                                  "", config.verbosity)
            if retval:
                # break
                break
            time.sleep(0.1)  # ... wait between reads
            attempts -= 1

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")
コード例 #2
0
def get(config, ip_address, bus_addresses, output_directory, strings, port):
    """Connect to the target IP address and log the string output for the given bus addresses"""
    # If the logging directory doesn't exist, create it
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    start_time = time.time()

    # convert string_count
    string_count, result = ap.convert_to_int(strings)
    if not result:
        print("Strings must be an integer")
        sys.exit(2)

    for string_addr in ap.parse_address_list(bus_addresses):
        attempts = 3
        while attempts > 0:
            # Try 3 times to make sure a successfull read
            retval = read_string(ip_address, port, str(string_addr),
                                 string_count, True, output_directory,
                                 config.verbosity)
            if retval:
                # break
                break
            time.sleep(0.1)  # ... wait between reads
            attempts -= 1

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")
コード例 #3
0
def discover(config, ip_address, bus_addresses, strings, port):
    """Connect to the target IP address and log the string output for the given bus addresses
       Do not write a log entry"""

    start_time = time.time()

    # Make sure its at least debug level 1
    if config.verbosity == 0:
        config.verbosity = 1

    # convert string_count
    string_count, result = ap.convert_to_int(strings)
    if not result:
        print("Strings must be an integer")
        sys.exit(2)

    for string_addr in ap.parse_address_list(bus_addresses):
        attempts = 3
        while attempts > 0:
            # Try 3 times to make sure a successfull read
            retval = read_string(ip_address, port, str(string_addr),
                                 string_count, False, "", config.verbosity)
            if retval:
                # break
                break
            time.sleep(0.1)  # ... wait between reads
            attempts -= 1

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")

    pass
コード例 #4
0
def get(config, ip_address, bus_addresses, output_directory, port):
    """Connect to the target IP address and log the inverter output for the given bus addresses"""
    # If the logging directory doesn't exist, create it
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    start_time = time.time()

    for inverter_addr in ap.parse_address_list(bus_addresses):
        time.sleep(1) # ... wait between reads
        # First get the inverter parameter data
        header, line, retval = read_inverter(ip_address, port, str(inverter_addr), config.verbosity)
        if retval:
            # Write the log entry, as a date entry in the log directory
            write_line(line, ip_address, str(inverter_addr), output_directory, header, config.verbosity)

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")
コード例 #5
0
def discover(config, ip_address, port, bus_addresses):
    """Connect to the target IP address and run a scan of 485 addresses"""

    start_time = time.time()

    for inverter_addr in ap.parse_address_list(bus_addresses):
        time.sleep(1) # ... wait between reads
        header, line, retval = read_inverter(ip_address, port, str(inverter_addr), config.verbosity)
        if retval:
            print("Found inverter at IP Address: ", ip_address, " and RS485 address: ", inverter_addr)
            if config.verbosity > 0:
                print("Header: ", header)
                print("Line: ", line)
        else:
            print("NO inverter/not responding at IP Address: ", ip_address, " and RS485 address: ", inverter_addr)

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")
コード例 #6
0
def log(config, device, modbus_addresses, output_directory, baud, port):
    """Connect to the target IP address and log the inverter output for the given bus addresses"""

    # If the logging directory doesn't exist, create it
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    # Check that no other scripts are running
    # The pidfile is based on the device, since there are multiple scripts running
    pidfile = PIDFILE + device.replace('/', '-') + '.pid'
    if ap.check_pidfile(pidfile, config.verbosity):
        print("This script is already running")
        sys.exit(4)

    conn_type = 'tcp'
    try:
        socket.inet_aton(device)
    except socket.error:
        conn_type = 'rtu'

    start_time = time.time()

    # This will check each address
    for address in ap.parse_address_list(modbus_addresses):
        count = 0
        while count < ATTEMPTS:
            retval = log_devices(device, address, conn_type, baud, port,
                                 output_directory, config.verbosity)
            if retval:
                break
            count += 1
            time.sleep(1)

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")

    # Remove the PID file
    if os.path.isfile(pidfile):
        os.unlink(pidfile)
コード例 #7
0
def get(config, ip_address, bus_addresses, output_directory, port):
    """Connect to the target IP address and log the weather station output for the given bus addresses"""
    # If the logging directory doesn't exist, create it
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)

    start_time = time.time()

    for weather_addr in ap.parse_address_list(bus_addresses):
        attempts = 3
        while attempts > 0:
            # Try 3 times to make sure a successfull read
            retval = read_weather(ip_address, port, str(weather_addr), True,
                                  output_directory, config.verbosity)
            if retval:
                # break
                break
            time.sleep(0.1)  # ... wait between reads
            attempts -= 1

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")
コード例 #8
0
def discover(config, device, modbus_addresses, baud, port):
    """Connect to the target IP address and run a scan of all Sunspec devices"""

    # Check that no other scripts are running
    # The pidfile is based on the device, since there are multiple scripts running
    pidfile = PIDFILE + device.replace('/', '-') + '.pid'
    if ap.check_pidfile(pidfile, config.verbosity):
        print("This script is already running")
        sys.exit(4)

    conn_type = 'tcp'
    try:
        socket.inet_aton(device)
    except socket.error:
        conn_type = 'rtu'

    start_time = time.time()

    # This will check each address
    for address in ap.parse_address_list(modbus_addresses):
        count = 0
        while count < ATTEMPTS:
            retval = discover_devices(device, address, conn_type, baud, port,
                                      config.verbosity)
            if retval:
                break
            count += 1
            time.sleep(1)

    elapsed_time = time.time() - start_time
    if config.verbosity > 0:
        print("This request took: ", elapsed_time, " seconds.")

    # Remove the PID file
    if os.path.isfile(pidfile):
        os.unlink(pidfile)