|
|||||||
You have just created a local server (singleton) host for one or more ASCOM driver classes.This project implements an ASCOM host server for one or more driver classes in a single-instance executable. It can be used to serve multiple instances of a single driver class (hub) or for providing driver services for multiple devices (e.g., Telescope and Focuser) to multiple applications. In the latter scenario, the multiple driver classes will often share one or more resources such as the serial connection and a microcontroller in the combined device. From the client's perspective, using the drivers served by the local server is exactly the same as if the drivers are loaded into the client's process space (in-proc servers). NOTE: Unless you are prepared to handle all of the timing issues that arise when multiple clients are accessing the properties and methods of your driver(s), stop now. Just because the local server serializes the calls to your driver(s)' properties and methods does not mean that there will be no timing or concurrency issues. Local server drivers are tricky to get right. There is no such thing as "ignorance is bliss" here.
This gets even more tricky if you decide to turn your local server into a "control panel" with the main form showing all the time and itself providing controls for your device. The UI messaging loop and thread, plus timed actions to refresh your displays, plus the events generated by user actions, plus the incoming calls from clients of your drivers all can add up to a nightmare unless you have the skills and patience to get it right. You're probably anxious to get going, but you really should read through the Theory of Operation and Detailed Use and Deployment below. You must do the following in order to complete your local server:
Notes
Theory of OperationThe local server is an executable which can provide multiple instances of multiple drivers to multiple clients. This capability is needed for two applications:
By simply dropping suitably developed driver assemblies into a known folder, the local server will register them for COM and ASCOM and serve any number of instances of the drivers' interfaces to any number of client programs. It does this by locating and loading the driver assemblies, analyzing them to detect their classes and interfaces, and implementing a class factory that can create instances of them for clients. A driver is an assembly which contains a class that implements one of the ASCOM standard driver interfaces and inherits the ReferenceCountedObjectBase class of the local server. Apart from that, driver assemblies are identical to those that are used in-process (DLL-type). The instructions above detail the steps needed to convert an in-process driver into one that can be served by the local server. The name of the local server is important, so we provide it as a template from which you can create a local server for your produce. To make this clear, let's assume that your company AlphaTech produces a telescope system which contains a microcontroller that is able to control not only the telescope mount, but also a focuser and a camera rotator. The mount, focuser, and rotator are all controlled via commands sent through a common serial line connecting the computer to the microcontroller, so you need a local server. In ASCOM, then, you probably want your system to appear as AlphaTech.Telescope, AlphaTech.Focuser, and AlphaTech.Rotator. Then you would name the local server AlphaTech. Be sure to give this due consideration before creating the template, the project name is the name of your local server. The fact that driver classes inherit from the local server's ReferenceCountedObjectBase class allows the local server to maintain a reference count on the driver class. If a client creates an instance of a served driver, the local server automatically starts up and provides an instance of the class to the client. Once started the local server can provide additional instances of any of its served driver classes. If the reference count of all served classes drops to zero as a result of clients releasing their instances, the local server will automatically exit. Registration services provided include not only the basic COM class registration, but also DCOM/AppID info needed to use the served classes from outbound connections from Software Bisque's TheSky. It also registers the served classes for the ASCOM Chooser. The "friendly" name of each served driver that appears in the chooser comes from the driver classes' assembly information ProductName. The COM ProgID for each served driver is ASCOM.localservername.drivertype, for example, ASCOM.AlphaTech.Telescope, where AlphaTech is the local server name and Telescope is the type of the driver. Unregistering removes all of this information from the operating system. Detailed Use and DeploymentOnce you have built your local server and the served driver class assemblies, here's how to use it. To register the served classes, activate the local server from a shell command line with the option /register (or /regserver, for VB6 compatibility): C:\xxx> ASCOM.$safeprojectname$.exe /register To unregister the local server and its drivers, activate the local server from a shell command line with the option /unregister (or /unregserver for VB6 compatibility): C:\xxx> ASCOM.$safeprojectname$.exe /unregister When the operating system starts the local server in response to a client creating one of it's served driver classes, the command option /embedding is included. The local server's code detects this and sets a variable that you can use. NOTE: On Vista and Windows 7, registering and unregistering require elevated privileges. When the local server is run as above, an Elevation Dialog will appear, requiring the user to either approve the operation, or if the user is not an administrator, to supply administrator credentials. When deploying a hub or set of drivers with the local server, you'll have to arrange for the driver assemblies to be placed in a subfolder under the local server called $safeprojectname$ServedClasses. That's all you need to do, though, the local server will find them. |
|