コード例 #1
0
        }// DeviceNameMatch()

        public static String[] FindHIDDevices(short vendorID, short productID)
        {
            Guid mHidGuid = Guid.Empty;

            ESnail.Utilities.Win32API.HID.HidD_GetHidGuid(ref mHidGuid);

            List <String> tDeviceList = new List <String>();

            String[] devPathName = new String[128];

            Boolean devicesFound = DeviceManagement.FindDeviceFromGuid(mHidGuid, ref devPathName);

            if (devicesFound)
            {
                Int32 memberIndex = 0;

                do
                {
                    SafeFileHandle mHidHandle = ESnail.Utilities.Win32API.WinBase.CreateFile(devPathName[memberIndex],
                                                                                             0,
                                                                                             ESnail.Utilities.Win32API.WinBase.FILE_SHARE_READ | ESnail.Utilities.Win32API.WinBase.FILE_SHARE_WRITE,
                                                                                             IntPtr.Zero,
                                                                                             ESnail.Utilities.Win32API.WinBase.OPEN_EXISTING,
                                                                                             0,
                                                                                             0);

                    if (!mHidHandle.IsInvalid)
                    {
                        Hid mHid = new Hid();

                        mHid.DeviceAttributes.Size = Marshal.SizeOf(mHid.DeviceAttributes);
                        Boolean success = ESnail.Utilities.Win32API.HID.HidD_GetAttributes(mHidHandle, ref mHid.DeviceAttributes);

                        if (success)
                        {
                            if ((mHid.DeviceAttributes.VendorID == vendorID) &&
                                (mHid.DeviceAttributes.ProductID == productID))
                            {
                                tDeviceList.Add(devPathName[memberIndex]);
                            }
                        }
                        mHidHandle.Close();
                    }
                    else
                    {
                        mHidHandle.Close();
                    }

                    memberIndex++;
                } while (!(memberIndex == devPathName.Length));
            }


            if (tDeviceList.Count > 0)
            {
                return(tDeviceList.ToArray());
            }

            return(null);
        }// getDevicePath()
コード例 #2
0
        }// closeFileHandle()

        /// <param name="messageData">
        /// The System.Windows.Forms.Message.LParam value.
        /// </param>
        public Boolean isDevice(IntPtr messageData)
        {
            Boolean result = false;

            /*
             * if (mFoundDevice)
             * {
             *  result = DeviceManagement.DeviceNameMatch(messageData, mDevicePathName);
             * }
             */

            if ((null != mDevicePathName) && (mDevicePathName.Trim() != ""))
            {
                try
                {
                    result = DeviceManagement.DeviceNameMatch(messageData, mDevicePathName);
                }
                catch (System.Exception e)
                {
                    System.Console.WriteLine(e.ToString());

                    return(false);
                }
            }


            return(result);
        }// isDevice()