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

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Mon Mar 17, 2014 6:07 pm

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 ?
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 6:40 pm

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
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 10:02 pm

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);
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 18, 2014 7:30 am

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Tue Mar 18, 2014 11:32 am

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
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 18, 2014 1:26 pm

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Tue Mar 18, 2014 6:46 pm

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

Postby steveastrouk » Tue Mar 18, 2014 7:17 pm

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...
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Wed Mar 19, 2014 8:31 am

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 Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Wed Mar 19, 2014 9:47 pm

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.
steveastrouk
Newbie
 
Posts: 0
Joined: Wed Feb 08, 2012 4:48 pm

Re: TC08 invoking usb_tc08_get_temp sample code

Postby Martyn » Thu Mar 20, 2014 8:14 am

Can you post your code again so that we can see what it looks like now. Thanks.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Fri Mar 21, 2014 9:42 pm

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.
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 21, 2014 10:34 pm

Possibly
Code: Select all
temp_buffer  : array [0..9] of real;
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: TC08 invoking usb_tc08_get_temp sample code

Postby steveastrouk » Mon Mar 24, 2014 7:37 pm

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 ?
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 24, 2014 8:00 pm

Yes it did. You could try it with the Visual Studio Express edition.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2339
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

PreviousNext

Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests