You need to develop some application-level protocol with some "Restart" command. As you need to do the restart on PC restart/shutdown, you can do this by using the class
Microsoft.Win32.SystemEvents
. You will need to handle the event
SessionEnding
or
SessionEnded
:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx[
^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionending.aspx[
^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionended.aspx[
^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendedeventargs.reason.aspx[
^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendreasons.aspx[
^].
[EDIT]
It could be something like this:
Microsoft.Win32.SystemEvents.SessionEnded += (sender, eventArgs) {
if (eventArgs.Reason == Microsoft.Win32.SessionEndReasons.SystemShutdown
&& IsMicrocontrollerConnected())
SendShutdownNotification();
};
You may or may not want to check the
Reason
. Another reason could be log off, and, if your application is a Windows Service, it is not a sufficient reason for resetting of the microcontroller, because your code can continue functioning without anyone logged on. A "regular" application will be terminated by logging off, so you would need to remove this check.
Also, you may not need the check
IsMicrocontrollerConnected
(whatever it is) or something like that, because the code shown above can add the shown event handler to the invocation list of this system event only when you already know that the microcontroller is connected and its state is ready to accept shutdown notification.
See also:
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendedeventhandler.aspx[
^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendedeventargs.aspx[
^].
[END EDIT]
The microcontroller program should receive and recognize this command and handle it properly. What is "the top of the program" for your "prog.asm" depends on the logic of this program. This should be pretty easy to do.
—SA