J
Jerry.Mouse
Guest
Hello, I have a small problem with WPD. I have Canon PowerShot S60 connected to PC via USB. I am trying to take a picture using WPD in C#, but there is some suspicious problem. The complette (and simple) source code is listed below. If I use
this line: properties.GetValues("DEVICE", keys, out values); everything is ok, but if I comment it out, the camera is NOT capable to take an image. The line pd.SendCommand(0, par, out res); is passed without error, but the image is not taken. Can someone from WPD team can help where is the problem ? By the way how can I read error messages from pd.SendCommand(0, par, out res); ??
Many thanks
Jerry
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PortableDeviceApiLib;
using PortableDeviceTypesLib;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace PD
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("begin");
PDProgram.DoWork();
}// static void Main
}// class Program
public class PDProgram //: IDisposable
{
public static void DoWork()
{
var m = new PortableDeviceApiLib.PortableDeviceManager();
m.RefreshDeviceList();
uint count = 1;
m.GetDevices(null, ref count);
string[] ids = new string[count];
m.GetDevices(ref ids[0], ref count);
Console.WriteLine("Device: {0}, num devs: {1}", ids[0], count);
Console.WriteLine();
PortableDeviceApiLib.PortableDevice pd = new PortableDevice();
var pdv = (PortableDeviceTypesLib.IPortableDeviceValues)new PortableDeviceValues();
pd.Open(ids[0], (PortableDeviceApiLib.IPortableDeviceValues)pdv);
IPortableDeviceContent content;
IPortableDeviceProperties properties;
pd.Content(out content);
content.Properties(out properties);
//this is the mysterious part
PortableDeviceApiLib.IPortableDeviceKeyCollection keys;
properties.GetSupportedProperties("DEVICE", out keys);
PortableDeviceApiLib.IPortableDeviceValues values;
properties.GetValues("DEVICE", keys, out values); // HERE, THIS LINE IS SUSPICIOUS
Thread.Sleep(1000);
//
var par = (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceValues();
PortableDeviceApiLib.IPortableDeviceValues res;
// WPD_PROPERTY_COMMON_COMMAND_CATEGORY
PortableDeviceApiLib._tagpropertykey WPD_PROPERTY_COMMON_COMMAND_CATEGORY = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0xF0422A9C, 0x5DC8, 0x4440, 0xB5, 0xBD, 0x5D, 0xF2, 0x88, 0x35, 0x65, 0x8A), pid = 1001 };
// WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE
PortableDeviceApiLib._tagpropertykey WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0x4FCD6982, 0x22A2, 0x4B05, 0xA4, 0x8B, 0x62, 0xD3, 0x8B, 0xF2, 0x7B, 0x32), pid = 2 };
// WPD_PROPERTY_COMMON_COMMAND_I
PortableDeviceApiLib._tagpropertykey WPD_PROPERTY_COMMON_COMMAND_ID = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0xF0422A9C, 0x5DC8, 0x4440, 0xB5, 0xBD, 0x5D, 0xF2, 0x88, 0x35, 0x65, 0x8A), pid = 1002 };
//
par.SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE.fmtid);
par.SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE.pid);
//
pd.SendCommand(0, par, out res);
uint pcelt = 0;
res.GetCount(ref pcelt);
Console.WriteLine("res: {0}", pcelt);
Console.WriteLine("Picture taken ok / I hope so ");
Console.ReadLine();
pd.Close();
}// public void Connect()
}// class PDProgram
}// namespace PD
Continue reading...
this line: properties.GetValues("DEVICE", keys, out values); everything is ok, but if I comment it out, the camera is NOT capable to take an image. The line pd.SendCommand(0, par, out res); is passed without error, but the image is not taken. Can someone from WPD team can help where is the problem ? By the way how can I read error messages from pd.SendCommand(0, par, out res); ??
Many thanks
Jerry
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PortableDeviceApiLib;
using PortableDeviceTypesLib;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace PD
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("begin");
PDProgram.DoWork();
}// static void Main
}// class Program
public class PDProgram //: IDisposable
{
public static void DoWork()
{
var m = new PortableDeviceApiLib.PortableDeviceManager();
m.RefreshDeviceList();
uint count = 1;
m.GetDevices(null, ref count);
string[] ids = new string[count];
m.GetDevices(ref ids[0], ref count);
Console.WriteLine("Device: {0}, num devs: {1}", ids[0], count);
Console.WriteLine();
PortableDeviceApiLib.PortableDevice pd = new PortableDevice();
var pdv = (PortableDeviceTypesLib.IPortableDeviceValues)new PortableDeviceValues();
pd.Open(ids[0], (PortableDeviceApiLib.IPortableDeviceValues)pdv);
IPortableDeviceContent content;
IPortableDeviceProperties properties;
pd.Content(out content);
content.Properties(out properties);
//this is the mysterious part
PortableDeviceApiLib.IPortableDeviceKeyCollection keys;
properties.GetSupportedProperties("DEVICE", out keys);
PortableDeviceApiLib.IPortableDeviceValues values;
properties.GetValues("DEVICE", keys, out values); // HERE, THIS LINE IS SUSPICIOUS
Thread.Sleep(1000);
//
var par = (PortableDeviceApiLib.IPortableDeviceValues)new PortableDeviceValues();
PortableDeviceApiLib.IPortableDeviceValues res;
// WPD_PROPERTY_COMMON_COMMAND_CATEGORY
PortableDeviceApiLib._tagpropertykey WPD_PROPERTY_COMMON_COMMAND_CATEGORY = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0xF0422A9C, 0x5DC8, 0x4440, 0xB5, 0xBD, 0x5D, 0xF2, 0x88, 0x35, 0x65, 0x8A), pid = 1001 };
// WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE
PortableDeviceApiLib._tagpropertykey WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0x4FCD6982, 0x22A2, 0x4B05, 0xA4, 0x8B, 0x62, 0xD3, 0x8B, 0xF2, 0x7B, 0x32), pid = 2 };
// WPD_PROPERTY_COMMON_COMMAND_I
PortableDeviceApiLib._tagpropertykey WPD_PROPERTY_COMMON_COMMAND_ID = new PortableDeviceApiLib._tagpropertykey() { fmtid = new Guid(0xF0422A9C, 0x5DC8, 0x4440, 0xB5, 0xBD, 0x5D, 0xF2, 0x88, 0x35, 0x65, 0x8A), pid = 1002 };
//
par.SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE.fmtid);
par.SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE.pid);
//
pd.SendCommand(0, par, out res);
uint pcelt = 0;
res.GetCount(ref pcelt);
Console.WriteLine("res: {0}", pcelt);
Console.WriteLine("Picture taken ok / I hope so ");
Console.ReadLine();
pd.Close();
}// public void Connect()
}// class PDProgram
}// namespace PD
Continue reading...