Applications - Getting Started

If you haven't yet read How ASCOM Works, you should really go there and read it now, along with the other information in the About ASCOM section of this web site. The How ASCOM Works page details the basics of connecting to and using a driver.

Also see Tom How's excellent video below ASCOM client astronomy development tutorial and introduction, which takes you through the entire process of developing a program that can control any telescope with an ASCOM driver.

Using ASCOM drivers differs in detail depending on the language you are using for your application. Over 20 languages on Windows can use drivers, so it's beyond the scope of this document to describe the details for each. The place to start is the documentation for your language that covers "COM Automation" or "ActiveX".

Visual Basic 6 has this built-in and is the simplest to use, however it has been de-supported by Microsoft. C++ is by far the most difficult language from which to use ASCOM drivers (or for that matter, any Windows Object). Since drivers in general only support "late binding", it's necessary to implement complex IDispatch-based code to call them. The ActiveX Template Library can be a help, but it's still really difficult. You'll have to write wrapper code and be very careful calling the interface members. The learning curve is steep. Consider how married you are to C++ before starting your new astronomy application development. Consider using a NET language. Beginning with Visual Studio 2010, C# supports late binding, so it's easy to use drivers from C# 2010. Visual Basic .NET has always supported late binding.

If you are developing in one of the .NET languages, the situation is much better. The ASCOM Client Toolkit is an assembly that greatly simplifies using drivers from .NET. Astronomy software developers wishing to use ASCOM drivers from .NET applications are encouraged to use this library, as it provides not only simplified access to drivers, but also automatic switching between the preferred early-binding interfaces and, for older drivers that don't support it, late-binding. If late binding is needed, the Client Toolkit hides all of the ugly details of calling a driver via its late-bound interface. Your code will always use native .NET class/object syntax.

It's very easy to use an ASCOM driver in most languages. The basic steps are:

  1. Create an instance of the driver
  2. Optionally, open the driver's setup window, allowing the user to set things like the COM port. The driver will remember these settings.
  3. Connect to the hardware
  4. Determine the optional capabilities of the device
  5. Prepare the device for your use

At this point you can control the device via the standard interface members (properties and methods). See the interface standard documents installed with the ASCOM Platform (if you included developer content - you're a developer, right?).

Here's a video by Tom How that takes you through the process of developing a simple astronomy application that can control any telescope with an ASCOM driver.
GO FULL SCREEN 1080p TO SEE THE CODE!

Hello World in JScript

The following script, written in the JScript language, shows how simple it is to control a telescope. We use the Telescope Simulator, part of the ASCOM Platform. The simulator is a Telescope driver; it's a great tool for testing your code. To switch over to talking to some other (real) telescope, all you need to do is change the driver ID from ScopeSim.Telescope to SomethingElse.Telescope. That's it!

var T = new ActiveXObject("ScopeSim.Telescope");    // Change for your driver's ID
T.SetupDialog();                                    // Comment this out once you set COM port, etc.
T.Connected = true;
WScript.StdOut.WriteLine("RA = " + T.RightAscension);
WScript.StdOut.WriteLine("DE = " + T.Declination);
if (T.CanSetTracking && !T.Tracking)
    T.Tracking = true;
WScript.StdOut.WriteLine("Slewing to 1 hour east of meridian...");
T.SlewToCoordinates(T.SiderealTime + 1.0, 0);
WScript.StdOut.WriteLine("... slew complete");
WScript.StdOut.Write("Press Enter to quit and release the driver ");
WScript.StdIn.ReadLine();

Create a file ASCOMHello.js with this script in it. Open a CMD shell and change to the directory containing the new script file. Run the script with the Windows Script Host cscript. This program plays the same role as (e.g.) the Perl or Python interpreters for those panguages.

C:\Foo\Bar\> cscript ASCOMHello.js
RA = 9.660283023289306
DE = -1.286254097879772e-7
Slewing to 1 hour east of meridian...
... slew complete
Press Enter to quit and release the driver

C:\Foo\Bar\>

After typing the command, you'll see the simulator's setup dialog appear, just hit cancel. Next you'll see the simulator in the taskbar, normalize it into view. You should see it slewing (unless it happens to already be pointing at the celestial equator an hour east of the meridian!). In any case, when you see the script's output saying the slew is complete, you can look over the simulator. When you press Enter, the simulator will disappear.

NOTE: If you are on a 64-bit system, you need to be running this in a 32-bit CMD shell, since the vast majority of drivers are 32-bit. To open a 32-bit CMD shell, run C:\Windows\SysWOW64\cmd.exe