Test and Measurement Forum

TC08 invoking usb_tc08_get_temp sample code

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

TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Sat Mar 08, 2014 6:42 pm

Does anyone have a sample or snippet of code invoking usb_tc08_get_temp ? I am trying to write Delphi2010 code, but C++ would be fine too. My code keeps throwing "error 3", which indicates I have an argument(s) wrong in my call.

I don't know what the "buffer length" parameter should be - there's no note in the reference manual

Code: Select all
PROCEDURE TMainForm.SystemTimerTimer(Sender: TObject);
var
  temp_buffer  : real;
  times_buffer : longint;
  buffer_length : LONGINT;
  overflow     : smallint;
  samplechannel: smallint;
  ok           : smallint;
  tpower       : word;
  MytimeNow    : real;
  errorcode :Smallint;
begin


    if (tc08_handle > 0) then
      begin
        if (not in_timer) then
          begin
            in_timer := true;
            with insertTestdata DO
            BEGIN

/////Call to get temp
            ok:=usb_tc08_get_temp (tc08_handle,temp_buffer,times_buffer,500,overflow,1,0,0);
            if ok<0 then
              BEGIN
               errorCode:=usb_tc08_get_last_error(tc08_handle);
                showmessage ('Error '+inttostr (errorcode));
              END;
            if (ok>0) then
              begin
                If NOT (isnan(temp_buffer)) THEN
                     BEGIN
                      Lab_probe.value:=temp_buffer;
                      parambyname('Probe_temp').Value:=temp_buffer;
                      temptimeseries.addXY(now,temp_buffer);
                     END


Previously, I have opened the device, turned on channel 1 and started the streaming process with the USB_TC08_run command.
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Mon Mar 10, 2014 9:14 am

I am not a Delphi programmer but in the following call

ok:=usb_tc08_get_temp (tc08_handle,temp_buffer,times_buffer,500,overflow,1,0,0);

temp_buffer, times_buffer and overflow need to be pointers. So you may need to assign a pointer buffer variable and set it to @buffer

ok:=usb_tc08_get_temp (tc08_handle,p_temp_buffer,p_times_buffer,500,p_overflow,1,0,0);

Buffer length informs the driver how big the buffers are. They needs to be large enough so that the buffers driver doesn't wrap, and overwrite, in the time that it takes to read and process values in your application.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Mon Mar 10, 2014 6:16 pm

Thanks Martyn,

In the .inc file, temp_buffer and times_buffer are declared as VAR types - the Pascal equivalent of pointers, I think, but I'll check in a minute.
Given I want the readings as fast as the TC-08 can make 'em, buffer can be quite small then ?
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Mon Mar 10, 2014 6:52 pm

This is the prototype function from the inc file.
function usb_tc08_get_temp(
handle : longint;
var temp_buffer : real;
var times_ms_buffer : longint;
buffer_length : longint;
var overflow : smallint;
channel : smallint;
units : smallint;
fill_missing : smallint)
: smallint;

Use of the VAR is Pascal's pass by reference. I do wonder if its been mis-declared here, but since there is no example source, its hard to see what the "correct" call should be.
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Tue Mar 11, 2014 7:32 am

Code: Select all
long usb_tc08_get_temp
(
short handle,
float * temp_buffer,
long * times_ms_buffer,
long buffer_length,
short * overflow,
short channel,
short units,
short fill_missing
)

handle is a short so it should be a small int, looks like a typo in the inc file.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Tue Mar 11, 2014 5:55 pm

OK, I fixed that. Still doesn't work.
I'm looking at the call
function usb_tc08_get_single(
handle : smallint;
var temp_buffer;
var overflow;
units : smallint)
: boolean;

The arguments have the same NAMES as the ones for get_temp. Should the ones in get_temp be the SAME ? ie temp_buffer isn't a SINGLE value, its an array of 9 elements ? Same as temp_buffer ?

Can you show me a C++ routine that uses get_temp ?? I can crosscheck the call there.
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Fri Mar 14, 2014 10:38 am

Any chance of a sample ? I'll have to scrap this TC-08 project if I can't get support.
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Fri Mar 14, 2014 11:22 am

I haven't any existing code, and currently can't put together an example, but you should be looking at something like
Code: Select all
float temp_buffer[buffer_length];
long times_ms_buffer[buffer_length];
short overflow;

ok = usb_tc08_get_temp(tc08_handle, temp_buffer, times_ms_buffer, buffer_length, &overflow, channel, USBTC08_UNITS_CENTIGRADE, fill_missing);
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Sat Mar 15, 2014 7:39 pm

Tried that thusly:
And it crashes on the call to get_temp

Debugger Exception Notification
---------------------------
Project Quench.exe raised exception class EAccessViolation with message 'Access violation at address 5C7454E2 in module 'usbtc08.dll'. Write of address 00000009'.

The code is now as you suggest

Code: Select all
PROCEDURE TMainForm.SystemTimerTimer(Sender: TObject);
var
  temp_buffer  : array[0..9] of single;
  times_buffer : array[0..9] of Longint;
  buffer_length : LONGINT;
  overflow     : smallint;
  samplechannel: smallint;
  ok           : smallint;
  tpower       : word;
  MytimeNow    : real;
  errorcode :Smallint;
begin


    if (tc08_handle > 0) then
      begin
        if (not in_timer) then
          begin
            with insertTestdata DO
            BEGIN
            ok:=usb_tc08_get_temp (tc08_handle,temp_buffer,times_buffer,9,overflow,0,0,0);
            if ok<0 then
              BEGIN
               errorCode:=usb_tc08_get_last_error(tc08_handle);
                showmessage ('Error '+inttostr (errorcode));
              END;
            if (ok>0) then
              begin
                If NOT (isnan(temp_buffer[0])) THEN


And I modified the .inc call.

Code: Select all
[code]function usb_tc08_get_temp(
         handle : smallint;
         var temp_buffer : array of single;
         var times_ms_buffer : array of longint;
         buffer_length : longint;
         var overflow : smallint;
         channel : smallint;
         units : smallint;
         fill_missing : smallint)
         : smallint;
{$IFDEF WIN32} stdcall; external 'usbtc08.dll'{$ENDIF}
[/code]
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Sun Mar 16, 2014 8:14 am

Should it be
Code: Select all
temp_buffer  : array[0..9] of real;

and
Code: Select all
var temp_buffer : array of real;
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Sun Mar 16, 2014 9:55 am

No, that causes the same error.

Steve
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Sun Mar 16, 2014 1:05 pm

I will have access to a TC08 when I am back in the office tomorrow so I will write a simple piece of code showing how to call the function.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Mon Mar 17, 2014 10:23 am

The following code sets up a buffer of 100 values and then starts the TC08 streaming.

If you set sleep to 1000 (1 second) the first five values in the buffer will be populated with readings the rest are void. If you set sleep to 10000 (10 seconds) you get 50 values.

With a sample interval of 100ms you get the cold junction and channel 1 read every 200ms, or 5 readings per second.

Code: Select all
int main(void)
{
   short hTemp;
   int i;
   float temp_buffer[100];
   long times_ms_buffer[100];
   short buffer_length = 100;
   short overflow;

   hTemp = usb_tc08_open_unit();
   usb_tc08_set_channel (hTemp, 1, 'K');
   usb_tc08_run(hTemp, 100);

   Sleep(1000);
   usb_tc08_get_temp(hTemp, temp_buffer, times_ms_buffer, buffer_length, &overflow, 1,0,0);

   for ( i= 0; i<100; ++i)
      printf("Temp %2f\n",temp_buffer[i]);

   usb_tc08_close_unit(hTemp);

}
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Mon Mar 17, 2014 2:42 pm

Martyn wrote:
Code: Select all
int main(void)
{
   short hTemp;
   int i;
   float temp_buffer[100];
   long times_ms_buffer[100];
   short buffer_length = 100;
   short overflow;

   hTemp = usb_tc08_open_unit();
   usb_tc08_set_channel (hTemp, 1, 'K');
   usb_tc08_run(hTemp, 100);

   Sleep(1000);
   usb_tc08_get_temp(hTemp, temp_buffer, times_ms_buffer, buffer_length, &overflow, 1,0,0);

   for ( i= 0; i<100; ++i)
      printf("Temp %2f\n",temp_buffer[i]);

   usb_tc08_close_unit(hTemp);

}


Thanks for that.

How many bytes are in your float type Martyn ?

Shouldn't your call to get_temp show "&temp_buffer" and "&times_ms_buffer" since they are passed by parameter to get_temp?

Steve
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Mon Mar 17, 2014 3:11 pm

4 bytes in the float as I am on 32bit

if you are using & it would be &temp_buffer[0] ie the address of the first float in the array, but the compiler knows what to do with temp_buffer
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2355
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Next

Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests