User Tools

Site Tools


Sidebar

Home

Documentation

Tutorial

Reference Manual

Installation

en:documentation:script_example

This is an old revision of the document!


Script example

This page give tips and example of scripting functions.
You can also look at the template code provided with the program.
For more details about a specific function see the script reference page.

Generality

We first look in detail at the code of the scope_unpark script you can use to unpark the telescope. To open this script locate the script tool, select “scope_unpark” in the dropdown list and click the Edit button.
This cover many programming basis.

The full script code look as following:

{
  This script unpark the telescope mount
}
 
var ok,parked: boolean;
    arg: TStringList;
    r: string;
begin
 
  // telescope connected?
  GetB('TELESCOPE_CONNECTED',ok);
  if not ok then begin
    logMsg('Telescope not connected!');
    exit;
  end;
 
  // get park status
  GetB('TELESCOPE_PARKED',parked);
 
  if parked then begin
    getSl('STRL1',arg);
    arg.clear;
    arg.add('OFF');
    r:=cmdArg('TELESCOPE_PARK',arg);
    if r<>msgOK then logMsg('Telescope park: '+r);
  end
  else begin
    logMsg('Telescope already unparked');
  end;
end.                                            

Take a look at each part in detail:

{
  This script unpark the telescope mount
}

Is a comment, you can use // {..} (*..*) to enclose your comments.


var ok,parked: boolean;
    arg: TStringList;
    r: string;

Define the variable we use later in the script.
Important variable type are: integer, double, string, boolean.
The Tstringlist type is use here to send a command argument to CCDciel.


  begin

The start of our script.


GetB('TELESCOPE_CONNECTED',ok);

We ask CCDciel about the status of a boolean variable to know if the telescope is connected, the result is in our variable ok.


  if not ok then begin
    logMsg('Telescope not connected!');
    exit;
  end;

We test the result of the previous command, ok is true if the telescope is connected, so we add the negation “not” to test for “not connected”. If the result of the test “not connected” is true we execute the code block starting at “begin” up to the corresponding “end”, this write a message in the log and exit the script.


GetB('TELESCOPE_PARKED',parked);

We continue and we do the same to check if the telescope is parked, with the result in our parked variable..


    if parked then begin

We test if the telescope is parked, in this case we can unpark.


GetSL('STRL1',arg);
arg.clear;

Request a TStringList object identified by STRL1. We clear any data that may stay in the object. We need this TStringlist to pass argument to a CCDciel command.


    arg.add('OFF');
    r:=cmdArg('TELESCOPE_PARK',arg);

Add the argument 'OFF' for the command and execute 'TELESCOPE_PARK' 'OFF'. This effectively unpark the telescope and the result is in variable r.


if r<>msgOK then logMsg('Telescope park: '+r);

We test the result is different than msgOK, in this case we write a message to the log to show the error from the driver.


 end.

The end of the script.

Open a document

The following code open an html page in the default web browser.
You can use any document type with this function, the document open with the default application the same way as if you double click the document in the file explorer.

begin
  OpenFile('document.html');
end.

Run a command

There is three different way to run an external command or program, depending if you want to wait for a result or the command completion or not.

No wait

If the command can run for an undetermined time or do not produce an output you need to use the following form.
This example run the Skychart program and exit immediately without waiting you exit Skychart.

begin
  Run('skychart');
end.

Wait until the end of the command

If you need to wait the end of a command but it only produce an exit code to signal success or failure you can use the following form.

begin
  if runWait('/bin/bash -c open_dome.sh') then
    logmsg('Dome opened')
  else
    logmsg('Fail to open the dome')  
end.

Wait for a result

The following command run the DIR command in the current directory. The result is stored in a stringlist and the first entry is show in the log.

var r:TstringList;
begin
  GetSL('STRL1',r);
  r.clear;
  RunOutput('dir',r);
  logmsg(r[0]);
end.
en/documentation/script_example.1551014964.txt.gz · Last modified: 2019/02/24 14:29 by pch