This examples shows how to setup the enviroment and run very basics RF examples from Python. There are two approaches: calling the CLR (Common Language Runtime) to directly interface with .NET classes and creating wrappers around the driver c dll using cpython. These examples use Python .NET as a way of importing the .NET classes into Python.
Please be aware that NI-RFSA neither NI-RFSG APIs are officially supported in Python. Official support is provided through .NET and LabVIEW APIs. This is provided as a last resort alternative but please remember that any issue, it being usability or bugs not reproducible in .NET or LabVIEW, will be your responsability.
-
Install Python 3.6.4
- Version of Python is tied to Python .NET, pick your version according to their support
- Install launcher for all users
- Add Python 3.6 to PATH
- Customization (pip, Documentation, IDLE, Test Suite, py launcher)
- Everything else left as default (03-26-2018)
-
Install Software Support
- RFSA be patient it is a big download
- .NET RFSA
- .NET RFSG
- National Instruments .NET Support
-
Install some Python Packages
- python -m pip install -U pip setuptools
- python -m pip install matplotlib
- python -m pip install numpy
-
Install pythonnet
- Installation Wiki 'pip install pythonnet'
-
Install .NET Framework 4.6.1
This scripts simply loads the clr and the RFSA .NET class library
python source\PythondotNetTest.py
This python script was created based on the RFSA example called: "RFSG Getting Started Finite Generation (IQ Device).vi"
This python script was created based on the RFSA example called: "RFSA Getting Started IQ (IQ Device).vi"
Instrument set with a pair mmpx cables looping I In (+/-) to I Out (+/-). The RFSG example will continuously generate until the user presses "enter". Please note that the acquired tone frequency is configured by shifting by 1 KHz the IQ Out Carrier Frequency instead of generating a waveform of 1 KHz at the configure IQ Rate. Run RFSG first which will continuously generate a tone and then run the RFSA script.
python source\RFSGGettingStartedIQDevice.py --resource <your device name>
python source\RFSAGettingStartedIQDevice.py --resource <your device name>
This example is very similar to first none triggered example but configures the RFSG to export a start trigger and the RFSA to wait 10 seconds for a trigger. Expected string can be found in the RFSA/G API help.
python source\RFSAGettingStartedIQDevice.py --resource <your device name> --trigger PXI_Trig0
python source\RFSGGettingStartedIQDevice.py --resource <your device name> --trigger PXI_Trig0
This example shows how to generate a trigger with a marker at a specific sample of the waveform. Using the timeout as a test you can now start the generation first and trigger your acquisition later because, everytime the generation loops the wfm, a trigger is sent over the selected terminal. In the previous example only the StartEvent sent out a trigger and this only happnes the first iteration of the waveform generation.
python source\RFSGGettingStartedIQDevice.py --resource <your device name> --marker PXI_Trig0
python source\RFSAGettingStartedIQDevice.py --resource <your device name> --trigger PXI_Trig0
- C:\Program Files (x86)\IVI Foundation\IVI\Microsoft.NET\Framework32\v4.0.30319\NationalInstruments.ModularInstruments.NIRfsa 17.1.0\NINETRfsaFx40Ref.chm
- C:\Program Files (x86)\IVI Foundation\IVI\Microsoft.NET\Framework32\v4.0.30319\NationalInstruments.ModularInstruments.NIRfsg 17.1.0\NINETRfsgFx40Ref.chm
- Enum codes can be found in the LabVIEW help for the API. (e.g. RFSG->Generation Mode 1000 means CW per "Arb:Generation Mode" Property in NI RFSG Signal Generation Help)
- https://github.com/pythonnet/pythonnet
- http://zone.ni.com/reference/en-XX/help/375857A-01/html/allmembers_t_nationalinstruments_complexdouble/
- https://stackoverflow.com/questions/19600315/how-to-use-a-net-method-which-modifies-in-place-in-python
- http://ironpython.net/documentation/dotnet/dotnet.html#methods-with-ref-or-out-parameters
- https://stackoverflow.com/questions/16484167/python-net-framework-reference-argument-double