AL_ASCOMTelescope

Top  Previous  Next

Enter topic text here.

 

(*

AL_ASCOMTelescope

 

This Delphi component is the implementation of Telescope driver

for Goto cumputerized telescope mounts.

Required: Installad ASCOM interface!

 

Outhor : Agócs László 2009 Hungary

Base on: Cartes du Ciel source code

 

*)

 

unit AL_ASCOMTelescope;

 

interface

 

uses

Windows,  Messages, SysUtils, Classes, Graphics, Controls,

Forms, Dialogs, ShellAPI,

StdCtrls, Buttons, inifiles, ComCtrls, Menus, ExtCtrls,

Astro;

 

Type

 

TAL_CustomASCOMTelescope = class(TComponent)

private

   FAutoConnect: boolean;

   FScopeName: string;

   FIniFile: TIniFile;

   FInitialized: boolean;

   FConnected: boolean;

   FRaLabel: TLabel;

   FDeLabel: TLabel;

   FEQCoord: TEQCoordStr;

   function GetASCOMInstallad: boolean;

   procedure SetAutoConnect(const Value: boolean);

   procedure SetIniFile(const Value: TIniFile);

   procedure SetScopeName(const Value: string);

   function GetEQCoord: TEQCoordStr;

   function GetConnected: boolean;

   function GetLatitude: double;

   procedure SetLatitude(const Value: double);

protected

   procedure LoadConfig;

   procedure SaveConfig;

   procedure OnTimer(Sender: TObject);

public

    T         : Variant;       // Telescope variant

    ini       : TIniFile;      // Ini file for parameters load/save

    inTimer   : TTimer;        // Timer for get Ra,De

 

    constructor Create(AOwner:TComponent); override;

    destructor Destroy; override;

 

    function ScopeConnect: boolean;

    function ScopeDisconnect : boolean;

    procedure ScopeAlign(ra,dec : double);

    function ScopeShowModal : boolean;

    procedure ScopeShow;

    procedure ScopeClose;

    function ScopeGetEqSys(var EqSys : double): boolean;

    function ScopeGetRaDec(var ar, de: double): boolean;

    function ScopeGetAltAz(var alt,az : double): boolean;

    function ScopeGetName: shortstring;

    procedure ScopeReset;

    function ScopeConnected : boolean;

    function ScopeInitialized : boolean;

    procedure ScopeGetInfo(var scopename : shortstring; var QueryOK,SyncOK,GotoOK : boolean; var refreshrate : integer);

    procedure ScopeSetObs(latitude,longitude : double);

    procedure ScopeGoto(ar,de : double);

 

    property IniFile : TIniFile read FIniFile write SetIniFile;

    property ASCOMInstallad: boolean read GetASCOMInstallad;

    Property AutoConnect: boolean read FAutoConnect write SetAutoConnect default False;

    Property Connected: boolean read GetConnected;

    Property ScopeName: string read FScopeName write SetScopeName;

    property Latitude: double read GetLatitude write SetLatitude;

    property RaLabel: TLabel read FRaLabel write FRaLabel;

    property DeLabel: TLabel read FDeLabel write FDeLabel;

    property EQCoord: TEQCoordStr read GetEQCoord write FEQCoord;

end;

 

TALTelescope = class(TAL_CustomASCOMTelescope)

published

    property IniFile;

    property ASCOMInstallad;

    Property AutoConnect;

    Property ScopeName;

    Property Connected;

end;

 

implementation

 

{ TAL_CustomASCOMTelescope }

 

constructor TAL_CustomASCOMTelescope.Create(AOwner: TComponent);

begin

inherited;

FAutoConnect := True;

FScopeName   := 'Celestron.Telescope';

if FIniFile = '' then

    FIniFile     := 'Telescope.ini';

IF FileExist(FIniFile) then

    LoadConfig;

inTimer   : TTimer.Create;

inTimer.OnTimer := OnTimer;

end;

 

destructor TAL_CustomASCOMTelescope.Destroy;

begin

SaveConfig;

inTimer.Free;

inherited;

end;

 

function TAL_CustomASCOMTelescope.GetASCOMInstallad: boolean;

var

V: variant;

begin

try

V := CreateOleObject('DriverHelper.Chooser');

V.devicetype:='Telescope';

FScopeName:=V.Choose(FScopeName);

V:=Unassigned;

SaveConfig;

Result := True;

except

   Result := False;

   Showmessage('No ASCOM telescope drivers are installed!');

end;

end;

 

procedure TAL_CustomASCOMTelescope.ScopeAlign(ra,dec: double);

begin

if not ScopeConnected then exit;

if T.CanSync then T.SyncToCoordinates(Ra,Dec);

end;

 

procedure TAL_CustomASCOMTelescope.ScopeClose;

begin

 

end;

 

function TAL_CustomASCOMTelescope.ScopeConnect: boolean;

begin

T:=Unassigned;

T := CreateOleObject(FScopeName);

T.connected:=true;

if T.connected then begin

    FConnected := True;

end else scopedisconnect(dis_ok);

end;

 

function TAL_CustomASCOMTelescope.ScopeConnected: boolean;

begin

result:=false;

if VarIsEmpty(T) then exit;

result:=T.connected;

end;

 

function TAL_CustomASCOMTelescope.ScopeDisconnect: boolean;

begin

if not VarIsEmpty(T) then begin

T.connected:=false;

T:=Unassigned;

FConnected := False;

Result := True;

end;

end;

 

function TAL_CustomASCOMTelescope.ScopeGetAltAz(var alt, az: double): boolean;

begin

if ScopeConnected then begin

  az:=cur_az;

  alt:=cur_alt;

  ok:=true;

end else ok:=false;

end;

 

function TAL_CustomASCOMTelescope.ScopeGetEqSys(var EqSys: double): boolean;

begin

 

end;

 

procedure TAL_CustomASCOMTelescope.ScopeGetInfo(var scopename: shortstring;

var QueryOK, SyncOK, GotoOK: boolean; var refreshrate: integer);

begin

if ScopeConnected  then begin

    name:=T.name;

    QueryOK:=true;

    SyncOK:=T.CanSync;

    GotoOK:=T.CanSlew;

end else begin

    name:='';

    QueryOK:=false;

    SyncOK:=false;

    GotoOK:=false;

end;

FScopeName := name;

refreshrate:=inTimer.interval;

end;

 

function TAL_CustomASCOMTelescope.ScopeGetName: shortstring;

begin

If Connected then Result := T.ScopeName;

end;

 

function TAL_CustomASCOMTelescope.ScopeGetRaDec(var ar, de: double): boolean;

begin

if ScopeConnected then begin

  ar:=Curdeg_x/15;

  de:=Curdeg_y;

  ok:=true;

end else ok:=false;

end;

 

procedure TAL_CustomASCOMTelescope.ScopeGoto(ar, de: double);

begin

if not ScopeConnected then exit;

if T.CanSlewAsync then T.SlewToCoordinatesAsync(ar,de)

                 else T.SlewToCoordinates(ar,de);

end;

 

procedure TAL_CustomASCOMTelescope.ScopeReset;

begin

 

end;

 

procedure TAL_CustomASCOMTelescope.ScopeSetObs(latitude,

longitude: double);

begin

 

end;

 

procedure TAL_CustomASCOMTelescope.ScopeShow;

begin

 

end;

 

function TAL_CustomASCOMTelescope.ScopeShowModal: boolean;

begin

 

end;

 

procedure TAL_CustomASCOMTelescope.SetAutoConnect(const Value: boolean);

begin

FAutoConnect := Value;

// Controlling ASCOM interface

If FAutoConnect then

    ASCOMInstallad:=True;

end;

 

procedure TAL_CustomASCOMTelescope.SetIniFile(const Value: TIniFile);

begin

FIniFile := Value;

end;

 

procedure TAL_CustomASCOMTelescope.SetScopeName(const Value: string);

begin

FScopeName := Value;

end;

 

procedure TAL_CustomASCOMTelescope.LoadConfig;

begin

Try

ini:=tinifile.create(extractfilepath(paramstr(0))+'scope.ini');

finally

ini.Free;

end;

end;

 

procedure TAL_CustomASCOMTelescope.SaveConfig;

begin

Try

ini:=tinifile.create(extractfilepath(paramstr(0))+'scope.ini');

ini.writestring('Ascom','name',ScopeName);

ini.writestring('Ascom','read_interval',IntToStr(inTimer.Interval));

ini.writeBool('Ascom','AltAz',ShowAltAz.Checked);

ini.writestring('observatory','latitude',lat.text);

ini.writestring('observatory','longitude',long.text);

finally

ini.Free;

end;

end;

 

procedure TAL_CustomASCOMTelescope.OnTimer(Sender: TObject);

begin

if Connected then begin

    if RaLabel<>nil then

       RaLabel.Caption := Ra;

    if DeLabel<>nil then

       DeLabel.Caption := De;

end;

end;

 

function TAL_CustomASCOMTelescope.GetEQCoord: TEQCoordStr;

var ra.de: double;

begin

if ScopeGetRaDec(ra,de) then begin

    Result.Ra := RaToStr(Ra);

    Result.De := RaToStr(De);

end;

end;

 

function TAL_CustomASCOMTelescope.GetConnected: boolean;

begin

 

end;

 

function TAL_CustomASCOMTelescope.GetLatitude: double;

begin

 

end;

 

function TAL_CustomASCOMTelescope.ScopeInitialized: boolean;

begin

 

end;

 

procedure TAL_CustomASCOMTelescope.SetLatitude(const Value: double);

begin

 

end;

 

end.