1 Reply Latest reply on Oct 25, 2018 8:14 AM by abga

    CYAPI   demo application\cpp\bulkloop    PerformBulkloopTransfer();

    yumingfoy_3247926

      In the demo there is a method of DWORD WINAPI CBulkLoopAppDlg::PerformBulkloopTransfer(LPVOID lParam);

      I didn't understand why bulkin at first。

       

      What's the target of next code?

       

          // Queue-up the first batch of transfer requests

          for (int nCount = 0; nCount < QueueSize; nCount++)

          {       

              ////////////////////BeginDataXFer will kick start the IN transactions.................

              contextsInput[nCount] = epBulkIn->BeginDataXfer(buffersInput[nCount], totalTransferSize, &inOvLap[nCount]);

              if (epBulkIn->NtStatus || epBulkIn->UsbdStatus)

              {

       

       

                  if (epBulkIn->UsbdStatus == USBD_STATUS_ENDPOINT_HALTED )

                  {

                      epBulkIn->Reset();

                      epBulkIn->Abort();

                      Sleep(50);

                      contextsInput[nCount] = epBulkIn->BeginDataXfer(buffersInput[nCount], totalTransferSize, &inOvLap[nCount]);

       

       

                  }

                  if (epBulkIn->NtStatus || epBulkIn->UsbdStatus)

                  {

                      // BeginDataXfer failed

                      // Handle the error now.

                      epBulkIn->Abort();

                      for (int j=0; j< QueueSize; j++)

                      {

                          CloseHandle(inOvLap[j].hEvent);

                          delete [] buffersInput[j];       

                      }  

       

       

                      pThis->m_edtFailure.SetWindowText(L"0x1");

                      // Bail out......

                      delete []contextsInput;

                      delete [] buffersInput;

                      CString strMsg;

                      strMsg.Format(L"BeginDataXfer Failed with (NT Status = 0x%X and USBD Status = 0x%X). Bailing out...", epBulkIn->NtStatus, epBulkIn->UsbdStatus);

                      AfxMessageBox(strMsg);

                      return 0;

                  }

              }

          }

        • 1. Re: CYAPI   demo application\cpp\bulkloop    PerformBulkloopTransfer();
          abga

          Hi Yu Ming,

           

          BeginDataXfer() is an asynchronous mode of data transfer. Here it starts the IN data transfer but it will wait for the data to come in out data transfer. Until out data transfer doesn't happen successfully it will wait. You can check this in the Out transfer code:

           

          //////////Wait till the transfer completion..///////////////////////////

                  if (!epBulkIn->WaitForXfer(&inOvLap[nCount], TIMEOUT_PER_TRANSFER_MILLI_SEC))

                  {

                      m_nFailure++;

                      epBulkIn->Abort();

                      if (epBulkIn->LastError == ERROR_IO_PENDING)

                          WaitForSingleObject(inOvLap[nCount].hEvent, TIMEOUT_PER_TRANSFER_MILLI_SEC);

                  }

                 

                  ////////////Read the trasnferred data from the device///////////////////////////////////////

                  if (epBulkIn->FinishDataXfer(buffersInput[nCount], readLength, &inOvLap[nCount], contextsInput[nCount]))

                  {

                      BytesXferred += totalTransferSize;

           

           

                      if (writeLength == readLength )

                      {

                          if (memcmp(buffersInput[nCount], bufferOutput, readLength) != 0) m_nFailure++;

                          else m_nSuccess++;

                      }

           

          Also refer the CyAPI guide to understand BeginDataXfer().

           

          Thanks & Regards

          Abhinav