Coder Social home page Coder Social logo

nifpga-python's Introduction

FPGA Interface Python API

Build Status

Overview

The National Instruments FPGA Interface Python API is used for communication between processor and FPGA within NI reconfigurable I/O (RIO) hardware such as NI CompactRIO, NI Single-Board RIO, NI FlexRIO, and NI R Series multifunction RIO.

With the FPGA Interface Python API, developers can use LabVIEW FPGA to program the FPGA within NI hardware and communicate to it from Python running on a host computer. This gives engineers and scientists with Python expertise the ability to take advantage of compiled LabVIEW FPGA bitfiles, also the option to reuse existing Python code.

Installation

NiFpga can be installed by cloning the master branch and then in a command line in the directory of setup.py run:

pip install --pre .

Or by installing from PyPI using:

pip install nifpga

nifpga supports Python 3.5+.

Examples

The FPGA Interface Python API is session based. LabVIEW FPGA will generate bitfiles (.lvbitx) that can be used to program the hardware. For additional information on sessions view our Read the docs documentation

Example usage of FPGA configuration functions:

with Session(bitfile="BitfilePath.lvbitx", resource="RIO0") as session:
    session.reset()
    session.run()
    my_control = session.registers["MyControl"]
    my_control.write(4)
    data = my_control.read()

See our readthedocs page for more detailed examples and documentation.

nifpga-python's People

Contributors

auchter avatar mgumble avatar nxtv2 avatar strainmike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nifpga-python's Issues

Request for nifpga to support more LabVIEW datatypes

Hi,

The current API allows Python code to read/write data to/from the running FPGA bitfile only when the data in question is made of very simple types (integers, booleans). The Python API doesn’t let the user interact with the bitfile for any of the more “complex” data types the FPGA bitfile may expose (for instance: fixed point number, a cluster representing the state of something on the FPGA). For most advanced use-cases where the bitfiles expose such data types, the nifpga Python module as-is cannot integrate with the existing NI FPGA code. Is there any plan to have nifpga support more types? I'd see a lot of value in adding such a feature.

Thanks,
Carlo

The use of CompactRIO and NI modules; handling analog input with nifpga.

[CompactRIO, nifpga API, FPGA]

Hello, I'm Robi. I would like to ask for help with a project. First, let me list the technologies I am working with.

The exact python version used: 3.10+
The exact versions of packages used:

  • nifpga API: 22.0.0
  • LabVIEW: 2017
  • NI CompactRIO (driver): 17.0
  • LabVIEW RT: 17.0
  • Numpy, Pandas, matplotlib, etc...
  • cRIO-9076
  • NI-9215
  • NI-9263
  • Windows 10

I would like to use the aforementioned modules from Python, but I am unable to do so because any data I read always returns 0.0, and I am also unable to write to the module outputs. Here's the setup: I write a program in LabVIEW to program the FPGA to measure an analog signal on the AI0 channel. I compile this program and create a bitfile, which I then use in Python. Everything works great in LabVIEW, but I cannot use the module output in Python because it always reads 0.0. What am I doing wrong? My code is good because if I use a constant instead of the module (AI0), then Python can handle it. So my question is, can the modules not be used from Python?

Occasionally Error: RpcServerMissing (-63044) when calling 'NiFpgaDll_Open'

I'm running unit tests, and after about fourty reads from cRio (by fourty Sessions) I start to get this error:

File "C:\Program Files (x86)\Jenkins\workspace\E-TEST\Test\helpers\motor_monitor_helper.py", line 30, in get_current_position
with Session(self.file, self.resource) as session:
File "C:\Python27\lib\site-packages\nifpga\session.py", line 109, in init
self._session)
File "C:\Python27\lib\site-packages\nifpga\status.py", line 100, in internal
_raise_or_warn_if_nonzero_status(status, function_name, argument_names, args)
File "C:\Python27\lib\site-packages\nifpga\status.py", line 66, in _raise_or_warn_if_nonzero_status
raise codes_to_exception_classes[status](function_name, argument_names, *args)
RpcServerMissingError: Error: RpcServerMissing (-63044) when calling 'NiFpgaDll_Open' with arguments:
bitfile path: 'b'C:\Program Files (x86)\Jenkins\workspace\E-TEST\Test\NiFpga_eTest.lvbitx''
signature: 'b'1EEE087A3560B2C0A53EF8014DCE226E''
resource: 'b'rio://10.0.4.89/RIO0''
attribute: 0x0
session: 0x0L

That line 30 of motor_monitor_helper.py is:

29    def get_current_position(self):
30        with Session(self.file, self.resource) as session:
31            Settings.get_instance().load()
32            positionCounts = session.registers['Position (Counts)'].read()
33            print("session.registers['Position (Counts)']: {}".format(positionCounts))
34            return float(positionCounts) / float(Settings.get_instance().encoder_resolution)

And after that I have to reset cRio to make it works again.
So, all that 40 reads go fine, and that it stops. I have changed tests that are running, but it depends only of number of tests, not of tests itself.

My python version is 2.7.16
nifpga is Version: 19.0.0

Registers ending with a whitespace are not shown correctly on the registers.keys()

When a FPGA LabView code has been compiled with a register with a name ending with a whitespace like( "MyRegister " ) is not correctly reported in session.registers.keys() .
print(session.registers.keys())
shows a
dict_keys(["MyRegister"])
instead of
dict_keys(["MyRegister "])

and even if it is reported wrongly the
session.registers["MyRegister"].write(0.0)
throw an error
KeyError("MyRegister")

niswitch.errors.DriverError: -1074118644: No legacy device supports the specified topology.

Hi,
I am getting following error while trying to open niswitch session in python.
niswitch.errors.DriverError: -1074118644: No legacy device supports the specified topology. Use a different topology, or configure the device under DAQmx and use the DAQmx resource descriptor.

Python code:
import niswitch
resource = "visa://192.168.1.1/PXI8::8::INSTR"
topology1 = "2566/16-SPDT"

with niswitch.Session(resource, topology1) as session:
session.connect(channel1='k0', channel2='com0')

Test environment details:
3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)]
Package Version


future 0.18.3
hightime 0.2.1
nidaqmx 0.5.7
nifpga 22.0.0
niswitch 1.4.5
numpy 1.19.5
pip 21.3.1
setuptools 28.8.0
six 1.16.0

(18.1) Attempting to open a bitfile containing an 'error cluster' errors

Creating a Bitifle with a error cluster control or indicator throws:
ValueError: invalid literal for int() with base 10: 'tring'

This is because error clusters claim to contain a String. They don't actually contain Strings as Strings are not supported on the FPGA, but claim to for compatibility with LabVIEW.

This issue was reported over email. Thanks for the quick bug report!

niFlexRIO_RouteSignal feature implementation

Hello,

I am currently using your API to run two NI_FPGA cards: PXIe_7976R and PXIe_5764. I am using backplane triggers to get them to talk to each other, but the 5764 requires those PXI triggers to be routed to signals that it's FPGA understands.

Inside labview, this function is performed by the subvi NI FlexRIO API "Route Signal", but isn't available in your API. Unfortunately, the intended purpose does not work in python without the achieving the proper routing.

I tried to add the function (screenshot from labview help shown below) niFlexRIO_RouteSignal to the session.py and nifpga.py source code, but quickly got over my head.

Would it be possible to implement this feature? Or perhaps receive some guidance on how to hot-wire this fix for my own purposes? I'm afraid I do not have much experience in editing APIs.

Thank you for any help.

image

Board compatibility

Hi,
we are considering buying a USB 7845R for a project, and I wanted to be sure that is compatible with the "nifpga" module since I can't find any information that explicitly says it.

Kind Regards

Error: InvalidResourceName (-63192) when calling 'NiFpgaDll_Open

Hi. I am getting following error while opening the session with NIFPGA:

nifpga.status.InvalidResourceNameError: Error: InvalidResourceName (-63192) when calling 'NiFpgaDll_Open' with arguments:
bitfile path: b'C:\Eclipse_WS\NIDAQMX\SquareNumber_FPGATarget_Test1_okVPBnie6P8.lvbitx'
signature: b'D9DA997A0C0155146DD77DAEC8CC6F9
NI-MAXProperty
TargetProperty
7'
resource: b'RIO1'
attribute: 0x0
session: 0x0

I cross checked the Resource name in NI-MAX and same name is updated in Target file as well. Pl find attached image of MAX and Project properties.

Test environment details:
3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)]
Package Version


future 0.18.3
nidaqmx 0.5.7
nifpga 22.0.0
numpy 1.19.5
pip 21.3.1
setuptools 28.8.0
six 1.16.0

Thanks,
Manish

InvalidResourceNameError from an lvbitx compiled from cloud compile service

How do I resolve this issue on InvalidResourceNameError?


with Session(bitfile="c:\temp\test.lvbitx", resource="RIO0") as session:
session.reset()
session.run()
my_indicator = session.registers['Frequency']
data = my_indicator.read()
print(data)

InvalidResourceNameError: Error: InvalidResourceName (-63192) when calling 'NiFpgaDll_Open' with arguments:
bitfile path: b'c:\temp\test.lvbitx'
signature: b'047C388B436FDC3224D0A45B4CA35251'
resource: b'RIO0'
attribute: 0x0
session: 0x0

NI myRio usege for FPGA Interface Python API

Hi all,
i wanna do some project on NI-myRio-1900 via using Python and i am a fresh starter, So far i can run my code and work on LabView2018 via the third party Add-on "Canopy" and from now on carry project on my Fpga module.. under the list of availeble device, i did not catch NI My-Rio, (The National Instruments FPGA Interface Python API is used for communication between processor and FPGA within NI reconfigurable I/O (RIO) hardware such as NI CompactRIO, NI Single-Board RIO, NI FlexRIO, and NI R Series multifunction RIO) is it suitable anyway ? or what should i do in order to work on it, can you suggest me any idea? NI myRio has two module both RT Processor, and FPGA, based Xilinx Z-7010, also i wonder can we install Ubuntu on these modules?
Thanks in advance..

Attribute Error on initialization of session py27 on win32

I tried creating a new session and ran into an attribute error.
traceback:

 self._dummy_session = Session(bitfile, resource, reset_if_last_session_on_exit=False, no_run=True)
  File "C:\python27\Lib\site-packages\nifpga\session.py", line 85, in __init__
    self._nifpga = _NiFpga()
  File "C:\python27\Lib\site-packages\nifpga\nifpga.py", line 336, in __init__
    library_function_infos=library_function_infos)
  File "C:\python27\Lib\site-packages\nifpga\statuscheckedlibrary.py", line 179, in __init__
    func = getattr(library, lfi.name_in_library)  # i.e., dlsym()
  File "C:\python27\Lib\ctypes\__init__.py", line 378, in __getattr__
    func = self.__getitem__(name)
  File "C:\python27\Lib\ctypes\__init__.py", line 383, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'NiFpgaDll_GetResourceIndex' not found

the Session object in this case is the one yielded by this import:

from nifpga import Session

My python version is:
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32

Error when loading old bitfiles with new nifpga-python

Guys, it's great you finally added cluster/fixpoint support! Unfortunately, the changes break compatibility to older biltfiles:

Consider this bitfile (created with npfpga-v17): https://raw.githubusercontent.com/ewine-project/Flexible-GFDM-PHY/master/Builds/USRP-Bitfile-0026.lvbitx

with recent nifpga-python (pip install nifpga) one gets this error:

$ python -c "import nifpga; nifpga.Bitfile('USRP-Bitfile-0026.lvbitx')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/e2/lib/python3.7/site-packages/nifpga/bitfile.py", line 36, in __init__
    reg = Register(reg_xml)
  File "/tmp/e2/lib/python3.7/site-packages/nifpga/bitfile.py", line 598, in __init__
    self._type = _parse_type(list(datatype)[0])
  File "/tmp/e2/lib/python3.7/site-packages/nifpga/bitfile.py", line 114, in _parse_type
    return _FXP(name, type_xml)
  File "/tmp/e2/lib/python3.7/site-packages/nifpga/bitfile.py", line 384, in __init__
    self._signed = True if type_xml.find("Signed").text.lower() == 'true' else False
AttributeError: 'NoneType' object has no attribute 'text'

System error when using pyinstaller

OS: Windows10 64bit
Labview: 2017
Labview Drivers: May2017
nifpga: 17.0.0.post2

The program runs fine when run from the command line. When I attempt to bundle it together into an executable for use I get the following error on the command line:

Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: unknown encoding: utf-8

Current thread 0x000037c8 (most recent call first):

I have tried removing all other imports and without nifpga everything works fine. Once I add the nifpga package into the mix I get this error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.