Versions Compared

Key

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

Description

This function takes an already initialized USB device list, searches for Trenz Electronic USB FX2 devices (Cypress driver derivative and VID = 0xbd0, PID=0x0300) connected to host computer's USB ports and counts them.
An internal operation that closes an handle to the CyUSB.sys driver (or a derivative like TE_USB_FX2_xx.sys) is executed instead (see page 33 of CyAPI.pdf).
If one or more devices are attached and

  • if 0 ≤ CardNumber ≤ (number of attached devices – 1), thenthe selected module is not directly given by USBDeviceList (CCyUSBDevice type). An internal operation that opens a handle to CyUSB.sys driver (or a derivative like TE driver) is executed instead (see page 45 of CyAPI.pdf). This handle is internally managed by CyAPI.lib, therefore there is no need to expose them to the user.
  • if CardNumber ≥ number of attached devices, thenUSBDeviceList (CyUSBDevice type) is not initialized to null (the device list is not erased). An internal operation that closes an handle to CyUSB.sys driver (or a derivative like TE driver) is executed instead (see page 33 of CyAPI.pdf).
Info
A more intuitive name for this function would have been TE_USB_FX2_SelectCard().
Note
You can use this function to select the desired module without the need to call TE_USB_FX2_Close() before. Though doing so would not cause any problems.
Close() is automatically carried out by the TE_USB_FX2_Open() function if a handle to the driver is already open (i.e. a TE_USB_FX2_Open() has been successfully called before).
Note

If no device is attached, USBDeviceList is not initialized to null (the device list is not erased).

Description of internal procedure

TE_USB_FX2_SetData_InstanceDriverBuffer() function instantiates the class used by CyAPI to use Bulk EndPoint (CCyBulkEndPoint, see pages 9 to 11) and initializes the parameters of this class instantiation.

The parameters are :

  1. Timeout
  2. XMODE_DIRECT (this parameter set the driver to single buffering, instead the slower double buffering)
  3. DeviceDriverBufferSize.

The last parameter force the instantiation of the driver buffer (SW side, on the host computer) for the endpoint 0x86; this buffer has a size in byte given by DeviceDriverBufferSize. This value is of great importance because the data throughput is strongly influenced by this parameter (see Data Transfer Throughput Optimization).

Use of the code

Declaration

Code Block
languagecpp
TE_USB_FX2_CYAPI int TE_USB_FX2_Open(CCyUSBDevice *USBDeviceList, int CardNumber);

Function Call

Your application program shall call this function like this:

Code Block
languagecpp
TE_USB_FX2_Open(USBDeviceList, CardNumber);

Parameters

Code Block
languagecpp
CCyUSBDevice *USBDeviceList

CCyUSBDevice is a type defined in CyAPI.lib. Its name is misleading because it is not a class that represents a single USB device, but it rather represents a list of USB devices.
CCyUSBDevice is the list of devices served by the CyUSB.sys driver (or a derivative like TE_USB_FX2_xx.sys). This parameter is passed by pointer. See page 7 and pages 23-49 of CyAPI.pdf (Cypress CyAPI Programmer's Reference).

Code Block
languagecpp
int CardNumber

This is the number of the selected Trenz Electronic USB FX2 device (module).

Return Value

int : integer type

This function returns true (ST_OK=0) if it is able to find the module selected by CardNumber. If unable to do so, it returns false (ST_ERROR=1).

Code Block
languagecpp
enum ST_Status
{
     ST_OK = 0,
     ST_ERROR = 1
};