PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Python NI FPGA API interface - NI FPGA 7971R

Solved!
Go to solution

Hi,

My objective is to use the Python API to run the FPGA application with an already compiled bitfile

First of all, I want to run a simple task : transfering the value of a counter (Count) from the FPGA to the host. My FPGA program is :

CCornu_0-1616576877680.png

The HOST VI I want to convert into Python is :

CCornu_1-1616576877693.png

 

Basically, i put a timer inside a while loop and an emergency stop button. When the While loop execute, I read the counter (« Count »)  (Do not mind the bad connections, I opened it from outside the project). I know the bitfile is working, I tried it with LabVIEW FPGA.

 

I went to the Python API site, I installed the package NIFPGA, I tested the examples (Registers, IRQ count) with the Ressource Name « PXI1Slot2 » and it worked.

 

Then i tried this script to replace my HOST VI :

###

from nifpga import Session

import time

Time_Sequence = 3.

bitfile='p20210316monitor_FPGATarget_FPGATEST20210318_ZGUx3jWKUdM.lvbitx'

with Session(bitfile,"PXI1Slot2") as session:

    session.reset()

    Counter = session.registers['Count']

    session.run()

    t0=t=time.time()

    while (t-t0)<Time_Sequence:

        Data=Counter.read()

        print(Data)

        t=time.time()

    session.abort()

###

 

It looks similar to the LabVIEW VI but it doesn’t work. The error log is :

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 790, in runfile

    execfile(filename, namespace)

  File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 77, in execfile

    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "C:/Users/MIDAS/Documents/Python Scripts/Interface LabVIEW/20210318_ClockTest.py", line 30, in <module>

    Data=Counter.read()

  File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\nifpga\session.py", line 370, in read

    self._read_func(self._session, self._resource, data)

  File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\lib\site-packages\nifpga\status.py", line 100, in internal

    _raise_or_warn_if_nonzero_status(status, function_name, argument_names, args)

  File "C:\WinPython-64bit-2.7.10.3\python-2.7.10.amd64\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)

nifpga.status.CommunicationTimeoutError: Error: CommunicationTimeout (-61046) when calling 'NiFpgaDll_ReadU32' with arguments:

               session: 0x1L

               indicator: 0x80010000L

               value: 0x0L

 

I don't know what I did wrong. Is there someone knowledgeable enough to help me with NI FPGA Pyhton API ?

 

Thank you very much

Download All
0 Kudos
Message 1 of 3
(1,936 Views)
Solution
Accepted by topic author CCornu

CommunicationTimeout (-61046)'s description is: An error was detected in the communication between the host computer and the FPGA target. If you are using any external clocks, make sure they are connected and within the supported specifications. Also, verify that the rate of any external clocks match the specified clock rates. If you are generating your clocks internally, please contact National Instruments Technical Support.

 

In this case the error is most likely trying to say that the external clock "IO Module\Data Clock" for your timed loop on the FPGA isn't running.  Is your FAM currently attached to your FlexRIO?  Does your LabVIEW code still run successfully?

 

The problem could also be that the clock hasn't fully started yet.  I notice in your LabVIEW code you have a "Wait" during your FPGA Run call.  If you add a similar sleep to your python code after run, does that fix the problem?

Message 2 of 3
(1,892 Views)

I added a time.sleep(5) after and now it's working like a charm! Thank you very much

0 Kudos
Message 3 of 3
(1,875 Views)