NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Restarting the cRio.

Solved!
Go to solution

Hi All

Just a quick question for some advice. You can restart the cRio from the FPGA but, if your FPGA is suffering from issues this doesn't necessarily work. This is a bit of an issue of you want a watchdog component to a program which has a last resort 'restart and hope for the best' option.

In C++ is there a way you would recommend restarting a cRio running real time OS without using the FPGA- there's lots of options out there so I wonder if there is best a best practice approach or just go for any linux based option?

Cheers

0 Kudos
Message 1 of 10
(5,852 Views)

If we are talking about C/C++ and the resulting application is being run by root/admin (e.g. it is started by an initscript), simply call system("reboot") (there are RT ramifications for using system() but considering you're rebooting, no big deal). You can also call reboot() but keep in mind that this will not call the shutdown initscripts and instead just reboots right away.

If this is from within a LVRT program, there is the Watchdog API that you can use to provide all of the functionality you're looking for without the need to implement everything yourself (a thread to act as watchdog, a means of thradsafe communication with the watchdog thread to "pet" it, etc.)

Message 2 of 10
(4,471 Views)

If it is LV there is a restart VI in the sys config API as well.

If you just want to restart your application instead of the entire controller I've been using a trick where a bash file is continuously ensuring the application is running and if it stops it restarts the application.  That way if the watchdog trips the exe just has to stop running and then the bash restarts it.  Something like:

#!/bin/bash

while !(./myProg.exe) do sleep 1 echo "Restarting program..." done

The command is your exe.  Although I haven't tried it I have thought about doing something fancy where depending on the return code the bash does something different.  In C you do that with the main() return code.  In LabVIEW you can't do that (I think), but you could write to a file and the bash read it.

Brian K.
Message 3 of 10
(4,471 Views)

Thanks Both.

Really helpful answers. Somewhat related, is there any way to access the User1 LED (not the FPGA LED) in C++? Looks easy in LabView but can't find any documentation on how the LED might be accessed if programming in another language?

0 Kudos
Message 4 of 10
(4,471 Views)
Solution
Accepted by topic author jamie_mac

Funny enough...yes.  I just figured it out.

const char* LED_ON = "255\n";

const char* LED_OFF = "0\n";

FILE *LED = NULL;

    LED = fopen("/sys/class/leds/nizynqcpld:status:red/brightness","w");

    while(1)

    {

        if (i%2 == 0)

            fwrite(LED_OFF,sizeof(char),2,LED);

        else

            fwrite(LED_ON,sizeof(char),4,LED);

        fflush(LED);

        sleep(1);

        i++;

    }

    fclose(LED);

Brian K.
Message 5 of 10
(4,471 Views)

Cheers Brian!

I would not have figured that out myself.

0 Kudos
Message 6 of 10
(4,471 Views)

also system("reboot") seems to work just fine.

0 Kudos
Message 7 of 10
(4,471 Views)

jamie_mac wrote:

Cheers Brad!

I would not have figured that out myself.

As much as I would like to steal credit from Brian_K (and, trust me, I would), he's the one who provided the code snippet.

0 Kudos
Message 8 of 10
(4,471 Views)

My apologies Brian! Message edited appropriately.

0 Kudos
Message 9 of 10
(4,471 Views)

Just for completeness: we do provide access to the LED's and operations like reboot through the NI System Configuration API, which has both LabVIEW and C interfaces. Reference docs for that are here: http://zone.ni.com/reference/en-XX/help/373242G-01/

If you want to use the same program on a variety of targets this might be easier for you. That said, if you're just on one target, or even just on Linux targets, the code you guys have discussed above will work fine and is more lightweight.

0 Kudos
Message 10 of 10
(4,471 Views)