Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Description

This function takes an already initialized USB device list and disposes it.

Due to the fact that we are coding C# here, the device list can or cannot be erased; this is in the scope of the garbage collector and it cannot be forced by the user. Sometimes it is erased instantly, some other times it is never erased, until the user closes the application program that uses this data.

Note

After this function is called this USBDeviceList (and its own derived TE_USB_FX2_Device variables) should never be used again.

Users may use this function only just before exiting their applications. If users use this function anywhere else, they should

  • manage System.ObjectDisposedException exceptions (try – catch) and
  • avoid using disposed resources.
Code Block
languagec#
try
{
	Application_Code()
;
}
	catch (System.ObjectDisposedException)
{
	Console.WriteLine("TE_USB_FX2_USBDevice disposed: you have tried to use a disposed resource!");
}

USBdevList is disposed by garbage collector, not set to null.

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

 

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

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

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

  • 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.
Note
titleDifference with C# TE_USB_FX2_Close() function

Managed C# TE_USB_FX2_Close() of TE_USB_FX2_CyUSB.dll disposes USBdevList.

Unmanaged C++ TE_USB_FX2_Close()
of TE_USB_FX2_CyAPI.dll

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()
of TE_USB_FX2_CyUSB.dll

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.

Use of the code

Declaration

Code Block
languagec#
public static bool TE_USB_FX2_Close(ref USBDeviceList USBdevList);

Function Call

Your application program shall call this function like this:

Code Block
languagec#
TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_Close(ref USBdevList);

Parameters

Code Block
languagec#
ref USBDeviceList USBdevList

USBDeviceList is a type defined in CyUSB.dll. USBdevList is the list of Trenz Electronic USB FX2 devices attached to the USB bus host computer. This parameter is passed by reference (ref). See page 139-140 of CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's Reference).

Return Value

bool : logical type

This function returns true if it is able to dispose the list. If unable to do so, it returns false.