TC08 invoking usb_tc08_get_temp sample code

Post general discussions on using our drivers to write your own software here
steveastrouk
Newbie
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote: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
God this is hard work.
What does the C++ prototype function look like for the DLL ?

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

I can't check until tomorrow, but the header file in the SDK would be a good starting point.

VB.Net, C#, LabVIEW, VBA, Matlab all have their difficulties, complicated even further when you throw in 64 bit.
Martyn
Technical Support Manager

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:I can't check until tomorrow, but the header file in the SDK would be a good starting point.

VB.Net, C#, LabVIEW, VBA, Matlab all have their difficulties, complicated even further when you throw in 64 bit.
NOW this IS a 64Bit system...

Is the header file for the 64 bit version identical to the 32 bit version ?

I see
/* must be called at least once per minute to ensure no data is lost */
PREF0 PREF1 long PREF2 PREF3(usb_tc08_get_temp) (
short handle,
float * temp_buffer,
long * times_ms_buffer, /* wraps back to zero after 24 days */
long buffer_length,
short * overflow,
short channel,
short units,
short fill_missing);

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

Are you building your code for 64bit in Delphi ?

If so are you using the 64bit dll from the x64 folder, and the 64bit kernel driver from system\amd64 folder of the SDK ?
Martyn
Technical Support Manager

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:Are you building your code for 64bit in Delphi ?

If so are you using the 64bit dll from the x64 folder, and the 64bit kernel driver from system\amd64 folder of the SDK ?
No, but the Windows 7 install is Win7 Pro, so that's 64bit

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

I am using Win 7 Pro 32 bit.

If you are compiling 32 bit application against 32 bit drivers you should be Ok, so I would look carefully at what Delphi does with respect to pointers for arrays of Reals, and try a few things out.
Martyn
Technical Support Manager

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:I am using Win 7 Pro 32 bit.

If you are compiling 32 bit application against 32 bit drivers you should be Ok, so I would look carefully at what Delphi does with respect to pointers for arrays of Reals, and try a few things out.
That's the sort of area I'm looking at now. If I give the function the arguments
..,temp_buffer[0],times_buffer[0].... it "runs", but I still get error 3.

Steve

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:I am using Win 7 Pro 32 bit.

If you are compiling 32 bit application against 32 bit drivers you should be Ok, so I would look carefully at what Delphi does with respect to pointers for arrays of Reals, and try a few things out.

This looks like the canonical method of addressing the DLL
function usb_tc08_get_temp(
handle : smallint;
temp_buffer : Pinteger;
times_ms_buffer : Pinteger;
buffer_length : smallint;
var overflow : smallint;
channel : smallint;
units : smallint;
fill_missing : smallint)
: smallint;

....and it still gives me error 3s...

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

You will need to be passing the address of the first element of the temp_buffer and times_ms_buffer arrays, not the actual values in these arrays.

If it is not possible to use the array itself, with some referencing, then you could create a pointer value, which you set to the address of the first element and then pass this pointer value in the call.
Martyn
Technical Support Manager

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:You will need to be passing the address of the first element of the temp_buffer and times_ms_buffer arrays, not the actual values in these arrays.

If it is not possible to use the array itself, with some referencing, then you could create a pointer value, which you set to the address of the first element and then pass this pointer value in the call.
Its not clear from what I posted, but that's what I have done.

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

Can you post your code again so that we can see what it looks like now. Thanks.
Martyn
Technical Support Manager

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:Can you post your code again so that we can see what it looks like now. Thanks.
This is the current INC file

Code: Select all

function usb_tc08_get_temp(
         handle : smallint;
         temp_buffer : Pinteger;
         times_ms_buffer : Pinteger;
         buffer_length : smallint;
         var overflow : smallint;
         channel : smallint;
         units : smallint;
         fill_missing : smallint)
         : smallint;
Pinteger is a pointer type.

Then my main loop, in a timer is:

Code: Select all

PROCEDURE TMainForm.SystemTimerTimer(Sender: TObject);
 var
  temp_buffer  : array [0..9] of single;
  times_buffer : array [0..9] of Integer;
  buffer_length : smallint;
  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;

//            function usb_tc08_get_temp(
      //         handle : smallint;
      //         var temp_buffer : real;
      //         var times_ms_buffer : longint;
      //         buffer_length : longint;
      //         var overflow : smallint;
      //         channel : smallint;
      //         units : smallint;
      //         fill_missing : smallint)
//         : smallint;
            with insertTestdata DO
            BEGIN
            ok:=usb_tc08_get_temp (tc08_handle,@temp_buffer[0],@times_buffer[0],100,overflow,0,0,0);
            if ok<0 then
              BEGIN
               errorCode:=usb_tc08_get_last_error(tc08_handle);
                showmessage ('Error '+inttostr (errorcode));
              END;
You can see my use of @in the call to get_temp, which should pass the address of the first element of the array to the Pinteger type.

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

Possibly

Code: Select all

temp_buffer  : array [0..9] of real;
Martyn
Technical Support Manager

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

Re: TC08 invoking usb_tc08_get_temp sample code

Post by steveastrouk »

Martyn wrote:Possibly

Code: Select all

temp_buffer  : array [0..9] of real;
This problem seems to be hanging on exactly how many bytes are in which datatype passed to the DLL - changing to real made no difference. Did that C example actually run on real hardware ?

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Post by Martyn »

Yes it did. You could try it with the Visual Studio Express edition.
Martyn
Technical Support Manager

Post Reply