Пример #1
0
        public static IWiaItem Connect(SonyCamera camera)
        {
            IWiaItem item;

            if (!Success(deviceManager.CreateDevice(camera.UniqueId, out item)))
            {
                item = null;
            }
            return(item);
        }
Пример #2
0
        public static byte[] SendCommand(SonyCamera camera, byte[] buffer, int outputBufferLength)
        {
            byte[] outputBuffer = new byte[outputBufferLength];
            int    readBytes;

            if (Success(camera.deviceExtras.Escape(256, buffer, buffer.Length, outputBuffer, outputBufferLength, out readBytes)) && readBytes > 0)
            {
                byte[] result = new byte[readBytes];
                Buffer.BlockCopy(outputBuffer, 0, result, 0, result.Length);
                return(result);
            }
            return(null);
        }
Пример #3
0
        public static SonyCamera[] FindCameras()
        {
            Dictionary <string, SonyCamera> cameras = new Dictionary <string, SonyCamera>();

            if (deviceManager == null)
            {
                deviceManager = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("a1f4e726-8cf1-11d1-bf92-0060081ed811"))) as IWiaDevMgr;
            }
            if (deviceManager == null)
            {
                return(new SonyCamera[0]);
            }

            IEnumWIA_DEV_INFO deviceInfo;

            if (Success(deviceManager.EnumDeviceInfo(Defs.WIA_DEVINFO_ENUM_LOCAL, out deviceInfo)) &&
                Success(deviceInfo.Reset()))
            {
                IWiaPropertyStorage propertyStorage;
                uint numFetchedStorage = 0;
                while (Success(deviceInfo.Next(1, out propertyStorage, ref numFetchedStorage)) && numFetchedStorage > 0)
                {
                    IEnumSTATPROPSTG propsEnumerator;
                    if (Success(propertyStorage.Enum(out propsEnumerator)) &&
                        Success(propsEnumerator.Reset()))
                    {
                        bool   knownName         = false;
                        bool   knownManufacturer = false;
                        string deviceId          = null;
                        string deviceName        = null;

                        uint          numFetchedProps;
                        STATPROPSTG[] props = new STATPROPSTG[1];
                        while (Success(propsEnumerator.Next(1, props, out numFetchedProps)) && numFetchedProps > 0)
                        {
                            for (int i = 0; i < numFetchedProps; i++)
                            {
                                STATPROPSTG prop = props[i];
                                switch (prop.lpwstrName)
                                {
                                case "Manufacturer":
                                    switch (GetPropertyValue(propertyStorage, prop.propid))
                                    {
                                    case "Sony Corporation":
                                        knownManufacturer = true;
                                        break;
                                    }
                                    break;

                                case "Name":
                                    deviceName = GetPropertyValue(propertyStorage, prop.propid);
                                    if (SonyCamera.SupportedCameras.Contains(deviceName))
                                    {
                                        knownName = true;
                                    }
                                    break;

                                case "Unique Device ID":
                                    deviceId = GetPropertyValue(propertyStorage, prop.propid);
                                    break;
                                }
                                //Console.WriteLine(prop.lpwstrName + " " + GetPropertyValue(propertyStorage, prop.propid));
                            }
                        }

                        if (!string.IsNullOrEmpty(deviceId) && knownManufacturer && knownName)
                        {
                            cameras[deviceId] = new SonyCamera(deviceId, deviceName);
                        }
                    }
                }
            }

            return(cameras.Values.ToArray());
        }
Пример #4
0
 public static byte[] SendCommand(SonyCamera camera, byte[] buffer)
 {
     return(SendCommand(camera, buffer, 0x100000));
 }