How to take Usb slot in the hub immediately after plugging it in? - windows-10

I am implementing a scenario where I should take the slot of a Usb immediately after I plug it in. 15 is what I want to take.
The code works fine after plugging in the 1st Usb. When I plug the 2nd Usb earlier than 1 minute after the 1st was plugged, I do not get any information for the 2nd Usb which is already plugged in. I will show you the code which handles the retrieve of the slot information. This method is executed after a fired event when a USB is plugged in.
Main thing: I have to wait more than 1 minute, then I can plug the 2nd Usb and take the slot. If I plug it in before waiting 1 minute after the 1st is plugged I do not take any information for the last Usb plugged.
static int GetPhysicalPort()
{
try
{
devices = new List<USBDeviceInfo>();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(#"Select * From Win32_PnPSignedDriver WHERE DeviceId LIKE 'USB\\VID%' AND Description = 'USB Mass Storage Device' "))
{
collection = searcher.Get();
searcher.Dispose();
}
foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceId"),
(string)device.GetPropertyValue("Description"),
(string)device.GetPropertyValue("Location")
));
}
collection.Dispose();
string LastAdded = devices[0].Location.Substring(6, 4);
Console.WriteLine(LastAdded);
return Convert.ToInt32(LastAdded);
}
catch (Exception e)
{
Console.WriteLine(e);
return 0;
}

As per WMI Win32_PnPSignedDriver class it would be the application which would be taking that much time to query or give results for the USB inserted second time. This depends on application to application as the pole rate or response rate of that application running this WMI query would be designed it such a way to give results in 1-2 min.
We could check the same in terms of OS level or WMI level to see if WMI as a whole is taking time to give query results on the machine.
Open Run command and type WBEMTEST.
Click on connect as it will connect the CIMV2 Namespace. Under this namespace lies the class Win32_PnPSignedDriver
As an when we query this class with the query select * from win32_PnPSignedDriver it would shows us some results instantly like for eg 60-70.
Now when you close it and again run he same query it would show some more or the same results depending on the OS etc.
The above will show us that WMI query or WMI as a whole is working the way it should be on the machine.
The issue could be caused by the application which is taking this much time to read the contents of the second USB as per the WMI query it is querying.

Related

How can I see the gateway connected individual device data in the IBM-watson-IoT dashboard?

How can I see the gateway connected individual device data in the IBM-watson-IoT dashboard ? Is there any specific way see that?
Right now I am sending data as:
//publishing device events with deviceType 'Raspi' and deviceId 'pi01' using the default quality of service
gatewayClient.publishDeviceEvent("Raspi","pi01", "status","json",'{"d" : { "cpu" : 60, "mem" : 50 }}');
console.log('event published');
But I am not able to see this data stream anywhere in the IBM-watson-IoT dashboard. It's showing the event as received but no data stream of device "pi01".
When data is sent as:
gatewayClient.publishGatewayEvent("status","json",'{"d" : { "cpu" : 40, "mem" : 50 }}');
this means as gateway. It shows "received data" when I am creating the card. But I dont want this, I have a different device connected with the gateway, so I want the new device data in a different data stream.
Please let me know if I am doing it right, and if yes then where can I see all that data.
The only way to do this in the Dashboard is in a Card. No other way in the Dashboard (though there are other ways outside of the dashboard). Your code looks fine. If you select your device in a Device centric card you can see the stream of values for just that gw-device in the properties or make graphs etc if they would help. It is its own stream of data; should not be mixed up with any other device even if they share the same gateway. Here is one gateway sending data for 2 devices using:
gatewayClient.publishDeviceEvent('SenseHat','sen-pi-xxx-gw' ,'event', 'json', '{"sugar":5, "salt":2}', 1);
gatewayClient.publishDeviceEvent('SenseHat','xx-gw-device' ,'event', 'json', '{"sugar":9, "salt":12}', 1);

What user inputs are required for a Digital TV Device Selection?

In the process of building a Digital TV graph, I need:
Network Provider -> Tuner -> Capture -> MPEG2-Demux -> MPEG2 TIF
-> MPEG2 Sections
-> Video Decoder -> VMR9
-> Audio Decoder -> DirectSound
It's obvious to me that I can hard-code in the name of the provider (Microsoft Network Provider), but do I need to prompt the user to select both a tuner and a capture device from the list of available devices, or can I somehow query for the tuner that corresponds to the capture device that the user has selected?
Basically I'm asking whether an API call exists similar to:
IMoniker *pTuner = GetTunerForCaptureDevice(pIMonikerSelectedCaptureDevice);
or whether it's standard to make the user choose both the tuner and the capture devices in their config.
The way that it seems that most applications deal with this problem is to go in the reverse direction. For the purposes of configuration, they provide list of all devices in the category KSCATEGORY_BDA_NETWORK_TUNER and allow the user to select one of the tuners.
After that device has been added to the graph, all devices are enumerated for the category of KSCATEGORY_BDA_RECEIVER_COMPONENT. For each item returned, the capture device item is added to the graph, and connect is called between the tuner output pin and capture input pin. Rough code: (without the necessary Releases()'s)
for (fFound=FALSE; !fFound; )
{
IMoniker *pIMoniker;
IBaseFilter *ppIBaseFilter;
hr = pIEnumMoniker->Next(1, &pIMoniker, NULL);
if (hr!=S_OK)
break;
hr = pIMoniker->BindToObject(NULL, NULL, __uuidof(IBaseFilter),
(void **)&ppIBaseFilter);
hr = m_pIGraphBuilder->AddFilter(*ppIBaseFilter, L"Capture filter");
hr = ConnectFilters(m_pIGraphBuilder, pITunerFilter, ppIBaseFilter)));
if (hr != S_OK)
{
m_pIGraphBuilder->RemoveFilter(ppIBaseFilter);
goto NextMoniker;
}
fFound = TRUE;
NextMoniker:
// release things here.
}
If any of the capture devices successfully connect pins, then the loop ends and that capture filter is used in the graph.
I went this direction of starting with a user selection of a tuner because I was seeing several products that returned more than one tuner device, and when attempting connections in the reverse order (capture, then tuner), I seemed to always be successfully connecting the wrong tuner.

Azure RoleInstance Id when scaling out, RoleEnvironmentTopologyChange not fired

Will the first instance deployed always end with a zero ? 0. like "xxxx_IN_0"
When scaling up to X instanses, will the next instanses always get 1 2 3 4 as the last number. ( I think so).
What happens when I scale down again? I read that it will take at random one of the instances. So when scaling down to 1 instance, I cant assume that I know what ID is the one that still are running?.
Anyone who have been playing with the IDs when scaling up and down and know those things?
The reason for me asking is that I have some extra logic that I want to run on only one, not less or more, of the instances. If I can assume that the "xxx_IN_0" is always present then i can just do it with a simple check that last of ID is zero. If not, I am considering to check all ids and if the current instance is the lowest, then it will do its magic.
If the last case, are there an event i can monitor for when scaling up or down is done?.
update
From Answer:
if (RoleEnvironment.IsAvailable)
{
RoleEnvironment.Changed += RoleEnvironment_Changed;
}
void RoleEnvironment_Changed(object sender, RoleEnvironmentChangedEventArgs e)
{
var change = e.Changes.OfType<RoleEnvironmentTopologyChange>().FirstOrDefault();
if (change != null)
{
Trace.TraceInformation("RoleEnvironmentTopologyChange at RoleName '{0}'", change.RoleName);
}
I do not get any information in my tracelog when i scale up and down.
There have to be set a internal endpoint to trigger the events:
<InternalEndpoint name="InternalEndpoint1" protocol="http" />
http://blogs.msdn.com/b/windowsazure/archive/2011/01/04/responding-to-role-topology-changes.aspx
You should listen to the RoleEnvironment.Changed event which occurs when the service configuration is changed.
When you receive this event, check the Changes property for an instance of RoleEnvironmentTopologyChange. This change will be reported when the number of instances are changed.
To determine on which server you should run that extra logic you could examine the list of roles and from there find all instances. Sort instances by id and select the first to be the special one.
However, if it is critical that only a single server run this special logic at any time, you will need a more stable solution.

Turn Based Participant Timeout Date Always NULL

Have been working on a two-player turn based game that uses a custom UI for match management. Considering restricting the app to iOS 6+ in order to use player timeouts. I would like to show the user the remaining amount of time to move, but the participant.timeoutDate is always null? Per the WWDC 2012 video (that says the timeout won't apply to the last participant in nextParticipants), I pass an array with two entries (opponent at index 0 and local player at index 1) when calling endTurnWithNextParticipants:turnTimeout:matchData:completionHandler: to take a turn. I've tried both GKTurnTimeoutDefault and various integer literals ... no luck ... always seems to be null. The player's last turn date works fine.
On the subject of player timeouts ... after I get them working, how is this delivered? I see GKTurnBasedMatchOutcomeTimeExpired ... does this come in a turn event?
From Apple's developer forum
Elian Gidoni -
+1
The doc should be:
timeoutDate
The date and time when the participant’s turn timed out. (read-only)

How to count the time a Windows users is logged in (VC++)

I am writing a Windows service for doing Parental Control (Visual C++).
I am having trouble with the following:
how to count the time a Windows user has been logged on today (time measured in hours)
how to trigger log-off from the user Windows account, when time per day exceeds a specified value, say 5 hours.
Any help is appreciated.
Regards!
To do that I think there may me several ways.
I think the simplest one is to use a timer that could be launched when the service start (or when your application start if placed in the startup menu).
For that you can use the SetTimer method associated to a WM_TIMER message :
http://msdn.microsoft.com/en-us/library/ms644906(v=vs.85).aspx
You should get the time before the launching of the timer using a CTime function for example :
CTime t;
t.GetCurrentTime ();
timeAtLaunched=t.GetSecond(); //or GetHour()
After that you can put a similar CTime call inside your timer function to have a currentTime value and calculate a difference between the currentTime value and the timeAtLaunched value
To keep the connected time during a day if an user connect and disconnect several times, you should keep the difference value inside a file or inside the registry.
To force logoff, you can use :
ExitWindowsEx (EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
SHTDN_REASON_MINOR_UPGRADE | SHTDN_REASON_FLAG_PLANNED)

Resources