NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Change embedded ui resolution at startup

Solved!
Go to solution

Hello

I am working width NI Linux Real-time on CRIO-9037 Labview 2015SP1.

First I attached a 2 meter VGA cable through a 'miniDisplay to VGA' adapter to my crio. The monitor resolution is 1440*900 and my front panel works well with it. After a while I need to increase the length of VGA cable , so I used a longer cable. But with the same monitor , the resolution decreased to 1024*768. I use the link below to fix my problem:

 

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019LZYSA2&l=en-US

 

I used the commands in the link and the resolution became 1440*900 again. I need to set the resolution each time when I turn on the crio. I copied the commands to a file (for the first step) and save them to a location on crio , when I tried to run the script I saved from terminal , I received the message "Can't open display : 0". It is confusing me because when I copy the same command from that file to terminal and hit 'Enter' the commands run successfully but when run the file , they not work and give me the message I said.

Also I tried to run the commands in my startup labview app (By System Exec vi) and I received the same message in labview vi.

 

This is the commands I used:

export DISPLAY=:0
xrandr --newmode "NewMode" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
xrandr --addmode DP1 NewMode
xrandr --output DP1 --mode NewMode

0 Kudos
Message 1 of 4
(3,661 Views)

Hi smojtabaei,

 

I just ran through the following processes and all worked successfully. In all tests, I used the commands you listed.

 

  1. Entered commands via SSH as admin.
  2. Entered commands via the terminal in the Embedded UI as lvuser.
  3. Created a file that I called as admin via SSH by ./<file_name>. The file had execute permissions and the following commands:

 

#!/bin/bash

export DISPLAY=:0
xrandr --newmode "NewMode" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
xrandr --addmode DP1 NewMode
xrandr --output DP1 --mode NewMode

 

Thanks,

Andy

 

0 Kudos
Message 2 of 4
(3,641 Views)
Solution
Accepted by topic author smojtabaei

I used the commands in the link and the resolution became 1440*900 again. I need to set the resolution each time when I turn on the crio. I copied the commands to a file (for the first step) and save them to a location on crio , when I tried to run the script I saved from terminal , I received the message "Can't open display : 0". It is confusing me because when I copy the same command from that file to terminal and hit 'Enter' the commands run successfully but when run the file , they not work and give me the message I said.

Also I tried to run the commands in my startup labview app (By System Exec vi) and I received the same message in labview vi.


The likely reason you're seeing the "Can't open display :0" error is because the desktop environment has not (fully) started by the time the script gets run i.e. the script runs before X/Xfce starts so there's no "display" yet. This is definitively true for a LabVIEW startup app which starts early in the boot process. If you do want to run this from LabVIEW then you will have to retry the commands if an error is returned (with some delay to give things a chance to start).

 

There are other ways to do this:

  • One option is to use the file Xfce saves when you explicitly set the resolution via the "Display" settings dialog. The display configuration file gets saved under: /home/lvuser/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml . Roughly the steps would be:
    • connect the cable that works at the higher resolution
    • open the Display settings dialog on the target and explicitly set the desired resolution (and click Apply). This might involve switching first to a different resolution.
    • once you have the '/home/lvuser/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml' file it will persist between reboots and you can copy it and re-use it after a format, edit it etc.
  • Another option is to run the script snippet from that linked white paper as an UI (Xfce) start-up app (as opposed to running it from .bashrc)
    • Save the script you've created as a separate executable file that is in the search path e.g. /usr/local/bin/setresolution.sh
    • Make sure the script has the shebang line "#!/bin/sh" as the first line. It would look something like this:

      • #!/bin/sh

        export DISPLAY=:0
        xrandr --newmode "NewMode" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
        xrandr --addmode DP1 NewMode
        xrandr --output DP1 --mode NewMode

    • Make the script executable with: chmod a+x /usr/local/bin/setresolution.sh
    • Create an Xfce autostart shortcut for it:
      • On the target via Embedded UI go to Settings->Session and Startup->Application Autostart
      • Click Add and populate the relevant fields. The important one is "Command" which should point to /usr/local/bin/setresolution.sh
    • This will create '.desktop' file under '/home/lvuser/.config/autostart' which will launch the script when the desktop environment starts (but not before). You can save and re-install this file if you want it to survive a re-format.
    • It is possible to create the .desktop autostart file from scratch if you don't want to deal with the on-target settings dialog. Take a look at other autostart shortcut files under '/home/lvuser/.config/autostart' for information.

Let me know how it goes, there are other ways to implement this if necessary, for example by using the xfconf-query utility to set the display settings. This integrates with the other Embedded UI (Xfce) settings and persists reboots.

Message 3 of 4
(3,632 Views)
Solution
Accepted by topic author smojtabaei

Thanks for detailed response.

The UI Start-up app didn't worked. I use ".bashrc" file and finally it works but with some notes that you and "tic.not.tock" mentioned in your responses.

 

Here's what id did:

- First I used putty to connect to CRIO terminal.

- Then edit ".bashrc" file in location "/home/lvuser/.bashrc" using vi editor.

- Add following lines to file :

 

#code for init of costum res
export DISPLAY=:0
xrandr --newmode "mode3" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
xrandr --addmode DP1 mode3
xrandr --output DP1 --mode mode3

 

- Save the file

 

After reboot it finally works.

 

 

 

Message 4 of 4
(3,585 Views)