Deactiving the backlight of T7A with a script

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
jarno.purontakanen
Posts: 2
Joined: Wed May 08, 2013 3:30 am

Deactiving the backlight of T7A with a script

Post by jarno.purontakanen »

Hi all,

I have a need to deactivate the backlight of T7A(the softcontrol variant) on certain events happening in the process and force it's activation when certain events happen. Problem is, I can't seem to get the backlightoff power state working. I have used code given in here as base of my script.

When T7A's screensaver is being used, the active power state is on with 0x12010000 (POWER_STATE_ON, POWER_STATE_BACKLIGHTON and POWER_STATE_PASSWORD set). When screensaver activates, the power state changes to backlightoff with 0x1001000 (POWER_STATE_ON and POWER_STATE_PASSWORD set).

When I try to mimic this with a script, I can wake the display up easily with the on state but trying to activate the backlightoff state always reverts back to on state and thus I cannot get it to power off the backlight. Also, the state POWER_STATE_IDLE (which is named screenoff) doesn't do anything and the state named systemidle which was suggested in the previous thread doesn't exist.

Here's my current script. The ActivateXxxPowerState() functions are called by tag's ValueOn event.

Code: Select all

    public partial class DisplayPower
    {
		[DllImport("coredll.dll", EntryPoint = "GetSystemPowerState")]
		private static extern uint CEGetSystemPowerState(StringBuilder Buffer, uint Length, out uint Flags);

		[DllImport("coredll.dll", EntryPoint = "SetSystemPowerState")]
		private static extern uint CESetSystemPowerState(char[] sState, uint StateFlags, uint Options);
		
		protected static Timer PowerStateRefreshTimer = null;
		
		static DisplayPower() {
			// Setup and start the refresh timer on system startup
			PowerStateRefreshTimer = new Timer();
			PowerStateRefreshTimer.Tick += new EventHandler(WritePowerStateToTag);
			PowerStateRefreshTimer.Interval = 5000;
			PowerStateRefreshTimer.Enabled = true;
		}
		
		public static uint ActivateHighPowerState() {
			//Sets the system state to "on"
			string state = "backlightoff";
			return CESetSystemPowerState(state.ToCharArray(), 0x0, 0x0);
		}
		
		public static uint ActivateLowPowerState() {
			//Sets the system state to "backlightoff"
			string state = "backlightoff";
			return CESetSystemPowerState(state.ToCharArray(), 0x0, 0x0);
		}
		
		public static string GetPowerState() {
			//Queries the system and finds out what the current power state is.
			StringBuilder systemStateName = new StringBuilder(20);
			uint systemState;
			CEGetSystemPowerState(systemStateName, (uint) systemStateName.Capacity , out systemState);
			return systemStateName.ToString();
		}

		public static uint GetPowerState(out string stateName, out uint state) {
			//Queries the system and finds out what the current power state is.
			StringBuilder systemStateName = new StringBuilder(20);
			uint systemState;
			uint cError = CEGetSystemPowerState(systemStateName, (uint) systemStateName.Capacity , out systemState);
			stateName = systemStateName.ToString();
			state = systemState;
			return cError;
			
		}

		protected static void WritePowerStateToTag(Object myObject, EventArgs myEventArgs) {
			// Write current power state of the display to plc
			uint state;
			string name;
			GetPowerState(out name, out state);
			Globals.Tags.Application_IXHELPERS_displayCurrentPowerState.SetString(string.Format("{0} 0x{1:X}",name,state));
		}
    }
Does anybody have a suggestion how to make this work?

- Jarno

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Deactiving the backlight of T7A with a script

Post by mark.monroe »

The POWER_STATE_USERIDLE puts the unit into a low power mode, which most of our units do not have, so it does nothing.

How are you calling the ActivateLowPowerState() function? If you do it via a button, the unit will immediately go back into a high power state because it senses the button press. You need to do it via some other method. Maybe try putting that in a timer as well.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

jarno.purontakanen
Posts: 2
Joined: Wed May 08, 2013 3:30 am

Re: Deactiving the backlight of T7A with a script

Post by jarno.purontakanen »

I actually have ActivateLowPowerState() and ActivateHighPowerState() called by tag triggers (ValueOn events). I also tried using starting a timer on tag trigger which then used those functions as callback. Both don't work.

While waiting the forum post to be approved I found out that atleast on Windows CE 6.5 there is no way to really force activation of backlightoff state as enabling it through SetSystemPowerState() is disallowed (msdn article). This is also reinforced by the fact that I noticed that when trying to set PowerState to backlightoff, the function returns a W32 error code of 0x00000057 ERROR_INVALID_PARAMETER (Win32 error codes). Interestingly when calling SetSystemPowerState(null,0x1001000,0x0) the error code doesn't appear even if the meaning is the same.

Any ideas?

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Deactiving the backlight of T7A with a script

Post by mark.monroe »

I spoke with the developers and they said that you can not turn off the back light on a TxA. The script that you are using works on a QTERM A7. The drivers for the QTERM Ax units are different than those used on the TxA, which would explain why the script works on an A7, but not a T7A.

I retested the script that was posted and found that it did dim the backlight on a A7, but not a T7A.

The only thing you can do to dim the backlight on a TxA unit is to use a system tag or set the screen saver. The system tag doesn't completely turn the backlight off, just dims it.
Snap 2013-05-15 at 07.56.45.jpg
Snap 2013-05-15 at 07.56.45.jpg (80.36 KiB) Viewed 11407 times
Snap 2013-05-15 at 07.57.18.jpg
Snap 2013-05-15 at 07.57.18.jpg (45.88 KiB) Viewed 11407 times
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

manuellux
Posts: 1
Joined: Tue Aug 20, 2013 5:19 am

Re: Deactiving the backlight of T7A with a script

Post by manuellux »

The backlight can be switched off/on using the screensaver.

Code: Select all

// switch backlight off after a delay of 1s (is 0 possible too?)
Neo.ApplicationFramework.Common.Service.ServiceContainerCF.GetService<Neo.ApplicationFramework.Interfaces.IBacklightService>().SetBacklightTimout(1);
Neo.ApplicationFramework.Common.Service.ServiceContainerCF.GetService<Neo.ApplicationFramework.Interfaces.IBacklightService>().SetAutomaticallyTurnOfBacklight(true);

// turn backlight on again and disable screensaver
Neo.ApplicationFramework.Common.Service.ServiceContainerCF.GetService<Neo.ApplicationFramework.Interfaces.IBacklightService>().TurnBacklightOn();
Neo.ApplicationFramework.Common.Service.ServiceContainerCF.GetService<Neo.ApplicationFramework.Interfaces.IBacklightService>().SetAutomaticallyTurnOfBacklight(false);
Note that this only works when nobody does touch the screen.

Manuel

Post Reply