Added extra check to ensure that slewing is return true whilst executing one of the ascom slew commands.
This commit is contained in:
@@ -23,7 +23,7 @@ namespace ASCOM.Meade.net
|
||||
// Your driver's DeviceID is ASCOM.Meade.net.Telescope
|
||||
//
|
||||
// The Guid attribute sets the CLSID for ASCOM.Meade.net.Telescope
|
||||
// The ClassInterface/None addribute prevents an empty interface called
|
||||
// The ClassInterface/None attribute prevents an empty interface called
|
||||
// _Meade.net from being created and used as the [default] interface
|
||||
//
|
||||
// Replace the not implemented exceptions with code to implement the function or
|
||||
@@ -78,6 +78,11 @@ namespace ASCOM.Meade.net
|
||||
/// </summary>
|
||||
private int _digitsDe = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Used to make sure that the slewing property returns true when in the middle of an ascom slew command, anything above 0 means that we are inside slewing commands.
|
||||
/// </summary>
|
||||
private int _forceSlewingCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Meade.net"/> class.
|
||||
/// Must be public for COM registration.
|
||||
@@ -2861,49 +2866,57 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public void SlewToAltAzAsync(double azimuth, double altitude, bool polar)
|
||||
{
|
||||
_forceSlewingCount++;
|
||||
try
|
||||
{
|
||||
CheckConnected("SlewToAltAzAsync");
|
||||
CheckParked();
|
||||
|
||||
if (altitude > 90)
|
||||
throw new InvalidValueException("Altitude cannot be greater than 90.");
|
||||
|
||||
if (altitude < 0)
|
||||
throw new InvalidValueException("Altitude cannot be less than 0.");
|
||||
|
||||
if (azimuth >= 360)
|
||||
throw new InvalidValueException("Azimuth cannot be 360 or higher.");
|
||||
|
||||
if (azimuth < 0)
|
||||
throw new InvalidValueException("Azimuth cannot be less than 0.");
|
||||
|
||||
LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude} polar={polar}");
|
||||
|
||||
if (polar)
|
||||
try
|
||||
{
|
||||
HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude };
|
||||
CheckConnected("SlewToAltAzAsync");
|
||||
CheckParked();
|
||||
|
||||
var utcDateTime = UTCDate;
|
||||
var latitude = SiteLatitude;
|
||||
var longitude = SiteLongitude;
|
||||
var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz);
|
||||
if (altitude > 90)
|
||||
throw new InvalidValueException("Altitude cannot be greater than 90.");
|
||||
|
||||
TargetRightAscension = raDec.RightAscension;
|
||||
TargetDeclination = raDec.Declination;
|
||||
if (altitude < 0)
|
||||
throw new InvalidValueException("Altitude cannot be less than 0.");
|
||||
|
||||
if (azimuth >= 360)
|
||||
throw new InvalidValueException("Azimuth cannot be 360 or higher.");
|
||||
|
||||
if (azimuth < 0)
|
||||
throw new InvalidValueException("Azimuth cannot be less than 0.");
|
||||
|
||||
LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude} polar={polar}");
|
||||
|
||||
if (polar)
|
||||
{
|
||||
HorizonCoordinates altAz = new HorizonCoordinates { Azimuth = azimuth, Altitude = altitude };
|
||||
|
||||
var utcDateTime = UTCDate;
|
||||
var latitude = SiteLatitude;
|
||||
var longitude = SiteLongitude;
|
||||
var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz);
|
||||
|
||||
TargetRightAscension = raDec.RightAscension;
|
||||
TargetDeclination = raDec.Declination;
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetAltitude = altitude;
|
||||
TargetAzimuth = azimuth;
|
||||
}
|
||||
|
||||
DoSlewAsync(polar);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
TargetAltitude = altitude;
|
||||
TargetAzimuth = azimuth;
|
||||
LogMessage("SlewToAltAzAsync", $"Error: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
|
||||
DoSlewAsync(polar);
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
LogMessage("SlewToAltAzAsync", $"Error: {ex.Message}");
|
||||
throw;
|
||||
_forceSlewingCount--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2992,14 +3005,12 @@ namespace ASCOM.Meade.net
|
||||
LogMessage("DoSlewAsync", "Beginning slew sequence");
|
||||
CheckConnected("DoSlewAsync");
|
||||
CheckParked();
|
||||
if (Slewing)
|
||||
if (GetSlewing(true))
|
||||
{
|
||||
LogMessage("DoSlewAsync", "Cannot start a slew whilst slew is in progress.");
|
||||
throw new ASCOM.InvalidOperationException("Cannot start a slew whilst slew is in progress.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (polar)
|
||||
{
|
||||
case true:
|
||||
@@ -3133,22 +3144,30 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public void SlewToCoordinatesAsync(double rightAscension, double declination)
|
||||
{
|
||||
_forceSlewingCount++;
|
||||
try
|
||||
{
|
||||
LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}");
|
||||
CheckConnected("SlewToCoordinatesAsync");
|
||||
CheckParked();
|
||||
try
|
||||
{
|
||||
LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}");
|
||||
CheckConnected("SlewToCoordinatesAsync");
|
||||
CheckParked();
|
||||
|
||||
TargetRightAscension = rightAscension;
|
||||
TargetDeclination = declination;
|
||||
DoSlewAsync(true);
|
||||
TargetRightAscension = rightAscension;
|
||||
TargetDeclination = declination;
|
||||
DoSlewAsync(true);
|
||||
|
||||
LogMessage("SlewToCoordinatesAsync", $"Completed Ra={rightAscension}, Dec={declination}");
|
||||
LogMessage("SlewToCoordinatesAsync", $"Completed Ra={rightAscension}, Dec={declination}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogMessage("SlewToCoordinatesAsync", $"Error: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
LogMessage("SlewToCoordinatesAsync", $"Error: {ex.Message}");
|
||||
throw;
|
||||
_forceSlewingCount--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3177,20 +3196,28 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public void SlewToTargetAsync()
|
||||
{
|
||||
_forceSlewingCount++;
|
||||
try
|
||||
{
|
||||
CheckConnected("SlewToTargetAsync");
|
||||
CheckParked();
|
||||
try
|
||||
{
|
||||
CheckConnected("SlewToTargetAsync");
|
||||
CheckParked();
|
||||
|
||||
if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter))
|
||||
throw new InvalidOperationException("No target selected to slew to.");
|
||||
if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter))
|
||||
throw new InvalidOperationException("No target selected to slew to.");
|
||||
|
||||
DoSlewAsync(true);
|
||||
DoSlewAsync(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogMessage("SlewToTargetAsync", $"Error: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
LogMessage("SlewToTargetAsync", $"Error: {ex.Message}");
|
||||
throw;
|
||||
_forceSlewingCount--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3214,12 +3241,7 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
try
|
||||
{
|
||||
var isSlewing = GetSlewing() || (IsConnected && IsSlewingToTarget());
|
||||
|
||||
if (isSlewing)
|
||||
SetSlewingMinEndTime();
|
||||
else if (_clock.UtcNow < SharedResourcesWrapper.EarliestNonSlewingTime)
|
||||
isSlewing = true;
|
||||
var isSlewing = GetSlewing(false);
|
||||
|
||||
LogMessage("Slewing", $"Result = {isSlewing}");
|
||||
return isSlewing;
|
||||
@@ -3242,19 +3264,24 @@ namespace ASCOM.Meade.net
|
||||
return TimeSpan.FromSeconds( SlewSettleTime + _profileProperties.SettleTime );
|
||||
}
|
||||
|
||||
private bool GetSlewing()
|
||||
private bool GetSlewing(bool isInternalCall)
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
if (Connected)
|
||||
result = MovingAxis() || IsSlewingToTarget();
|
||||
result = (!isInternalCall && _forceSlewingCount > 0) || MovingAxis() || IsSlewingToTarget();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMessage("GetSlewing", $"Result = {result}");
|
||||
}
|
||||
|
||||
if (result)
|
||||
SetSlewingMinEndTime();
|
||||
else if (_clock.UtcNow < SharedResourcesWrapper.EarliestNonSlewingTime)
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3809,18 +3836,18 @@ namespace ASCOM.Meade.net
|
||||
UtcCorrection = GetUtcCorrection()
|
||||
};
|
||||
|
||||
int month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger();
|
||||
int day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger();
|
||||
int year = telescopeDateDetails.TelescopeDate.Substring(6, 2).ToInteger();
|
||||
var month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger();
|
||||
var day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger();
|
||||
var year = telescopeDateDetails.TelescopeDate.Substring(6, 2).ToInteger();
|
||||
|
||||
if (year < 2000) //todo fix this hack that will create a Y2K100 bug
|
||||
{
|
||||
year = year + 2000;
|
||||
year += 2000;
|
||||
}
|
||||
|
||||
int hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger();
|
||||
int minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger();
|
||||
int second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger();
|
||||
var hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger();
|
||||
var minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger();
|
||||
var second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger();
|
||||
|
||||
var utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) +
|
||||
telescopeDateDetails.UtcCorrection;
|
||||
|
||||
Reference in New Issue
Block a user