Example #1
0
        private static void Read_USB_Thread()
        {
            int num  = 0;
            int num2 = 0;

            GenericHID.m_we_are_in_read_loop = true;
            Utilities.OVERLAPPED          oVERLAPPED          = default(Utilities.OVERLAPPED);
            Utilities.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = default(Utilities.SECURITY_ATTRIBUTES);
            sECURITY_ATTRIBUTES.lpSecurityDescriptor = 0;
            sECURITY_ATTRIBUTES.bInheritHandle       = Convert.ToInt32(true);
            sECURITY_ATTRIBUTES.nLength = Marshal.SizeOf(sECURITY_ATTRIBUTES);
            //int hEvent = Utilities.CreateEvent(ref sECURITY_ATTRIBUTES, Convert.ToInt32(false), Convert.ToInt32(false), "");
            //oVERLAPPED.hEvent = hEvent;
            while (GenericHID.m_we_are_in_read_loop)
            {
                Array.Clear(GenericHID.m_read_buffer, 0, GenericHID.m_read_buffer.Length);
                oVERLAPPED.Offset     = 0;
                oVERLAPPED.OffsetHigh = 0;
                //bool flag = GenericHID.ReadFile(Utilities.m_flags.HID_read_handle, GenericHID.m_read_buffer, (int)Utilities.m_flags.irbl, ref num2, ref oVERLAPPED);
                bool flag = false;
                if (flag)
                {
                    if (GenericHID.USBDataAvailable != null)
                    {
                        GenericHID.USBDataAvailable();
                        GenericHID.m_packet_is_copied.WaitOne(1000, false);
                    }
                }
                else
                {
                    int lastError = 0;                    // USB.GetLastError();
                    int num3      = lastError;
                    if (num3 != 38)
                    {
                        if (num3 != 997)
                        {
                            num++;
                        }
                        else
                        {
                            //sUtilities.WaitForSingleObject(oVERLAPPED.hEvent, 2000);
                            //bool overlappedResult = USB.GetOverlappedResult(Utilities.m_flags.HID_read_handle, ref oVERLAPPED, ref num2, 0);
                            bool overlappedResult = false;
                            if (overlappedResult && GenericHID.USBDataAvailable != null)
                            {
                                GenericHID.USBDataAvailable();
                                GenericHID.m_packet_is_copied.WaitOne(1000, false);
                            }
                        }
                    }
                    else
                    {
                        num++;
                    }
                }
            }
            num++;
        }
Example #2
0
 public static void Cleanup()
 {
     if (GenericHID.m_read_thread.IsAlive)
     {
         GenericHID.Kill_Read_Thread();
     }
     USBWrite.Kill_Write_Thread();
     USBWrite.Dispose_Of_Write_Objects();
     //Utilities.CloseHandle(Utilities.m_flags.HID_write_handle);
     //Utilities.CloseHandle(Utilities.m_flags.HID_read_handle);
     GenericHID.m_usb_packet_mutex.Close();
 }
Example #3
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 #4
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);
        }