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
        private static void Read_USB_Thread()
        {
            Utilities.SECURITY_ATTRIBUTES security_attributes;
            int num = 0;
            int pNumberOfBytesRead = 0;

            m_we_are_in_read_loop = true;
            Utilities.OVERLAPPED pOverlapped = new Utilities.OVERLAPPED();
            security_attributes = new Utilities.SECURITY_ATTRIBUTES {
                lpSecurityDescriptor = 0,
                bInheritHandle       = Convert.ToInt32(true),
                nLength = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES))
            };
            int num3 = Utilities.CreateEvent(ref security_attributes, Convert.ToInt32(false), Convert.ToInt32(false), "");

            pOverlapped.hEvent = num3;
            while (m_we_are_in_read_loop)
            {
                Array.Clear(m_read_buffer, 0, m_read_buffer.Length);
                pOverlapped.Offset     = 0;
                pOverlapped.OffsetHigh = 0;
                if (ReadFile(Utilities.m_flags.HID_read_handle, m_read_buffer, Utilities.m_flags.irbl, ref pNumberOfBytesRead, ref pOverlapped))
                {
                    if (USBDataAvailable != null)
                    {
                        USBDataAvailable();
                        m_packet_is_copied.WaitOne(0x3e8, false);
                    }
                }
                else
                {
                    switch (USB.GetLastError())
                    {
                    case 0x26:
                    {
                        num++;
                        continue;
                    }

                    case 0x3e5:
                    {
                        Utilities.WaitForSingleObject(pOverlapped.hEvent, 0x7d0);
                        if (USB.GetOverlappedResult(Utilities.m_flags.HID_read_handle, ref pOverlapped, ref pNumberOfBytesRead, 0) && (USBDataAvailable != null))
                        {
                            USBDataAvailable();
                            m_packet_is_copied.WaitOne(0x3e8, false);
                        }
                        continue;
                    }
                    }
                    num++;
                }
            }
            num++;
        }
Example #3
0
 private static void Read_USB_Thread()
 {
     Utilities.SECURITY_ATTRIBUTES security_attributes;
     int num = 0;
     int pNumberOfBytesRead = 0;
     m_we_are_in_read_loop = true;
     Utilities.OVERLAPPED pOverlapped = new Utilities.OVERLAPPED();
     security_attributes = new Utilities.SECURITY_ATTRIBUTES {
         lpSecurityDescriptor = 0,
         bInheritHandle = Convert.ToInt32(true),
         nLength = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES))
     };
     int num3 = Utilities.CreateEvent(ref security_attributes, Convert.ToInt32(false), Convert.ToInt32(false), "");
     pOverlapped.hEvent = num3;
     while (m_we_are_in_read_loop)
     {
         Array.Clear(m_read_buffer, 0, m_read_buffer.Length);
         pOverlapped.Offset = 0;
         pOverlapped.OffsetHigh = 0;
         if (ReadFile(Utilities.m_flags.HID_read_handle, m_read_buffer, Utilities.m_flags.irbl, ref pNumberOfBytesRead, ref pOverlapped))
         {
             if (USBDataAvailable != null)
             {
                 USBDataAvailable();
                 m_packet_is_copied.WaitOne(0x3e8, false);
             }
         }
         else
         {
             switch (USB.GetLastError())
             {
                 case 0x26:
                 {
                     num++;
                     continue;
                 }
                 case 0x3e5:
                 {
                     Utilities.WaitForSingleObject(pOverlapped.hEvent, 0x7d0);
                     if (USB.GetOverlappedResult(Utilities.m_flags.HID_read_handle, ref pOverlapped, ref pNumberOfBytesRead, 0) && (USBDataAvailable != null))
                     {
                         USBDataAvailable();
                         m_packet_is_copied.WaitOne(0x3e8, false);
                     }
                     continue;
                 }
             }
             num++;
         }
     }
     num++;
 }