Changing Embedded UI Resolution from the Linux Command Line

Updated Oct 24, 2020


Operating System

  • NI Linux Real-Time

How can I change the resolution of my Embedded UI display on my NI Linux Real-Time controller from the command line of the cRIO?

To make this change from the command line, connect to the Linux shell and then read on to configure the resolution of the embedded UI.

Step 1: Configure Environment Variables

First, you need to set the DISPLAY environment variable to point to the X server. To do this, type export DISPLAY=:0 into the command line. Now that the system knows where to find the X server, we can use the xrandr command to make changes to our display settings.

If you would like to see a list of all detected outputs, you can type xrandr. Note that doing this will return an error if you don't update the DISPLAY environment variable first.

Step 2: Create a Display Mode 

Let's say that your monitor hardware has a display resolution of 1024x768.  In order to display the embedded UI in this resolution, we need to create a display mode for this resolution. The xrandrcommand needs to be provided a mode list, which is a series of arguments which define the screen resolution, refresh rate, DPI, and other flags. 

Sometimes, your display's manual will document compatible mode lists. If it doesn't, you will need to generate one. Fortunately, there is another command line utility called cvt which can calculate a mode line given a desired horizontal and vertical resolution. To continue with our example, to acquire a mode line for our 1024x768 resolution display, you would type cvt 1024 768. This results in the following output:

Now that you have a valid arguments for the resolution you've chosen, you need to actually create a mode line in Xfce. You can do this by calling xrandr --newmode <modeline> where <modeline> corresponds to the output of the cvt command. Note that the result includes a string contained in quotes. This is the name of the mode line, so you can replace this with whatever name you choose. Using the output from our example (except for the word Modeline at the beginning), and the name "NewMode", this is what this should look like:

You can confirm the addition was successful by calling xrandr again. You should see your new mode under the VIRTUAL1 disconnected display port section.

Step 3: Enable New Mode

Now you need to add your mode as an option under your display port, which is identified as DP1 by default. You can do this by typing xrandr --addmode <display_port> <mode_name>. So, for the mode NewMode, you would type xrandr --addmode DP1 NewMode. Calling xrandr again will reveal that the mode now appears under DP1.

To enable your new mode, you must call xrandr --output <display_port> --mode <mode_name>. Assuming you have a monitor set up with your controller, you will now see the changes take effect. However, these changes will not be persistent upon reboot. If you are satisfied with the results of your change, continue this procedure to make these changes persistent.

Step 4: Make Changes Persistent

The steps above only make changes to the current session and will be lost upon restarting your system. To make sure these settings are applied upon reboot, you need to add these configuration commands to .bashrc, a script file that resides in the home directory of every user. Embedded UI executes under the lvuser user account, so in this case we will be making changes to the .bashrc file located at /home/lvuser/.bashrc. You can use a command-line text editor or you can transfer the file to your local machine, make the necessary changes, and transfer it back to the target

If you wanted to make the changes made by the display mode NewMode, the addition to your file might look something like this:

#code for init of custom res
export DISPLAY=:0
xrandr --newmode "NewMode" 63.50 1024 1072 1176 1328  768 771 775 798 -hsync +vsync
xrandr --addmode DP1 NewMode
xrandr --output DP1 --mode NewMode

Save your changes and reboot your controller. It will now boot up using your custom resolution.

Additional Information

NI Linux Real-Time will natively query the monitor and pick the closest supported resolution.  This procedure is recommended for monitors whose default resolution crops the Settings Manager dialog out of the display itself.  For monitors where Settings Manager is visible, it is recommended that you change the display size with your mouse from the UI itself. 

Also note that when following this procedure, unexpected escape/linefeed characters may be introduced due to formatting differences between text editors. View your .bashrc file using vi (the default text editor for NI Linux Real-Time) to ensure no unexpected characters have been introduced.