Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#include <utility.h>
#include <ansi_c.h>
#include <cvirte.h>
#include "usbtc08.h"

#define NCH 4

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                           LPSTR lpszCmdLine, int nCmdShow)
{
        int i,no_of_units, minimum_interval;
        int16_t channel, overflow_flags;
        int16_t new_handle, handle, error_code, handle_array[10];
        float value_array[9];
        char tc08string[USBTC08_MAX_INFO_CHARS];
        USBTC08_INFO tc08info;
       
        if (InitCVIRTE (hInstance, 0, 0) == 0)
                return -1;    /* out of memory */

        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;
        printf ("no. of units: %d\n",no_of_units);
// 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\n", error_code);
// could terminate the application here
                return 1;
        }
//      Delay(5.);

        handle = handle_array[0];
        usb_tc08_get_unit_info(handle_array[0], &tc08info);
        usb_tc08_get_formatted_info(handle, tc08string, USBTC08_MAX_INFO_CHARS);
        printf ("%s\n",tc08string);
        usb_tc08_get_unit_info2(handle, tc08string, USBTC08_MAX_INFO_CHARS, USBTC08LINE_BATCH_AND_SERIAL);
        printf ("%s\n",tc08string);

//========================================================
// Setting up and converting readings with Get Single mode
//========================================================
        usb_tc08_set_mains(handle, 0); // use 50Hz mains noise rejection
//      for (channel = 0; channel < USBTC08_MAX_CHANNELS + 1; channel++)
        for (channel = 0; channel < NCH+1; channel++)
        {
// Set each channel up as a type K thermocouple
// Channel 0 is the cold junction and will be enabled
// by setting the third argument to anything other than ' '
                usb_tc08_set_channel(handle, channel, 'K');
        }
// Find out the approximate conversion time for a call to
// usb_tc08_get_single
        minimum_interval = usb_tc08_get_minimum_interval_ms(handle);
        printf("Conversion time: %d\n", minimum_interval);
// Collect readings
        for (i = 0; i < 20; i++)
        {
// do the conversion for all channels
                usb_tc08_get_single(handle, value_array, &overflow_flags, 0);
// print out the values
//              printf("\n\nTime: %d minute(s)", i);
                for (channel = 0; channel < NCH+1; channel++)
                {
// Check for overflows on each channel
// with a bitwise & comparator
// Shift the comparison bit to match the channel
                        if (overflow_flags &(1 << channel))
                        {
                                printf("\nChannel %d overflowed", channel);
                        }
                        else // no overflow
                        {
                                printf("\nChannel %d: %f", channel, value_array[channel]);
                        }
                }
                Delay(2.);
        }
        for (i = 0; i < no_of_units; i++)
        {
                usb_tc08_close_unit(handle_array[i]);
        }
        Delay(2.);
        return 0;
}