Example #1
0
        public static bool Find_HID_Device(ushort p_VendorID, ushort p_PoductID, ushort p_index, ref IntPtr p_ReadHandle, ref IntPtr p_WriteHandle, ref string p_devicepath, ref Guid p_HidGuid)
        {
            ushort num  = 0;
            bool   flag = GenericHID.Get_HID_Device(p_VendorID, p_PoductID, p_index, ref p_ReadHandle, ref p_WriteHandle, ref p_devicepath, true, ref p_HidGuid, ref num);

            if (flag)
            {
                flag = GenericHID.Kick_Off_Read_Thread();
                if (flag)
                {
                    flag = USBWrite.kick_off_write_thread();
                }
            }
            return(flag);
        }
Example #2
0
        /*
         * {
         *      [MethodImpl(32)]
         *      add
         *      {
         *              GenericHID.USBDataAvailable = (GenericHID.USBNotifier)Delegate.Combine(GenericHID.USBDataAvailable, value);
         *      }
         *      [MethodImpl(32)]
         *      remove
         *      {
         *              GenericHID.USBDataAvailable = (GenericHID.USBNotifier)Delegate.Remove(GenericHID.USBDataAvailable, value);
         *      }
         * }
         */


        /*
         * [DllImport("hid.dll")]
         * public static extern void HidD_GetHidGuid(ref Guid HidGuid);
         *
         * [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
         * public static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid, string Enumerator, int hwndParent, int Flags);
         *
         * [DllImport("setupapi.dll")]
         * public static extern int SetupDiEnumDeviceInterfaces(IntPtr DeviceInfoSet, int DeviceInfoData, ref Guid InterfaceClassGuid, int MemberIndex, ref GenericHID.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData);
         *
         * [DllImport("setupapi.dll", CharSet = CharSet.Auto)]
         * public static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr DeviceInfoSet, ref GenericHID.SP_DEVICE_INTERFACE_DATA DeviceInterfaceData, IntPtr DeviceInterfaceDetailData, int DeviceInterfaceDetailDataSize, ref int RequiredSize, IntPtr DeviceInfoData);
         *
         * [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
         * public static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, ref GenericHID.SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition, uint dwFlagsAndAttributes, int hTemplateFile);
         *
         * [DllImport("hid.dll")]
         * public static extern int HidD_GetAttributes(IntPtr HidDeviceObject, ref GenericHID.HIDD_ATTRIBUTES Attributes);
         *
         * [DllImport("hid.dll")]
         * public static extern bool HidD_GetPreparsedData(IntPtr HidDeviceObject, ref IntPtr PreparsedData);
         *
         * [DllImport("hid.dll")]
         * public static extern int HidP_GetCaps(IntPtr PreparsedData, ref GenericHID.HIDP_CAPS Capabilities);
         *
         * [DllImport("setupapi.dll")]
         * public static extern int SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);
         *
         * [DllImport("hid.dll")]
         * public static extern bool HidD_FreePreparsedData(ref IntPtr PreparsedData);
         *
         * [DllImport("kernel32.dll")]
         * public static extern int CloseHandle(IntPtr hObject);
         *
         * [DllImport("hid.dll")]
         * public static extern bool HidD_GetNumInputBuffers(IntPtr HidDeviceObject, ref int NumberBuffers);
         *
         * [DllImport("hid.dll")]
         * public static extern bool HidD_SetNumInputBuffers(IntPtr HidDeviceObject, int NumberBuffers);
         *
         * [DllImport("kernel32.dll")]
         * public static extern int GetLastError();
         *
         * [DllImport("kernel32.dll", SetLastError = true)]
         * public static extern bool GetOverlappedResult(IntPtr hFile, ref Utilities.OVERLAPPED lpOverlapped, ref int lpNumberOfBytesTransferred, int bWait);
         *
         * [DllImport("kernel32", SetLastError = true)]
         * public static extern bool ReadFile(IntPtr hFile, byte[] Buffer, int NumberOfBytesToRead, ref int pNumberOfBytesRead, ref Utilities.OVERLAPPED pOverlapped);
         *
         * [DllImport("kernel32.dll", SetLastError = true)]
         * private static extern int ClearCommError(IntPtr hFile, out uint lpErrors, IntPtr lpStat);
         */

        public static bool Find_HID_Device(ushort p_VendorID, ushort p_PoductID)
        {
            IntPtr zero  = IntPtr.Zero;
            IntPtr zero2 = IntPtr.Zero;
            Guid   empty = Guid.Empty;
            string text  = "";
            ushort num   = 0;
            bool   flag  = GenericHID.Get_HID_Device(p_VendorID, p_PoductID, 0, ref zero, ref zero2, ref text, false, ref empty, ref num);

            if (flag)
            {
                flag = GenericHID.Kick_Off_Read_Thread();
                if (flag)
                {
                    flag = USBWrite.kick_off_write_thread();
                }
            }
            return(flag);
        }