LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect "You're about to be signing out" using Call Library Function.

Solved!
Go to solution

Hi,
I'm trying to use "Call Library Function" for detecting the message: "You're about to be signed out", that is triggerd by a Wago 759-870 UPS when there is a Power failure (buffermode).
I think this message is a standard Windows 10 popup which are used whenever Windows is planning to shutdown within a certain time...
Any idea what Library name/Function name(and nIndex) that is needed for detecting this message(when its generated)? 🙂

 

0 Kudos
Message 1 of 23
(3,472 Views)

As far as I can tell, the message is a result of the SystemPowerStatus changing. Not sure if you can detect the message itself.

 

The SystemPowerStatus can be detected with a dll:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa373231(v=vs.85).aspx

Haven't done this, and really don't recommend it. It might not even be possible in pure LV (smells like you need a callback).

 

However, this is pretty easy in .net:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa373231(v=vs.85).aspx

If you dig around you can even get a .net callback event so you don't need to poll the status:

https://stackoverflow.com/questions/5378449/c-sharp-raise-event-on-powerstatus-change

 

If you arm the .net callback VI with a user event, you can catch the status event in a normal event structure, so it fits in nicely with the rest of your program.

 

Get SystemPowerStatus.png

 

0 Kudos
Message 2 of 23
(3,449 Views)

I think the ".NET" approach will do the trick 🙂 !
I'm have not used ".NET" that much, so I can't seem to find "SystemInformation"...
Under what assembly do you find the "SystemInformation" ( Select Class-> .NET -> "Browse" ) ?

0 Kudos
Message 3 of 23
(3,420 Views)

If you are used to Call Library Node's, you're going to love .net. It is soo much easier to use. Some things are tricky, but usually C# translates very well to LabVIEW, providing an internet full of resources.

 

The "browse" in LabVIEW is not very useful. Again, when you're used to it, it gets easier.

 

The namespace alone is not enough. System might have a System.Windows, System.Windows might have a System.Windows.Forms, and mscorlib might have all of them as well.

 

The usual approach is to google the function\class to find the MSDN help. For SystemInformation, it's here:

https://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation(v=vs.110).aspx

 

Assembly is the important part:

Assembly: System.Windows.Forms (in System.Windows.Forms.dll) 

As a rule, that is where to find it.

 

A special note on this example. There is no constructor, the property is "static". So you need create a property and select browse on it.

 

 

Message 4 of 23
(3,409 Views)

I see Smiley Happy !

I have tried to use the "SystemInformation" -> "PowerStatus" to detect the change in the "Online/Offline" value and it does not work since the UPS immediately kicks in (the power status stays the same). This is a desktop PC which has no battery other then the UPS, so there will not be any power toggle (Online/Offline). The only confirmation I get on power failure is from the UPS itself that triggers the pop-up message ("You're about to be signed out"). So what i'm looking for is the "event" itself and I found this:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa376889(v=vs.85).aspx

Can this be used with .NET (System.Windows.Forms)?

 

0 Kudos
Message 5 of 23
(3,365 Views)

I see Smiley Happy !

Well, I have now tried to use the "SystemInformation->PowerStatus->PowerLineStatus", but it does not work since the power source stays on when the power is lost and the UPS kicks in.

This is a desktop without any battery source except from the UPS, so the PowerStatus will there not change.

 

So again, I think that the message generated from Windows ("You're about to be signed out") is the one I have to detect somehow, since the UPS triggers this message when entering "Buffer mode".

 

I found this:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa376889(v=vs.85).aspx

Can this be used with .NET?

0 Kudos
Message 6 of 23
(3,373 Views)

You can do that. Not sure if it works 100%, IIRC, the system will shut down even if you cancel. If you just want to quit the application when the event is raised, it might do the trick if you're fast enough. I think LV might quit LV anyway. Not sure.

 

Anyway... You need to create a Register Event Callback node. Wire a .NET constant to it, and browse to Microsoft.Win32.SystemEvents (System assembly). Create a callback VI, and in there put a popup as a first test, a user event if it works.

0 Kudos
Message 7 of 23
(3,369 Views)

I've tried to make this "Register Event Callback node" with link to "Microsoft.Win32.SystemEvents", but I dont seem to get it right.

Could you be so kind to make a "snippet" out of this for me? Smiley Happy

 

0 Kudos
Message 8 of 23
(3,355 Views)

Sure. You still need to create a callback vi. I've successfully tested that with a BatteryStatus change event.

 

Not sure if you need SessionEnded or SessionEnding, I'd try both. In the callback, you probably get general event nodes. You might need to cast them to the specific event that you know it is if you want more properties\methods. Not sure if there are any...

SystemEvent Callback.png

0 Kudos
Message 9 of 23
(3,349 Views)

I guess it was a little more difficult to receive a value(true/false) from Windows than originally expected Smiley Frustrated.

0 Kudos
Message 10 of 23
(3,341 Views)