Back to Homepage

Computers and Programming

Amateur Radio
Antenna (1)

Antenna (2)
(norwegian text)

Antenna (2) English text

W-8010 Dipole trimming PC Program

Download MiniVNA bug fix

New: MiniVNA antenna analyzer program

New: CB antenna as a radio amateur antenna

An example on how to deal with TellStick

Based on the TellStick DLL which publishes all the necessary functions and procedures for a Delphi program, I'll try to show how you can operate Tellstick from within your own Delphi program.

A short example that is shown here is just an example on how to address the TellStick routines.  In my example I'll browse through all connected receivers from Waveman.  Both TellStick and Waveman products (receivers and transmitters) may be purchased from any dealer listed on the Telldus home page, for example your nearest Clas Ohlson shop.

The program

First of all you have to declare all the routines in the TelldusCore.dll (this Dynamic Link Library is installed as a part of the TellStick Windows program package downloadable from Telldus).

For easy acces to this DLL, make a copy of the TelldusCore.DLL to the same directory where you plan to save your TellStick Delphi project.

The program will call C(++) routines from the DLL, these routines (C functions) are described on the Telldus home page in detail.

They must be declared in your Delphi program under the Implementation section, like this:

Function tdTurnOn (deviceID: Integer): Boolean; Stdcall; External 'TelldusCore.dll';

Procedure tdInit; Stdcall; External 'TelldusCore.dll';

Procedure tdClose; Stdcall; External 'TelldusCore.dll';

Procedure tdReleaseString (S: String); Stdcall; External 'TelldusCore.dll';

Function tdTurnOff (deviceID: Integer): Boolean; Stdcall; External 'TelldusCore.dll';

Function tdBell (deviceID: Integer): Boolean; Stdcall; External 'TelldusCore.dll';

Function tdDim (deviceID: Integer; Level: Byte): Boolean; Stdcall; External 'TelldusCore.dll';

Function tdMethods (deviceID: Integer; methodsSupported: Integer): Integer;
Stdcall; External 'TelldusCore.dll';

Function tdGetDeviceId (a: Integer): Integer; Stdcall; External 'TelldusCore.dll';

Function tdGetName (I: Integer): PChar; Stdcall; External 'TelldusCore.dll';

Function tdGetNumberOfDevices: Integer; Stdcall; External 'TelldusCore.dll';

Procedure tdSetName (intDeviceId: Integer; chNewName: String); Stdcall; External 'TelldusCore.dll';

Procedure tdRemoveDevice (intDeviceId: Integer); Stdcall; External 'TelldusCore.dll';

Procedure tdAddDevice; Stdcall; External 'TelldusCore.dll';

Function tdLastSentCommand (intDeviceId, methodsSupported: Integer): Integer;
Stdcall; External 'TelldusCore.dll';

Function tdLastSentValue (intDeviceId: Integer): PChar; Stdcall; External 'TelldusCore.dll';

Function tdGetModel (intDeviceId: Integer): PChar; Stdcall; External 'TelldusCore.dll';

Function tdSetModel (intDeviceId: Integer; Model: PChar): Boolean; Stdcall; External 'TelldusCore.dll';

Function tdRemovdevice (intDeviceId: Integer): Boolean; Stdcall; External 'TelldusCore.dll';

It's important to use the "Stdcall" clause, otherwise your program will thow a lot of exceptions when you run it!  That's based on how C(++) is exporting these routines and parameters.

You may copy and paste these functions and procedures into your own program from above.  I'm not sure if all routines are listed, but for my purposeand example they are OK so far.

In my little test program, I will list all TellStick receivers, with their names and last command status.  For the sake of ease I will list these parameters in a TMemo, which I name M1 for short.

Drop a memo and a button on a new project's form.  Double-click the button and write the code in the button's OnClick procedure and give the memo the name of M1 as shown below in my example:

Procedure TForm1.Button1Click (Sender: TObject);
   Antall, I, ID, iLastCmd : Integer; //Antall is the number of devices, in Norwegian :-)
   LastCommand, Name : PChar;

   Antall:= tdGetNumberOfDevices;
   For I:= 0 To Antall - 1 Do
      ID:= tdGetDeviceId (I);
      If ID > -1 Then // if ID = -1 then we have an error!
        Name:= tdGetName (ID); //get the name for this ID

        // Get last sent command for each unit from the Registry:
        iLastCmd:= tdLastSentCommand (ID, TELLSTICK_TURNON Or TELLSTICK_TURNOFF);
        Case iLastCmd Of
          1: LastCommand:= 'Turn On';
          2: LastCommand:= 'Turn Off';
        End; //Case

       // Fill in the text in the memo box M1:
       M1.Lines.Add ('Switch ' + IntToStr (ID) + ': Name "' + Name +
                    '": Last command was "' + LastCommand + '"');

       // Fill in the StringGrid SG1: // SG1 is a stringgrid with sorting capabilities.
       SG1.Cells [0, I]:= LastCommand;
       SG1.Cells [1, I]:= tdGetModel (ID);
       SG1.Cells [2, I]:= IntToStr (ID);
       SG1.Cells [3, I]:= Name;
     End;  //If
    End;  // For
End;  // procedure

I forgot to mention that you should also declare all the Constants

TELLSTICK_TURNOFF  = 2;  //etc etc.

Here's the contents of the M1 memo box when I run this program:


This example should get you going to program anything you want, for example to switch off / on lamps at runrise and sunset, and a lots of other fun and useful stuff for your home.

Please also begin your program with a call to tdInit and tdClose when terminating the program.



Any questions? Discuss this article on the forum in (Computers and Programs) has its own subforum for TellStick.

Hit counter: 4252 . since 16.04.2010