Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Scroll Title
titleFunction Translation from DEWESoft C++ to Trenz Electronic C++
Dewesoft C++ DLLTrenz Electronic C++ DLL
HANDLE m_handle = 0;

CCyUSBDevice *USBdevList = new CCyUSBDevice((HANDLE)0,CYUSBDRV_GUID,true);

Tip
The handles are internally managed by CyAPI.lib and there is no need to expose them to the user.
Note
CyUSBDevice TE_USB_FX2_USBDevice doesn't explicitly exist in C++, unlike the C# case; this is a shortcoming of CyAPI.lib.
d=0; USBdevList->Open(d); // Open automatically calls Close() if necessary
vID = USBdevList->VendorID; // not (USBdevList->TE_USB_FX2_USBDevice).VendorID as logically expected
pID = USBdevList->ProductID; // not (USBdevList->TE_USB_FX2_USBDevice).ProductID as logically expected


cout << endl << TE0300_ScanCards() << endl;cout << endl << TE_USB_FX2_ScanCards(USBdevList) << endl;
TE0300_Open(&m_handle, 0) !=0;

TE_USB_FX2_Open(USBdevList, 0)!=0;

Tip
titleTE_USB_FX2_Open()
In the code, it is possible to call TE_USB_FX2_Open() where TE0300_Open() is used.


Note
titleTE_USB_FX2_Open() act as Close() for other TE USB handles already open

When a new handle to the device driver is open (TE_USB_FX2_Open() run successfully) other internal handles (inside USBDeviceList) are automatically closed by TE_USB_FX2_Open() function. No more than one handle can be active on the same time. It is a behavior inherithed by CyAPI.dll Open() function. For this reason, TE_USB_FX2_Close() function is almost useless.

d=0; USBdevList->Open(d); // Open automatically calls Close() if necessary (from the Cypress CyAPI documentation)

Note
titleTE_USB_FX2_Open() as SelectCard()
TE_USB_FX2_Open(USBdevList, x) acts more as a SelectCard() function because the list of USB devices is already created in USBdevList.
TE0300_Open(&m_handle, 1)!=0;TE_USB_FX2_Open(USBdevList, 1)!=0
TE0300_Close(&m_handle);

TE_USB_FX2_Close(USBdevList);

Tip

This function closes all internal handles of USBDeviceList.

This function does NOT differ much from from its homonym of the previous TE0300DLL.dll; the only difference is that this function closes a handle (like TE0300DLL.dll) to the driver but the handle is not exposed to user because it is not exposed by USBDeviceList (unlike TE0300DLL.dll).

In the code, it is possible to call TE_USB_FX2_Close() where TE0300_Close() is used, but

  • it is rare that you would ever need to call TE_USB_FX2_Close() explicitly (though doing so would not cause any problems).
  • TE_USB_FX2_Open() realize automatically much of the TE_USB_FX2_Close() work. Close is automatically carried out by the TE_USB_FX2_Open() function, if another handle to the same device driver is already open (i.e. a TE_USB_FX2_Open() has been successfully used before).

 

Note
titleWarning about derived variables
If TE_USB_FX2_Close() is called, then dynamically allocated members of the CCyUSBDevice class are de-allocated. And, all "shortcut" pointers to elements of the EndPoints array (ControlEndPt, IsocIn/OutEndPt, BulkIn/OutEndPt, InterruptIn/OutEndPt) are reset to NULL.
TE0300_SendCommand(handle, cmd, cmd_length, reply, &reply_length, timeout)TE_USB_FX2_SendCommand(USBdevList, cmd, cmd_length, reply, reply_length, timeout)
 Equivalent code doesn't exist

TE_USB_FX2_SetData_InstanceDriverBuffer ( USBdevList, &BulkOutEP, PI_EP8, timeout, DeviceDriverBufferSize);

Tip

Example: in TE0300DLL.dll, the SET buffer size is fixed to 2 Kbyte, while in TE_USB_FX2_CyAPI.dll you are free to choose 4 Kbyte or more.

BufferSize has a strong influence on DataThroughput. If BufferSize is too small, the data throughput can be 1/3 to 1/2 of the maximum value (33-36 Mbyte/s for read transactions).

You should instance the driver buffer only one time and not for every transmission, otherwise you could half your data throughput.

 Equivalent code doesn't exist

TE_USB_FX2_GetData_InstanceDriverBuffer ( USBdevList, &BulkInEP, PI_EP6, timeout, DeviceDriverBufferSize);

Tip

Example: in TE0300DLL.dll, the GET buffer size is fixed to 2 Kbyte, while in TE_USB_FX2_CyAPI.dll you are free to choose 4 Kbyte or more.

BufferSize has a strong influence on DataThroughput. If BufferSize is too small, the DataThroughput can be 1/3 to 1/2 of the maximum value (25-28 Mbyte/s for write transactions).

You should instance the driver buffer only one time and not for every transmission, otherwise you could half your data throughput.

...

 

 
Scroll Title
titleWrite Data Test Example

Dewesoft C++ DLL

Trenz Electronic C++ DLL

void WriteData(unsigned int handle)
{
void WriteData(CCyUSBDevice *USBdevList,
unsigned
int DeviceDriverBufferSize,
int
TX_PACKET_LEN, unsigned long TIMEOUT)
{

    int packetlen = TX_PACKET_LEN;
    unsigned int packets = 1200;    
    //allocate memory
    byte * data;  
    data = new byte [TX_PACKET_LEN*packets];

    long packetlen = TX_PACKET_LEN;
    unsigned int packets = 1200;
    //allocate memory  
    byte
* data;
    byte * data_temp = NULL;
    data = new byte [TX_PACKET_LEN*packets];

    unsigned int total_cnt = 0;
    unsigned int errors = 0;
    unsigned int total_cnt = 0;
    unsigned int errors = 0;
   

    CCyBulkEndPoint *BulkOutEP = NULL;
    TE_USB_FX2_SetData_InstanceDriverBuffer
( USBdevList, CardNo, &BulkOutEP, PI_EP8,TIMEOUT,
DeviceDriverBufferSize);

    SetData (data);
    ResetFX2FifoStatus(handle);
    //starts test

    SendFPGAcommand(handle,
FX22MB_REG0_START_RX);

    SetData (data);
    ResetFX2FifoStatus(USBdevList);
    //starts test
    SendFPGAcommand(USBdevList,
FX22MB_REG0_START_RX);

    //StopWatch starts
   
ElapsedTime.Start();
    for (unsigned int i = 0; i < packets; i++)
    {
        packetlen = RX_PACKET_LEN;
    //StopWatch starts
   
ElapsedTime.Start();
    for (unsigned int i = 0; i < packets; i++)
    {
        packetlen = RX_PACKET_LEN;
 

       data_temp = &data[total_cnt];

        if (TE0300_GetData(handle, data+total_cnt,
&packetlen, PI_EP8,TIMEOUT_MS))
        {
            cout << "ERROR write" << endl;
            errors++;
            break;
        }
        total_cnt += packetlen;
    }
    TheElapsedTime = ElapsedTime.Stop(false);
    //DEBUG StopWatch timer
    SendFPGAcommand(handle,
FX22MB_REG0_STOP);
    //stops test
    delete data;
}

       if (TE_USB_FX2_GetData(&BulkInEP,data_temp,
packetlen))
        {
            cout << "ERROR write" << endl;
            errors++;
            break;
        }
        total_cnt += (packetlen);
    }
    TheElapsedTime = ElapsedTime.Stop(false);
    //DEBUG StopWatch timer
    SendFPGAcommand(USBDevice,
FX22MB_REG0_STOP);
    //stops test
    delete data;
}