Loss of events/actions for USB Device

If you have a question or need help, this is the place to be.
jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Wed Dec 20, 2017 7:13 pm

I just had the power issue come up in a different forum. If it is a matter of powering up EG AFTER the devices turn back on then would there be a way to delay the re-initialization of EG? What would happen if someone added a wait some time for 30 seconds to 1 minute to the very top of their tree? Would that ensure that at least the plugins will load last and possibly avoid the whole thing where a plugin loads before the device?

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Wed Dec 20, 2017 7:48 pm

the issue is not with the startup of EG. But with how windows handles shutting down the devices and turning them back on after a S state change.

I believe it does this at the same time. so depending on how many applications you have running at that time. and also depending on when you had EG start. and also if an application programmer was a dumbass and didn't program his application in a manner that would start a thread to instruct his program what to do and release the notification (this would slow the notifications from windows that the PC was changing power state) and depending on how fast Windows manages to shutdown the devices the device being powered off can happen before a application ever gets a notice that the power state is changing. so the program sees the devices get detached from the system.

and when the computer fires back up the same crap happens. so the devices get reattached before the program wakes up so the program doesn't see the devices get reattached and there for thinks they are still unattached.

Now in EG land we have accounted for this happening. If a plugin developer has not decided to code his/her plugin to use the OnComputerResume and OnComputerSuspend methods that are apart of the PluginBase class (which they need to subclass in order for their plugin to work) to "rescan" for devices then that is the fault of the plugin developer. If you are specifically referring to the MCE Vista+ plugin, this plugin has external files that are attached to the plugin that are written and compiled in C or C++ code. I am not sure if the piece of that plugin that would handle the device are in the plugin it's self or in the external files. It is always best to bring this issue up to the developer/maintainer of the plugin and reference this post to them, as they may not know of those 2 methods and would be willing to fix the issue. It takes a very large amount of time to fix a plugin that one did not write or is not familiar with.

There is no problem with EG. technically speaking there is no issue with Windows (in regards to how it handles this). We do not have the ability to control what others run on their PC. and We do not have control over how other developers decide to write their applications. We have coded in a notification system to let the plugins know of the state change. There really is nothing more we can do. If it is with a plugin that is no longer being maintained. and someone is having an issue with it. I am sure either Topic or I and possibly one of the other contributors will step up and fix it. But we need to know what plugin it is. and we would know by having the issue posted in that plugins support thread.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Wed Dec 20, 2017 8:13 pm

They were able to solve the problem by using different hardware

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Wed Dec 20, 2017 9:24 pm

by changing the hardware it changes the order in which the devices get processed. and now that new device gets shutdown after the app receives notification.

I have researched this issue over and over again. there are simply way to many factors that can change that order. the simple answer is the plugin needs to handle it.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Wed Dec 20, 2017 9:26 pm

I have gone through the Atric plugin and rewritten some of it. It is not backwards compatible with the old plugin. the old one will have to be removed first then this one installed. It has built into it the handling of the USP powering down issue. I am not able to test this plugin except for loading it into EG.

Let me know if there are any errors.
Attachments
Atric-1.1.0.egplugin
(613.28 KiB) Downloaded 40 times
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Fri Dec 22, 2017 3:30 pm

So how would it effect things if all devices were plugged into a powered usb hub? There comes a point where your motherboard cannot realistically power all of your devices so this is usually necessary anyway (At least on a laptop)? Do the mechanics of all of these devices receiving and losing power create the problem or does it come from how well each device and or windows sends messages about power state changes? If the device never loses power, then would the device ever try to signal windows that power has been lost or restored? For PCI devices I believe there are also power management settings, and I'm betting Windows will always do better with a PCI connection than a USB? I have a powered USB hub, and I don't put the machine to sleep but when it happens on accident I don't think I get these kinds of problems. I'll have to test some and see.

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Fri Dec 22, 2017 4:17 pm

when it powers down the USB ports, no USB the hub is no longer connected. whether or not the hub is powered.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Fri Dec 22, 2017 4:23 pm

unless all of the USB ports are configured to not sleep.

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Fri Dec 22, 2017 4:47 pm

if you have all of the USB ports configured to not sleep and to not power down. and the bios also configured the same for the USB ports. then there should be no issue.

Now there are several different S states.

=============================================================================
System power state S1 is a sleeping state with the following characteristics:

Power consumption - Less consumption than in S0 and greater than in the other sleep states. Processor clock is off and bus clocks are stopped.

Software resumption - Control restarts where it left off.

Hardware latency - Typically no more than two seconds.

System hardware context - All context retained and maintained by hardware.


=============================================================================
System power state S2 is similar to S1 except that the CPU context and contents of the system cache are lost because the processor loses power. State S2 has the following characteristics:

Power consumption - Less consumption than in state S1 and greater than in S3. Processor is off. Bus clocks are stopped; some buses might lose power.
Software resumption - After wake-up, control starts from the processor's reset vector.
Hardware latency - Two seconds or more; greater than or equal to the latency for S1.
System hardware context - CPU context and system cache contents are lost.


=============================================================================
System power state S3 is a sleeping state with the following characteristics:

Power consumption - Less consumption than in state S2. Processor is off and some chips on the motherboard also might be off.

Software resumption - After the wake-up event, control starts from the processor's reset vector.

Hardware latency - Almost indistinguishable from S2.

System hardware context - Only system memory is retained. CPU context, cache contents, and chipset context are lost.


=============================================================================
System power state S4, the hibernate state, is the lowest-powered sleeping state and has the longest wake-up latency. To reduce power consumption to a minimum, the hardware powers off all devices. Operating system context, however, is maintained in a hibernate file (an image of memory) that the system writes to disk before entering the S4 state. Upon restart, the loader reads this file and jumps to the system's previous, prehibernation location.

If a computer in state S1, S2, or S3 loses all AC or battery power, it loses system hardware context and therefore must reboot to return to S0. A computer in state S4, however, can restart from its previous location even after it loses battery or AC power because operating system context is retained in the hibernate file. A computer in the hibernate state uses no power (with the possible exception of trickle current).

State S4 has the following characteristics:

Power consumption - Off, except for trickle current to the power button and similar devices.

Software resumption - System restarts from the saved hibernate file. If the hibernate file cannot be loaded, rebooting is required. Reconfiguring the hardware while the system is in the S4 state might result in changes that prevent the hibernate file from loading correctly.

Hardware latency - Long and undefined. Only physical interaction returns the system to the working state. Such interaction might include the user pressing the ON switch or, if the appropriate hardware is present and wake-up is enabled, an incoming ring for the modem or activity on a LAN. The machine can also awaken from a resume timer if the hardware supports it.

System hardware context - None retained in hardware. The system writes an image of memory in the hibernate file before powering down. When the operating system is loaded, it reads this file and jumps to its previous location.

so depending on which one you have your bios using will also impact what is happening with the devices.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Fri Dec 22, 2017 5:35 pm

Not saying this is easy or even possible but what about creating a default hibernation file? I think the file itself is called hyberfil.sys. Would modifying that so it tells windows to resume certain devices in a certain order possibly fix some issues. Just curious, and wondering if it's even worth investigating.

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Fri Dec 22, 2017 7:07 pm

The mechanism to handle this issue is in place. it simply needs to be used.


It could be as simple as restarting the plugin in most cases.
If you like the work I have been doing then feel free to Image

jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Sat Dec 23, 2017 4:21 am

For the sake of documenting it, I use a power USB hub and after countless restarts I don't have any weird issues with things powering up. I use a gyration RF remote in combination with the Generic HID plugin to READ events, and the same gyration remote with the MCE IR plugin to SEND output IR blasts through a Microsoft Ehome IR transceiver with an external blaster connected to it.

jachin99
Experienced User
Posts: 547
Joined: Sat Feb 13, 2016 8:39 pm

Re: Loss of events/actions for USB Device

Post by jachin99 » Sat Dec 23, 2017 4:23 am

kgschlosser wrote:
Fri Dec 22, 2017 7:07 pm
The mechanism to handle this issue is in place. it simply needs to be used.


It could be as simple as restarting the plugin in most cases.
Is this part of the plugin review/rewrite you have alluded to in the past?

User avatar
kgschlosser
Site Admin
Posts: 4250
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Loss of events/actions for USB Device

Post by kgschlosser » Sat Dec 23, 2017 4:43 am

one of the things we will check once the plugin repository gets up and running fully.

The single largest purpose for reviewing plugins is not to try to make work for a developer. It is to inform the developer of any changes in the API whether it be upcoming or something they may not know about. And also to make less work for the next person that happens to work on the plugin. Having a standardized format and "style" (i use this term loosely) will help in understanding what is happening inside the plugin. One of the things I would love to see done is to have plugins made in a fashion where any API for connecting/communicating with a piece of hardware or software is made in a manner that would allow it to be run independently of EG. the reason for this is if we make a version of EG that has some pretty massive API changes it would allow someone to be able to separate the 2 parts and easily create a plugin for the new version.

We have been in discussion about Making EG a service based program. and possibly making it so it can run on Linux and Windows alike. and offering a web interface and a console/GUI. This no doubt would break the current EG API. and there are a whole lot of plugins that would have to be rewritten. and some of them being as complex as they are may not make it into a newer version of EG because of the amount of rewriting that would be necessary.

Making a change like this would require plugins to be reviewed to make adding support for a newer version of EG easier.
If you like the work I have been doing then feel free to Image

Post Reply