Dewesoft C++ DLL to Trenz Electronic C# DLL Porting Guide
How to write C# programs using the new DLL starting from the old DLL.
There are some major differences between the two DLLs.
feature | Dewesoft C++ DLL | Trenz Electronic C# DLL |
programming language | C++ | C# |
architecture | standard | stacked |
Handles | present | absent |
structures | embedded | defined in Cypress CyAPI.h |
parameters* | less | more |
freedom* | less | more |
Dewesoft C++ DLL | Trenz Electronic C# DLL | |
HANDLE m_handle = 0; | CyUSBDevice TE_USB_FX2_USBDevice = null;
| |
cout << endl << TE0300_ScanCards() << endl; | int NumberOfCardAttached = TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_ScanCards(ref USBdevList); | |
TE0300_Open(&m_handle, 0)!=0 | TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open | |
TE0300_Open(&m_handle, 1)!=0 | TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open | |
TE0300_Close(&m_handle); | TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Close | |
TE0300_SendCommand(handle, cmd, cmd_length, reply, &reply_length, timeout) | TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand |
Note 1:
TE_USB_FX2_Open(TE_USB_FX2_USBDevice, USBdevList, x) acts more as a SelectCard() function because the list of USB devices is already created in USBdevList. TE_USB_FX2_USBDevice is the selected device number x.
Note 2:
In the code, it is possible to call TE_USB_FX2_Open() where TE0300_Open() is used.In the code, it is not recommended to call TE_USB_FX2_Close() where TE0300_Close() is used. This function differs from its homonym of the previous TE0300DLL.dll in that it does not close a Handle but disposes (erases) all USB devices in the list USBdevList.
If you want to close the current USB device (card) without opening another one, you shall use TE_USB_FX2_Open() with a device number (CardNumber) that certainly does not exist (e.g. CardNumber = 200, because there can be a maximum of 127 USB devices connected to a single host controller). The reason of this behavior is due to the CyUSB.dll as explained by Cypress document CyUSB.NET.pdf, pages 132-133 and pages 139-140: "You should never invoke the Dispose() method of a USBDevice directly. Rather, the appropriate technique is to call the Dispose() method of the USBDeviceList object that contains the USBDevice objects".
Unmanaged C++ TE_USB_FX2_Open() | 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. |
Managed C# TE_USB_FX2_Open() | You can use this function to select the desired module without the need to call TE_USB_FX2_Close() before. This function is not necessary. |
Unmanaged C++ TE_USB_FX2_Close() | It can be freely called but it is rare that you would ever need to call TE_USB_FX2_Close() explicitly (though doing so would not cause any problems). |
Managed C# TE_USB_FX2_Close() | It cannot be freely called and it is rare that you would ever need to call TE_USB_FX2_Close() explicitly. Furthermore, if it is used in the wrong way, the program can raise exceptions. |
Dewesoft C++ DLL | Trenz Electronic C# DLL |
void ResetFX2FifoStatus(HANDLE handle) | static void ResetFX2FifoStatus(CyUSBDevice TE_USB_FX2_USBDevice) |
Dewesoft C++ DLL | Trenz Electronic C# DLL |
void ReadData(unsigned int handle) | static void ReadDataFPGAIntegrity(CyUSBDevice TE_USB_FX2_USBDevice, int BUFFER_SIZE, uint TIMEOUT_MS) |
Dewesoft C++ DLL | Trenz Electronic C# DLL |
void WriteData(unsigned int handle) | static void WriteData(CyUSBDevice TE_USB_FX2_USBDevice, int BUFFER_SIZE, uint TIMEOUT_MS) |
version | date | author | description |
0.9 | 2012-06-01 | SP, FDR | Release Preview. |
1.0 |
|
| Initial release. |
1.1 | 2013-04-23 | SP | Improved description of TE_USB_FX2_Open() and TE_USB_FX2_Close() functions |