Author Topic: Interrupting an IN command  (Read 7933 times)

acfasano

  • Member
  • ***
  • Posts: 6
Interrupting an IN command
« on: February 11, 2015, 07:57:50 pm »
Hello, everybody,

I have a puzzling situation. I am communicating to a HID device. When my host software (VB.NET 2013) sends na Out Packet (64 Bytes) it will make the processor on the HID device to do a certain task.
Just after sending the Out Packed, the host software starts polling for the In packet, which eventually will be sent by the HID device when it finishes its task.

Sometimes, the user has to stop the process that the HID is executing before it finishes and outputs the IN Packet. There comes trouble.
It means that the Asynchronous command

currentAsyncResult = fileStreamdevicedata.BeginRead(recv_buf, 0, recv_buf.Length, New AsyncCallback(AddressOf GetInputReport), recv_buf)

has to stop executing before we can send na Out Packet to make the hid device to stop what is it doing...
To do that, the only way I found was a CloseCommunication comand (As per HID 60 example) before I send the Out packet that will instruct the HID to stop doing the task.
The problem that sometimes happens (Very seldom) is that it does not work and the the host software hangs ...

Has anyone had experience with a similar situation ?

Thanks

Antonio
Brazil
 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interrupting an IN command
« Reply #1 on: February 11, 2015, 09:36:07 pm »
Why do you have to interrupt the asynchronous Read in order to send Output data? The asynchronous operation doesn't block the program thread.

acfasano

  • Member
  • ***
  • Posts: 6
Re: Interrupting an IN command
« Reply #2 on: February 13, 2015, 03:46:21 pm »
If you try it and monitor the USB traffic with a USB protocol analyzer, you will see that it does not send an Out packet while the thread started by the
 fileStreamdevicedata.BeginRead(recv_buf, 0, recv_buf.Length, New AsyncCallback(AddressOf GetInputReport), recv_buf) is processing.
The Packet does not go out until an In packet is received or the USB communication is interrupted and the Device is found again ...

It is very strange ...

Would you have a working example of a software that is waiting for an In Packet and is able to send Out packets meanwhile ?
Could you share that with me ?

Thanks

Antonio

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interrupting an IN command
« Reply #3 on: February 13, 2015, 06:39:57 pm »
Be sure that the code that is requesting to send data is in a different program thread.

My HID example code is here:

http://janaxelson.com/hidpage.htm#MyExampleCode