Reboot after close

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
KevinA.
Posts: 34
Joined: Wed Oct 24, 2012 1:22 pm

Re: Reboot after close

Post by KevinA. »

Thanks again for your fast help Mark, really appreciated!!

uhwalter
Posts: 6
Joined: Wed Sep 12, 2012 12:35 am

Re: Reboot after close

Post by uhwalter »

Hello Mark,

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);                                         
                               }
but in the most cases, not in all, the panel loses the date and time. Is there a way to avoid this?

Regards Uwe

AMitchneck
Posts: 137
Joined: Mon Jun 11, 2012 2:10 pm

Re: Reboot after close

Post by AMitchneck »

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

Post Reply