Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,7 @@
#### [niscope] Unreleased
- Added
- (Common) Added `nitlsconfig[grpc]>=1.0.0a2` to the optional gRPC dependencies.
- Added the `niscope_external_clocking.py` example.
- Changed
- Removed

Expand Down
9 changes: 9 additions & 0 deletions docs/niscope/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Examples

`You can download all niscope examples for latest version here <https://github.com/ni/nimi-python/releases/download/niscope-1.5.0/niscope_examples.zip>`_

niscope_external_clocking.py
----------------------------

.. literalinclude:: ../../src/niscope/examples/niscope_external_clocking.py
:language: python
:linenos:
:encoding: utf8
:caption: `(niscope_external_clocking.py) <https://github.com/ni/nimi-python/blob/master/src/niscope/examples/niscope_external_clocking.py>`_

niscope_fetch.py
----------------

Expand Down
62 changes: 62 additions & 0 deletions src/niscope/examples/niscope_external_clocking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/python

import argparse
import niscope
import sys


def example(resource_name, channel_names, options, min_record_length, voltage_range, voltage_offset, source, rate, divisor, multiplier, total_iterations):
print(f'Starting acquisition on resource {resource_name}, for {total_iterations} iterations.')
with niscope.Session(resource_name=resource_name, options=options) as session:
channels = session.channels[channel_names]
channels.configure_vertical(range=voltage_range, coupling=niscope.VerticalCoupling.DC, offset=voltage_offset)
session.configure_trigger_immediate()
session.horz_min_num_pts = min_record_length
session.samp_clk_timebase_src = source
session.samp_clk_timebase_rate = rate
session.samp_clk_timebase_div = divisor
session.sample_clock_timebase_multiplier = multiplier

iterations = 0
while iterations < total_iterations:
# read() initiates the acquisition, waits for it to complete and fetches the data
channels.read(num_samples=min_record_length)
iterations += 1

print('Completed {} acquisitions.'.format(iterations))


def _main(argsv):
parser = argparse.ArgumentParser(description='Acquires a waveform using an external sample clock.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-n', '--resource-name', default='PXI1Slot3', help='Specifies the resource name of the device to initialize.')
parser.add_argument('-c', '--channels', default='0', help='Comma-separated list of channels to acquire')
parser.add_argument('-v', '--voltage-range', default=1.0, type=float, help='Specifies the peak-to-peak input range for the specified channels in volts.')
parser.add_argument('--voltage-offset', default=0.0, type=float, help='Specifies the location of the center of the range. The value is with respect to ground and is in volts.')
parser.add_argument('-l', '--min-record-length', default=1000, type=int, help='Specifies the minimum number of points you require in the waveform record for each channel.')
parser.add_argument('-s', '--source', default='VAL_CLK_IN', type=str, help='Specifies the source of the sample clock timebase, which is the timebase used to control waveform sampling.')
parser.add_argument('-r', '--rate', default=1e8, type=float, help='Specifies the frequency in hertz of the external clock used as the timebase source.')
parser.add_argument('-d', '--divisor', default=1, type=int, help='Divides the sample clock timebase rate. Together with --multiplier, the actual sample rate is the timebase rate x multiplier / divisor.')
parser.add_argument('-m', '--multiplier', default=1, type=int, help='Multiplies the sample clock timebase rate. Values other than 1 are only valid on devices that support time-interleaved sampling (TIS), and valid values vary by device and configuration.')
parser.add_argument('--total-iterations', default=100, type=int, help='Number of acquisitions to perform before stopping.')
parser.add_argument('-op', '--option-string', default='', type=str, help='Specifies the initial value of certain properties for the session.')
args = parser.parse_args(argsv)
example(args.resource_name, args.channels, args.option_string, args.min_record_length, args.voltage_range, args.voltage_offset, args.source, args.rate, args.divisor, args.multiplier, args.total_iterations)


def main():
_main(sys.argv[1:])


def test_example():
options = {'simulate': True, 'driver_setup': {'Model': '5164', 'BoardType': 'PXIe', }, }
# The PXIe-5164 only accepts a 1 GHz sample clock timebase
example('PXI1Slot2', '0', options, 1000, 1.0, 0.0, 'VAL_CLK_IN', 1e9, 1, 1, 2)


def test_main():
cmd_line = ['--option-string', 'Simulate=1, DriverSetup=Model:5164; BoardType:PXIe', '--rate', '1e9', '--total-iterations', '2', ]
_main(cmd_line)


if __name__ == '__main__':
main()
Loading