Test and Measurement Forum

PROBLEM: Getting Serial number from TC-08 USB device

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

PROBLEM: Getting Serial number from TC-08 USB device

Postby duxxx001 » Tue Jun 07, 2005 1:01 pm

Hi,

I'm writting custom program for TC-08 (USB), using Delphi, and I found your example quite helpful. Unfortunately I can't figure out how to get device serial number using Delphi. Using PicoLog recorder software I found serial to be GJY02/154, but how can I get this info in my program.

This information is essential for my application, since I need two TC-08 devices working at the same time, and I need to distinguish them in my program.

Here is what I tried (though unsuccessfuly):
_______________________________________________
1) From C header I've seen following function which appeared to me that it might be the right one, so I translated it into delphi (usbtc08.h)
Code: Select all
/* Structures *****************************************************/

typedef struct tUSBTC08Info
  {
  short size;
  short DriverVersion;
  short PicoppVersion;
  short HardwareVersion;
  short Variant;
  char  szSerial[USBTC08_MAX_SERIAL_CHARS];
  char  szCalDate[USBTC08_MAX_DATE_CHARS];
  } USBTC08_INFO, *LPUSBTC08_INFO;


/*====================================================================

PREF0 PREF1 short PREF2 PREF3(usb_tc08_get_unit_info) (short handle, USBTC08_INFO * info);


Delphi version of the above function (my translation):
Code: Select all
type
TUSBTC08_INFO = record
  size: smallint;
  DriverVersion: smallint;
  PicoppVersion: smallint;
  HardwareVersion: smallint;
  Variant: smallint;
  szSerial: Array[0..11] of Char;
  szCalDate: Array[0..9] of Char;
end;
PUSBTC08_INFO = ^TUSBTC08_INFO;

function usb_tc08_get_unit_info (handle: smallint; info: PUSBTC08_INFO):smallint;   stdcall; external 'usbtc08.dll';


This approach gave me some unreadable values for szSerial and szCalDate properties. Actually these unreadable values are same before and after calling specified function, suggesting that specified function does not use specified structure at all.
_______________________________________________

2. Tried to use usb_tc08_get_formatted_info(), but without success.
_______________________________________________

3. Tried to use usb_tc08_get_info(), but version returned is always zero (obviously not correct)
_______________________________________________

Looking forward to any help.

Regards,
Dusan
Please Note: No trees were destroyed in sending this contaminant free message. However, we do concede that significant number of electrons may have been inconvenienced.
User avatar
duxxx001
Active User
Active User
 
Posts: 6
Joined: Tue Jun 07, 2005 12:11 pm
Location: Edinburgh

Postby Sarah » Mon Jun 13, 2005 8:24 am

Hi Dusan

Thank you for your post.

The usb_tc08_get_formatted_info routine:

short usb_get_formatted_info ( short handle, char * unit_info, short string_length)

Needs to include the arguments listed, are you including these?

Have you tried the usb_tc08_get_unit_info() routine?

Let me know how you get on.

Best Regards
Sarah
 

Postby duxxx001 » Mon Jun 13, 2005 12:06 pm

Sarah wrote:The usb_tc08_get_formatted_info routine:

short usb_get_formatted_info ( short handle, char * unit_info, short string_length)

Needs to include the arguments listed, are you including these?

Yes, all these are included, since it is not possible to compile program if you do not pass specified number of arguments. In the original pascal version of the driver you supply, unit_info is type: BYTE, instead of char* equivalent. ANyway I tried all possible combinations of datatypes, and nothing.

Sarah wrote:Have you tried the usb_tc08_get_unit_info() routine?

That one is included in my first post. In the original version of pascal driver, this routine is not declared at all, so I declared it, based on the information from C header file (details in my first post).

Unfortunately that also doesn't give me what I want.
Last edited by duxxx001 on Mon Jun 13, 2005 3:39 pm, edited 1 time in total.
Please Note: No trees were destroyed in sending this contaminant free message. However, we do concede that significant number of electrons may have been inconvenienced.
User avatar
duxxx001
Active User
Active User
 
Posts: 6
Joined: Tue Jun 07, 2005 12:11 pm
Location: Edinburgh

Postby duxxx001 » Mon Jun 13, 2005 2:56 pm

Here is a C version of code which tries to get device's serial number. Also, I included few other functions that might be used for some identification. Result is the same as in Delphi case - NOT WORKING.
It would be of great help if I could get driver source code, so I can exactly see what is going on in a specific routine.


Code: Select all
/**************************************************************************
* C program for getting Serial Number of TC-08 (USB) device
* author: Dusan P Djurdjevic, Edinburgh UNI, 2005.
***************************************************************************/

#include <stdio.h>
#include "usbtc08.h"

#define TC_TYPE_K 'K'

int main()
{
  short          hTC08;
  USBTC08_INFO   devinfo;
  char           str[50];
  int            ok;
  float          temp_buffer;
  short          temp_int_buffer;
  short          overflow;

  // open unit
  hTC08 = usb_tc08_open_unit ();

  // check if everything OK
  if (hTC08 <= 0)
      {
      printf("Error Code: %d\n",usb_tc08_get_last_error (0));
      return(99);
      }


  // set one channel to verify that device is working
  ok = usb_tc08_set_channel (hTC08, 0, TC_TYPE_K);
  usb_tc08_get_single(hTC08, &temp_buffer, &overflow,0);
  printf("Temperature reading on Chanel 0: %.3f\n\n", temp_buffer);

  // get device information
  // 1.
  usb_tc08_get_unit_info(hTC08, &devinfo);
  printf ("1. usb_tc08_get_unit_info(handle, *info):\n");
  printf ("\tSize: %d\n",devinfo.size);
  printf ("\tDriverVersion: %d\n",devinfo.DriverVersion);
  printf ("\tHardwareVersion: %d\n",devinfo.HardwareVersion);
  printf ("\tVariant: %d\n",devinfo.Variant);
  printf ("\tszSerial: %s\n",devinfo.szSerial);
  printf ("\tszCalDate: %s\n\n",devinfo.szCalDate);

  // 2.
  usb_tc08_get_formatted_info(hTC08, str, 50);
  printf ("2. usb_tc08_get_formatted_info (handle, *unit_info, string_length):\n");
  printf ("\tunit_info: %s\n\n",str); 

  // 3.
  ok = usb_tc08_legacy_get_driver_version();
  printf ("3. usb_tc08_legacy_get_driver_version:\n");
  printf ("\tResult: %d\n\n",ok);

  // 4.
  usb_tc08_legacy_get_version(&temp_int_buffer,hTC08);
  printf ("4. usb_tc08_legacy_get_version(*version, handle):\n");
  printf ("\tVersion: %d\n\n",temp_int_buffer); 
}


Result from this sample program:
Code: Select all
D:\Projects\Experiments_SEE\Driver\Drivers\Win32>usbtc08.exe
Temperature reading on Chanel 0: 26.531

1. usb_tc08_get_unit_info(handle, *info):
        Size: 16048
        DriverVersion: 30659
        HardwareVersion: 30657
        Variant: -1
        szSerial:   3½┬wHô├wP$ò
        szCalDate: $ò

2. usb_tc08_get_formatted_info (handle, *unit_info, string_length):
        unit_info:

3. usb_tc08_legacy_get_driver_version:
        Result: 257

4. usb_tc08_legacy_get_version(*version, handle):
        Version: 1


All "readable" numbers are not unique to the device unfortunately, plus junk in szSerial can not be used, since it is not permanent. Just to mention that even if you do not call usb_tc08_get_unit_info at all, you will get very similar answer (i.e. Values of *info are not changed after calling usb_tc08_get_unit_info ).
On the other hand 2nd routine in the example returns only empty string.
Please Note: No trees were destroyed in sending this contaminant free message. However, we do concede that significant number of electrons may have been inconvenienced.
User avatar
duxxx001
Active User
Active User
 
Posts: 6
Joined: Tue Jun 07, 2005 12:11 pm
Location: Edinburgh

Postby Sarah » Tue Jun 14, 2005 11:36 am

Hi

Thank you for your post.

We have tracked down the root of this issue. You need to add the following line of code:

devinfo.size = sizeof(USBTC08_INFO);

Above the line:

usb_tc08_get_unit_info(hTC08, &devinfo);

This should then work. We will update our manuals accordinly with this.

Hope this helps

Best Regards
Sarah
 

Postby duxxx001 » Tue Jun 14, 2005 1:10 pm

Sarah wrote:Hi

You need to add the following line of code:

devinfo.size = sizeof(USBTC08_INFO);

Above the line:

usb_tc08_get_unit_info(hTC08, &devinfo);

Yes this works now, and Delphi example works fine as well with it. Perhaps it should be better if this initialisation of devinfo structure take place inside the driver.
Anyway, I will create new driver wrapper for Delphi, so that making custom applications is much simpler under this developing environment. It will be installed in the IDE as component.

Re this issue: I still have no idea why usb_tc08_get_formatted_info is not working, and what kind of the output it should produce after all.
Please Note: No trees were destroyed in sending this contaminant free message. However, we do concede that significant number of electrons may have been inconvenienced.
User avatar
duxxx001
Active User
Active User
 
Posts: 6
Joined: Tue Jun 07, 2005 12:11 pm
Location: Edinburgh

Re: PROBLEM: Getting Serial number from TC-08 USB device

Postby bigdutch » Sat Dec 03, 2011 2:00 am

Hi

Even after following this code I am still getting strange characters.

Dusan left out the bit of Delphi code that showed how it all work at the end!

Here is my code.
Code: Select all
=========================================================================================
  Type
  TUSBTC08_INFO = record
  size: smallint;
  DriverVersion: smallint;
  PicoppVersion: smallint;
  HardwareVersion: smallint;
  Variant: smallint;
  szSerial: Array[0..11] of Char;
  szCalDate: Array[0..9] of Char;
end;
  PUSBTC08_INFO = ^TUSBTC08_INFO;
  function usb_tc08_get_unit_info (handle: smallint; info: PUSBTC08_INFO):smallint;   stdcall; external 'usbtc08.dll';
.
.
.
procedure TForm1.StartClick(Sender: TObject);
var
  ok   : boolean;  s  : string;  error_code  : smallint;  ascii    : smallint; 
  info        : TUSBTC08_INFO;

begin
// first TC-08
  if (tc08_handle < 1) then
    begin
      lbStatus.Text := 'Opening TC08 No.1';
      repaint;
      tc08_handle := usb_tc08_open_unit ();

      if (tc08_handle > 0) then  begin
          info.size := sizeof(TUSBTC08_INFO);
          usb_tc08_get_unit_info(tc08_handle,@info);
===================================================================================

When I break the run and cursor over the @info variable i get strange characters for the serial and cal date:
I must be doing something daft with the variables I am using!

If anyone could help me on the last bit (Dusan?) that would be great.

Regards

Richard
bigdutch
Newbie
 
Posts: 0
Joined: Sat Dec 03, 2011 1:42 am

Re: PROBLEM: Getting Serial number from TC-08 USB device

Postby bigdutch » Sun Dec 04, 2011 10:37 pm

Hi

I solved my Delphi serial extraction problem by re-examining the USBTC08.h file for the USB_tc08_get_unit_info routine. It is actually;

Code: Select all
typedef struct tUSBTC08Info
  {
  short size;
  char DriverVersion[USBTC08_MAX_VERSION_CHARS];   // different from Dusan's example
  short PicoppVersion;
  short HardwareVersion;
  short Variant;
  char  szSerial[USBTC08_MAX_SERIAL_CHARS];
  char  szCalDate[USBTC08_MAX_DATE_CHARS];
  } USBTC08_INFO, *LPUSBTC08_INFO;

Note:  the DriverVersion parameter is of char type NOT a short (unless you were using an earlier driver or other logical explanation).

I found the USBTC08_MAX variables also from the C header USBTC08.h

/* General Defines **************************************************/
#define USBTC08_MAX_FILTER_SIZE   255
#define USBTC08_MAX_SAMPLE_BUFFER 600 /* Max readings that usb_tc08_get_temp will ever return */
#define USBTC08_MAX_INFO_CHARS    256
#define USBTC08_MAX_DATE_CHARS    9
#define USBTC08_MAX_SERIAL_CHARS  11
#define USBTC08_MAX_VERSION_CHARS 12

So my final Delphi code is:

  private
    { Private declarations }

  public
    { Public declarations }

  end;

  Type
   TUSBTC08_INFO = record
   size: smallint;
   DriverVersion: Array[0..11] of char;
   PicoppVersion: smallint;
   HardwareVersion: smallint;
   Variant: smallint;
   szSerial: Array[0..10] of Char;
   szCalDate: Array[0..8] of Char;
end;
  PUSBTC08_INFO = ^TUSBTC08_INFO;
  function usb_tc08_get_unit_info (handle: smallint; info: PUSBTC08_INFO):smallint;   stdcall; external 'usbtc08.dll';

.
Your code here etc
.
procedure Tform1. get serial and cal date(Sender: TObject);
var
  info        : TUSBTC08_INFO;
begin
     if (tc08_handle > 0) then
        begin
          info.size := sizeof(TUSBTC08_INFO);
          usb_tc08_get_unit_info(tc08_handle,@info);
          tcserial:=info.szSerial;
.
more code etc
.


The main problem was that using a short type in the driverversion parameter was obviously giving the wrong pointer location.

Be aware that the returned values may have to be trimmed to exclude unused end chars!

I have coded this in XE2.

Best Regards

Richard
bigdutch
Newbie
 
Posts: 0
Joined: Sat Dec 03, 2011 1:42 am


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests