You could just pull out your reusable code units and build them into ASCOM components using Visual Basic or even C++. But that assumes you are familiar with Visual Basic 6. And right now getting VB6, which supports Automation and ASCOM natively is difficult. You can use VB.NET which produces .NET components that use "COM-Interop" to expose themselves to ASCOM, but it costs serious money and has a rather large learning curve. Why not build simple components with a text editor?
WSCs provide you with an easy way to create reusable ASCOM components in script! You create script components using any Windows scripting language and a text editor such as Notepad. If you read about WSCs on the net, you'll find most articles talk about them in the context of Active Server Pages, and talk about using the WSC Wizard. For ASCOM work we strongly recommend you invest in a copy of PrimalScript from Sapien Technologies. This program is an integrated development environment for WSCs. Nonetheless, you may find that Notepad or some other text editor is plenty good enough.
We'll assume you're familiar with ASCOM concepts of objects, methods, and properties, and you know what a ProgID is (hint: Meade.Telescope and MaxIm.CCDCamera are ProgIDs). The objective is to create a full-fledged ASCOM component with Notepad! Let's cut to the chase:You can drag through and copy this XML to the clipboard.
<?xml version="1.0" ?>
<package>
<comment>
<![CDATA[
Your component documentation goes here
]]>
</comment>
<component id="Main">
<?component error="true" debug="true" ?>
<registration
progid="Your.Component"
description="A short description"
remotable="no">
</registration>
<object id="ACPApp" progid="ACP.Application"
events="false" reference="true"/>
<object id="FSO" progid="Scripting.FileSystemObject"
events="false" reference="false"/>
<object id="MaxIm" progid="MaxIm.Application"
events="false" reference="true"/>
<object id="Util" progid="ACP.Util"
events="false" reference="false"/>
<public>
Your interface definition
</public>
<script id="Main" language="VBScript">
<![CDATA[
Dim Telescope, Camera, Dome, Weather
Set Telescope = Util.ScriptTelescope ' Shortcuts
Set Camera = Util.ScriptCamera
Set Dome = Util.Dome
Set Weather = Util.Weather
Your script implementation
]]>
</script>
</component>
</package>
Jones.WeatherStation
.<method name="xxx">
<parameter name="param1">
<parameter name="param2">
</method>
This would be implemented in the <script> section (assuming VBScript) as:
{Function|Sub} xxx(param1, param2)
For properties:
<property name="yyy">
<get/>
<put/>
</property>
This would be implemented in the <script> section (assuming VBScript) as:
Function get_yyy()
and
Function put_yyy()
If you don't want to allow setting of the property, omit the <put/> tag from the <property name="yyy"> tag and omit the Function put_yyy() implementation. Methods that don't return a value should be implemented as Sub
and not Function
. All exposed properties and methods must be hooked up this way, with a declaration in the <public> section and a corresponding implementation in the <script> section.
VBScript
or JScript
.Function
or Sub
will be executed when an ACP script creates your component. Beware, though, that raised errors in such initialization code will not flow through to your script. Instead you'll get a "script stopped unexpectedly" error from your ACP script's call to CreateObject().By default ACP does not "see" your component and it's member functions. To activate it for ACP it must be registered with the Windows OS. This is simple on 32-bit systems: Right click on mycomponent.wsc and select Register. If you see a success popup, it's ready to go. If you see a failure popup, there is a mistake in the code or XML.
On 64-bit systems it's a bit more complicated, as the component must be registered with the 32-bit siubsystem of Windows:
Error Message RegSvr32 DllRegisterServerEx in C:\WINNT\system32\scrobj.dll failed. Return code was; 0x800a03ea
. If you get this, you have a compilation (scripting) error in your code. To see what the error is, including the line number, turn on the Error Switch described in the preceding section. You will get a popup box with diagnostic info that should help you identify your coding error.
Set thing = CreateObject("Your.Component")
...
thing.yyy = "test"
...
Call thing.xxx(foo, bar)
That's it in a nutshell. Now have a look at the Windows Script Component documentation in the Microsoft Windows Script 5.6 help file. It's included in the ACP help content.