-
Notifications
You must be signed in to change notification settings - Fork 9
1. Getting Started
pyniscope is a wrapper for the NI-SCOPE drivers from National Instruments.
- Download and install the NI-SCOPE driver from National Instruments. It's big and bloaty. Make sure it installs NI-MAX (the "measurement and automation explorer") as well.
- Download the pyniscope zip file and unzip its contents into a temporary directory of your choosing.
- From the command line, navigate to this temporary directory and run the command
python setup.py install
. This should copy everything into your site-packages (or dist-packages) directory.
Run the NI-MAX program that came with NI-SCOPE, and under the "Devices and Interfaces", look for your NI-SCOPE card and determine its name. For the following, let's call the device "Carl".
First we have to import the pyniscope library and create an instance of the "Scope" object:
>>> import niscope
>>> s = niscope.Scope("Carl")
Next, configure the timing, vertical scale, and trigger method:
>>> s.ConfigureHorizontalTiming()
>>> s.ConfigureVertical()
0
>>> s.ConfigureTrigger()
At this point, the scope is ready to acquire data with the default parameters. The following command:
>>> s.InitiateAcquisition()
will "arm" the acquisition. To retrieve next (triggered) data set:
>>> s.Fetch()
This will return a (weirdly-transposed) numpy array of y-values. It's up to you to keep track of the time step, as specified by the "sampleRate" argument in s.ConfigureHorizontalTiming()
.
It seems the best way to learn how to use the card's full set of features is to search the NI site and download the NI-SCOPE Function Reference Help (for the C programming language). The functions listed there look similar to those called above.
import niscope as _niscope
import ctypes as _ctypes
string_buffer = ' '*1024
def get_scope_names():
"""
Hackily returns a list of the NI-SCOPE devices present on the machine.
"""
# we're in C Land, so we have to declare our variables explicitly
device_count = _ctypes.c_int32()
# handle by which to interact with the NI hardware
vi_session = _niscope.ViSession()
# handle to the dll that came with the NI software
niModInstDLL = _ctypes.WinDLL('niModInst')
# DLL call to count the number of SCOPE devices
getattr(niModInstDLL,
'niModInst_OpenInstalledDevicesSession')(
'NI-SCOPE', # type of device
_ctypes.byref(vi_session), # session handle
_ctypes.byref(device_count)) # number of devices
# assemble a list of devices
devices = []
for n in range(device_count.value):
getattr(niModInstDLL,
'niModInst_GetInstalledDeviceAttributeViString')(
vi_session, # session handle
n, # index of device
0, # 0 means device name
len(string_buffer), # length of the query
string_buffer) # place to dump the data
# strip off the BS and add it to the list!
devices.append(string_buffer[0:string_buffer.find('\x00')])
return devices