Getting the current device time - c#

I'm using WIA (Windows Image Acquisition) to grab photos from a camera. Using WIA 2.0, .net 4 C#, my test device is a Nikon D90 (yup, I have it actually plugged in). So the scenario is:
User has camera plugged into PC
User takes a photo from the camera itself
My application downloads the image via WIA
All of the above is working.
The problem I'm having is getting the current time from the device itself. The first time I get the time from the device I get the correct time, all good. If I run my application again, WIA seems to cache the time I got earlier and returns that, which is useless.
// use the WIA.DeviceManager to get the deviceInfo (not shown)
var device = deviceInfo.Connect();
var prop = device.Properties["Device Time"];
Vector deviceTimeVector = (Vector)prop.get_Value();
var deviceTime = deviceTimeVector.Date;
Does anyone who's done some work with WIA know how to reliably get the current time from a device? I've tried a synchronise but this doesn't seem to have any effect.
_device.ExecuteCommand(WIA.CommandID.wiaCommandSynchronize);
Open to suggestions too. I was thinking my only other way would be to "calibrate" the device by taking a test shot, checking what the time taken of that picture was but there's problems with this too.
Please let me know if you need any information.

Related

Why can't a windows service created in C# detect that a screen saver is currently running?

As part of some work I need to get done for Windows 10, I have written a code in C# that essentially detects every minute whether a PC is in screen saver mode or not, and it writes to a table in MySQL the relevant status ("PC in use" if the screen saver is off, "available PC" if the screen saver is on).
I did this using (full link if required - https://www.codeproject.com/Articles/17067/Controlling-The-Screen-Saver-With-C):
// Returns TRUE if the screen saver is actually running
public static bool GetScreenSaverRunning( )
{
bool isRunning = false;
SystemParametersInfo( SPI_GETSCREENSAVERRUNNING, 0,
ref isRunning, 0 );
return isRunning;
}
The code works flawlessly in console application mode (I made a loop to test it out over a minute with a check up on screen save status every 10 seconds), this means in MySQL the status was set correctly every time, depending on the screen save status at the moment of the check up.
The problem occurs when I use this code for a windows service. The service is installed correctly, the log on tab is set on Local System (I also tried with the logged in user instead, same results) and I allow the service to interact with the desktop, just in case, but the difference here is that no matter if the PC enters screen save or not, it always returns false on GetScreenSaverRunning(), thus setting the status of the PC in MySQL as "PC in use", even if the screen saver is on at the moment of check up.
I get the sense that the problem isn't in the code itself, since it works without any issues as a console application, but perhaps something behind the scenes. I tried to search here and on many other websites, haven't found anything related to such a problem.
Does anyone have any idea at all what might be the issue? Any help and/or suggestions will be greatly appreciated!
Thank you in advance.
(I could post the code if required, but it is pretty much straight forward and the main part of it, controlling the screen save detection, is taken from the website mentioned above, afterwards it's a simple if (GetScreenSaverRunning() == true) )
Ever since Vista, Services are barred from a Interactive Session. Even if they run under the same rights, they do not get a interactive Session. I would guess that is getting in the way here.
While you can overwrite this behavior in the Service settings, this is not adviseable for new code. Consider making this a Background Task started by the Task Sheduler instead.
Because the windows service runs in different session then the windows logon. You can't interact with the desktop related services unless you run the windows service in win logon session. There used to be an option in Windows service manager where you can set the properties to "Interact with desktop session" but I don't think that ever worked.
There's a work around to run the windows service using the win logo session.
See this helper class that can get the current logged on user session and interact with the desktop services. https://github.com/murrayju/CreateProcessAsUser/blob/master/ProcessExtensions/ProcessExtensions.cs

Windows RT (r-pi IoT 10) HID device

I am trying to use a HID (DualShock 4) connected to my R-PI 3 running Windows 10 IoT in a C# universal app. I was using the Device Enumeration sample as a guideline and managed to display the IDs of all connected devices. I could see that the connected DualShock was correctly enumerated because it logged the \\?\HID#VID_054C&PID_05C4....
So naturally the next thing I wanted to do was opening the device for communication. Since it is an HID I was using the HidDevice class with var device = await HidDevice.FromIdAsync(args.Id, FileAccessMode.ReadWrite);. Sadly the returned device is always null, nothing on the screen is prompted or so.
Next I assumed there at least has to be some kind of USB interface accessible so I went for var device = await UsbDevice.FromIdAsync(args.Id);
But now I am getting A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F) or sometimes also The process cannot access the file because it is being used by another process.
How can I talk to my device? :(

Contents Transfer Not Available Now, Sony A6000

I've got Sony A6000 camera with the latest firmware(3.20) and latest Smart Remote Control application (4.30). I've been trying to write application for transferring images, but faced with issues.
I can't switch camera function to Contents Transfer mode.
Repro steps:
Run Smart Remote Control app on my camera;
Sucesfully connect device to camera via WI-FI;
Discover the camera with parameter ST=urn:schemas-sony-com:service:ScalarWebAPI:1;
Receive response Location http://ip:port/scalarwebapi_dd.xml (instead mentioned in doc http://ip:port/dd.xml);
Parsed scalarwebapi_dd.xml contains guide, accessControl and camera services (instead mentioned in doc camera, system and avContent);
Request with getAvailableApiList method return the following:
getVersions, getMethodTypes, getApplicationInfo, getAvailableApiList, getEvent, startRecMode, stopRecMode.
Successfully run request with "startRecMode" method;
"getAvailableApiList" result doesn't contain "getCameraFunction" and
"setCameraFunction"
"getCameraFunction" return the following result:
{"id":1,"error":[1,"Not Available Now"]}
What I'm doing wrong?
Smart Remote 4.30 should give you the avContent services. I had an older version that had the same guide, accessControl, camera but after I updated it had the avContent service.
You can also try using getEvent to troubleshoot the camera status. This could shed some light into why the services aren't available.

Using CameraCaptureTask to launch the default camera app

Windows Phone 8 gives the ability to change the default camera app with another one downloaded from the store, making this new app the one that's launched when you hit the camera hardware button.
So I was wondering if is there any chance to launch this app using the CameraCaptureTask.
What I'd like to do is something simple like
var camera = new CameraCaptureTask();
camera.Show();
camera.Completed += new EventHandler<PhotoResult>(camera_Completed);
but I want this to work with the default app that the user chose on its device, and not with the basic Microsoft's one.
I've not found anything online, so I'm asking to you guys if I can make what I want.
Sorry, not possible with the current API.

Programmatically enabling Windows 8 Pro mobile broadband device

Background
The company I work on is developing a kiosk-like application for tablets running Windows 8 Pro (on desktop mode). The user shouldn't be able to access anything that isn't the application itself: charms will be disabled, the taskbar will be hidden behind the application, etc.
This also means the user shouldn't be able to change network settings, leaving the responsability to keep the device always connected to us. Up to now, I had success using the Mobile Broadband API to assure the device is connected whenever there's a mobile network available. It'll detect disconnect events and try to connect again.
The Problem
Although the user shouldn't be able to do it, I'm considering the case where the user follows this steps:
User opens right-side charm,
clicks on Settings,
clicks on Network,
clicks on More PC Settings,
clicks on Wireless, and
disables the mobile broadband device.
I would like to be able to revert this programmatically and enable it again.
The Attempts
I have tried some different ways to force 3G being reenabled. Most of them give me the same result: they supposedly enable the device without errors, but I still cannot use it. Enable-NetAdapter in Powershell doesn't throw errors, and the Enable method of Win32_NetworkAdapter appears to work, but no dice.
I thought maybe the method IMbnRadio::SetSoftwareRadioState could be what I'm after, but I can't get to it when the device is disabled. The method IMbnInterfaceManager::GetInterfaces throws a COMException claiming the element could not be found (HRESULT = 0x80070490).
MbnInterfaceManager mbnInterfaceManager = new MbnInterfaceManager();
IMbnInterfaceManager interfaceManager = (IMbnInterfaceManager)mbnInterfaceManager;
// The following line throws a COMException:
IMbnInterface[] interfaces = (IMbnInterface[])interfaceManager.GetInterfaces();
mobileInterface = interfaces[0];
mobileRadio = (IMbnRadio)mobileInterface;
uint requestId;
mobileRadio.SetSoftwareRadioState(MBN_RADIO.MBN_RADIO_ON, out requestId);
Is there a way to override user preferences set on "More PC Settings?"
I found a sketchy way to solve this. Keep in mind this is undocumented, wrong, shameless and immoral, and will probably break eventually. The client is aware of this, but prefers to keep the access to the OS limited.
The setting in case is saved in the Registry. At least in the computers I've checked, it's stored in HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0022 in a key named RadioOff.
The Airplane Mode setting is also stored in the Registry, but in a different place. It's at HKLM\SYSTEM\CurrentControlSet\Control\RadioManagement\SystemRadioState in a key named (Default).
After changing these keys and rebooting, everything seems to work fine. I'll repeat though: you really shouldn't be doing this, especially the Airplane Mode thing.

Categories

Resources