from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction, Status
from time import sleep
from msvcrt import kbhit
import winsound
import pywinusb.hid as hid # pip install pywinusb
import urllib.request
import pyglet # pip install Pyglet
import os.path
from threading import Thread
import math

# You will probably need to replace "myVirtualBench" with the name of your device.
# By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
# You can see the device's name in the VirtualBench Application under File->About
virtualbench = PyVirtualBench('myVirtualBench')
selected_instrument_index = 0 # a global index to reference the currently selected instrument in the global 'instruments' array

def text_to_speech_async(mystr):
    ''' Converts the user input string 'mystr' into audio that is output to the computer speakers.
        Note, this function is asynchronous we return while the audio is still playing.
    '''
    file_cache_dir = os.path.expanduser("~/Desktop/text_to_speech_cache/") # User-defined directory (change this to your liking)
    if (os.path.isdir(file_cache_dir) == False):
        os.makedirs(file_cache_dir)
    file_path = file_cache_dir + mystr + ".mpeg"
    # We only should hit the network if the audio is not in the cache
    if (os.path.isfile(file_path) == False):
        url = "http://translate.google.com/translate_tts?tl=en&q=" + mystr.replace(" ", "%20")
        req = urllib.request.Request(url, data=None, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'})
        response_contents = urllib.request.urlopen(req)
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction, Status
import winsound

# This examples demonstrates how to make continuity measurements using the Digital
# Multimeter (DMM) on a VirtualBench.

try:
    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')
    dmm = virtualbench.acquire_digital_multimeter();
    dmm.configure_measurement(DmmFunction.RESISTANCE)
    is_beeping = False

    print("Insert test leads into the VirtualBench device.  When the test leads touch one another, you should hear a beep noise.")

    while (True):
        try:
            if (dmm.read() < 100 and is_beeping == False): # 100 Ohlms
                winsound.PlaySound('continuity_beep.wav', winsound.SND_FILENAME | winsound.SND_ASYNC | winsound.SND_LOOP)
                is_beeping = True;
        except PyVirtualBenchException as e:
            winsound.PlaySound(None, 0) # Stops audio from playing
            is_beeping = False;
            if (e.status != Status.WARNING_DMM_OVERRANGE):
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction
from datetime import datetime

# This examples demonstrates how to query calibration information from a
# VirtualBench device.

try:
    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')

    # Read and display calibration information.
    calibration_date, recommended_calibration_interval, calibration_interval = virtualbench.get_calibration_information()
    seconds_since_1970, fractional_seconds = virtualbench.convert_timestamp_to_values(calibration_date)
    print("Device was last calibrated: %s UTC" % datetime.utcfromtimestamp(seconds_since_1970))
    print("Recommended calibration interval: %d months, calibration interval: %d months" % (recommended_calibration_interval, calibration_interval));

    adjustment_date, adjustment_temperature = virtualbench.get_mixed_signal_oscilloscope_calibration_adjustment_information();
    seconds_since_1970, fractional_seconds = virtualbench.convert_timestamp_to_values(adjustment_date)
    print("MSO was last adjusted: %s UTC" % datetime.utcfromtimestamp(seconds_since_1970))
    print("Temperature was: %f" % adjustment_temperature);

    adjustment_date, adjustment_temperature = virtualbench.get_function_generator_calibration_adjustment_information()
    seconds_since_1970, fractional_seconds = virtualbench.convert_timestamp_to_values(adjustment_date)
    print("FGEN was last adjusted: %s UTC" % datetime.utcfromtimestamp(seconds_since_1970))
Beispiel #4
0
from pyvirtualbench import PyVirtualBench, PyVirtualBenchException

# This examples demonstrates how to make measurements using the Power
# Supply (PS) on a VirtualBench.

try:
    # Power Supply Configuration
    channel = "ps/+25V"
    voltage_level = 1.0
    current_limit = 0.5

    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')
    ps = virtualbench.acquire_power_supply()

    ps.configure_voltage_output(channel, voltage_level, current_limit)
    ps.enable_all_outputs(True)

    for i in range(10):
        voltage_measurement, current_measurement, ps_state = ps.read_output(channel)
        print("Measurement [%d]: %f V\t%f A\t(%s)" % (i, voltage_measurement, current_measurement, str(ps_state)))

    ps.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
finally:
    virtualbench.release()
    try:
        a_seconds_since_1970, a_fractional_seconds = virtualbench.convert_timestamp_to_values(
            a_timestamp)
        b_seconds_since_1970, b_fractional_seconds = virtualbench.convert_timestamp_to_values(
            b_timestamp)
        return (a_seconds_since_1970 - b_seconds_since_1970
                ) + a_fractional_seconds - b_fractional_seconds
    except PyVirtualBenchException as e:
        return 0.0


try:
    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')
    mso = virtualbench.acquire_mixed_signal_oscilloscope()

    # Configure the acquisition using auto setup
    mso.auto_setup()

    # Query the configuration that was chosen to properly interpret the data.
    sample_rate, acquisition_time, pretrigger_time, sampling_mode = mso.query_timing(
    )
    channels = mso.query_enabled_analog_channels()
    channels_enabled, number_of_channels = virtualbench.collapse_channel_string(
        channels)

    # Start the acquisition.  Auto triggering is enabled to catch a misconfigured trigger condition.
    mso.run()
Beispiel #6
0
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction
from datetime import datetime

# This examples demonstrates how to query calibration information from a
# VirtualBench device.

try:
    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')

    # Read and display calibration information.
    calibration_date, recommended_calibration_interval, calibration_interval = virtualbench.get_calibration_information(
    )
    seconds_since_1970, fractional_seconds = virtualbench.convert_timestamp_to_values(
        calibration_date)
    print("Device was last calibrated: %s UTC" %
          datetime.utcfromtimestamp(seconds_since_1970))
    print(
        "Recommended calibration interval: %d months, calibration interval: %d months"
        % (recommended_calibration_interval, calibration_interval))

    adjustment_date, adjustment_temperature = virtualbench.get_mixed_signal_oscilloscope_calibration_adjustment_information(
    )
    seconds_since_1970, fractional_seconds = virtualbench.convert_timestamp_to_values(
    # Channel Configuration
    clock_rate = I2cClockRate.ONE_HUNDRED_KHZ # 100kHz

    # You will probably need to replace "0x50" address with the address for your
    # attached chip.  You can find the address by looking at the datasheet for
    # your attached chip.
    address = 0x50
    address_size = I2cAddressSize.SEVEN_BITS
    enable_pullups = False

    # Data
    data_to_write = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
    data_read_size = len(data_to_write)
    timeout = 10.0

    virtualbench = PyVirtualBench()
    i2c = virtualbench.acquire_inter_integrated_circuit(bus)

    i2c.configure_bus(clock_rate, address, address_size, enable_pullups)

    # Write and read from the bus.
    for i in range(10):
        data_read, number_of_bytes_written = i2c.write_read(data_to_write, timeout, data_read_size)

        print("Iteration %d:" % i)
        print("Wrote %d bytes" % number_of_bytes_written)
        for i in range(number_of_bytes_written): print("0x%02x" % data_to_write[i])

        print("Read %d bytes" % len(data_read))
        for i in range(len(data_read)): print("0x%02x" % data_read[i])
from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, Waveform

# This examples demonstrates how to configure and generate a standard
# waveform from the Function Generator (FGEN) on a VirtualBench.

try:
    # Waveform Configuration
    waveform_function = Waveform.SQUARE
    amplitude = 10.0  # 10V
    dc_offset = 0.0  # 0V
    frequency = 500000.0  # 500kHz
    duty_cycle = 50.0  # 50% (Used for Square and Triangle waveforms)

    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')
    fgen = virtualbench.acquire_function_generator()

    fgen.configure_standard_waveform(waveform_function, amplitude, dc_offset,
                                     frequency, duty_cycle)

    # Start driving the signal. The waveform will continue until Stop is called, even if you close the session.
    fgen.run()

    fgen.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
finally:
    virtualbench.release()
    # MISO (Master In Slave Out) input/output maps to Digital I/O Pin 2 on VirtualBench device
    # CS (Chip Select) output maps to Digital I/O Pin 3 on VirtualBench device

    # Channel Configuration
    clock_rate = 10000000.0  # 10MHz
    clock_polarity = Polarity.IDLE_LOW
    clock_phase = ClockPhase.FIRST_EDGE
    chip_select_polarity = Polarity.IDLE_HIGH

    # Data
    data_to_write = [0x82,
                     0]  # Read WHO_AM_I 0x82 register on attached SPI device
    data_read_size = len(data_to_write)
    bytes_per_frame = -1

    virtualbench = PyVirtualBench()
    spi = virtualbench.acquire_serial_peripheral_interface(bus)

    spi.configure_bus(clock_rate, clock_polarity, clock_phase,
                      chip_select_polarity)

    # Write and read from the bus.
    data_read = spi.write_read(data_to_write, bytes_per_frame, data_read_size)

    print("Received %d bytes:" % len(data_read))
    for i in range(len(data_read)):
        print("%d (0x%02x) = %d (0x%02x)" % (i, i, data_read[i], data_read[i]))

    spi.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    bus = "myVirtualBench/i2c/0"

    # Channel Configuration
    clock_rate = I2cClockRate.ONE_HUNDRED_KHZ  # 100kHz
    address = 0x50
    address_size = I2cAddressSize.SEVEN_BITS
    enable_pullups = False

    # Data
    data_to_write = [0, 1, 2, 3, 4, 5, 6, 7]
    data_read_size = len(data_to_write)
    timeout = 10.0

    virtualbench = PyVirtualBench()
    i2c = virtualbench.acquire_inter_integrated_circuit(bus)

    i2c.configure_bus(clock_rate, address, address_size, enable_pullups)

    # Write and read from the bus.
    for i in range(10):
        data_read = i2c.write_read(data_to_write, timeout, data_read_size)

        print("Iteration %d:" % i)
        print("Wrote: %s" % data_to_write)
        print("Read: %s" % data_read)

    i2c.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
Beispiel #11
0
from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction, Status
from time import sleep
from msvcrt import kbhit
import winsound
import pywinusb.hid as hid  # pip install pywinusb
import urllib.request
import pyglet  # pip install Pyglet
import os.path
from threading import Thread
import math

# You will probably need to replace "myVirtualBench" with the name of your device.
# By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
# You can see the device's name in the VirtualBench Application under File->About
virtualbench = PyVirtualBench('myVirtualBench')
selected_instrument_index = 0  # a global index to reference the currently selected instrument in the global 'instruments' array


def text_to_speech_async(mystr):
    ''' Converts the user input string 'mystr' into audio that is output to the computer speakers.
        Note, this function is asynchronous we return while the audio is still playing.
    '''
    file_cache_dir = os.path.expanduser(
        "~/Desktop/text_to_speech_cache/"
    )  # User-defined directory (change this to your liking)
    if (os.path.isdir(file_cache_dir) == False):
        os.makedirs(file_cache_dir)
    file_path = file_cache_dir + mystr + ".mpeg"
    # We only should hit the network if the audio is not in the cache
    if (os.path.isfile(file_path) == False):
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    bus = "myVirtualBench/spi/0"

    # Channel Configuration
    clock_rate = 10000000.0 # 10MHz
    clock_polarity = Polarity.IDLE_LOW
    clock_phase = ClockPhase.FIRST_EDGE
    chip_select_polarity = Polarity.IDLE_HIGH

    # Data
    data_to_write = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
    data_read_size = len(data_to_write)
    bytes_per_frame = -1

    virtualbench = PyVirtualBench()
    spi = virtualbench.acquire_serial_peripheral_interface(bus)

    spi.configure_bus(clock_rate, clock_polarity, clock_phase, chip_select_polarity)

    # Write and read from the bus.
    for i in range(10):
        data_read = spi.write_read(data_to_write, bytes_per_frame, data_read_size)

        print("Iteration %d:" % i)
        print("Wrote: %s" % data_to_write)
        print("Read: %s" % data_read)

    spi.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
# THE SOFTWARE.

from pyvirtualbench import PyVirtualBench, PyVirtualBenchException

# This examples demonstrates how to generate and read static digital signals
# using the Digital (Dig) lines on a VirtualBench.

try:
    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    channels_to_write = "myVirtualBench/dig/0:3"
    channels_to_read = "myVirtualBench/dig/4:7"

    data_to_write = [True, False, True, True]

    virtualbench = PyVirtualBench()
    dio = virtualbench.acquire_digital_input_output(channels_to_write)

    for i in range(10):
        dio.write(channels_to_write, data_to_write)
        print("[%d] Wrote to  %s: %s" % (i, channels_to_write, data_to_write))
        print("[%d] Read from %s: %s" %
              (i, channels_to_read, dio.read(channels_to_read)))

    dio.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
finally:
    virtualbench.release()
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

from pyvirtualbench import PyVirtualBench, PyVirtualBenchException, DmmFunction

# This examples demonstrates how to make measurements using the Digital
# Multimeter (DMM) on a VirtualBench.

try:
    # You will probably need to replace "myVirtualBench" with the name of your device.
    # By default, the device name is the model number and serial number separated by a hyphen; e.g., "VB8012-309738A".
    # You can see the device's name in the VirtualBench Application under File->About
    virtualbench = PyVirtualBench('myVirtualBench')
    dmm = virtualbench.acquire_digital_multimeter()
    dmm.configure_measurement(DmmFunction.DC_VOLTS, True, 10.0)

    for i in range(10):
        print("Measurement %d: %f V" % (i, dmm.read()))

    dmm.release()
except PyVirtualBenchException as e:
    print("Error/Warning %d occurred\n%s" % (e.status, e))
finally:
    virtualbench.release()