Exemplo n.º 1
0
 public InteractionData DeviceInteraction(InteractionData tx, int n)
 {
     try
     {
         //int rxCount = HIDStream.Read(InputReport, 0, m_nInputReportLength);
         if (HIDProcCallback != null)
         {
             HIDProcCallback(-2);
         }
         HIDStream.Write(tx.GetDataList(), 0, m_nOutputReportLength);
         byte[]       InputReport = new byte[m_nInputReportLength];
         IAsyncResult ia          = HIDStream.BeginRead(InputReport, 0, m_nInputReportLength, null, null);
         for (int s = 0; s < n; s++)
         {
             if (ia.AsyncWaitHandle.WaitOne(500, false))
             {
                 if (HIDProcCallback != null)
                 {
                     HIDProcCallback(-1);
                 }
                 InteractionData rx = new InteractionData(InputReport);
                 return(rx);
             }
             else
             {
                 if (HIDProcCallback != null)
                 {
                     HIDProcCallback(s + 1);
                 }
             }
         }
         if (HIDProcCallback != null)
         {
             HIDProcCallback(-1);
         }
         HIDStream.Close();
         HIDStream.Dispose();
         HIDStream = null;
         m_hHandle = CreateFile(hidPath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
         HIDStream = new FileStream(m_hHandle, FileAccess.Read | FileAccess.Write, m_nInputReportLength, true);
         return(null);
     }
     catch (IOException ex)
     {
         // The device was removed!
         throw new HIDDeviceException(ex.Message + ":Device was removed");
     }
 }