Added explicit locks around all sequences of commands.

This commit is contained in:
2019-05-09 18:00:17 +01:00
parent 9ec9610a3b
commit 0c1d7d7f09
@@ -561,6 +561,9 @@ namespace ASCOM.MeadeAutostar497.Controller
Thread.Sleep(duration); //todo figure out if this is really needed
}
else
{
SerialPort.Lock();
try
{
_serialPort.Command(":RG#"); //Make sure we are at guide rate
_serialPort.Command($":M{d}#");
@@ -571,6 +574,11 @@ namespace ASCOM.MeadeAutostar497.Controller
Thread.Sleep(200);
_serialPort.Command($":Q{d}#");
}
finally
{
SerialPort.Unlock();
}
}
}
public void Park()
@@ -593,12 +601,20 @@ namespace ASCOM.MeadeAutostar497.Controller
}
public void SlewToCoordinatesAsync(double rightAscension, double declination)
{
SerialPort.Lock();
try
{
TargetRightAscension = rightAscension;
TargetDeclination = declination;
DoSlewAsync(true);
}
finally
{
SerialPort.Unlock();
}
}
public void SlewToAltAz(double azimuth, double altitude)
{
@@ -662,12 +678,20 @@ namespace ASCOM.MeadeAutostar497.Controller
}
public void SlewToAltAzAsync(double azimuth, double altitude)
{
SerialPort.Lock();
try
{
TargetAltitude = altitude;
TargetAzimuth = azimuth;
DoSlewAsync(false);
}
finally
{
SerialPort.Unlock();
}
}
public void SyncToTarget()
{
@@ -707,10 +731,13 @@ namespace ASCOM.MeadeAutostar497.Controller
private bool _movingPrimary;
private bool _movingSecondary;
public void MoveAxis(TelescopeAxes axis, double rate)
{
SerialPort.Lock();
try
{
var absrate = Math.Abs(rate);
switch(absrate)
switch (absrate)
{
case 0:
//do nothing, it's ok this time as we're halting the slew.
@@ -767,6 +794,7 @@ namespace ASCOM.MeadeAutostar497.Controller
//Returns: Nothing
_movingPrimary = true;
}
break;
case TelescopeAxes.axisSecondary:
if (rate == 0)
@@ -799,6 +827,11 @@ namespace ASCOM.MeadeAutostar497.Controller
throw new ASCOM.MethodNotImplementedException("Can not move this axis.");
}
}
finally
{
SerialPort.Unlock();
}
}
public void FocuserHalt()
{
@@ -809,6 +842,9 @@ namespace ASCOM.MeadeAutostar497.Controller
//todo remove the polar parameter and split method into two.
private void DoSlewAsync( bool polar)
{
SerialPort.Lock();
try
{
switch (polar)
{
@@ -837,6 +873,7 @@ namespace ASCOM.MeadeAutostar497.Controller
throw new ASCOM.DriverException("This error should not happen");
}
break;
case false:
var maResponse = SerialPort.CommandChar(":MA#");
@@ -850,9 +887,15 @@ namespace ASCOM.MeadeAutostar497.Controller
{
throw new ASCOM.InvalidOperationException("fault");
}
break;
}
}
finally
{
SerialPort.Unlock();
}
}
public bool UserNewerPulseGuiding { get; set; } = true; //todo make this a device setting
}