EasyManua.ls Logo

PICO USB TC-08 - New USB Mode and Legacy Mode; Usb_Tc08_Open_Unit

PICO USB TC-08
43 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Technical reference
16
© 2005 Pico Technology Limited. All rights reserved.
USBTC08044-2
3.3.2
New USB mode and legacy mode
3.3.2.1
usb_tc08_open_unit
short usb_tc08_open_unit (void)
This routine returns a valid handle to the USB TC-08 if the driver successfully opens it. If
the routine fais, see the error code explanations in the
usb_tc08_get_last_error
section.
If
you wish to use more than one USB TC-08, call this routine once for each unit connected
to the PC. The function will return 0 if there are no more units found. The driver is thread-
safe and will not allow access to a single unit from more than one application. If,
therefore,
usb_tc08_open_unit
does not find a unit, check that other applications are
not using the USB TC-08. This includes applications on other user accounts on the same
computer, where fast user switching is supported.
Note: The
usb_tc08_open_unit
function provides a simple way to open USB TC-08
units. However, the function call locks up the calling thread until the attached USB TC-08
unit has been fully enumerated. If a single-threaded application needs to perform
concurrent processing, such as displaying a progress bar, use
usb_tc08_open_unit_async
.
Arguments:
None
Returns:
Positive short
- The handle to a unit.
0
- No more units were found.
-1
- Unit failed to open. Call
usb_tc08_get_last_error
with a handle of
0 to obtain the error code.
Example
The following code is a fragment of a C application which demonstrates how to open
multiple units with the USB TC-08 driver. The handles to the open units are stored in an
array for later use:
//======================================================
// Opening multiple units
//======================================================
for
(i =
0
; (new_handle =
usb_tc08_open_unit
()) >
0
; i++)
{
// store the handle in an array
handle_array[i] = new_handle;
}
no_of_units = i;
// deal with the error if there is one,
// if new_handle was zero, then there was no error
// and we reached the last available unit
if
(new_handle == -
1
)
{
error_code =
usb_tc08_get_last_error
(
0
);
printf(
"Unit failed to open\nThe error code is %d"
, error_code);
// could terminate the application here
}
//