Test and Measurement Forum

Daqfactory TC08 cant read thermocouple, can read cold junct.

Post general discussions on using our drivers to write your own software here

Daqfactory TC08 cant read thermocouple, can read cold junct.

Postby blaatje » Thu Jun 18, 2015 9:48 am

I am trying to use the TC08 with Daqfactory, so to automate my tests. Somehow I am unable to read any of the 8 thermocouples on the machine, while I somehow am able to read the cold junction that is inside the machine.

I've tested with Picolog recorder and all the termocouples seem to be working and the cold junction gives the same temperature in Picolog as it does in Daqfactory.

Code:
Code: Select all
global minimum_interval
global interval_allowed
global error_status
global no_of_readings

global temp_buffer
global times_ms_buffer
global overflow


Define MAX_INPUT_CHANNELS = 8

extern("C:\Libraries\usbtc08.dll", "short usb_tc08_open_unit",                                                                 "u_tc08_open",             "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_stop(short)",                                                               "u_tc08_stop",             "stdcall")
extern("C:\Libraries\usbtc08.dll", "short tc08_close_unit(short)",                                                             "u_tc08_close",            "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_open_unit_async",                                                           "u_tc08_open_async",       "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_open_unit_progress(short, short)",                                          "u_tc08_progress",         "stdcall")
extern("C:\Libraries\usbtc08.dll", "word usb_tc08_close_unit(word)",                                                           "u_tc08_close",            "stdcall")
extern("C:\Libraries\usbtc08.dll", "word usb_tc08_set_channel(short, short, char)",                                            "u_tc08_set_channel",      "stdcall")
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_get_minimum_interval_ms(short)",                                             "u_tc08_get_min",          "stdcall")
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_run(short, long)",                                                           "u_tc08_run",              "stdcall")
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_get_temp(short, float[1], long[1], long, short[1], short, short, short)",    "u_tc08_get_temp",         "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_get_single(short, float[9], short[1], short)",                              "u_tc08_get_single",       "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_get_last_error",                                                            "u_tc08_get_error",        "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_set_mains(short, short)",                                                   "u_tc08_set_mains",        "stdcall") 

/*
* USB handle for TC08 module(s)
*/
global usbHandle

usbHandle = u_tc08_open

if (usbHandle == -1)
   ? "Unit failed to open: " + getErrorCode(usbHandle)
   else
     if (usbHandle == 0)
         ? "No more units were found"
      else
      ? "usbHandle of the unit is: " + usbHandle
      endif
   endif
endif

// Use 50Hz or 60Hz mains noise rejection. 2nd par: 0 = 50Hz, 1= 60Hz

error_status = u_tc08_set_mains(usbHandle, 0)

if(error_status == 0)
   ? "Error set mains: ", + getErrorCode(error_status)
else
   ? "Mains rejection set correctly"
endif


/*
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 ' '
*/
for (Private.count = 0, Private.count <= MAX_INPUT_CHANNELS, Private.count++)
   u_tc08_set_channel(usbHandle, Private.count, 'K')
endfor

// find out how fast the unit can sample in its current setup state
minimum_interval = u_tc08_get_min(usbHandle)

if(minimum_interval > 0)
   ? "Minimum interval is set to: " + minimum_interval
else
   ? "Minimum interval error message: ", + getErrorCode(u_tc08_get_error)
endif

// sample as fast as possible
interval_allowed = u_tc08_run(usbHandle, minimum_interval)

if ( interval_allowed == 0)
   ? "Error interval_allowed by driver: ", + getErrorCode(interval_allowed)
else
   ? "Interval allowed by the driver: ", + interval_allowed
endif


while(1) 
   for (Private.count = 0, Private.count <= MAX_INPUT_CHANNELS, Private.count++)
   /*
      To specify a pointer, you should put the at symbol (@) in front of the
      name of the variable you wish to point to in the function call
   */
   error_status = u_tc08_get_temp(usbHandle, @temp_buffer, @times_ms_buffer, 1, @overflow, Private.count, 0, 0)
   
   if (error_status == -1)
      ? "get_temp error occured: " + getErrorCode(error_status)
   else
      if (error_status == 0)
         ? "Currently no readings to collect"
      endif
   else
      ? Format("Data: %.1f", temp_buffer)
      ? "number of readings collected: " + error_status
   endif
   
         
   delay(0.1)
   endfor
endwhile


Response from the command window:
Code: Select all
usbHandle of the unit is: 1
Mains rejection set correctly
Minimum interval is set to: 900
Interval allowed by the driver: 900
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 1.0
number of readings collected: 0
Data: 0.0
number of readings collected: 1
Data: 25.1
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0


If anyone has any tips or sees any problems in my code, please feel welcome to comment!
blaatje
Newbie
 
Posts: 0
Joined: Thu Jun 18, 2015 8:35 am

Re: Daqfactory TC08 cant read thermocouple, can read cold ju

Postby Hitesh » Fri Jun 19, 2015 10:24 am

Hi blaatje,

Try increasing the sleep interval to one second or greater.

You may also wish to keep a separate array for each channel and have a length greater than 1 for each array.

Have you referred to the C/C# examples in the SDK?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1997
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Daqfactory TC08 cant read thermocouple, can read cold ju

Postby blaatje » Mon Jun 22, 2015 8:17 am

Hey Hitesh,

Thanks for your speedy reply, I've tried raising the delay to 1 or even 2 seconds, but this does not seem to change anything.

I'll try to reiterate my problem with a new example. In the next example I initiate and read out channel 0(the cold junction) succesfully, as you can see in the results below the code.

Code: Select all
global minimum_interval
global interval_allowed
global error_status
global no_of_readings

global temp_buffer
global times_ms_buffer
global overflow


Define MAX_INPUT_CHANNELS = 8

extern("C:\Libraries\usbtc08.dll", "short usb_tc08_open_unit",                                                                 "u_tc08_open",             "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_stop(short)",                                                               "u_tc08_stop",             "stdcall")
extern("C:\Libraries\usbtc08.dll", "short tc08_close_unit(short)",                                                             "u_tc08_close",            "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_open_unit_async",                                                           "u_tc08_open_async",       "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_open_unit_progress(short, short)",                                          "u_tc08_progress",         "stdcall")
extern("C:\Libraries\usbtc08.dll", "word usb_tc08_close_unit(word)",                                                           "u_tc08_close",            "stdcall")
extern("C:\Libraries\usbtc08.dll", "word usb_tc08_set_channel(short, short, char)",                                            "u_tc08_set_channel",      "stdcall")
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_get_minimum_interval_ms(short)",                                             "u_tc08_get_min",          "stdcall")
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_run(short, long)",                                                           "u_tc08_run",              "stdcall")
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_get_temp(short, float[1], long[1], long, short[1], short, short, short)",    "u_tc08_get_temp",         "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_get_single(short, float[9], short[1], short)",                              "u_tc08_get_single",       "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_get_last_error",                                                            "u_tc08_get_error",        "stdcall")
extern("C:\Libraries\usbtc08.dll", "short usb_tc08_set_mains(short, short)",                                                   "u_tc08_set_mains",        "stdcall")

/*
* USB handle for TC08 module(s)
*/
global usbHandle

usbHandle = u_tc08_open

if (usbHandle == -1)
   ? "Unit failed to open: " + getErrorCode(usbHandle)
   else
     if (usbHandle == 0)
         ? "No more units were found"
      else
      ? "usbHandle of the unit is: " + usbHandle
      endif
   endif
endif

// Use 50Hz or 60Hz mains noise rejection. 2nd par: 0 = 50Hz, 1= 60Hz

error_status = u_tc08_set_mains(usbHandle, 0)

if(error_status == 0)
   ? "Error set mains: ", + getErrorCode(error_status)
else
   ? "Mains rejection set correctly"
endif


/*
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 ' '
*/

u_tc08_set_channel(usbHandle, 0, 'K')

// find out how fast the unit can sample in its current setup state
minimum_interval = u_tc08_get_min(usbHandle)

if(minimum_interval > 0)
   ? "Minimum interval is set to: " + minimum_interval
else
   ? "Minimum interval error message: ", + getErrorCode(u_tc08_get_error)
endif

// sample as fast as possible
interval_allowed = u_tc08_run(usbHandle, minimum_interval)

if ( interval_allowed == 0)
   ? "Error interval_allowed by driver: ", + getErrorCode(interval_allowed)
else
   ? "Interval allowed by the driver: ", + interval_allowed
endif


while(1) 
   /*
      To specify a pointer, you should put the at symbol (@) in front of the
      name of the variable you wish to point to in the function call
   */
   error_status = u_tc08_get_temp(usbHandle, @temp_buffer, @times_ms_buffer, 100, @overflow, 0, 0, 0)
   
   if (error_status == -1)
      ? "get_temp error occured: " + getErrorCode(error_status)
   else
      if (error_status == 0)
         ? "Currently no readings to collect"
      endif
     
   else
      ? Format("Data: %.1f", temp_buffer)
      ? "number of readings collected: " + error_status
   endif
   
         
   delay(0.1)
endwhile


results:
Code: Select all
usbHandle of the unit is: 1
Mains rejection set correctly
Minimum interval is set to: 100
Interval allowed by the driver: 100
Data: 1.0
number of readings collected: 0
Data: 23.8
number of readings collected: 1
Data: 23.8
number of readings collected: 1
Data: 23.8


But if I were to change the channel to one, then I would only get 0.0 back as a result. To change the channel to 1, I've changed the following lines in the code:

Code: Select all
change
u_tc08_set_channel(usbHandle, 0, 'K')
into
u_tc08_set_channel(usbHandle, 1, 'K')

and

change
error_status = u_tc08_get_temp(usbHandle, @temp_buffer, @times_ms_buffer, 100, @overflow, 0, 0, 0)
into
error_status = u_tc08_get_temp(usbHandle, @temp_buffer, @times_ms_buffer, 100, @overflow, 1, 0, 0)

and

change
delay(0.1)
into
delay(0.2)


And I get as a result:
Code: Select all
usbHandle of the unit is: 1
Mains rejection set correctly
Minimum interval is set to: 200
Interval allowed by the driver: 200
Data: 1.0
number of readings collected: 0
Data: 0.0
number of readings collected: 1
Data: 0.0
number of readings collected: 1
Data: 0.0
blaatje
Newbie
 
Posts: 0
Joined: Thu Jun 18, 2015 8:35 am

Re: Daqfactory TC08 cant read thermocouple, can read cold ju

Postby Hitesh » Mon Jun 22, 2015 4:34 pm

Hi blaatje,

Couple of questions looking at the code snippets:

In your function definitions, you have:

Code: Select all
extern("C:\Libraries\usbtc08.dll", "long usb_tc08_get_temp(short, float[1], long[1], long, short[1], short, short, short)",    "u_tc08_get_temp",         "stdcall")

Does a long data type in your programming language correspond to a 32-bit or 64-bit integer. It should be a 32-bit integer data type.

Also, does float[1] above refer to a pointer to an array of one value?

Does calling usb_tc_08_get_single() work?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1997
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests