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));
}
}
- Jarno