Error when using tc08 get temp

Post your .Net discussions here
Post Reply
JacobDixon
Newbie
Posts: 0
Joined: Wed May 30, 2012 8:38 am

Error when using tc08 get temp

Post by JacobDixon »

Hi,

Im trying to use tc08 get temp in c# and it keeps returning empty values and an error code of 133758979, I've tried googling the error code but it returns no results, does any one know what the error code is? my code is below:

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Singleton_Birch_Temperature_Logger
{
    public partial class Menu : Form
    {
        [DllImport("usbtc08.dll")]
        public static extern short usb_tc08_open_unit();
        [DllImport("usbtc08.dll")]
        public static extern int usb_tc08_close_unit(short handle);
        [DllImport("usbtc08.dll")]
        public static extern int usb_tc08_set_channel(short handle, int channel, byte tc_type);
        [DllImport("usbtc08.dll")]
        public static extern int usb_tc08_set_mains(short handle, int sixty_herts);
        [DllImport("usbtc08.dll")]
        public static extern long usb_tc08_get_single(short handle, ref Single temp, ref int overflow, int units);
        [DllImport("usbtc08.dll")]
        public static extern int usb_tc08_get_last_error(short handle);
        [DllImport("usbtc08.dll")]
        public static extern long usb_tc08_run(short handle, long interval_ms);
        [DllImport("usbtc08.dll")]
        public static extern long usb_tc08_get_temp(short handel, ref Single temp_buffer, long buffer_length, ref int overflow, int channel, int units, int fill_missing);
        [DllImport("usbtc08.dll")]
        public static extern short usb_tc08_get_minimum_interval_ms(short handle); 

        short tc08Handle;

        public Menu()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if (tc08Handle < 1)
            {
                tc08Handle = usb_tc08_open_unit();

                if (tc08Handle > 0)
                {
                    usb_tc08_set_mains(tc08Handle, 0);
                    usb_tc08_set_channel(tc08Handle, 1, 75);
                    short min_interval = usb_tc08_get_minimum_interval_ms(tc08Handle);
                    usb_tc08_run(tc08Handle, min_interval);
                    tmrTimer.Interval = min_interval; 
                    tmrTimer.Start();
                }
                else
                {
                    if (tc08Handle == 0)
                        MessageBox.Show("Unable to open TC-08", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                        MessageBox.Show("Error Code: " + usb_tc08_get_last_error(0), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
                MessageBox.Show("It's already running", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            if (tc08Handle > 0)
            {
                usb_tc08_close_unit(tc08Handle);
                tc08Handle = -1;
                tmrTimer.Stop();
            }
            else
                MessageBox.Show("It isn't running", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tmrTimer_Tick(object sender, EventArgs e)
        {
            Single[] temp_buffer = new Single[9];
            long[] times_buffer = new long[9];
            int[] overflow_flag = new int[9];

            usb_tc08_get_temp(tc08Handle, ref temp_buffer[0], 9, ref overflow_flag[0], 1, 0, 0);
            //usb_tc08_get_single(tc08Handle, ref temp_buffer[0], ref overflow_flag[0], 0);

            lblLastReading.Text = usb_tc08_get_last_error(tc08Handle).ToString(); // Math.Round(temp_buffer[1], 1).ToString();
            MessageBox.Show(usb_tc08_get_last_error(tc08Handle).ToString());
            tmrTimer.Stop();
        }
    }
}

Thanks,
Jacob Dixon

JacobDixon
Newbie
Posts: 0
Joined: Wed May 30, 2012 8:38 am

Re: Error when using tc08 get temp

Post by JacobDixon »

I've just found out that this method wouldnt be suitable for what my client requires anyway,

Sorry and Thanks,
Jacob Dixon

Post Reply