Added messages to include information about what is being sent via the serial port.

This commit is contained in:
2022-07-25 16:07:55 +01:00
parent 6428e6d31b
commit 7287990240
5 changed files with 37 additions and 26 deletions
@@ -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")]
+3 -3
View File
@@ -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
@@ -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);
+26 -15
View File
@@ -99,21 +99,25 @@ namespace ASCOM.Meade.net
/// <param name="message"></param>
/// <param name="raw"></param>
/// <returns></returns>
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
+4 -4
View File
@@ -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()