Versions Compared

Key

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

Introduction

How to write C# programs using the new DLL starting from the old DLL.

...

Scroll Title
titleFeature of Dewesoft C++ DLL and Trenz Electronic C# DLL

feature

Dewesoft C++ DLL

Trenz Electronic C# DLL

programming language

C++

C#

architecture

standard
(TE0300DLL.dll)

stacked
(TE_USB_FX2_CyUSB.dll requires Cypress CyUSB.dll);

Handles

present

absent

structures

embedded

defined in Cypress CyAPI.h

parameters*

less

more

freedom*

less

more

buffer size2 Kbyte (fixed)4 Kbyte or more (it can be changed)

Function translation

Scroll Title
titleTranslation example between the DLLs

Dewesoft C++ DLL

Trenz Electronic C# DLL

HANDLE m_handle = 0;

CyUSBDevice TE_USB_FX2_USBDevice = null;
USBDeviceList USBdevList = new USBDeviceList(CyConst.DEVICES_CYUSB);

Tip
The handles are internally managed by CyUSB.dll and there is no need to expose them to the user.
Tip
CyUSBDevice TE_USB_FX2_USBDevice take the place of handles for C# programmers.

cout << endl << TE0300_ScanCards() << endl;

int NumberOfCardAttached = TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_ScanCards(ref USBdevList);
Console.WriteLine(" {0} ", NumberOfCardAttached);

TE0300_Open(&m_handle, 0)!=0

TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open
(ref TE_USB_FX2_USBDevice, ref USBdevList, 0) == false

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() as SelectCard()
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 (0 in this case).

TE0300_Open(&m_handle, 1)!=0

TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Open
(ref TE_USB_FX2_USBDevice, ref USBdevList, 1) == false

TE0300_Close(&m_handle);

TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Close
(ref USBdevListToDispose);

Note
iconfalse

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.

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".

TE0300_SendCommand(handle, cmd, cmd_length, reply, &reply_length, timeout)

TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SendCommand
(ref TE_USB_FX2_USBDevice, ref cmd, ref cmd_length,
ref reply, ref reply_length, TIMEOUT_MS)

...