Example Code

FPGA Interface Python Example for NI Linux Real-Time

Code and Documents

Attachment

Overview

 

This example demonstrates how you can use the FPGA Interface Python API to perform host-to-target and target-to-host communication with a compiled LabVIEW FPGA bitfile (.LVBITX). The idea for this example, as well as the LabVIEW project and bitfile are pulled directly from the existing FPGA Interface C API Example by ColdenR.

 

Description

 

This example runs from the command line of the NI Linux Real-Time OS (this example specifically uses the CompactRIO-9068), and showcases the following:

 

  • Opening and closing FPGA Interface sessions
  • Reading to and writing from indicators and controls
  • Setting up, reading to, and writing from DMA FIFOs
  • Using IRQs for FPGA/Host synchronization
  • Integration with basic Python data logging techniques

 

Hardware and Software Requirements

 

 

Steps to Implement or Execute Code

 

1. Follow the installation procedure for NI Linux RT on the Python FPGA Interface Getting Started page

 1a. Install the appropriate drivers onto your Windows machine. This example uses the cRIO-9068, so we would install the CompactRIO drivers.

2. Enable SSH OR the serial console through NI MAX

2a. Connect via SSH OR the serial console and log in as an administrator (same link as above)

2b. Run these commands to install the FPGA Interface Python API: 

 

opkg_python.png

 

3. Leaving your SSH or serial console open, transfer the example Python script (‘main.py’) and bitfile (‘MyBitfile.lvbitx’) to the Real-Time target (**note: if your target is not a cRIO-9068, you will have to recompile the FPGA VI for your specific target).

3a. Set up either WebDAV (recommended; default installation) or FTP.

3b. Move the files to any location on the Real-Time target (ensuring that they’re both in the same directory). On the example RIO, I placed these in the /home/lvuser directory:

 

Webdav_files.JPG

4. In your SSH or serial session, navigate to the directory that you placed the files in and run the Python script:

 

SSH_run.JPG

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors