From 92ab807eaed84f4d3adb559537488346e4812ee0 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 3 Sep 2020 20:35:37 +0100 Subject: [PATCH] Code inspections --- Meade.net.Telescope/Telescope.cs | 198 +++++++++--------- .../SharedResourcesUnitTests.cs | 5 +- Meade.net.focuser/Focuser.cs | 64 +++--- Meade.net/MeadeTelescopeBase.cs | 20 +- 4 files changed, 145 insertions(+), 142 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 6feade6..d3e4bc3 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -132,7 +132,7 @@ namespace ASCOM.Meade.net public void SetupDialog() { LogMessage("SetupDialog", "Opening setup dialog"); - _sharedResourcesWrapper.SetupDialog(); + SharedResourcesWrapper.SetupDialog(); ReadProfile(); LogMessage("SetupDialog", "complete"); //// consider only showing the setup dialog if not connected @@ -171,68 +171,68 @@ namespace ASCOM.Meade.net { //Read the screen case "readdisplay": - var output = _sharedResourcesWrapper.SendString(":ED#"); + var output = SharedResourcesWrapper.SendString(":ED#"); return output; //top row of buttons case "enter": - _sharedResourcesWrapper.SendBlind(":EK13#"); + SharedResourcesWrapper.SendBlind(":EK13#"); break; case "mode": - _sharedResourcesWrapper.SendBlind(":EK9#"); + SharedResourcesWrapper.SendBlind(":EK9#"); break; case "longmode": - _sharedResourcesWrapper.SendBlind(":EK11#"); + SharedResourcesWrapper.SendBlind(":EK11#"); break; case "goto": - _sharedResourcesWrapper.SendBlind(":EK24#"); + SharedResourcesWrapper.SendBlind(":EK24#"); break; case "0": //light and 0 - _sharedResourcesWrapper.SendBlind(":EK48#"); + SharedResourcesWrapper.SendBlind(":EK48#"); break; case "1": - _sharedResourcesWrapper.SendBlind(":EK49#"); + SharedResourcesWrapper.SendBlind(":EK49#"); break; case "2": - _sharedResourcesWrapper.SendBlind(":EK50#"); + SharedResourcesWrapper.SendBlind(":EK50#"); break; case "3": - _sharedResourcesWrapper.SendBlind(":EK51#"); + SharedResourcesWrapper.SendBlind(":EK51#"); break; case "4": - _sharedResourcesWrapper.SendBlind(":EK52#"); + SharedResourcesWrapper.SendBlind(":EK52#"); break; case "5": - _sharedResourcesWrapper.SendBlind(":EK53#"); + SharedResourcesWrapper.SendBlind(":EK53#"); break; case "6": - _sharedResourcesWrapper.SendBlind(":EK54#"); + SharedResourcesWrapper.SendBlind(":EK54#"); break; case "7": - _sharedResourcesWrapper.SendBlind(":EK55#"); + SharedResourcesWrapper.SendBlind(":EK55#"); break; case "8": - _sharedResourcesWrapper.SendBlind(":EK56#"); + SharedResourcesWrapper.SendBlind(":EK56#"); break; case "9": - _sharedResourcesWrapper.SendBlind(":EK57#"); + SharedResourcesWrapper.SendBlind(":EK57#"); break; case "up": - _sharedResourcesWrapper.SendBlind(":EK94#"); + SharedResourcesWrapper.SendBlind(":EK94#"); break; case "down": - _sharedResourcesWrapper.SendBlind(":EK118#"); + SharedResourcesWrapper.SendBlind(":EK118#"); break; case "back": - _sharedResourcesWrapper.SendBlind(":EK87#"); + SharedResourcesWrapper.SendBlind(":EK87#"); break; case "forward": - _sharedResourcesWrapper.SendBlind(":EK69#"); + SharedResourcesWrapper.SendBlind(":EK69#"); break; case "?": - _sharedResourcesWrapper.SendBlind(":EK63#"); + SharedResourcesWrapper.SendBlind(":EK63#"); break; default: LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); @@ -317,7 +317,7 @@ namespace ASCOM.Meade.net CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); - _sharedResourcesWrapper.SendBlind(command); + SharedResourcesWrapper.SendBlind(command); // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other @@ -339,7 +339,7 @@ namespace ASCOM.Meade.net // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - return _sharedResourcesWrapper.SendString(command); + return SharedResourcesWrapper.SendString(command); //throw new ASCOM.MethodNotImplementedException("CommandString"); } @@ -349,9 +349,9 @@ namespace ASCOM.Meade.net Connected = false; // Clean up the tracelogger and util objects - _tl.Enabled = false; - _tl.Dispose(); - _tl = null; + Tl.Enabled = false; + Tl.Dispose(); + Tl = null; } public bool Connected @@ -374,10 +374,10 @@ namespace ASCOM.Meade.net ReadProfile(); LogMessage("Connected Set", "Connecting to port {0}", ComPort); - var connectionInfo = _sharedResourcesWrapper.Connect("Serial", DriverId, _tl); + var connectionInfo = SharedResourcesWrapper.Connect("Serial", DriverId, Tl); try { - LogMessage("Connected Set", $"Connected to port {ComPort}. Product: {_sharedResourcesWrapper.ProductName} Version:{_sharedResourcesWrapper.FirmwareVersion}"); + LogMessage("Connected Set", $"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); _userNewerPulseGuiding = IsNewPulseGuidingSupported(); _targetDeclination = InvalidParameter; @@ -411,7 +411,7 @@ namespace ASCOM.Meade.net } catch (Exception) { - _sharedResourcesWrapper.Disconnect("Serial", DriverId); + SharedResourcesWrapper.Disconnect("Serial", DriverId); throw; } } @@ -423,7 +423,7 @@ namespace ASCOM.Meade.net else { LogMessage("Connected Set", "Disconnecting from port {0}", ComPort); - _sharedResourcesWrapper.Disconnect("Serial", DriverId); + SharedResourcesWrapper.Disconnect("Serial", DriverId); IsConnected = false; } } @@ -457,12 +457,12 @@ namespace ASCOM.Meade.net return true; default: - if (_sharedResourcesWrapper.ProductName == TelescopeList.Autostar497) + if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) { return FirmwareIsGreaterThan(TelescopeList.Autostar497_31Ee); } - if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { return true; } @@ -473,7 +473,7 @@ namespace ASCOM.Meade.net private bool IsLongFormatSupported() { - if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC) + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC) { return false; } @@ -482,7 +482,7 @@ namespace ASCOM.Meade.net private bool IsGuideRateSettingSupported() { - if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { return true; } @@ -491,7 +491,7 @@ namespace ASCOM.Meade.net private bool FirmwareIsGreaterThan(string minVersion) { - var currentVersion = _sharedResourcesWrapper.FirmwareVersion; + var currentVersion = SharedResourcesWrapper.FirmwareVersion; var comparison = String.Compare(currentVersion, minVersion, StringComparison.Ordinal); return comparison >= 0; } @@ -508,9 +508,9 @@ namespace ASCOM.Meade.net return; } - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { - var result = _sharedResourcesWrapper.SendString(":GZ#"); + var result = SharedResourcesWrapper.SendString(":GZ#"); //:GZ# Get telescope azimuth //Returns: DDD*MM# or DDD*MM’SS# //The current telescope Azimuth depending on the selected precision. @@ -520,7 +520,7 @@ namespace ASCOM.Meade.net if (IsLongFormat != setLongFormat) { _utilities.WaitForMilliseconds(500); - _sharedResourcesWrapper.SendBlind(":U#"); + SharedResourcesWrapper.SendBlind(":U#"); //:U# Toggle between low/hi precision positions //Low - RA displays and messages HH:MM.T sDD*MM //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS @@ -534,7 +534,7 @@ namespace ASCOM.Meade.net private bool TogglePrecision() { LogMessage("TogglePrecision", "Toggling slewing precision"); - var result = _sharedResourcesWrapper.SendChar(":P#"); + var result = SharedResourcesWrapper.SendChar(":P#"); //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. //Returns: //“HIGH PRECISION” Current setting after this command. @@ -552,10 +552,10 @@ namespace ASCOM.Meade.net break; } - _sharedResourcesWrapper.ReadCharacters(throwAwayCharacters); + SharedResourcesWrapper.ReadCharacters(throwAwayCharacters); //Make sure that the buffers are cleared out. - _sharedResourcesWrapper.SendBlind("#"); + SharedResourcesWrapper.SendBlind("#"); return highPrecision; } @@ -574,7 +574,7 @@ namespace ASCOM.Meade.net { CheckConnectedAndValidateSite(site, "SelectSite"); - _sharedResourcesWrapper.SendBlind($":W{site}#"); + SharedResourcesWrapper.SendBlind($":W{site}#"); //:W# //Set current site to, an ASCII digit in the range 1..4 //Returns: Nothing @@ -635,7 +635,7 @@ namespace ASCOM.Meade.net throw new ArgumentOutOfRangeException(nameof(site), site, Resources.Telescope_GetSiteName_Site_out_of_range); } - var result = _sharedResourcesWrapper.SendChar(command); + var result = SharedResourcesWrapper.SendChar(command); if (result != "1") { throw new InvalidOperationException("Failed to set site name."); @@ -649,22 +649,22 @@ namespace ASCOM.Meade.net switch (site) { case 1: - return _sharedResourcesWrapper.SendString(":GM#"); + return SharedResourcesWrapper.SendString(":GM#"); //:GM# Get Site 1 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. case 2: - return _sharedResourcesWrapper.SendString(":GN#"); + return SharedResourcesWrapper.SendString(":GN#"); //:GN# Get Site 2 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. case 3: - return _sharedResourcesWrapper.SendString(":GO#"); + return SharedResourcesWrapper.SendString(":GO#"); //:GO# Get Site 3 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. case 4: - return _sharedResourcesWrapper.SendString(":GP#"); + return SharedResourcesWrapper.SendString(":GP#"); //:GP# Get Site 4 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. @@ -713,7 +713,7 @@ namespace ASCOM.Meade.net CheckConnected("AbortSlew"); LogMessage("AbortSlew", "Aborting slew"); - _sharedResourcesWrapper.SendBlind(":Q#"); + SharedResourcesWrapper.SendBlind(":Q#"); //:Q# Halt all current slewing //Returns:Nothing @@ -731,7 +731,7 @@ namespace ASCOM.Meade.net const char ack = (char) 6; - var alignmentString = _sharedResourcesWrapper.SendChar(ack.ToString()); + var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString()); //ACK <0x06> Query of alignment mounting mode. //Returns: //A If scope in AltAz Mode @@ -782,13 +782,13 @@ namespace ASCOM.Meade.net switch (value) { case AlignmentModes.algAltAz: - _sharedResourcesWrapper.SendBlind(":AA#"); + SharedResourcesWrapper.SendBlind(":AA#"); //:AA# Sets telescope the AltAz alignment mode //Returns: nothing break; case AlignmentModes.algPolar: case AlignmentModes.algGermanPolar: - _sharedResourcesWrapper.SendBlind(":AP#"); + SharedResourcesWrapper.SendBlind(":AP#"); //:AP# Sets telescope to Polar alignment mode //Returns: nothing break; @@ -828,7 +828,7 @@ namespace ASCOM.Meade.net private HorizonCoordinates CalcAltAzFromTelescopeEqData() { - var altitudeData = _sharedResourcesWrapper.Lock(() => new AltitudeData + var altitudeData = SharedResourcesWrapper.Lock(() => new AltitudeData { UtcDateTime = UTCDate, SiteLongitude = SiteLongitude, @@ -1084,7 +1084,7 @@ namespace ASCOM.Meade.net { CheckConnected("Declination Get"); - var result = _sharedResourcesWrapper.SendString(":GD#"); + var result = SharedResourcesWrapper.SendString(":GD#"); //:GD# Get Telescope Declination. //Returns: sDD*MM# or sDD*MM’SS# //Depending upon the current precision setting for the telescope. @@ -1172,7 +1172,7 @@ namespace ASCOM.Meade.net } LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)"); - _sharedResourcesWrapper.SendBlind($":Rg{value:00.0}#"); + SharedResourcesWrapper.SendBlind($":Rg{value:00.0}#"); //:RgSS.S# //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed @@ -1253,22 +1253,22 @@ namespace ASCOM.Meade.net //do nothing, it's ok this time as we're halting the slew. break; case 1: - _sharedResourcesWrapper.SendBlind(":RG#"); + SharedResourcesWrapper.SendBlind(":RG#"); //:RG# Set Slew rate to Guiding Rate (slowest) //Returns: Nothing break; case 2: - _sharedResourcesWrapper.SendBlind(":RC#"); + SharedResourcesWrapper.SendBlind(":RC#"); //:RC# Set Slew rate to Centering rate (2nd slowest) //Returns: Nothing break; case 3: - _sharedResourcesWrapper.SendBlind(":RM#"); + SharedResourcesWrapper.SendBlind(":RM#"); //:RM# Set Slew rate to Find Rate (2nd Fastest) //Returns: Nothing break; case 4: - _sharedResourcesWrapper.SendBlind(":RS#"); + SharedResourcesWrapper.SendBlind(":RS#"); //:RS# Set Slew rate to max (fastest) //Returns: Nothing break; @@ -1283,22 +1283,22 @@ namespace ASCOM.Meade.net { case ComparisonResult.Equals: _movingPrimary = false; - _sharedResourcesWrapper.SendBlind(":Qe#"); + SharedResourcesWrapper.SendBlind(":Qe#"); //:Qe# Halt eastward Slews //Returns: Nothing - _sharedResourcesWrapper.SendBlind(":Qw#"); + SharedResourcesWrapper.SendBlind(":Qw#"); //:Qw# Halt westward Slews //Returns: Nothing break; case ComparisonResult.Greater: - _sharedResourcesWrapper.SendBlind(":Me#"); + SharedResourcesWrapper.SendBlind(":Me#"); //:Me# Move Telescope East at current slew rate //Returns: Nothing _movingPrimary = true; break; case ComparisonResult.Lower: - _sharedResourcesWrapper.SendBlind(":Mw#"); + SharedResourcesWrapper.SendBlind(":Mw#"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing _movingPrimary = true; @@ -1310,21 +1310,21 @@ namespace ASCOM.Meade.net { case ComparisonResult.Equals: _movingSecondary = false; - _sharedResourcesWrapper.SendBlind(":Qn#"); + SharedResourcesWrapper.SendBlind(":Qn#"); //:Qn# Halt northward Slews //Returns: Nothing - _sharedResourcesWrapper.SendBlind(":Qs#"); + SharedResourcesWrapper.SendBlind(":Qs#"); //:Qs# Halt southward Slews //Returns: Nothing break; case ComparisonResult.Greater: - _sharedResourcesWrapper.SendBlind(":Mn#"); + SharedResourcesWrapper.SendBlind(":Mn#"); //:Mn# Move Telescope North at current slew rate //Returns: Nothing _movingSecondary = true; break; case ComparisonResult.Lower: - _sharedResourcesWrapper.SendBlind(":Ms#"); + SharedResourcesWrapper.SendBlind(":Ms#"); //:Ms# Move Telescope South at current slew rate //Returns: Nothing _movingSecondary = true; @@ -1346,7 +1346,7 @@ namespace ASCOM.Meade.net if (AtPark) return; - _sharedResourcesWrapper.SendBlind(":hP#"); + SharedResourcesWrapper.SendBlind(":hP#"); //:hP# Autostar, Autostar II and LX 16”Slew to Park Position //Returns: Nothing AtPark = true; @@ -1396,7 +1396,7 @@ namespace ASCOM.Meade.net } LogMessage("PulseGuide", "Using new pulse guiding technique"); - _sharedResourcesWrapper.SendBlind($":Mg{d}{duration:0000}#"); + SharedResourcesWrapper.SendBlind($":Mg{d}{duration:0000}#"); //:MgnDDDD# //:MgsDDDD# //:MgeDDDD# @@ -1461,7 +1461,7 @@ namespace ASCOM.Meade.net get { CheckConnected("RightAscension Get"); - var result = _sharedResourcesWrapper.SendString(":GR#"); + var result = SharedResourcesWrapper.SendString(":GR#"); //:GR# Get Telescope RA //Returns: HH:MM.T# or HH:MM:SS# //Depending which precision is set for the telescope @@ -1557,7 +1557,7 @@ namespace ASCOM.Meade.net { CheckConnected("SiteLatitude Get"); - var latitude = _sharedResourcesWrapper.SendString(":Gt#"); + var latitude = SharedResourcesWrapper.SendString(":Gt#"); //:Gt# Get Current Site Latitude //Returns: sDD* MM# //The latitude of the current site. Positive inplies North latitude. @@ -1585,7 +1585,7 @@ namespace ASCOM.Meade.net int m = Convert.ToInt32(60 * (absValue - d)); var commandString = $":St{sign}{d:00}*{m:00}#"; - var result = _sharedResourcesWrapper.SendChar(commandString); + var result = SharedResourcesWrapper.SendChar(commandString); //:StsDD*MM# //Sets the current site latitude to sDD* MM# //Returns: @@ -1602,7 +1602,7 @@ namespace ASCOM.Meade.net { CheckConnected("SiteLongitude Get"); - var longitude = _sharedResourcesWrapper.SendString(":Gg#"); + var longitude = SharedResourcesWrapper.SendString(":Gg#"); //:Gg# Get Current Site Longitude //Returns: sDDD*MM# //The current site Longitude. East Longitudes are expressed as negative @@ -1640,7 +1640,7 @@ namespace ASCOM.Meade.net var commandstring = $":Sg{d:000}*{m:00}#"; - var result = _sharedResourcesWrapper.SendChar(commandstring); + var result = SharedResourcesWrapper.SendChar(commandstring); //:SgDDD*MM# //Set current site’s longitude to DDD*MM an ASCII position string //Returns: @@ -1703,7 +1703,7 @@ namespace ASCOM.Meade.net var latitude = SiteLatitude; var longitude = SiteLongitude; - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); @@ -1723,12 +1723,12 @@ namespace ASCOM.Meade.net { CheckConnected("DoSlewAsync"); - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { switch (polar) { case true: - var response = _sharedResourcesWrapper.SendChar(":MS#"); + var response = SharedResourcesWrapper.SendChar(":MS#"); //:MS# Slew to Target Object //Returns: //0 Slew is Possible @@ -1743,17 +1743,17 @@ namespace ASCOM.Meade.net break; case "1": //Below Horizon - string belowHorizonMessage = _sharedResourcesWrapper.ReadTerminated(); + string belowHorizonMessage = SharedResourcesWrapper.ReadTerminated(); LogMessage("DoSlewAsync", $"Slew failed \"{belowHorizonMessage}\""); throw new InvalidOperationException(belowHorizonMessage); case "2": //Below minimum elevation - string belowMinimumElevationMessage = _sharedResourcesWrapper.ReadTerminated(); + string belowMinimumElevationMessage = SharedResourcesWrapper.ReadTerminated(); LogMessage("DoSlewAsync", $"Slew failed \"{belowMinimumElevationMessage}\""); throw new InvalidOperationException(belowMinimumElevationMessage); case "3": //Telescope can hit the mount - string canHitMountMessage = _sharedResourcesWrapper.ReadTerminated(); + string canHitMountMessage = SharedResourcesWrapper.ReadTerminated(); LogMessage("DoSlewAsync", $"Slew failed \"{canHitMountMessage}\""); throw new InvalidOperationException(canHitMountMessage); default: @@ -1764,7 +1764,7 @@ namespace ASCOM.Meade.net break; case false: - var maResponse = _sharedResourcesWrapper.SendChar(":MA#"); + var maResponse = SharedResourcesWrapper.SendChar(":MA#"); //:MA# Autostar, LX 16”, Autostar II – Slew to target Alt and Az //Returns: //0 - No fault @@ -1801,7 +1801,7 @@ namespace ASCOM.Meade.net LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}"); CheckConnected("SlewToCoordinatesAsync"); - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { TargetRightAscension = rightAscension; TargetDeclination = declination; @@ -1864,7 +1864,7 @@ namespace ASCOM.Meade.net if (_isGuiding) return false; - var result = _sharedResourcesWrapper.SendString(":D#"); + var result = SharedResourcesWrapper.SendString(":D#"); //:D# Requests a string of bars indicating the distance to the current target location. //Returns: //LX200's – a string of bar characters indicating the distance. @@ -1892,7 +1892,7 @@ namespace ASCOM.Meade.net LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); CheckConnected("SyncToCoordinates"); - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { TargetRightAscension = rightAscension; TargetDeclination = declination; @@ -1906,7 +1906,7 @@ namespace ASCOM.Meade.net LogMessage("SyncToTarget", "Executing"); CheckConnected("SyncToTarget"); - var result = _sharedResourcesWrapper.SendString(":CM#"); + var result = SharedResourcesWrapper.SendString(":CM#"); //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //Returns: //LX200's - a "#" terminated string with the name of the object that was synced. @@ -1955,7 +1955,7 @@ namespace ASCOM.Meade.net var command = $":Sd{s}{dms}#"; LogMessage("TargetDeclination Set", $"{command}"); - var result = _sharedResourcesWrapper.SendChar(command); + var result = SharedResourcesWrapper.SendChar(command); //:SdsDD*MM# //Set target object declination to sDD*MM or sDD*MM:SS depending on the current precision setting //Returns: @@ -2003,7 +2003,7 @@ namespace ASCOM.Meade.net //todo implement the low precision version var hms = _utilities.HoursToHMS(value, ":", ":", ":", 2); - var response = _sharedResourcesWrapper.SendChar($":Sr{hms}#"); + var response = SharedResourcesWrapper.SendChar($":Sr{hms}#"); //:SrHH:MM.T# //:SrHH:MM:SS# //Set target object RA to HH:MM.T or HH: MM: SS depending on the current precision setting. @@ -2062,12 +2062,12 @@ namespace ASCOM.Meade.net switch (value) { case DriveRates.driveSidereal: - _sharedResourcesWrapper.SendBlind(":TQ#"); + SharedResourcesWrapper.SendBlind(":TQ#"); //:TQ# Selects sidereal tracking rate //Returns: Nothing break; case DriveRates.driveLunar: - _sharedResourcesWrapper.SendBlind(":TL#"); + SharedResourcesWrapper.SendBlind(":TL#"); //:TL# Set Lunar Tracking Rage //Returns: Nothing break; @@ -2104,7 +2104,7 @@ namespace ASCOM.Meade.net private TimeSpan GetUtcCorrection() { - string utcOffSet = _sharedResourcesWrapper.SendString(":GG#"); + string utcOffSet = SharedResourcesWrapper.SendString(":GG#"); //:GG# Get UTC offset time //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the @@ -2129,15 +2129,15 @@ namespace ASCOM.Meade.net LogMessage("UTCDate", "Get started"); - var telescopeDateDetails = _sharedResourcesWrapper.Lock(() => + var telescopeDateDetails = SharedResourcesWrapper.Lock(() => { var tdd = new TelescopeDateDetails { - TelescopeDate = _sharedResourcesWrapper.SendString(":GC#"), + TelescopeDate = SharedResourcesWrapper.SendString(":GC#"), //:GC# Get current date. //Returns: MM/DD/YY# //The current local calendar date for the telescope. - TelescopeTime = _sharedResourcesWrapper.SendString(":GL#"), + TelescopeTime = SharedResourcesWrapper.SendString(":GL#"), //:GL# Get Local Time in 24 hour format //Returns: HH:MM:SS# //The Local Time in 24 - hour Format @@ -2173,13 +2173,13 @@ namespace ASCOM.Meade.net CheckConnected("UTCDate Set"); - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { var utcCorrection = GetUtcCorrection(); var localDateTime = value - utcCorrection; string localStingCommand = $":SL{localDateTime:HH:mm:ss}#"; - var timeResult = _sharedResourcesWrapper.SendChar(localStingCommand); + var timeResult = SharedResourcesWrapper.SendChar(localStingCommand); //:SLHH:MM:SS# //Set the local Time //Returns: @@ -2191,7 +2191,7 @@ namespace ASCOM.Meade.net } string localDateCommand = $":SC{localDateTime:MM/dd/yy}#"; - var dateResult = _sharedResourcesWrapper.SendChar(localDateCommand); + var dateResult = SharedResourcesWrapper.SendChar(localDateCommand); //:SCMM/DD/YY# //Change Handbox Date to MM/DD/YY //Returns: @@ -2204,8 +2204,8 @@ namespace ASCOM.Meade.net } //throwing away these two strings which represent - _sharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data# - _sharedResourcesWrapper.ReadTerminated(); // # + SharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data# + SharedResourcesWrapper.ReadTerminated(); // # }); } } @@ -2320,12 +2320,12 @@ namespace ASCOM.Meade.net { var profileProperties = new ProfileProperties { - TraceLogger = _tl.Enabled, + TraceLogger = Tl.Enabled, ComPort = ComPort, GuideRateArcSecondsPerSecond = GuideRate }; - _sharedResourcesWrapper.WriteProfile(profileProperties); + SharedResourcesWrapper.WriteProfile(profileProperties); } #endregion } diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 7a803b8..1b95ab2 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -375,7 +375,10 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.Transmit("#:GG#")).Callback(() => { serialPortReturn = ""; }); _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn); - var result = Assert.Throws(() => { var connectionResult = SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); }); + var result = Assert.Throws(() => + { + SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object); + }); Assert.That(result.Message, Is.EqualTo("Input string was not in a correct format.")); _traceLoggerMock.Verify( x => x.LogIssue("Connect", "Unable to decode response from the telescope, This is likely a hardware serial communications error."), Times.Once); diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index b797dcd..5b68fba 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -78,17 +78,17 @@ namespace ASCOM.Meade.net /// public void SetupDialog() { - _tl.LogMessage("SetupDialog", "Opening setup dialog"); - _sharedResourcesWrapper.SetupDialog(); + Tl.LogMessage("SetupDialog", "Opening setup dialog"); + SharedResourcesWrapper.SetupDialog(); ReadProfile(); - _tl.LogMessage("SetupDialog", "complete"); + Tl.LogMessage("SetupDialog", "complete"); } public ArrayList SupportedActions { get { - _tl.LogMessage("SupportedActions Get", "Returning empty arraylist"); + Tl.LogMessage("SupportedActions Get", "Returning empty arraylist"); return new ArrayList(); } } @@ -104,7 +104,7 @@ namespace ASCOM.Meade.net CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); - _sharedResourcesWrapper.SendBlind(command); + SharedResourcesWrapper.SendBlind(command); // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other @@ -126,16 +126,16 @@ namespace ASCOM.Meade.net // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - return _sharedResourcesWrapper.SendString(command); + return SharedResourcesWrapper.SendString(command); //throw new ASCOM.MethodNotImplementedException("CommandString"); } public void Dispose() { // Clean up the tracelogger and util objects - _tl.Enabled = false; - _tl.Dispose(); - _tl = null; + Tl.Enabled = false; + Tl.Dispose(); + Tl = null; } public bool Connected @@ -147,7 +147,7 @@ namespace ASCOM.Meade.net } set { - _tl.LogMessage("Connected", "Set {0}", value); + Tl.LogMessage("Connected", "Set {0}", value); if (value == IsConnected) return; @@ -156,14 +156,14 @@ namespace ASCOM.Meade.net try { ReadProfile(); - _sharedResourcesWrapper.Connect("Serial", DriverId, _tl); + SharedResourcesWrapper.Connect("Serial", DriverId, Tl); try { IsConnected = true; } catch (Exception) { - _sharedResourcesWrapper.Disconnect("Serial", DriverId); + SharedResourcesWrapper.Disconnect("Serial", DriverId); throw; } } @@ -175,7 +175,7 @@ namespace ASCOM.Meade.net else { LogMessage("Connected Set", "Disconnecting from port {0}", ComPort); - _sharedResourcesWrapper.Disconnect("Serial", DriverId); + SharedResourcesWrapper.Disconnect("Serial", DriverId); IsConnected = false; } } @@ -197,7 +197,7 @@ namespace ASCOM.Meade.net { //string name = "Short driver name - please customise"; string name = DriverDescription; - _tl.LogMessage("Name Get", name); + Tl.LogMessage("Name Get", name); return name; } } @@ -212,20 +212,20 @@ namespace ASCOM.Meade.net { CheckConnected("Absolute Get"); - _tl.LogMessage("Absolute Get", false.ToString()); + Tl.LogMessage("Absolute Get", false.ToString()); return false; // This is a relative focuser } } public void Halt() { - _tl.LogMessage("Halt", "Halting"); + Tl.LogMessage("Halt", "Halting"); CheckConnected("Halt"); //todo fix this issue: A single halt command is sometimes missed by the #909 apm, so let's do it a few times to be safe. - _sharedResourcesWrapper.SendBlind(":FQ#"); + SharedResourcesWrapper.SendBlind(":FQ#"); //:FQ# Halt Focuser Motion //Returns: Nothing } @@ -234,7 +234,7 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("IsMoving Get", false.ToString()); + Tl.LogMessage("IsMoving Get", false.ToString()); return false; // This focuser always moves instantaneously so no need for IsMoving ever to be True } } @@ -243,12 +243,12 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("Link Get", Connected.ToString()); + Tl.LogMessage("Link Get", Connected.ToString()); return Connected; // Direct function to the connected method, the Link method is just here for backwards compatibility } set { - _tl.LogMessage("Link Set", value.ToString()); + Tl.LogMessage("Link Set", value.ToString()); Connected = value; // Direct function to the connected method, the Link method is just here for backwards compatibility } } @@ -258,7 +258,7 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("MaxIncrement Get", _maxIncrement.ToString()); + Tl.LogMessage("MaxIncrement Get", _maxIncrement.ToString()); return _maxIncrement; // Maximum change in one move } } @@ -268,14 +268,14 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("MaxStep Get", _maxStep.ToString()); + Tl.LogMessage("MaxStep Get", _maxStep.ToString()); return _maxStep; } } public void Move(int position) { - _tl.LogMessage("Move", position.ToString()); + Tl.LogMessage("Move", position.ToString()); CheckConnected("Move"); if (position < -MaxIncrement || position > MaxIncrement) @@ -290,7 +290,7 @@ namespace ASCOM.Meade.net if (ReverseFocusDirection) direction = !direction; - _sharedResourcesWrapper.Lock(() => + SharedResourcesWrapper.Lock(() => { //backlash compensation. var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0; @@ -305,7 +305,7 @@ namespace ASCOM.Meade.net //ApplyBacklashCompensation(direction); if (direction & backlashCompensationSteps != 0) { - _tl.LogMessage("Move", "Applying backlash compensation"); + Tl.LogMessage("Move", "Applying backlash compensation"); MoveFocuser(!direction, backlashCompensationSteps); } @@ -320,7 +320,7 @@ namespace ASCOM.Meade.net if (!UseDynamicBreaking) return; - _tl.LogMessage("Move", "Applying dynamic breaking"); + Tl.LogMessage("Move", "Applying dynamic breaking"); PerformFocuserMove(directionOut); Halt(); @@ -349,7 +349,7 @@ namespace ASCOM.Meade.net private void PerformFocuserMove(bool directionOut) { - _sharedResourcesWrapper.SendBlind(directionOut ? ":F+#" : ":F-#"); + SharedResourcesWrapper.SendBlind(directionOut ? ":F+#" : ":F-#"); //:F+# Start Focuser moving inward (toward objective) //Returns: None @@ -363,7 +363,7 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("StepSize Get", "Not implemented"); + Tl.LogMessage("StepSize Get", "Not implemented"); throw new PropertyNotImplementedException("StepSize", false); } } @@ -372,13 +372,13 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("TempComp Get", false.ToString()); + Tl.LogMessage("TempComp Get", false.ToString()); return false; } // ReSharper disable once ValueParameterNotUsed set { - _tl.LogMessage("TempComp Set", "Not implemented"); + Tl.LogMessage("TempComp Set", "Not implemented"); throw new PropertyNotImplementedException("TempComp", false); } } @@ -387,7 +387,7 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("TempCompAvailable Get", false.ToString()); + Tl.LogMessage("TempCompAvailable Get", false.ToString()); return false; // Temperature compensation is not available in this driver } } @@ -396,7 +396,7 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("Temperature Get", "Not implemented"); + Tl.LogMessage("Temperature Get", "Not implemented"); throw new PropertyNotImplementedException("Temperature", false); } } diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index f34ac52..c9a9e4e 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -12,7 +12,7 @@ namespace ASCOM.Meade.net /// /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// - protected static TraceLogger _tl; + protected static TraceLogger Tl; /// /// Driver description that displays in the ASCOM Chooser. @@ -27,23 +27,23 @@ namespace ASCOM.Meade.net protected string Precision; protected string GuidingStyle; - protected readonly ISharedResourcesWrapper _sharedResourcesWrapper; + protected readonly ISharedResourcesWrapper SharedResourcesWrapper; public MeadeTelescopeBase() { - _sharedResourcesWrapper = new SharedResourcesWrapper(); + SharedResourcesWrapper = new SharedResourcesWrapper(); } public MeadeTelescopeBase(ISharedResourcesWrapper sharedResourcesWrapper) { - _sharedResourcesWrapper = sharedResourcesWrapper; + SharedResourcesWrapper = sharedResourcesWrapper; } protected void Initialise() { var typeName = GetType().Name; - _tl = new TraceLogger("", $"Meade.Generic.{typeName}"); + Tl = new TraceLogger("", $"Meade.Generic.{typeName}"); ReadProfile(); // Read device configuration from the ASCOM Profile store @@ -58,8 +58,8 @@ namespace ASCOM.Meade.net /// protected void ReadProfile() { - var profileProperties = _sharedResourcesWrapper.ReadProfile(); - _tl.Enabled = profileProperties.TraceLogger; + var profileProperties = SharedResourcesWrapper.ReadProfile(); + Tl.Enabled = profileProperties.TraceLogger; ComPort = profileProperties.ComPort; BacklashCompensation = profileProperties.BacklashCompensation; ReverseFocusDirection = profileProperties.ReverseFocusDirection; @@ -68,7 +68,7 @@ namespace ASCOM.Meade.net Precision = profileProperties.Precision; GuidingStyle = profileProperties.GuidingStyle.ToLower(); - LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}"); + LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); LogMessage("ReadProfile", $"Backlash Steps: {BacklashCompensation}"); LogMessage("ReadProfile", $"Dynamic breaking: {UseDynamicBreaking}"); @@ -86,7 +86,7 @@ namespace ASCOM.Meade.net public static void LogMessage(string identifier, string message, params object[] args) { var msg = String.Format(message, args); - _tl.LogMessage(identifier, msg); + Tl.LogMessage(identifier, msg); } /// @@ -98,7 +98,7 @@ namespace ASCOM.Meade.net { get { - _tl.LogMessage("Description Get", DriverDescription); + Tl.LogMessage("Description Get", DriverDescription); return DriverDescription; } }