CYAPI demo application\cpp\bulkloop PerformBulkloopTransfer();

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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.hEvent);

                    delete [] buffersInput;       

                }  

                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;

            }

        }

    }

0 Likes
1 Solution
abhinavg_21
Moderator
Moderator
Moderator
50 likes received 25 likes received 10 likes received

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

View solution in original post

0 Likes
1 Reply
abhinavg_21
Moderator
Moderator
Moderator
50 likes received 25 likes received 10 likes received

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

0 Likes