ASCOM for end user application developers
ASCOM is a nice platform providing unified access to astronomical hardware controllable from a computer. Hardware makers provide ASCOM driver and end user apps like PHD or Nebulosity may start using it without problems or additional drivers. For developers - those that want to make drivers or use the ASCOM API - the journey to ASCOM starts at digging through raw documentation. Some help may be found also on the mailing list. It's not documented as well as Django, but still - it's usable.
We start with installing additional components that give documentation and few handy libraries. ASCOM platform uses .NET framework and provides .NET API. For other languages there is full API access via COM.
The documentation is in Program Files/ASCOM/Platform 6 Developer Components/Developer Documentation (or "Program Files (x86)" on 64-bit Windows). The most interesting is PlatformDeveloperHelp.chm containing few examples and all the namespace of the ASCOM API.
End user apps are those who use the ASCOM drivers/API to control the hardware like a mount or a camera. In most such cases we will use ASCOM.DriverAccess to do that. It gives a API to control domes, filter wheels, focuser, rotators or mounts. In PlatformDeveloperHelp.chm you will find the whole namespace for this library.
For languages outside .NET platform we have to use the COM technology. Here is a simple Python script that slews the mount:
import win32com.client #needed to load COM objects #Identyfikator sterownika #ASCOM.Simulator.Telescope tel = win32com.client.Dispatch("Celestron.Telescope") if tel.Connected: print " ->Telescope was already connected" else: tel.Connected = True if tel.Connected: print " Connected to telescope now" else: print " Unable to connect to telescope, expect exception" tel.Tracking = True tel.SlewToCoordinates(12.34, 86.7) # !!!pick coords currently in sky! tel.Connected = False
win32com.client.Dispatch is used to load the library - a driver "id" in this case. "Celestron.Telescope" is the ID of the Celestron ASCOM driver that controls Celestron and SkyWatcher mounts. This driver has the same API as ASCOM.DriverAccess.Telescope. At start we connect to the device setting "Connected" to True. Then we set Tracking to True to order the mount to start tracking (sidereal rate by default). "SlewToCoordinates" method will slew the mount to given coordinates (RightAscension, Declination).
To use the equipment the user wants we need to give him the ability to choose it. We need the driver ID like "Celestron.Telescope" and we will get it via ASCOM.Utilities.Chooser - this class shows the choose window for every type of equipment.
import win32com.client #needed to load COM objects x = win32com.client.Dispatch("ASCOM.Utilities.Chooser") x.DeviceType = 'Telescope' print x.Choose(None)
Chooser supports all type of equipment handled by ASCOM. Choose method will show the choose window and will return the driver ID when user closes it. All settings applied by the user will be saved too.
IronPython is a Python implementation on the .NET platform. As such it can use .NET libraries, like so:
#-*- coding: utf-8 -*- import clr # załadowanie DLL clr.AddReference("ASCOM.DriverAccess.dll") from ASCOM.DriverAccess import * #a = Telescope('ASCOM.Simulator.Telescope') a = Telescope('Celestron.Telescope') a.Connected = True a.SlewToCoordinates(11.11, 11.11) a.TrackingRate = 0 a.Tracking = True a.Connected = False
The API is the same, only import is different. In the folder with the script I placed the ASCOM.DriverAccess.dll that can be found in Program Files/ASCOM/Platform 6 Developer Components/Components/Platform6. The script is executed by IronPython interpreter - ipy.exeIn case of camers it looks quite similar:
#-*- coding: utf-8 -*- import clr clr.AddReference("ASCOM.DriverAccess.dll") from ASCOM.DriverAccess import * a = Camera('ASCOM.Simulator.Camera') a.Connected = True a.StartExposure(1, True) wait = True while wait: if a.ImageReady: wait = False print list(a.ImageArray)
The "images" is an ImageArray object which needs to be somehow saved as a FITS file (didn't made that work yet). For .NET there is CSharpFITS (and pyFITS for Python) which can be used. This library also requires nunit - install it and copy/load nunit.framework.dll in the script:
clr.AddReference("nunit.framework.dll") clr.AddReference("CSharpFITS.dll") from nom.tam.fits import *