Added explicit locks around all sequences of commands.
This commit is contained in:
@@ -562,14 +562,22 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_serialPort.Command(":RG#"); //Make sure we are at guide rate
|
SerialPort.Lock();
|
||||||
_serialPort.Command($":M{d}#");
|
try
|
||||||
Thread.Sleep(duration);
|
{
|
||||||
_serialPort.Command($":Q{d}#");
|
_serialPort.Command(":RG#"); //Make sure we are at guide rate
|
||||||
|
_serialPort.Command($":M{d}#");
|
||||||
|
Thread.Sleep(duration);
|
||||||
|
_serialPort.Command($":Q{d}#");
|
||||||
|
|
||||||
//classic only !!!, this is needed since once in a while one is not enough
|
//classic only !!!, this is needed since once in a while one is not enough
|
||||||
Thread.Sleep(200);
|
Thread.Sleep(200);
|
||||||
_serialPort.Command($":Q{d}#");
|
_serialPort.Command($":Q{d}#");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SerialPort.Unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,10 +602,18 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
|
|
||||||
public void SlewToCoordinatesAsync(double rightAscension, double declination)
|
public void SlewToCoordinatesAsync(double rightAscension, double declination)
|
||||||
{
|
{
|
||||||
TargetRightAscension = rightAscension;
|
SerialPort.Lock();
|
||||||
TargetDeclination = declination;
|
try
|
||||||
|
{
|
||||||
|
TargetRightAscension = rightAscension;
|
||||||
|
TargetDeclination = declination;
|
||||||
|
|
||||||
DoSlewAsync(true);
|
DoSlewAsync(true);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SerialPort.Unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SlewToAltAz(double azimuth, double altitude)
|
public void SlewToAltAz(double azimuth, double altitude)
|
||||||
@@ -663,10 +679,18 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
|
|
||||||
public void SlewToAltAzAsync(double azimuth, double altitude)
|
public void SlewToAltAzAsync(double azimuth, double altitude)
|
||||||
{
|
{
|
||||||
TargetAltitude = altitude;
|
SerialPort.Lock();
|
||||||
TargetAzimuth = azimuth;
|
try
|
||||||
|
{
|
||||||
|
TargetAltitude = altitude;
|
||||||
|
TargetAzimuth = azimuth;
|
||||||
|
|
||||||
DoSlewAsync(false);
|
DoSlewAsync(false);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SerialPort.Unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SyncToTarget()
|
public void SyncToTarget()
|
||||||
@@ -708,95 +732,104 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
private bool _movingSecondary;
|
private bool _movingSecondary;
|
||||||
public void MoveAxis(TelescopeAxes axis, double rate)
|
public void MoveAxis(TelescopeAxes axis, double rate)
|
||||||
{
|
{
|
||||||
var absrate = Math.Abs(rate);
|
SerialPort.Lock();
|
||||||
|
try
|
||||||
switch(absrate)
|
|
||||||
{
|
{
|
||||||
case 0:
|
var absrate = Math.Abs(rate);
|
||||||
//do nothing, it's ok this time as we're halting the slew.
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
SerialPort.Command(":RG#");
|
|
||||||
//:RG# Set Slew rate to Guiding Rate (slowest)
|
|
||||||
//Returns: Nothing
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
SerialPort.Command(":RC#");
|
|
||||||
//:RC# Set Slew rate to Centering rate (2nd slowest)
|
|
||||||
//Returns: Nothing
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
SerialPort.Command(":RM#");
|
|
||||||
//:RM# Set Slew rate to Find Rate (2nd Fastest)
|
|
||||||
//Returns: Nothing
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
SerialPort.Command(":RS#");
|
|
||||||
//:RS# Set Slew rate to max (fastest)
|
|
||||||
//Returns: Nothing
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ASCOM.InvalidValueException($"Rate {rate} not supported");
|
|
||||||
|
|
||||||
|
switch (absrate)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
//do nothing, it's ok this time as we're halting the slew.
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
SerialPort.Command(":RG#");
|
||||||
|
//:RG# Set Slew rate to Guiding Rate (slowest)
|
||||||
|
//Returns: Nothing
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
SerialPort.Command(":RC#");
|
||||||
|
//:RC# Set Slew rate to Centering rate (2nd slowest)
|
||||||
|
//Returns: Nothing
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
SerialPort.Command(":RM#");
|
||||||
|
//:RM# Set Slew rate to Find Rate (2nd Fastest)
|
||||||
|
//Returns: Nothing
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
SerialPort.Command(":RS#");
|
||||||
|
//:RS# Set Slew rate to max (fastest)
|
||||||
|
//Returns: Nothing
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ASCOM.InvalidValueException($"Rate {rate} not supported");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (axis)
|
||||||
|
{
|
||||||
|
case TelescopeAxes.axisPrimary:
|
||||||
|
if (rate == 0)
|
||||||
|
{
|
||||||
|
_movingPrimary = false;
|
||||||
|
SerialPort.Command(":Qe#");
|
||||||
|
//:Qe# Halt eastward Slews
|
||||||
|
//Returns: Nothing
|
||||||
|
SerialPort.Command(":Qw#");
|
||||||
|
//:Qw# Halt westward Slews
|
||||||
|
//Returns: Nothing
|
||||||
|
}
|
||||||
|
else if (rate > 0)
|
||||||
|
{
|
||||||
|
SerialPort.Command(":Me#");
|
||||||
|
//:Me# Move Telescope East at current slew rate
|
||||||
|
//Returns: Nothing
|
||||||
|
_movingPrimary = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SerialPort.Command(":Mw#");
|
||||||
|
//:Mw# Move Telescope West at current slew rate
|
||||||
|
//Returns: Nothing
|
||||||
|
_movingPrimary = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case TelescopeAxes.axisSecondary:
|
||||||
|
if (rate == 0)
|
||||||
|
{
|
||||||
|
_movingSecondary = false;
|
||||||
|
SerialPort.Command(":Qn#");
|
||||||
|
//:Qn# Halt northward Slews
|
||||||
|
//Returns: Nothing
|
||||||
|
SerialPort.Command(":Qs#");
|
||||||
|
//:Qs# Halt southward Slews
|
||||||
|
//Returns: Nothing
|
||||||
|
}
|
||||||
|
else if (rate > 0)
|
||||||
|
{
|
||||||
|
SerialPort.Command(":Mn#");
|
||||||
|
//:Mn# Move Telescope North at current slew rate
|
||||||
|
//Returns: Nothing
|
||||||
|
_movingSecondary = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SerialPort.Command(":Ms#");
|
||||||
|
//:Ms# Move Telescope South at current slew rate
|
||||||
|
//Returns: Nothing
|
||||||
|
_movingSecondary = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ASCOM.MethodNotImplementedException("Can not move this axis.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
switch (axis)
|
|
||||||
{
|
{
|
||||||
case TelescopeAxes.axisPrimary:
|
SerialPort.Unlock();
|
||||||
if (rate == 0)
|
|
||||||
{
|
|
||||||
_movingPrimary = false;
|
|
||||||
SerialPort.Command(":Qe#");
|
|
||||||
//:Qe# Halt eastward Slews
|
|
||||||
//Returns: Nothing
|
|
||||||
SerialPort.Command(":Qw#");
|
|
||||||
//:Qw# Halt westward Slews
|
|
||||||
//Returns: Nothing
|
|
||||||
}
|
|
||||||
else if (rate > 0)
|
|
||||||
{
|
|
||||||
SerialPort.Command(":Me#");
|
|
||||||
//:Me# Move Telescope East at current slew rate
|
|
||||||
//Returns: Nothing
|
|
||||||
_movingPrimary = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SerialPort.Command(":Mw#");
|
|
||||||
//:Mw# Move Telescope West at current slew rate
|
|
||||||
//Returns: Nothing
|
|
||||||
_movingPrimary = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TelescopeAxes.axisSecondary:
|
|
||||||
if (rate == 0)
|
|
||||||
{
|
|
||||||
_movingSecondary = false;
|
|
||||||
SerialPort.Command(":Qn#");
|
|
||||||
//:Qn# Halt northward Slews
|
|
||||||
//Returns: Nothing
|
|
||||||
SerialPort.Command(":Qs#");
|
|
||||||
//:Qs# Halt southward Slews
|
|
||||||
//Returns: Nothing
|
|
||||||
}
|
|
||||||
else if (rate > 0)
|
|
||||||
{
|
|
||||||
SerialPort.Command(":Mn#");
|
|
||||||
//:Mn# Move Telescope North at current slew rate
|
|
||||||
//Returns: Nothing
|
|
||||||
_movingSecondary = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SerialPort.Command(":Ms#");
|
|
||||||
//:Ms# Move Telescope South at current slew rate
|
|
||||||
//Returns: Nothing
|
|
||||||
_movingSecondary = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ASCOM.MethodNotImplementedException("Can not move this axis.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,47 +843,57 @@ namespace ASCOM.MeadeAutostar497.Controller
|
|||||||
//todo remove the polar parameter and split method into two.
|
//todo remove the polar parameter and split method into two.
|
||||||
private void DoSlewAsync( bool polar)
|
private void DoSlewAsync( bool polar)
|
||||||
{
|
{
|
||||||
switch (polar)
|
SerialPort.Lock();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
case true:
|
switch (polar)
|
||||||
var response = SerialPort.CommandChar(":MS#");
|
{
|
||||||
//:MS# Slew to Target Object
|
case true:
|
||||||
//Returns:
|
var response = SerialPort.CommandChar(":MS#");
|
||||||
//0 Slew is Possible
|
//:MS# Slew to Target Object
|
||||||
//1<string># Object Below Horizon w/string message
|
//Returns:
|
||||||
//2<string># Object Below Higher w/string message
|
//0 Slew is Possible
|
||||||
|
//1<string># Object Below Horizon w/string message
|
||||||
|
//2<string># Object Below Higher w/string message
|
||||||
|
|
||||||
switch (response)
|
switch (response)
|
||||||
{
|
{
|
||||||
case '0':
|
case '0':
|
||||||
//We're slewing everything should be working just fine.
|
//We're slewing everything should be working just fine.
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
//Below Horizon
|
//Below Horizon
|
||||||
string belowHorizonMessage = SerialPort.ReadTerminated("#");
|
string belowHorizonMessage = SerialPort.ReadTerminated("#");
|
||||||
throw new ASCOM.InvalidOperationException(belowHorizonMessage);
|
throw new ASCOM.InvalidOperationException(belowHorizonMessage);
|
||||||
case '2':
|
case '2':
|
||||||
//Below Horizon
|
//Below Horizon
|
||||||
string belowMinimumElevationMessage = SerialPort.ReadTerminated("#");
|
string belowMinimumElevationMessage = SerialPort.ReadTerminated("#");
|
||||||
throw new ASCOM.InvalidOperationException(belowMinimumElevationMessage);
|
throw new ASCOM.InvalidOperationException(belowMinimumElevationMessage);
|
||||||
default:
|
default:
|
||||||
throw new ASCOM.DriverException("This error should not happen");
|
throw new ASCOM.DriverException("This error should not happen");
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case false:
|
|
||||||
var maResponse = SerialPort.CommandChar(":MA#");
|
|
||||||
//:MA# Autostar, LX 16”, Autostar II – Slew to target Alt and Az
|
|
||||||
//Returns:
|
|
||||||
//0 - No fault
|
|
||||||
//1 – Fault
|
|
||||||
// LX200 – Not supported
|
|
||||||
|
|
||||||
if (maResponse == '1')
|
break;
|
||||||
{
|
case false:
|
||||||
throw new ASCOM.InvalidOperationException("fault");
|
var maResponse = SerialPort.CommandChar(":MA#");
|
||||||
}
|
//:MA# Autostar, LX 16”, Autostar II – Slew to target Alt and Az
|
||||||
break;
|
//Returns:
|
||||||
|
//0 - No fault
|
||||||
|
//1 – Fault
|
||||||
|
// LX200 – Not supported
|
||||||
|
|
||||||
|
if (maResponse == '1')
|
||||||
|
{
|
||||||
|
throw new ASCOM.InvalidOperationException("fault");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SerialPort.Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user