Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 363 | f9daq | 1 | #include <utility.h> |
| 2 | #include <ansi_c.h> |
||
| 3 | #include <cvirte.h> |
||
| 4 | #include "usbtc08.h" |
||
| 5 | |||
| 6 | #define NCH 4 |
||
| 7 | |||
| 8 | int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, |
||
| 9 | LPSTR lpszCmdLine, int nCmdShow) |
||
| 10 | { |
||
| 11 | int i,no_of_units, minimum_interval; |
||
| 12 | int16_t channel, overflow_flags; |
||
| 13 | int16_t new_handle, handle, error_code, handle_array[10]; |
||
| 14 | float value_array[9]; |
||
| 15 | char tc08string[USBTC08_MAX_INFO_CHARS]; |
||
| 16 | USBTC08_INFO tc08info; |
||
| 17 | |||
| 18 | if (InitCVIRTE (hInstance, 0, 0) == 0) |
||
| 19 | return -1; /* out of memory */ |
||
| 20 | |||
| 21 | for (i = 0; (new_handle = usb_tc08_open_unit()) > 0; i++) |
||
| 22 | { |
||
| 23 | // store the handle in an array |
||
| 24 | handle_array[i] = new_handle; |
||
| 25 | } |
||
| 26 | no_of_units = i; |
||
| 27 | printf ("no. of units: %d\n",no_of_units); |
||
| 28 | // deal with the error if there is one, if new_handle was zero, then |
||
| 29 | // there was no error and we reached the last available unit |
||
| 30 | if (new_handle == -1) |
||
| 31 | { |
||
| 32 | error_code = usb_tc08_get_last_error(0); |
||
| 33 | printf("Unit failed to open\nThe error code is %d\n", error_code); |
||
| 34 | // could terminate the application here |
||
| 35 | return 1; |
||
| 36 | } |
||
| 37 | // Delay(5.); |
||
| 38 | |||
| 39 | handle = handle_array[0]; |
||
| 40 | usb_tc08_get_unit_info(handle_array[0], &tc08info); |
||
| 41 | usb_tc08_get_formatted_info(handle, tc08string, USBTC08_MAX_INFO_CHARS); |
||
| 42 | printf ("%s\n",tc08string); |
||
| 43 | usb_tc08_get_unit_info2(handle, tc08string, USBTC08_MAX_INFO_CHARS, USBTC08LINE_BATCH_AND_SERIAL); |
||
| 44 | printf ("%s\n",tc08string); |
||
| 45 | |||
| 46 | //======================================================== |
||
| 47 | // Setting up and converting readings with Get Single mode |
||
| 48 | //======================================================== |
||
| 49 | usb_tc08_set_mains(handle, 0); // use 50Hz mains noise rejection |
||
| 50 | // for (channel = 0; channel < USBTC08_MAX_CHANNELS + 1; channel++) |
||
| 51 | for (channel = 0; channel < NCH+1; channel++) |
||
| 52 | { |
||
| 53 | // Set each channel up as a type K thermocouple |
||
| 54 | // Channel 0 is the cold junction and will be enabled |
||
| 55 | // by setting the third argument to anything other than ' ' |
||
| 56 | usb_tc08_set_channel(handle, channel, 'K'); |
||
| 57 | } |
||
| 58 | // Find out the approximate conversion time for a call to |
||
| 59 | // usb_tc08_get_single |
||
| 60 | minimum_interval = usb_tc08_get_minimum_interval_ms(handle); |
||
| 61 | printf("Conversion time: %d\n", minimum_interval); |
||
| 62 | // Collect readings |
||
| 63 | for (i = 0; i < 20; i++) |
||
| 64 | { |
||
| 65 | // do the conversion for all channels |
||
| 66 | usb_tc08_get_single(handle, value_array, &overflow_flags, 0); |
||
| 67 | // print out the values |
||
| 68 | // printf("\n\nTime: %d minute(s)", i); |
||
| 69 | for (channel = 0; channel < NCH+1; channel++) |
||
| 70 | { |
||
| 71 | // Check for overflows on each channel |
||
| 72 | // with a bitwise & comparator |
||
| 73 | // Shift the comparison bit to match the channel |
||
| 74 | if (overflow_flags &(1 << channel)) |
||
| 75 | { |
||
| 76 | printf("\nChannel %d overflowed", channel); |
||
| 77 | } |
||
| 78 | else // no overflow |
||
| 79 | { |
||
| 80 | printf("\nChannel %d: %f", channel, value_array[channel]); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | Delay(2.); |
||
| 84 | } |
||
| 85 | for (i = 0; i < no_of_units; i++) |
||
| 86 | { |
||
| 87 | usb_tc08_close_unit(handle_array[i]); |
||
| 88 | } |
||
| 89 | Delay(2.); |
||
| 90 | return 0; |
||
| 91 | } |