//Use this constructor to initialize a device
        public Colorimeter(SafeFileHandle handle, string pathName)
        {
            //  Get handles to use in requesting Input and Output reports.
            readHandle          = handle;
            colorimeterPathName = pathName;

            //get the Hid Handle from the pathName
            hidHandle = FileIO.CreateFile(colorimeterPathName, 0, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);


            //  Learn the capabilities of the device.
            MyHid.Capabilities          = MyHid.GetDeviceCapabilities(hidHandle);
            MyHid.DeviceAttributes.Size = Marshal.SizeOf(MyHid.DeviceAttributes);

            Hid.HidD_GetAttributes(hidHandle, ref MyHid.DeviceAttributes);


            // Initialize input report buffer
            inputBuffer  = new byte[MyHid.Capabilities.InputReportByteLength];
            newInputData = false;

            writeHandle = FileIO.CreateFile(colorimeterPathName, FileIO.GENERIC_WRITE, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);

            //  Flush any waiting reports in the input buffer. (optional)
            MyHid.FlushQueue(readHandle);
        }
Пример #2
0
        //  If IsRange is false, UsageMin is the Usage and UsageMax is unused.
        //  If IsStringRange is false, StringMin is the String index and StringMax is unused.
        //  If IsDesignatorRange is false, DesignatorMin is the designator index and DesignatorMax is unused.

        public static string FindDevicePath(short productID, short vendorID, String[] devicePathNames)
        {
            try
            {
                if (devicePathNames.Length > 0)
                {
                    foreach (var devicePathName in devicePathNames)
                    {
                        //iterate through all possible device paths to see if the hidhandle matches the ones for out devices
                        var hidHandle = FileIO.CreateFile(devicePathName, 0, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0);

                        if (!hidHandle.IsInvalid)
                        {
                            //we need to set this in another location, as it has nothing to do with this method
                            //moving this to Colorimeter constructor
                            //MyHid.DeviceAttributes.Size = Marshal.SizeOf(MyHid.DeviceAttributes);

                            var hidDeviceAttributes = new Hid.HIDD_ATTRIBUTES();

                            if (Hid.HidD_GetAttributes(hidHandle, ref hidDeviceAttributes))
                            {
                                //  Find out if the device matches the one we're looking for.
                                if ((hidDeviceAttributes.VendorID == vendorID) && (hidDeviceAttributes.ProductID == productID))
                                {
                                    return(devicePathName);
                                }
                                else
                                {
                                    hidHandle.Close();
                                }
                            }
                            else
                            {
                                hidHandle.Close();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }