예제 #1
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate usage of the CAN protocol API.")

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()
        with openDwfDevice(
                dwf, serial_number_filter=args.serial_number_filter) as device:
            demo_can_protocol_api(device.digitalCan)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(description="Demonstrate LED control for the Digital Discovery.")

    DEFAULT_MODULATION_FREQUENCY = 1.0

    parser.add_argument(
            "-sn", "--serial-number-filter",
            type=str,
            nargs='?',
            dest="serial_number_filter",
            help="serial number filter to select a specific Digilent Waveforms device"
        )

    parser.add_argument(
            "-f", "--modulation-frequency",
            type=float,
            default=DEFAULT_MODULATION_FREQUENCY,
            dest="modulation_frequency",
            help="LED modulation frequency (default: {} Hz)".format(DEFAULT_MODULATION_FREQUENCY)
        )

    args = parser.parse_args()

    dwf = DwfLibrary()
    try:
        with openDwfDevice(dwf, enum_filter = DwfEnumFilter.DDiscovery,
                           serial_number_filter=args.serial_number_filter) as device:
            demo_led_brightness_device_parameter(device, args.modulation_frequency)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate DigitalOut instrument usage.")

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()

        # A helper function to select the most suitable configuration.
        # Select the first configuration with the highest possible "DigitalOutBufferSize" configuration parameter.
        def maximize_digital_out_buffer_size(configuration_parameters):
            return configuration_parameters[
                DwfEnumConfigInfo.DigitalOutBufferSize]

        with openDwfDevice(
                dwf,
                serial_number_filter=args.serial_number_filter,
                score_func=maximize_digital_out_buffer_size) as device:
            demo_digital_out_instrument_api(device.digitalOut)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #4
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate simplest possible AnalogIn instrument usage.")

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()
        with openDwfDevice(
                dwf, serial_number_filter=args.serial_number_filter) as device:
            demo_analog_input_instrument_api_simple(device.analogIn)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #5
0
def test2():

    # 2 regimes: attenuation >= 10 and attenuation < 10.

    dwf = DwfLibrary()

    with dwf.device.open(-1) as device:

        analogIn = device.analogIn

        CH1 = 0
        CH2 = 1

        channel_index = CH1

        data_dtype = np.dtype([("attenuation", np.float64), ("offset", np.float64), ("range", np.float64)])
        data = []

        for value in np.linspace(0.01, 100.00, 10000):
            analogIn.reset()
            analogIn.channelAttenuationSet(channel_index, value)

            curr_attenuation = analogIn.channelAttenuationGet(channel_index)
            curr_offset      = analogIn.channelOffsetGet(channel_index)
            curr_range       = analogIn.channelRangeGet(channel_index)

            assert curr_attenuation == value

            data.append((curr_attenuation, curr_offset, curr_range))

            print(curr_attenuation, curr_offset, curr_range)

        data = np.array(data, dtype=data_dtype)

        np.save("att.npy", data)
예제 #6
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Show AnalogOut channel information.")

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    args = parser.parse_args()

    dwf = DwfLibrary()

    # A helper function to select the most suitable device configuration.
    # Select the first configuration with the highest available "AnalogOutChannelCount" configuration parameter.
    def maximize_analog_out_channel_count(configuration_parameters):
        return configuration_parameters[
            DwfEnumConfigInfo.AnalogOutChannelCount]

    with openDwfDevice(dwf,
                       serial_number_filter=args.serial_number_filter,
                       score_func=maximize_analog_out_channel_count) as device:
        show_analog_out_channel_info(device.analogOut)
예제 #7
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate effect of the AnalogOut symmetry setting.")

    DEFAULT_NUM_PERIODS = 3

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    parser.add_argument(
        "-np",
        "--num-periods",
        type=int,
        default=DEFAULT_NUM_PERIODS,
        dest="num_periods",
        help="number of periods of the function (default: {})".format(
            DEFAULT_NUM_PERIODS))

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()

        # A helper function to select the most suitable configuration.
        # Select the first configuration with the highest possible "AnalogInBufferSize" configuration parameter.
        def maximize_analog_in_buffer_size(configuration_parameters):
            return configuration_parameters[
                DwfEnumConfigInfo.AnalogInBufferSize]

        with openDwfDevice(
                dwf,
                serial_number_filter=args.serial_number_filter,
                score_func=maximize_analog_in_buffer_size) as device:
            analog_output_am_modulation_demo(device, args.num_periods)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #8
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description=
        "Demonstrate usage of the I2C protocol API with an ADXL345 accelerometer."
    )

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    parser.add_argument(
        "--use-alt-address",
        action='store_true',
        dest="use_alt_address",
        help=
        "use alternate I2C address (0x53) instead of default I2C address (0x1d) for the ADXL345."
    )

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()
        with openDwfDevice(
                dwf, serial_number_filter=args.serial_number_filter) as device:
            set_positive_supply_voltage(device.analogIO, 3.3)
            demo_i2c_protocol_api(device.digitalI2c, args.use_alt_address)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #9
0
def test3():

    # We reset, set the attenuation to some constant, then sweep over the offset.

    # We try to see if we understand what values the channelOffset can take.

    dwf = DwfLibrary()

    with dwf.device.open(-1) as device:

        analogIn = device.analogIn

        analogIn.reset()

        CH1 = 0
        CH2 = 1

        channel_index = CH1

        data_dtype = np.dtype([("vary", np.float64), ("attenuation", np.float64), ("offset", np.float64), ("range", np.float64)])

        data = []
        for vary in np.linspace(1.0, 2.0, 10001):
            analogIn.reset()
            analogIn.channelOffsetSet(channel_index, vary)

            curr_attenuation = analogIn.channelAttenuationGet(channel_index)
            curr_offset      = analogIn.channelOffsetGet(channel_index)
            curr_range       = analogIn.channelRangeGet(channel_index)

            data.append((vary, curr_attenuation, curr_offset, curr_range))

            print(vary, curr_attenuation, curr_offset, curr_range)

        data = np.array(data, dtype=data_dtype)

        np.save("vary_offset.npy", data)
예제 #10
0
def main():
    """Parse arguments and start AnalogIO demo."""

    parser = argparse.ArgumentParser(description="Demonstrate usage of the AnalogIO functionality.")

    parser.add_argument(
            "-sn", "--serial-number-filter",
            type=str,
            nargs='?',
            dest="serial_number_filter",
            help="serial number filter to select a specific Digilent Waveforms device"
        )

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()
        with openDwfDevice(dwf, serial_number_filter = args.serial_number_filter) as device:
            demo_analog_io_api(device.analogIO)
            demo_analog_io_continuous_readout(device.analogIO, "USB Monitor")
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #11
0
def list_devices(use_obsolete_api: bool, list_configurations: bool,
                 full_tooltips_flag: bool):
    """List the devices supported by the DWF library."""

    # pylint: disable = too-many-locals, too-many-branches, too-many-statements, too-many-nested-blocks

    dwf = DwfLibrary()

    num_devices = dwf.deviceEnum.enumerateDevices()

    if num_devices == 0:
        print("No Digilent Waveforms devices found.")

    for device_index in range(num_devices):

        device_type = dwf.deviceEnum.deviceType(device_index)
        is_open = dwf.deviceEnum.deviceIsOpened(device_index)
        user_name = dwf.deviceEnum.userName(device_index)
        device_name = dwf.deviceEnum.deviceName(device_index)
        serial = dwf.deviceEnum.serialNumber(device_index)

        if num_devices == 1:
            header = "Device information for device #{} ({} device found)".format(
                device_index, num_devices)
        else:
            header = "Device information for device #{} ({} of {} devices found)".format(
                device_index, device_index + 1, num_devices)

        print(header)
        print("=" * len(header))
        print()
        print("  device ........... : {}".format(device_type[0]))
        print("  version .......... : {}".format(device_type[1]))
        print("  open ............. : {}".format(is_open))
        print("  user_name ........ : {!r}".format(user_name))
        print("  device_name ...... : {!r}".format(device_name))
        print("  serial ........... : {!r}".format(serial))
        print()

        if use_obsolete_api:

            ai_channels = dwf.deviceEnum.analogInChannels(device_index)
            ai_buffer_size = dwf.deviceEnum.analogInBufferSize(device_index)
            ai_bits = dwf.deviceEnum.analogInBits(device_index)
            ai_frequency = dwf.deviceEnum.analogInFrequency(device_index)

            print("  Analog-in information (obsolete API)")
            print("  ------------------------------------")
            print()
            print("  number of channels ...... : {!r}".format(ai_channels))
            print("  buffer size ............. : {!r}".format(ai_buffer_size))
            print("  bits .................... : {!r}".format(ai_bits))
            print("  frequency ............... : {!r}".format(ai_frequency))
            print()

        if list_configurations:

            # This regexp defines the strings that are printed directly (not via the string lookup table).
            re_short_strings = re.compile("^[A-Za-z0-9._]{1,8}$")

            configuration_data = {}

            num_config = dwf.deviceEnum.enumerateConfigurations(device_index)

            string_lookup_table: Dict[str, str] = {}

            for configuration_parameter in DwfEnumConfigInfo:

                for configuration_index in range(num_config):
                    config_value = str(
                        dwf.deviceEnum.configInfo(configuration_index,
                                                  configuration_parameter))

                    if not full_tooltips_flag and configuration_parameter == DwfEnumConfigInfo.TooltipText:
                        shorthand = "({})".format(len(config_value))
                        configuration_data[(
                            configuration_index,
                            configuration_parameter)] = shorthand
                    elif config_value in string_lookup_table:
                        configuration_data[(configuration_index, configuration_parameter)] = \
                            string_lookup_table[config_value]
                    elif not re_short_strings.match(config_value):
                        shorthand = "[{}]".format(len(string_lookup_table))
                        string_lookup_table[config_value] = shorthand
                        configuration_data[(
                            configuration_index,
                            configuration_parameter)] = shorthand
                    else:
                        configuration_data[(
                            configuration_index,
                            configuration_parameter)] = config_value

            print("  Configuration:          {}".format("  ".join(
                "{:8d}".format(configuration_index)
                for configuration_index in range(num_config))))
            print("  ----------------------  {}".format("  ".join(
                "--------" for configuration_index in range(num_config))))

            for configuration_parameter in DwfEnumConfigInfo:

                if not full_tooltips_flag and configuration_parameter == DwfEnumConfigInfo.TooltipText:
                    parameter_name = "{} (length)".format(
                        configuration_parameter.name)
                else:
                    parameter_name = configuration_parameter.name

                print("  {:22}  {}".format(
                    parameter_name,
                    "  ".join("{:>8s}".format(configuration_data[(
                        configuration_index, configuration_parameter)])
                              for configuration_index in range(num_config))))
            print()

            if string_lookup_table:

                max_width = 80

                print(
                    "  Strings referenced in the preceding table (with newlines replaced by '•'):"
                )
                print()
                for (k, v) in string_lookup_table.items():
                    k = k.replace('\n', '•')
                    idx = 0
                    while True:
                        if idx == 0:
                            print("  {:<4} {!r}".format(
                                v, k[idx:idx + max_width]))
                        else:
                            print("       {!r}".format(k[idx:idx + max_width]))
                        idx += max_width
                        if idx >= len(k):
                            break
                    print()
예제 #12
0
def show_version():
    """Show the pydwf and DWF library version number."""

    dwf = DwfLibrary()
    print("pydwf version ............ : {}".format(pydwf.__version__))
    print("DWF library version ...... : {}".format(dwf.getVersion()))
예제 #13
0
def main():
    """Parse arguments and start Spinning Globe demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate AnalogOut continuous,"
        " synchronous playback of sample data on two channels.")

    DEFAULT_SAMPLE_FREQUENCY = 600.0e3
    DEFAULT_REFRESH_FREQUENCY = 60.0
    DEFAULT_REVOLUTIONS_PER_SECOND = 0.1
    DEFAULT_GSHHS_RESOLUTION = 2

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    parser.add_argument(
        "-fs",
        "--sample-frequency",
        type=float,
        default=DEFAULT_SAMPLE_FREQUENCY,
        dest="sample_frequency",
        help="analog output sample frequency (default: {} Hz)".format(
            DEFAULT_SAMPLE_FREQUENCY))

    parser.add_argument(
        "-fr",
        "--refresh-frequency",
        type=float,
        default=DEFAULT_REFRESH_FREQUENCY,
        dest="refresh_frequency",
        help="number of shape redraws per second (default: {} Hz)".format(
            DEFAULT_REFRESH_FREQUENCY))

    parser.add_argument(
        "-rps",
        "--revolutions-per-sec",
        type=float,
        default=DEFAULT_REVOLUTIONS_PER_SECOND,
        dest="revolutions_per_sec",
        help="globe revolutions per second (default: {})".format(
            DEFAULT_REVOLUTIONS_PER_SECOND))

    parser.add_argument(
        "-res",
        "--resolution",
        type=int,
        default=DEFAULT_GSHHS_RESOLUTION,
        dest="resolution",
        help="resolution of GSHHS dataset (1--5, default: {})".format(
            DEFAULT_GSHHS_RESOLUTION))

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()

        # A helper function to select the most suitable device configuration.
        # Select the first configuration with the highest possible "AnalogOutBufferSize" configuration parameter.
        def maximize_analog_out_buffer_size(configuration_parameters):
            return configuration_parameters[
                DwfEnumConfigInfo.AnalogOutBufferSize]

        with openDwfDevice(
                dwf,
                serial_number_filter=args.serial_number_filter,
                score_func=maximize_analog_out_buffer_size) as device:
            spinning_globe_demo(device.analogOut, args.resolution,
                                args.sample_frequency, args.refresh_frequency,
                                args.revolutions_per_sec)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #14
0
def test1():

    dwf = DwfLibrary()

    with dwf.device.open(-1) as device, open("random_changes.txt", "w") as fo:

        analogIn = device.analogIn

        analogIn.reset()

        CH1 = 0
        CH2 = 0

        channel_index = CH1

        prev_attenuation = analogIn.channelAttenuationGet(channel_index)
        prev_offset      = analogIn.channelOffsetGet(channel_index)
        prev_range       = analogIn.channelRangeGet(channel_index)

        settings = ["attenuation", "offset", "range"]

        (co_min, co_max, co_nsteps) = analogIn.channelOffsetInfo()
        co_nsteps = round(co_nsteps)

        i = 0
        while True:

            setting = random.choice(settings)

            if setting == "attenuation":
                value = xround(np.random.uniform(0.125, 100))
                analogIn.channelAttenuationSet(channel_index, value)
            elif setting == "offset":
                value = xround(np.random.uniform(-30.0, 30.0))
                analogIn.channelOffsetSet(channel_index, value)
            elif setting == "range":
                value = xround(np.random.uniform(0.125, 100.0))
                analogIn.channelRangeSet(channel_index, value)

            curr_attenuation = analogIn.channelAttenuationGet(channel_index)
            curr_offset      = analogIn.channelOffsetGet(channel_index)
            curr_range       = analogIn.channelRangeGet(channel_index)

            curr_attenuation2 = analogIn.channelAttenuationGet(channel_index)
            curr_offset2      = analogIn.channelOffsetGet(channel_index)
            curr_range2       = analogIn.channelRangeGet(channel_index)

            assert curr_attenuation == curr_attenuation2
            assert curr_offset == curr_offset2
            assert curr_range == curr_range2

            report = "{:30.20f} {:30.20f} {:30.20f}    {:20s} {:10.5f}    {:30.20f} {:30.20f} {:30.20f}".format(prev_attenuation, prev_offset, prev_range, setting, value, curr_attenuation, curr_offset, curr_range)

            print(report)
            print(report, file=fo, flush=True)

            i += 1
            if i % 10000 == 0:
                return
                fo.flush()

            prev_attenuation = curr_attenuation
            prev_offset      = curr_offset
            prev_range       = curr_range
예제 #15
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate analog input recording with triggering.")

    DEFAULT_SAMPLE_FREQUENCY = 100.0e3
    DEFAULT_RECORD_LENGTH = 0.100

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    parser.add_argument(
        "-fs",
        "--sample-frequency",
        type=float,
        default=DEFAULT_SAMPLE_FREQUENCY,
        help="sample frequency, in samples per second (default: {} Hz)".format(
            DEFAULT_SAMPLE_FREQUENCY))

    parser.add_argument(
        "-r",
        "--record-length",
        type=float,
        default=DEFAULT_RECORD_LENGTH,
        help="record length, in seconds (default: {} s)".format(
            DEFAULT_RECORD_LENGTH))

    parser.add_argument("-x",
                        "--disable-trigger",
                        action="store_false",
                        dest="trigger",
                        help="disable triggering (default: enabled)")

    args = parser.parse_args()

    dwf = DwfLibrary()

    # A helper function to select the most suitable configuration.
    # Select the first configuration with the highest possible "AnalogInBufferSize" configuration parameter.
    def maximize_analog_in_buffer_size(configuration_parameters):
        return configuration_parameters[DwfEnumConfigInfo.AnalogInBufferSize]

    try:
        with openDwfDevice(
                dwf,
                serial_number_filter=args.serial_number_filter,
                score_func=maximize_analog_in_buffer_size) as device:

            analogOut = device.analogOut
            analogIn = device.analogIn

            # We want to see 5 full cycles in the acquisition window.
            analog_out_frequency = 5 / args.record_length

            # Signal amplitude in Volt. The AnalogOut instrument can do 5 Vpp, so 2.5 V amplitude is the maximum.
            analog_out_amplitude = 2.5

            # Signal offset in Volt.
            analog_out_offset = 0.0

            print("Configuring analog output signals ({} Hz) ...".format(
                analog_out_frequency))

            configure_analog_output(analogOut, analog_out_frequency,
                                    analog_out_amplitude, analog_out_offset)

            time.sleep(
                2.0
            )  # Wait for a bit to ensure the stability of the analog output signals.

            run_demo(analogIn, args.sample_frequency, args.record_length,
                     args.trigger, analog_out_frequency)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
예제 #16
0
def main():
    """Parse arguments and start demo."""

    parser = argparse.ArgumentParser(
        description="Demonstrate AnalogOut continuous,"
        " synchronous playback of sample data on two channels.")

    DEFAULT_SHAPE = "circle"
    DEFAULT_SAMPLE_FREQUENCY = 48.0e3
    DEFAULT_REFRESH_RATE = 100.0
    DEFAULT_REVOLUTIONS_PER_SECOND = 0.1
    DEFAULT_NUM_POINTS = 5
    DEFAULT_POLY_STEP = 1

    parser.add_argument(
        "-sn",
        "--serial-number-filter",
        type=str,
        nargs='?',
        dest="serial_number_filter",
        help=
        "serial number filter to select a specific Digilent Waveforms device")

    parser.add_argument(
        "--shape",
        choices=("circle", "poly"),
        default=DEFAULT_SHAPE,
        dest="shape",
        help="shape to be output on CH1:X and CH2:Y (default: {})".format(
            DEFAULT_SHAPE))

    parser.add_argument(
        "-fs",
        "--sample-frequency",
        type=float,
        default=DEFAULT_SAMPLE_FREQUENCY,
        dest="sample_frequency",
        help="output sample frequency, in samples/sec (default: {} Hz)".format(
            DEFAULT_SAMPLE_FREQUENCY))

    parser.add_argument(
        "-fr",
        "--refresh-frequency",
        type=float,
        default=DEFAULT_REFRESH_RATE,
        dest="refresh_frequency",
        help="number of shape redraws per second (default: {} Hz)".format(
            DEFAULT_REFRESH_RATE))

    parser.add_argument(
        "-rps",
        "--revolutions-per-sec",
        type=float,
        default=DEFAULT_REVOLUTIONS_PER_SECOND,
        dest="revolutions_per_sec",
        help="globe revolutions per second (default: {})".format(
            DEFAULT_REVOLUTIONS_PER_SECOND))

    parser.add_argument(
        "-np",
        "--num-points",
        type=int,
        default=DEFAULT_NUM_POINTS,
        dest="num_points",
        help="poly mode only: number of poly points (default: {})".format(
            DEFAULT_NUM_POINTS))

    parser.add_argument(
        "-ps",
        "--poly-step",
        type=int,
        default=DEFAULT_POLY_STEP,
        dest="poly_step",
        help="poly mode only: steps to the next poly point (default: {})".
        format(DEFAULT_POLY_STEP))

    args = parser.parse_args()

    try:
        dwf = DwfLibrary()

        # A helper function to select the most suitable configuration.
        # Select the first configuration with the highest possible "AnalogOutBufferSize" configuration parameter.
        def maximize_analog_out_buffer_size(configuration_parameters):
            return configuration_parameters[
                DwfEnumConfigInfo.AnalogOutBufferSize]

        with openDwfDevice(
                dwf,
                serial_number_filter=args.serial_number_filter,
                score_func=maximize_analog_out_buffer_size) as device:
            demo_analog_output_instrument_api(device.analogOut, args.shape,
                                              args.sample_frequency,
                                              args.refresh_frequency,
                                              args.revolutions_per_sec,
                                              args.num_points, args.poly_step)
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")
예제 #17
0
def main():
    """Parse arguments and start demo."""

    # pylint: disable=too-many-locals

    waveform_map = {
        "dc"        : DwfAnalogOutFunction.DC,
        "sine"      : DwfAnalogOutFunction.Sine,
        "square"    : DwfAnalogOutFunction.Square,
        "triangle"  : DwfAnalogOutFunction.Triangle,
        "ramp-up"   : DwfAnalogOutFunction.RampUp,
        "ramp-down" : DwfAnalogOutFunction.RampDown,
        "noise"     : DwfAnalogOutFunction.Noise,
        "pulse"     : DwfAnalogOutFunction.Pulse,
        "trapezium" : DwfAnalogOutFunction.Trapezium,
        "sinepower" : DwfAnalogOutFunction.SinePower
    }

    parser = argparse.ArgumentParser(description="Demonstrate AnalogOut waveform output.")

    DEFAULT_WAVEFORM  = "sine"
    DEFAULT_FREQUENCY = 1.0e3
    DEFAULT_AMPLITUDE = 5.0
    DEFAULT_OFFSET    = 0.0
    DEFAULT_SYMMETRY  = 50.0
    DEFAULT_PHASE     = 0.0

    parser.add_argument(
            "-sn", "--serial-number-filter",
            type=str,
            nargs='?',
            dest="serial_number_filter",
            help="serial number filter to select a specific Digilent Waveforms device"
        )

    parser.add_argument(
            "-c", "--continue",
            action='store_true',
            dest="continue_playing",
            help="configure instrument to continue playing and quit program immediately"
        )

    parser.add_argument(
            "-w", "--waveform",
            choices=waveform_map,
            default=DEFAULT_WAVEFORM,
            dest="waveform",
            help="waveform be output (default: {})".format(DEFAULT_WAVEFORM)
        )

    parser.add_argument(
            "-f", "--frequency",
            type=float,
            default=DEFAULT_FREQUENCY,
            dest="frequency",
            help="output frequency (default: {} Hz)".format(DEFAULT_FREQUENCY)
        )

    parser.add_argument(
            "-a", "--amplitude",
            type=float,
            default=DEFAULT_AMPLITUDE,
            dest="amplitude",
            help="output amplitude (default: {} V)".format(DEFAULT_AMPLITUDE)
        )

    parser.add_argument(
            "-o", "--offset",
            type=float,
            default=DEFAULT_OFFSET,
            dest="offset",
            help="output offset (default: {} V)".format(DEFAULT_OFFSET)
        )

    parser.add_argument(
            "-s", "--symmetry",
            type=float,
            default=DEFAULT_SYMMETRY,
            dest="symmetry",
            help="output offset (default: {} %%)".format(DEFAULT_SYMMETRY)
        )

    parser.add_argument(
            "-p", "--phase",
            type=float,
            default=DEFAULT_PHASE,
            dest="phase",
            help="output phase (default: {})".format(DEFAULT_PHASE)
        )

    parser.add_argument(
            "-d1", "--default-channel-1",
            action='store_true',
            dest="default_ch1",
            help="ignore command line settings for channel 1, use defaults."
        )
    parser.add_argument(
            "-d2", "--default-channel-2",
            action='store_true',
            dest="default_ch2",
            help="ignore command line settings for channel 2, use defaults."
        )

    args = parser.parse_args()

    arg_settings = channel_settings(
            waveform_map[args.waveform],
            args.frequency,
            args.amplitude,
            args.offset,
            args.symmetry,
            args.phase
        )

    default_settings = channel_settings(
            waveform_map[DEFAULT_WAVEFORM],
            DEFAULT_FREQUENCY,
            DEFAULT_AMPLITUDE,
            DEFAULT_OFFSET,
            DEFAULT_SYMMETRY,
            DEFAULT_PHASE
        )

    ch1_settings = default_settings if args.default_ch1 else arg_settings
    ch2_settings = default_settings if args.default_ch2 else arg_settings

    try:
        dwf = DwfLibrary()

        with openDwfDevice(dwf, serial_number_filter = args.serial_number_filter) as device:
            demo_analog_output_instrument_api(
                device.analogOut,
                args.continue_playing,
                ch1_settings,
                ch2_settings,
            )
    except PyDwfError as exception:
        print("PyDwfError: {}".format(exception))
    except KeyboardInterrupt:
        print("Keyboard interrupt, ending demo.")