Swig generated python bindings for Digilent Wave forms library.
Directory | Description |
---|---|
examples | A short module with some examples how to use the library. |
tools | Different helper (badly documented) helperscripts. |
test | Python scripts which call every generated function (Most of the tests is generated). |
Currenty this module is tested and used on a debian testing 64 bit installation. If you have such a Linux distribution or a similar one it will probably work.
There is no support for Microsoft Windows, yet.
The library is still in an experimental state. To build the shared wrapper library just call make in the pydwf folder. This will create a pydwf subfolder where the swig generated python code and the compiled wrapper shared libraryy is put.
To build the code you need make, gcc and swig. And of course the WaveForms SDK from digilent already installed on your system. The dwf.i file in this repo is generated against Version 2.7.5 of the Digilent Waveforms SDK.
Just call (as root):
make install
To use this python wrapper install the module as described above. To use the module in Python import it:
from pydwf import dwf
All the function available in the WaveForms SDK Reference Manual are available in the python wrapper. However there are some changes to pyhonize the usage:
- Drop any FDwf from any function call: The call to FDwfGetLastError becomes dwf.GetLastError
- The error code returned by the C-Function will raise an python exception with a text description obtained by the FDwfGetLastErrorMsg function.
- Any variables given as reference to the C-Function to be modified is returned in the python module as new instance of python datatype: Eg. a call :
FDwfDeviceOpen(idxDevice, &hdwf)
becomeshdwf = dwf.FDwfDeviceOpen(idxDevice)
- There are some exceptions to the last rule: If the input parameter is an array of defined size eg. functions
FDwfEnumDeviceName
orFDwfEnumUserName
are returned in the passed variable. - Further the C-functions
FDwfAnalogInStatusData
should be used with numpy-Float data array. A size need not be given as the wrapper knows the size of the Numpy array. See the AcquireAnalog function in the aDiscovery.py example script. - The
FDwfDigitalInStatusData
should be used with a uint16 numpy array. See AcquireDigital function in the aDiscovery.py example script. - Any C-constants are used with the same name as in the manual. Eg. the C-Enum
trigsrcPC
becomesdwf.trigsrcPC