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()
# 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])