difference between begindataxfer and xferdata functions

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

cross mob
Anonymous
Not applicable

I am using cyc68013 development kit for my application of data transfer.
I am sending and receiving 8 bytes of buffer means length = 8.
I am using bulk end points.

the coding I am using in vc++ is here

UCHAR *outContext= USBDevice->BulkOutEndPt->BeginDataXfer((unsigned char *)buffer, length,&outOvLap);

UCHAR *inContext = USBDevice->BulkInEndPt->BeginDataXfer(inBuf, length,&inOvLap);
USBDevice->BulkInEndPt->WaitForXfer(&inOvLap,200);


with this coding I get the required speed say, my complete test run in 62 seconds, I have not used waitforxfer in sending data.

but when I used this coding in c#

outEndpoint.XferData(ref outData, ref xferLen);
inEndpoint.XferData(ref inData, ref xferLen);

my test run in 124 seconds. why
what is the difference between them.
and it is very hard to understand begindataxfer in c#.

please also I need virtual com port driver and hex for 68013 128axc.

Thanks in Advance.

0 Likes
2 Replies
Anonymous
Not applicable

Xferdata just calls Begindataxfer, waitforxfer and finishdataxfer in sequence and does error handling accordingly.

   

Waitforxfer is the one which implements the timeout period for larger transfers your approach most probably won't work.

   

Regards,

   

Anand

0 Likes
Anonymous
Not applicable

1. please help me know about the code line in red color.

   

STDMETHODIMP CComb::twopinresult(int firstpin, int secondpin, int *pinsresult)
{
    CCyUSBDevice  *USBDevice = new  CCyUSBDevice(NULL);
    OVERLAPPED outOvLap, inOvLap;
    outOvLap.hEvent  = CreateEvent(NULL, false, false, "CYUSB_OUT");
    inOvLap.hEvent   = CreateEvent(NULL, false, false, "CYUSB_IN");

    char buffer[8]="***###";
    unsigned char  inBuf[8]="000000";

    unsigned int OMIfirstpincardno ;
    unsigned int OMIsecondpincardno;
    unsigned int OMIfirstpinonboard ;
    unsigned int OMIsecondpinonboard ;

    LONG  length = 8;

    char tempbyte1;
    char tempbyte2;
   
        OMIfirstpincardno = (firstpin - 1) / 100;
        OMIfirstpinonboard = ((firstpin - 1) - (OMIfirstpincardno * 100));
        tempbyte1 = OMIfirstpinonboard;
        tempbyte2 = tempbyte1;

            switch(tempbyte1 & 0x07)
            {
            case 0x00:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x04;
                break;
            case 0x01:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x02;
                break;
            case 0x02:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x06;
                break;
            case 0x03:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x01;
                break;
            case 0x04:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x07;
                break;
            case 0x05:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x00;
                break;
            case 0x06:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x05;
                break;
            case 0x07:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x03;
                break;
            }

            sprintf(&buffer[1],"%c",OMIfirstpincardno);
            sprintf(&buffer[2],"%c",tempbyte1);

        OMIsecondpincardno = (secondpin - 1) / 100;
        OMIsecondpinonboard = ((secondpin - 1) - (OMIsecondpincardno * 100));
        tempbyte1 = OMIsecondpinonboard;
        tempbyte2 = tempbyte1;

            switch(tempbyte1 & 0x07)
            {
            case 0x00:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x04;
                break;
            case 0x01:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x02;
                break;
            case 0x02:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x06;
                break;
            case 0x03:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x01;
                break;
            case 0x04:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x07;
                break;
            case 0x05:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x00;
                break;
            case 0x06:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x05;
                break;
            case 0x07:
                tempbyte1     = tempbyte2 & 0xF8;
                tempbyte1     = tempbyte1 | 0x03;
                break;
            }

            sprintf(&buffer[3],"%c",OMIsecondpincardno);
            sprintf(&buffer[4],"%c",tempbyte1);
            buffer[5] =  0xFC;        //  1111 1100
            buffer[6] = 0x00;

    UCHAR  *outContext= USBDevice->BulkOutEndPt->BeginDataXfer((unsigned char *)buffer, length,&outOvLap);


    UCHAR  *inContext = USBDevice->BulkInEndPt->BeginDataXfer(inBuf, length,&inOvLap);
    USBDevice->BulkInEndPt->WaitForXfer(&inOvLap,100);

    if (inBuf[1] == 255)
    {
        *pinsresult = 0;
    }
    else
    {
        *pinsresult = 1;   
    }

    CloseHandle(outOvLap.hEvent);
     CloseHandle(inOvLap.hEvent);


    return S_OK;
}

   

2. I am running this function 499500 times. each time I have to take the handle which is actually consuming time.

   

what should I do to take the all handles in constructor and calling begindataxfer in function or method.

   

this way only begindataxfer will be running in loop no handles.

   

 

   

Thank s in advance

   

Ameen Sharif

0 Likes