1

I want to control a STM32 microcontroller using the USB interface. Jan Axelson (http://www.lvr.com/hidpage.htm#MyExampleCode) has created some applications to show the usage of the USB HID class which is now my base source.

To check if my device has some pending data I have created a thread calling the Filestream.BeginRead() routine. Now I want to abort/cancel this request, because it is still open/blocked after exiting that thread (setting a variable to cancel the thread loop). So I am wondering how to perform a cancellation this BeginRead() call. Or do you have a better idea how to check for continuous sent data of the USB device?

// USB read data from device thread
while (boRunThread)
{
    if (boStopThread)
    {
        // perform clean-up, cancel BeginRead
        // ... Abort(ar)???
    }
    if (botransfer == false)
    {
        botransfer = true;  // Signal pending transfer
        ar = fileStreamDeviceData.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, callb, inputReportBuffer);
    }
}
Kit
  • 20,354
  • 4
  • 60
  • 103
  • Did you try simply disposing the stream? – Jon Dec 07 '11 at 15:32
  • Yes, but it doesn't work checking the IAsyncResult ar.IsComplete returns false. I'll have to call thread.abort to cancel the loop. ;-( –  Dec 07 '11 at 15:41

0 Answers0