Reboot after close
Re: Reboot after close
Thanks again for your fast help Mark, really appreciated!!
Re: Reboot after close
Hello Mark,
I'm using this function too in my T7A:
but in the most cases, not in all, the panel loses the date and time. Is there a way to avoid this?
Regards Uwe
I'm using this function too in my T7A:
Code: Select all
[DllImport("coredll.dll", EntryPoint = "SetSystemPowerState")]
private static extern uint CESetSystemPowerState(char[] sState, uint StateFlags, uint Options);
public static void Reboot()
{
//Sets the system state to "reboot"
//That will soft reboot the unit.
string systemStateName = "reboot";
uint nError = CESetSystemPowerState(systemStateName.ToCharArray(), 0, 0x0);
}
Regards Uwe
-
- Posts: 137
- Joined: Mon Jun 11, 2012 2:10 pm
Re: Reboot after close
I have a T7A with the following class for reading/writing the system time as well as rebooting. You could use it if you'd like:
Code: Select all
public class SystemCtrl
{
private const uint POWER_STATE_RESET = 0x00800000;
private struct SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Millisecond;
};
// Reboots system
[System.Runtime.InteropServices.DllImport("coredll.dll", EntryPoint = "SetSystemPowerState", SetLastError = true)]
private static extern uint SetSystemPowerState(IntPtr psState, uint StateFlags, uint Options);
// Get's local time
[System.Runtime.InteropServices.DllImport("coredll.dll", EntryPoint="GetLocalTime", SetLastError = true)]
private static extern bool GetLocalTime(ref SystemTime st);
// Set's local time
[System.Runtime.InteropServices.DllImport("coredll.dll", EntryPoint="SetLocalTime", SetLastError = true)]
private static extern bool SetLocalTime(ref SystemTime st);
public static void Reboot()
{
SetSystemPowerState(IntPtr.Zero, POWER_STATE_RESET, 0);
}
public static DateTime Time
{
get
{
SystemTime st = new SystemTime();
GetLocalTime(ref st);
return new DateTime((int)(st.Year), (int)(st.Month), (int)(st.Day), (int)(st.Hour), (int)(st.Minute), (int)(st.Second), (int)(st.Millisecond));
}
set
{
SystemTime st = new SystemTime();
DateTime dt = (DateTime)value;
st.Year = (ushort)(dt.Year);
st.Month = (ushort)(dt.Month);
st.DayOfWeek = (ushort)(dt.DayOfWeek);
st.Day = (ushort)(dt.Day);
st.Hour = (ushort)(dt.Hour);
st.Minute = (ushort)(dt.Minute);
st.Second = (ushort)(dt.Second);
st.Millisecond = (ushort)(dt.Millisecond);
SetLocalTime(ref st);
}
}
}
Adam M.
Controls Engineer
FlexEnergy
Controls Engineer
FlexEnergy