Example #1
0
 public Transform()
 {
     this.disposedValue = false;
     this.TL            = new TraceLogger("", "Transform");
     this.TL.Enabled    = RegistryCommonCode.GetBool("Trace Transform", false);
     this.TL.LogMessage("New", "Trace logger created OK");
     this.Utl                 = new Util();
     this.Sw                  = new Stopwatch();
     this.SwRecalculate       = new Stopwatch();
     this.AstroUtl            = new ASCOM.Astrometry.AstroUtils.AstroUtils();
     this.SOFA                = new ASCOM.Astrometry.SOFA.SOFA();
     this.RAJ2000Value        = double.NaN;
     this.DECJ2000Value       = double.NaN;
     this.RATopoValue         = double.NaN;
     this.DECTopoValue        = double.NaN;
     this.SiteElevValue       = double.NaN;
     this.SiteLatValue        = double.NaN;
     this.SiteLongValue       = double.NaN;
     this.RefracValue         = false;
     this.LastSetBy           = ASCOM.Astrometry.Transform.Transform.SetBy.Never;
     this.RequiresRecalculate = true;
     this.JulianDateTTValue   = 0.0;
     this.CheckGAC();
     this.TL.LogMessage("New", "NOVAS initialised OK");
 }
Example #2
0
        public SOFA()
        {
            disposedValue = false;
            StringBuilder lpszPath = new StringBuilder(260);

            TL         = new TraceLogger("", "SOFA");
            TL.Enabled = RegistryCommonCode.GetBool("Trace NOVAS", false);
            Utl        = new Util();
            string lpFileName;

            if (Is64Bit())
            {
                ASCOM.Astrometry.SOFA.SOFA.SHGetSpecialFolderPath(IntPtr.Zero, lpszPath, 44, false);
                lpFileName = lpszPath.ToString() + "\\ASCOM\\Astrometry\\SOFA11-64.dll";
            }
            else
            {
                lpFileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + "\\ASCOM\\Astrometry\\SOFA11.dll";
            }
            TL.LogMessage("New", "Loading SOFA library DLL: " + lpFileName);
            SofaDllHandle = ASCOM.Astrometry.SOFA.SOFA.LoadLibrary(lpFileName);
            int lastWin32Error = Marshal.GetLastWin32Error();

            if (SofaDllHandle != IntPtr.Zero)
            {
                TL.LogMessage("New", "Loaded SOFA library OK");
                TL.LogMessage("New", "SOFA Initialised OK");
            }
            else
            {
                TL.LogMessage("New", "Error loading SOFA library: " + lastWin32Error.ToString("X8"));
                throw new HelperException("Error code returned from LoadLibrary when loading SOFA library: " + lastWin32Error.ToString("X8"));
            }
        }
Example #3
0
 /// <summary>
 /// Creates an instance of the camera class.
 /// </summary>
 /// <param name="cameraId">The ProgID for the camera</param>
 public Camera(string cameraId)
 {
     TL                      = new TraceLogger("", "DriverAccessCamera");
     TL.Enabled              = RegistryCommonCode.GetBool(GlobalConstants.DRIVERACCESS_TRACE, GlobalConstants.DRIVERACCESS_TRACE_DEFAULT);
     _memberFactory          = new MemberFactory(cameraId, TL);
     _driverInterfaceVersion = InterfaceVersion;
 }
        public AscomDriver(string deviceProgId) : this()
        {
            this.TL         = new TraceLogger("", "DriverAccess");
            this.TL.Enabled = false;
            this.TL.Enabled = RegistryCommonCode.GetBool("Trace DriverAccess", false);
            this.TL.LogMessage("AscomDriver", "Successfully created TraceLogger");
            this.deviceType = this.GetType().Name.ToUpper();
            this.TL.LogMessage("AscomDriver", "Device type: " + this.GetType().Name);

            this.TL.LogMessage("AscomDriver", "Device ProgID: " + deviceProgId);
            MemberFactory = new MemberFactory(deviceProgId, TL);
        }
Example #5
0
        /// <summary>
        /// Creates a new instance of the <see cref="AscomDriver"/> class.
        /// </summary>
        /// <param name="deviceProgId">The prog id. of the device being created.</param>
        public AscomDriver(string deviceProgId)
        {
            // Create a new TraceLogger and enable if appropriate
            TL         = new TraceLogger("", "DriverAccess");
            TL.Enabled = RegistryCommonCode.GetBool(GlobalConstants.DRIVERACCESS_TRACE, GlobalConstants.DRIVERACCESS_TRACE_DEFAULT);
            TL.LogMessage("AscomDriver", "Successfully created TraceLogger");
            TL.LogMessage("AscomDriver", "Device ProgID: " + deviceProgId);

            //deviceType = deviceProgId.Substring(deviceProgId.LastIndexOf(".") + 1).ToUpper();
            deviceType = this.GetType().Name.ToUpperInvariant();
            TL.LogMessage("AscomDriver", "Device type: " + this.GetType().Name);

            memberFactory = new MemberFactory(deviceProgId, TL); // Create a MemberFactory object and pass in the TraceLogger
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Focuser"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public Focuser()
        {
            try
            {
                TL         = new TraceLogger("", "FocusSimulator");
                TL.Enabled = RegistryCommonCode.GetBool(GlobalConstants.SIMULATOR_TRACE, GlobalConstants.SIMULATOR_TRACE_DEFAULT);
                TL.LogMessage("New", "Started");

                //check to see if the profile is ok
                if (ValidateProfile())
                {
                    TL.LogMessage("New", "Validated OK");
                    KeepMoving      = false;
                    LastOffset      = 0;
                    RateOfChange    = 1;
                    MouseDownTime   = DateTime.MaxValue; //Initialise to "don't accelerate" value
                    RandomGenerator = new Random();      //Temperature fluctuation random generator
                    LoadFocuserKeyValues();
                    TL.LogMessage("New", "Loaded Key Values");
                    //Handbox = new FocuserHandboxForm(this);
                    //Handbox.Hide();
                    //TL.LogMessage("FocusSettingsForm", "Created Handbox");

                    // start a timer that monitors and moves the focuser
                    _moveTimer          = new System.Timers.Timer();
                    _moveTimer.Elapsed += new System.Timers.ElapsedEventHandler(MoveTimer_Tick);
                    _moveTimer.Interval = 100;
                    _moveTimer.Enabled  = true;
                    _lastTemp           = Temperature;
                    Target = _position;

                    TL.LogMessage("New", "Started Simulation");
                }
                else
                {
                    TL.LogMessage("New", "Registering Profile");
                    RegisterWithProfile();
                    TL.LogMessage("New", "Registered OK");
                }

                TL.LogMessage("New", "Completed");
            }
            catch (Exception ex)
            {
                TL.LogMessageCrLf("New Exception", ex.ToString());
                Console.WriteLine($"Focuser: {ex}");
            }
        }
Example #7
0
        /// <summary>
        /// Crates a new instance of the NativeHelpers component
        /// </summary>
        /// <exception cref="HelperException">Thrown if the NativeHelpers support library DLL cannot be loaded</exception>
        public NativeHelpers()
        {
            int lastError;

            TL         = new TraceLogger("NativeHelpers");
            TL.Enabled = RegistryCommonCode.GetBool(GlobalConstants.TRACE_UTIL, GlobalConstants.TRACE_UTIL_DEFAULT);
            try
            {
                string VideoDllFile = null;
                System.Text.StringBuilder ReturnedPath = new System.Text.StringBuilder(260);

                //Find the root location of the common files directory containing the ASCOM support files.
                if (Is64Bit()) // 64bit application so find the 32bit folder location, usually Program Files (x86)\Common Files
                {
                    VideoDllFile = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86) + VIDEOUTILS_DLL_LOCATION + VIDEOUTILS64_DLL_NAME;
                }
                else //32bit application so just go with the .NET returned value usually, Program Files\Common Files
                {
                    VideoDllFile = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + VIDEOUTILS_DLL_LOCATION + VIDEOUTILS32_DLL_NAME;
                }

                TL.LogMessage("New", "Loading NativeHelpers library DLL: " + VideoDllFile);

                VideoDllHandle = LoadLibrary(VideoDllFile);
                lastError      = Marshal.GetLastWin32Error();

                if (VideoDllHandle != IntPtr.Zero) // Loaded successfully
                {
                    TL.LogMessage("New", "Loaded NativeHelpers library OK");
                }
                else // Did not load
                {
                    TL.LogMessage("New", "Error loading NativeHelpers library: " + lastError.ToString("X8"));
                    throw new HelperException("Error code returned from LoadLibrary when loading NativeHelpers library: " + lastError.ToString("X8"));
                }
                TL.LogMessage("NativeHelpers", "Created");
            }
            catch (Exception ex)
            {
                TL.LogMessageCrLf("NativeHelpers ctor", ex.ToString());
            }
        }
Example #8
0
 /// <summary>
 ///   Creates a Switch object with the given Prog ID
 /// </summary>
 /// <param name = "switchId"></param>
 public Switch(string switchId)
 {
     TL             = new TraceLogger("", "DriverAccessSwitch");
     TL.Enabled     = RegistryCommonCode.GetBool(GlobalConstants.DRIVERACCESS_TRACE, GlobalConstants.DRIVERACCESS_TRACE_DEFAULT);
     _memberFactory = new MemberFactory(switchId, TL);
 }
Example #9
0
        static void Main(string[] args)
        {
            string errMsg;

            // Add unhandled exception handlers
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);                        // Add the event handler for handling UI thread exceptions to the event.
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);                                       // Set the unhandled exception mode to force all exceptions to go through our handler.
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); // Add the event handler for handling non-UI thread exceptions to the event.

            TL         = new TraceLogger("", "AlpacaDynamicClientManager");
            TL.Enabled = RegistryCommonCode.GetBool(GlobalConstants.TRACE_UTIL, GlobalConstants.TRACE_UTIL_DEFAULT);

            try
            {
                string commandParameter = ""; // Initialise the supplied parameter to empty string

                TL.LogMessage("Main", $"Number of parameters: {args.Count()}");
                foreach (string arg in args)
                {
                    TL.LogMessage("Main", $"Received parameter: \"{arg}\"");
                }

                if (args.Length > 0)
                {
                    commandParameter = args[0];                  // Copy any supplied command parameter to the parameter variable
                }
                TL.LogMessage("Main", string.Format(@"Supplied parameter: ""{0}""", commandParameter));
                commandParameter = commandParameter.TrimStart(' ', '-', '/', '\\'); // Remove any parameter prefixes and leading spaces
                commandParameter = commandParameter.TrimEnd(' ');                   // Remove any trailing spaces

                TL.LogMessage("Main", string.Format(@"Trimmed parameter: ""{0}""", commandParameter));

                switch (commandParameter.ToUpperInvariant()) // Act on the supplied parameter, if any
                {
                case "":
                case "MANAGEDEVICES":

                    // Run the application in user interactive mode
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    TL.LogMessage("Main", "Starting device management form");
                    Application.Run(new ManageDevicesForm(TL));

                    break;

                case "CREATEALPACACLIENT":

                    // Validate supplied parameters before passing to the execution method
                    if (args.Length < 5)
                    {
                        // Validate the number of parameters - must be 5: Command DeviceType COMDeviceNumber ProgID DeviceName
                        errMsg = $"The CreateAlpacaClient command requires 4 parameters: DeviceType COMDeviceNumber ProgID DeviceName e.g. /CreateAlpacaClient Telescope 1 ASCOM.AlpacaDynamic1.Telescope \"Device Chooser description\"";
                        TL.LogMessageCrLf("CreateAlpacaClient", errMsg);
                        MessageBox.Show(errMsg, "ASCOM Dynamic Client Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // Validate that the supplied device type is one that is supported for Alpaca
                    if (!supportedDeviceTypes.Contains(args[1], StringComparer.OrdinalIgnoreCase))
                    {
                        errMsg = $"The supplied ASCOM device type '{args[1]}' is not supported: The command format is \"/CreateAlpacaClient ASCOMDeviceType AlpacaDeviceUniqueID\" e.g. /CreateAlpacaClient Telescope 84DC2495-CBCE-4A9C-A703-E342C0E1F651";
                        TL.LogMessageCrLf("CreateAlpacaClient", errMsg);
                        MessageBox.Show(errMsg, "ASCOM Dynamic Client Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // Validate that the supplied device number is an integer
                    int  comDevicenumber;
                    bool comDevicenunberIsInteger = int.TryParse(args[2], out comDevicenumber);
                    if (!comDevicenunberIsInteger)
                    {
                        errMsg = $"The supplied COM device number is not an integer: {args[2]}";
                        TL.LogMessageCrLf("CreateAlpacaClient", errMsg);
                        MessageBox.Show(errMsg, "ASCOM Dynamic Client Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    string localServerPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86) + SharedConstants.ALPACA_CLIENT_LOCAL_SERVER_PATH;
                    TL.LogMessage("CreateAlpacaClient", $"Alpaca local server folder: {localServerPath}");

                    // The supplied parameters pass validation so run the create device form to obtain the device description and create the driver
                    CreateAlpacaClient(args[1], comDevicenumber, args[3], args[4], localServerPath);     // Call the execution method with correctly cased device type and unique ID parameters
                    string localServerExe = $"{localServerPath}\\{SharedConstants.ALPACA_CLIENT_LOCAL_SERVER}";
                    TL.LogMessage("CreateAlpacaClient", $"Alpaca local server exe name: {localServerExe}");
                    RunLocalServer(localServerExe, "-regserver", TL);

                    break;

                case "CREATENAMEDCLIENT":

                    // Validate supplied parameters before passing to the execution method
                    if (args.Length < 4)
                    {
                        // Validate the number of parameters - must be 4: Command DeviceType COMDeviceNumber ProgID
                        errMsg = $"The CreateAlpacaClient command requires 3 parameters: DeviceType COMDeviceNumber ProgID e.g. /CreateAlpacaClient Telescope 1 ASCOM.AlpacaDynamic1.Telescope";
                        TL.LogMessageCrLf("CreateAlpacaClient", errMsg);
                        MessageBox.Show(errMsg, "ASCOM Dynamic Client Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // Validate that the supplied device type is one that is supported for Alpaca
                    if (!supportedDeviceTypes.Contains(args[1], StringComparer.OrdinalIgnoreCase))
                    {
                        errMsg = $"The supplied ASCOM device type '{args[1]}' is not supported: The command format is \"/CreateAlpacaClient ASCOMDeviceType AlpacaDeviceUniqueID\" e.g. /CreateAlpacaClient Telescope 84DC2495-CBCE-4A9C-A703-E342C0E1F651";
                        TL.LogMessageCrLf("CreateAlpacaClient", errMsg);
                        MessageBox.Show(errMsg, "ASCOM Dynamic Client Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // Validate that the supplied device number is an integer
                    comDevicenunberIsInteger = int.TryParse(args[2], out comDevicenumber);
                    if (!comDevicenunberIsInteger)
                    {
                        errMsg = $"The supplied COM device number is not an integer: {args[2]}";
                        TL.LogMessageCrLf("CreateAlpacaClient", errMsg);
                        MessageBox.Show(errMsg, "ASCOM Dynamic Client Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    localServerPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86) + SharedConstants.ALPACA_CLIENT_LOCAL_SERVER_PATH;
                    TL.LogMessage("CreateAlpacaClient", $"Alpaca local server folder: {localServerPath}");

                    // The supplied parameters pass validation so run the create device form to obtain the device description and create the driver
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    TL.LogMessage("Main", "Starting device creation form");
                    Application.Run(new CreateDeviceForm(args[1], comDevicenumber, args[3], localServerPath, TL));

                    break;

                default:     // Unrecognised parameter so flag this to the user
                    errMsg = $"Unrecognised command: '{commandParameter}', the valid command are:\r\n" +
                             $"/CreateAlpacaClient DeviceType COMDeviceNumber ProgID DeviceName\r\n" +
                             $"CreateNamedClient DeviceType COMDeviceNumber ProgID\r\n" +
                             $"/ManageDevices";
                    TL.LogMessage("Main", errMsg);
                    MessageBox.Show(errMsg, "ASCOM Dynamic Clients", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            catch (Exception ex)
            {
                errMsg = ("DynamicRemoteClients exception: " + ex.ToString());
                TL.LogMessageCrLf("Main", errMsg);
                MessageBox.Show(errMsg, "ASCOM Dynamic Clients", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            TL.Enabled = false;
            TL.Dispose();
            TL = null;
        }
Example #10
0
 /// <summary>
 /// Creates a FilterWheel object with the given Prog ID
 /// </summary>
 /// <param name="filterWheelId"></param>
 public FilterWheel(string filterWheelId)
 {
     TL             = new TraceLogger("", "DriverAccessFilterWheel");
     TL.Enabled     = RegistryCommonCode.GetBool(GlobalConstants.DRIVERACCESS_TRACE, GlobalConstants.DRIVERACCESS_TRACE_DEFAULT);
     _memberFactory = new MemberFactory(filterWheelId, TL);
 }