diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 6c7565f..53f48eb 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2679,10 +2679,10 @@ namespace Meade.net.Telescope.UnitTests } [TestCase(DriveRates.driveSidereal, "60.1")] - [TestCase(DriveRates.driveSolar, "60.0")] + [TestCase(DriveRates.driveSidereal, "60.0")] [TestCase(DriveRates.driveLunar, "57.9")] [TestCase(DriveRates.driveSidereal, "+60.1")] - [TestCase(DriveRates.driveSolar, "+60.0")] + [TestCase(DriveRates.driveSidereal, "+60.0")] [TestCase(DriveRates.driveLunar, "+57.9")] [TestCase(DriveRates.driveLunar, "57.3")] [TestCase(DriveRates.driveLunar, "58.9")] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 967beea..86a2acb 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -3597,10 +3597,10 @@ namespace ASCOM.Meade.net DriveRates result; - if (rateDouble.Equals(60.1)) + if (rateDouble.Between(59.9, 60.1)) result = DriveRates.driveSidereal; - else if (rateDouble.Equals(60.0)) - result = DriveRates.driveSolar; + //else if (rateDouble.Equals(60.0)) + // result = DriveRates.driveSolar; else if (rateDouble.Between(57.3, 58.9)) result = DriveRates.driveLunar; else diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 6eef33d..8ca906c 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -53,7 +53,7 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.ReceiveCounted(1)).Returns(expectedResult); - var result = SharedResources.SendChar(command, raw); + var result = SharedResources.SendChar(_traceLoggerMock.Object, command, raw); _serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.Transmit(expectedCommand), Times.Once); @@ -70,7 +70,7 @@ namespace Meade.net.UnitTests _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(expectedResult); - var result = SharedResources.SendString(transmitMessage, includePrefix); + var result = SharedResources.SendString(_traceLoggerMock.Object, transmitMessage, includePrefix); _serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once); diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index db51f2e..9757ab3 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -99,21 +99,25 @@ namespace ASCOM.Meade.net /// /// /// - public static string SendString(string message, bool raw = false) + public static string SendString(ITraceLogger traceLogger, string message, bool raw = false) { lock (LockObject) { SharedSerial.ClearBuffers(); var encodedMessage = raw ? message : $"#:{message}#"; + traceLogger.LogMessage("SendString", $"Transmitting {encodedMessage}", false); SharedSerial.Transmit(encodedMessage); try { - return SharedSerial.ReceiveTerminated("#").TrimEnd('#'); + var result = SharedSerial.ReceiveTerminated("#").TrimEnd('#'); + traceLogger.LogMessage("SendString", $"Received {result}", false); + return result; } catch (COMException ex) { + traceLogger.LogIssue("SendString", ex.Message); if (ex.Message.Contains("Timed out waiting for received data")) throw new TimeoutException(ex.Message, ex); @@ -122,34 +126,41 @@ namespace ASCOM.Meade.net } } - public static bool SendBool(string command, bool raw = false) + public static bool SendBool(ITraceLogger traceLogger, string command, bool raw = false) { - var result = SendChar(command, raw); + var result = SendChar(traceLogger, command, raw); return result == "1"; } - public static string SendChar(string command, bool raw = false) + public static string SendChar(ITraceLogger traceLogger, string command, bool raw = false) { - return SendChars(command, raw, count: 1); + return SendChars(traceLogger, command, raw, count: 1); } - public static string SendChars(string command, bool raw = false, int count = 1) + public static string SendChars(ITraceLogger traceLogger, string command, bool raw = false, int count = 1) { lock (LockObject) { SharedSerial.ClearBuffers(); var encodedMessage = raw ? command : $"#:{command}#"; + traceLogger.LogMessage("SendChars", $"Transmitting {encodedMessage}", false); SharedSerial.Transmit(encodedMessage); try { - return SharedSerial.ReceiveCounted(count); + var result = SharedSerial.ReceiveCounted(count); + traceLogger.LogMessage("SendChars", $"Received {result}", false); + return result; } - catch (COMException ex) when (ex.Message.Contains("Timed out waiting for received data")) + catch (COMException ex) { - throw new TimeoutException(ex.Message, ex); + traceLogger.LogIssue("SendString", ex.Message); + if (ex.Message.Contains("Timed out waiting for received data")) + throw new TimeoutException(ex.Message, ex); + + throw; } } } @@ -404,7 +415,7 @@ namespace ASCOM.Meade.net //Test if communication is working. try { - string utcOffSet = SendString("GG"); + string utcOffSet = SendString( traceLogger, "GG"); } catch (Exception) { @@ -433,7 +444,7 @@ namespace ASCOM.Meade.net //SendBlind($"SB{newSpeedIndex}"); try { - var speedChanged = SendChar($"SB{newSpeedIndex}"); + var speedChanged = SendChar(traceLogger, $"SB{newSpeedIndex}"); if (speedChanged == "1") { SharedSerial.Connected = false; @@ -458,8 +469,8 @@ namespace ASCOM.Meade.net try { - ProductName = SendString("GVP"); - FirmwareVersion = SendString("GVN"); + ProductName = SendString(traceLogger, "GVP"); + FirmwareVersion = SendString(traceLogger, "GVN"); } catch (Exception ex) { @@ -479,7 +490,7 @@ namespace ASCOM.Meade.net try { - string utcOffSet = SendString("GG"); + string utcOffSet = SendString(traceLogger, "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 diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index d5231a2..4f2d5c1 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -68,7 +68,7 @@ namespace ASCOM.Meade.net.Wrapper public string SendString(ITraceLogger traceLogger, string message, bool raw = false) { - return SharedResources.SendString(message, raw); + return SharedResources.SendString(traceLogger, message, raw); } public void SendBlind(ITraceLogger traceLogger, string message, bool raw = false) @@ -78,17 +78,17 @@ namespace ASCOM.Meade.net.Wrapper public bool SendBool(ITraceLogger traceLogger, string command, bool raw = false) { - return SharedResources.SendBool(command, raw); + return SharedResources.SendBool(traceLogger, command, raw); } public string SendChar(ITraceLogger traceLogger, string message, bool raw = false) { - return SharedResources.SendChar(message, raw); + return SharedResources.SendChar(traceLogger, message, raw); } public string SendChars(ITraceLogger traceLogger, string message, bool raw = false, int count = 1) { - return SharedResources.SendChars(message, raw, count); + return SharedResources.SendChars(traceLogger, message, raw, count); } public string ReadTerminated()