- Omega 8 Channel Thermocouple USB Data Acquisition Module User's Guide

Technical reference
19
Example
The following code is a fragment of a C application which demonstrates how to open a
single unit with the asynchronous open unit functions:
//======================================================
// Opening a unit asynchronously
//======================================================
// Tell the driver to start enumerating the unit in the background
// (usb_tc08_open_unit_async returns immediately)
result = usb_tc08_open_unit_async();
// handle any error conditions
if (result == -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
}
else if (result == 0)
{
printf("No USB TC08 units found");
// could terminate the application here
}
// No errors, so start polling usb_tc08_open_unit_progress
// continuously for its enumeration state
do
{
result = usb_tc08_open_unit_progress(&handle, &progress);
switch (result)
{
case USBTC08_PROGRESS_FAIL: // enum equates to: -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
break;
case USBTC08_PROGRESS_PENDING: // enum equates to: 0
printf("\nThe unit is %d percent enumerated", progress);
Sleep(500); // wait for approx. half a second
break;
case USBTC08_PROGRESS_COMPLETE: // enum equates to: 1
printf("\n\nThe unit with handle '%d', opened successfully",
handle);
break;
}
}
while (result == USBTC08_PROGRESS_PENDING);
//
// Start using the open unit
//