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.")
示例#2
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.")
示例#3
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.")
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.")
示例#5
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)
示例#6
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.")
示例#7
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.")
示例#8
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.")
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.")
示例#10
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))
示例#11
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.")
示例#12
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.")