Upgraded the error handling to ensure that all serial commands are executed after checking that there is a connection open.

This commit is contained in:
2019-05-20 17:06:53 +01:00
parent 7cb50de30d
commit 678b5f1ece
3 changed files with 121 additions and 46 deletions
+86 -15
View File
@@ -86,7 +86,7 @@ namespace ASCOM.Meade.net
/// <summary> /// <summary>
/// Private variable to hold the connected state /// Private variable to hold the connected state
/// </summary> /// </summary>
private bool connectedState; private bool _connectedState;
/// <summary> /// <summary>
/// Private variable to hold an ASCOM Utilities object /// Private variable to hold an ASCOM Utilities object
@@ -98,7 +98,7 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
private AstroUtils astroUtilities; private AstroUtils astroUtilities;
private AstroMaths astroMaths; private readonly AstroMaths _astroMaths;
/// <summary> /// <summary>
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
@@ -111,17 +111,17 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
public Telescope() public Telescope()
{ {
tl = new TraceLogger("", "Meade.net"); tl = new TraceLogger("", "Meade.net.Telescope");
ReadProfile(); // Read device configuration from the ASCOM Profile store ReadProfile(); // Read device configuration from the ASCOM Profile store
tl.LogMessage("Telescope", "Starting initialisation"); tl.LogMessage("Telescope", "Starting initialisation");
connectedState = false; // Initialise connected to false _connectedState = false; // Initialise connected to false
utilities = new Util(); //Initialise util object utilities = new Util(); //Initialise util object
astroUtilities = new AstroUtils(); // Initialise astro utilities object astroUtilities = new AstroUtils(); // Initialise astro utilities object
//TODO: Implement your additional construction here //TODO: Implement your additional construction here
astroMaths = new AstroMaths(); _astroMaths = new AstroMaths();
tl.LogMessage("Telescope", "Completed initialisation"); tl.LogMessage("Telescope", "Completed initialisation");
} }
@@ -141,8 +141,10 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
public void SetupDialog() public void SetupDialog()
{ {
tl.LogMessage("SetupDialog", "Opening setup dialog");
SharedResources.SetupDialog(); SharedResources.SetupDialog();
ReadProfile(); ReadProfile();
tl.LogMessage("SetupDialog", "complete");
//// consider only showing the setup dialog if not connected //// consider only showing the setup dialog if not connected
//// or call a different dialog if connected //// or call a different dialog if connected
//if (IsConnected) //if (IsConnected)
@@ -233,17 +235,32 @@ namespace ASCOM.Meade.net
if (value) if (value)
{ {
LogMessage("Connected Set", "Connecting to port {0}", comPort); LogMessage("Connected Set", "Connecting to port {0}", comPort);
SharedResources.Connect("Serial"); try
connectedState = true; {
SharedResources.Connect("Serial");
try
{
SelectSite(1);
SetLongFormat(true);
SelectSite(1); _connectedState = true;
SetLongFormat(true); }
catch (Exception)
{
SharedResources.Disconnect("Serial");
throw;
}
}
catch (Exception ex)
{
LogMessage("Connected Set", "Error connecting to port {0} - {1}", comPort, ex.Message);
}
} }
else else
{ {
LogMessage("Connected Set", "Disconnecting from port {0}", comPort); LogMessage("Connected Set", "Disconnecting from port {0}", comPort);
SharedResources.Disconnect("Serial"); SharedResources.Disconnect("Serial");
connectedState = false; _connectedState = false;
} }
} }
} }
@@ -352,6 +369,8 @@ namespace ASCOM.Meade.net
public void AbortSlew() public void AbortSlew()
{ {
CheckConnected("AbortSlew");
tl.LogMessage("AbortSlew", "Aborting slew"); tl.LogMessage("AbortSlew", "Aborting slew");
SharedResources.SendBlind(":Q#"); SharedResources.SendBlind(":Q#");
//:Q# Halt all current slewing //:Q# Halt all current slewing
@@ -364,6 +383,8 @@ namespace ASCOM.Meade.net
{ {
tl.LogMessage("AlignmentMode Get", "Getting alignmode"); tl.LogMessage("AlignmentMode Get", "Getting alignmode");
CheckConnected("AlignmentMode Get");
const char ack = (char) 6; const char ack = (char) 6;
var alignmentString = SharedResources.SendChar(ack.ToString()); var alignmentString = SharedResources.SendChar(ack.ToString());
@@ -405,6 +426,8 @@ namespace ASCOM.Meade.net
} }
set set
{ {
CheckConnected("AlignmentMode Set");
switch (value) switch (value)
{ {
case AlignmentModes.algAltAz: case AlignmentModes.algAltAz:
@@ -431,6 +454,8 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("Altitude get");
var altAz = CalcAltAzFromTelescopeEqData(); var altAz = CalcAltAzFromTelescopeEqData();
tl.LogMessage("Altitude", $"{altAz.Altitude}"); tl.LogMessage("Altitude", $"{altAz.Altitude}");
return altAz.Altitude; return altAz.Altitude;
@@ -464,9 +489,9 @@ namespace ASCOM.Meade.net
} }
}); });
double hourAngle = astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude, double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude,
altitudeData.equatorialCoordinates.RightAscension); altitudeData.equatorialCoordinates.RightAscension);
var altAz = astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.equatorialCoordinates); var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.equatorialCoordinates);
return altAz; return altAz;
} }
@@ -519,6 +544,8 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("Azimuth get");
//var result = SharedResources.SendString(":GZ#"); //var result = SharedResources.SendString(":GZ#");
//:GZ# Get telescope azimuth //:GZ# Get telescope azimuth
//Returns: DDD*MM#T or DDD*MMSS# //Returns: DDD*MM#T or DDD*MMSS#
@@ -695,6 +722,8 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("Declination Get");
var result = SharedResources.SendString(":GD#"); var result = SharedResources.SendString(":GD#");
//:GD# Get Telescope Declination. //:GD# Get Telescope Declination.
//Returns: sDD* MM# or sDD*MMSS# //Returns: sDD* MM# or sDD*MMSS#
@@ -811,6 +840,7 @@ namespace ASCOM.Meade.net
public void MoveAxis(TelescopeAxes axis, double rate) public void MoveAxis(TelescopeAxes axis, double rate)
{ {
tl.LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); tl.LogMessage("MoveAxis", $"Axis={axis} rate={rate}");
CheckConnected("MoveAxis");
var absRate = Math.Abs(rate); var absRate = Math.Abs(rate);
@@ -907,6 +937,7 @@ namespace ASCOM.Meade.net
public void Park() public void Park()
{ {
tl.LogMessage("Park", "Parking telescope"); tl.LogMessage("Park", "Parking telescope");
CheckConnected("Park");
if (AtPark) if (AtPark)
return; return;
@@ -923,6 +954,8 @@ namespace ASCOM.Meade.net
public void PulseGuide(GuideDirections direction, int duration) public void PulseGuide(GuideDirections direction, int duration)
{ {
tl.LogMessage("PulseGuide", $"pulse guide direction {direction} duration {duration}"); tl.LogMessage("PulseGuide", $"pulse guide direction {direction} duration {duration}");
CheckConnected("PulseGuide");
string d = string.Empty; string d = string.Empty;
switch (direction) switch (direction)
{ {
@@ -988,6 +1021,7 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("RightAscension Get");
var result = SharedResources.SendString(":GR#"); var result = SharedResources.SendString(":GR#");
//:GR# Get Telescope RA //:GR# Get Telescope RA
//Returns: HH: MM.T# or HH:MM:SS# //Returns: HH: MM.T# or HH:MM:SS#
@@ -1079,6 +1113,8 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("SiteLatitude Get");
var latitude = SharedResources.SendString(":Gt#"); var latitude = SharedResources.SendString(":Gt#");
//:Gt# Get Current Site Latitude //:Gt# Get Current Site Latitude
//Returns: sDD* MM# //Returns: sDD* MM#
@@ -1092,6 +1128,8 @@ namespace ASCOM.Meade.net
{ {
tl.LogMessage("SiteLatitude Set", $"{utilities.DegreesToDMS(value)}"); tl.LogMessage("SiteLatitude Set", $"{utilities.DegreesToDMS(value)}");
CheckConnected("SiteLatitude Set");
if (value > 90) if (value > 90)
throw new InvalidValueException("Latitude cannot be greater than 90 degrees."); throw new InvalidValueException("Latitude cannot be greater than 90 degrees.");
@@ -1117,6 +1155,8 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("SiteLongitude Get");
var longitude = SharedResources.SendString(":Gg#"); var longitude = SharedResources.SendString(":Gg#");
//:Gg# Get Current Site Longitude //:Gg# Get Current Site Longitude
//Returns: sDDD* MM# //Returns: sDDD* MM#
@@ -1136,6 +1176,9 @@ namespace ASCOM.Meade.net
var newLongitude = value; var newLongitude = value;
tl.LogMessage("SiteLongitude Set", $"{utilities.DegreesToDMS(newLongitude)}"); tl.LogMessage("SiteLongitude Set", $"{utilities.DegreesToDMS(newLongitude)}");
CheckConnected("SiteLongitude Set");
if (newLongitude > 180) if (newLongitude > 180)
throw new InvalidValueException("Longitude cannot be greater than 180 degrees."); throw new InvalidValueException("Longitude cannot be greater than 180 degrees.");
@@ -1178,6 +1221,7 @@ namespace ASCOM.Meade.net
public void SlewToAltAz(double azimuth, double altitude) public void SlewToAltAz(double azimuth, double altitude)
{ {
tl.LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}"); tl.LogMessage("SlewToAltAz", $"Az=~{azimuth} Alt={altitude}");
CheckConnected("SlewToAltAz");
SlewToAltAzAsync(azimuth, altitude); SlewToAltAzAsync(azimuth, altitude);
@@ -1197,6 +1241,8 @@ namespace ASCOM.Meade.net
if (value < 0) if (value < 0)
throw new ASCOM.InvalidValueException("Altitide cannot be less than 0."); throw new ASCOM.InvalidValueException("Altitide cannot be less than 0.");
CheckConnected("TargetAltitude Set");
//todo this serial string does not work. Calculate the EQ version instead. //todo this serial string does not work. Calculate the EQ version instead.
var dms = utilities.DegreesToDMS(value, "*", "'", "",0); var dms = utilities.DegreesToDMS(value, "*", "'", "",0);
@@ -1224,6 +1270,8 @@ namespace ASCOM.Meade.net
if (value < 0) if (value < 0)
throw new ASCOM.InvalidValueException("Azimuth cannot be less than 0."); throw new ASCOM.InvalidValueException("Azimuth cannot be less than 0.");
CheckConnected("TargetAzimuth Set");
//todo this serial string does not work. Calculate the EQ version instead. //todo this serial string does not work. Calculate the EQ version instead.
var dms = utilities.DegreesToDM(value, "*" ); var dms = utilities.DegreesToDM(value, "*" );
@@ -1256,6 +1304,7 @@ namespace ASCOM.Meade.net
throw new ASCOM.InvalidValueException("Azimuth cannot be less than 0."); throw new ASCOM.InvalidValueException("Azimuth cannot be less than 0.");
tl.LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}"); tl.LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}");
CheckConnected("SlewToAltAzAsync");
HorizonCoordinates altAz = new HorizonCoordinates(); HorizonCoordinates altAz = new HorizonCoordinates();
altAz.Azimuth = azimuth; altAz.Azimuth = azimuth;
@@ -1267,7 +1316,7 @@ namespace ASCOM.Meade.net
SharedResources.Lock(() => SharedResources.Lock(() =>
{ {
var raDec = astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz); var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, altAz);
TargetRightAscension = raDec.RightAscension; TargetRightAscension = raDec.RightAscension;
TargetDeclination = raDec.Declination; TargetDeclination = raDec.Declination;
@@ -1283,6 +1332,8 @@ namespace ASCOM.Meade.net
private void DoSlewAsync(bool polar) private void DoSlewAsync(bool polar)
{ {
CheckConnected("DoSlewAsync");
SharedResources.Lock(() => SharedResources.Lock(() =>
{ {
switch (polar) switch (polar)
@@ -1335,6 +1386,8 @@ namespace ASCOM.Meade.net
public void SlewToCoordinates(double rightAscension, double declination) public void SlewToCoordinates(double rightAscension, double declination)
{ {
tl.LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}"); tl.LogMessage("SlewToCoordinates", $"Ra={rightAscension}, Dec={declination}");
CheckConnected("SlewToCoordinates");
SlewToCoordinatesAsync(rightAscension, declination); SlewToCoordinatesAsync(rightAscension, declination);
while (Slewing) //wait for slew to complete while (Slewing) //wait for slew to complete
@@ -1346,6 +1399,7 @@ namespace ASCOM.Meade.net
public void SlewToCoordinatesAsync(double rightAscension, double declination) public void SlewToCoordinatesAsync(double rightAscension, double declination)
{ {
tl.LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}"); tl.LogMessage("SlewToCoordinatesAsync", $"Ra={rightAscension}, Dec={declination}");
CheckConnected("SlewToCoordinatesAsync");
SharedResources.Lock(() => SharedResources.Lock(() =>
{ {
@@ -1360,6 +1414,7 @@ namespace ASCOM.Meade.net
public void SlewToTarget() public void SlewToTarget()
{ {
tl.LogMessage("SlewToTarget", "Executing"); tl.LogMessage("SlewToTarget", "Executing");
CheckConnected("SlewToTarget");
SlewToTargetAsync(); SlewToTargetAsync();
while (Slewing) while (Slewing)
@@ -1372,6 +1427,8 @@ namespace ASCOM.Meade.net
public void SlewToTargetAsync() public void SlewToTargetAsync()
{ {
CheckConnected("SlewToTargetAsync");
if (TargetDeclination == INVALID_PARAMETER || TargetRightAscension == INVALID_PARAMETER) if (TargetDeclination == INVALID_PARAMETER || TargetRightAscension == INVALID_PARAMETER)
throw new ASCOM.InvalidOperationException("No target selected to slew to."); throw new ASCOM.InvalidOperationException("No target selected to slew to.");
@@ -1393,6 +1450,8 @@ namespace ASCOM.Meade.net
if (movingAxis()) if (movingAxis())
return true; return true;
CheckConnected("Slewing Get");
var result = SharedResources.SendString(":D#"); var result = SharedResources.SendString(":D#");
//:D# Requests a string of bars indicating the distance to the current target location. //:D# Requests a string of bars indicating the distance to the current target location.
//Returns: //Returns:
@@ -1414,6 +1473,7 @@ namespace ASCOM.Meade.net
public void SyncToCoordinates(double rightAscension, double declination) public void SyncToCoordinates(double rightAscension, double declination)
{ {
tl.LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); tl.LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}");
CheckConnected("SyncToCoordinates");
SharedResources.Lock(() => SharedResources.Lock(() =>
{ {
@@ -1427,6 +1487,8 @@ namespace ASCOM.Meade.net
public void SyncToTarget() public void SyncToTarget()
{ {
tl.LogMessage("SyncToTarget", "Executing"); tl.LogMessage("SyncToTarget", "Executing");
CheckConnected("SyncToTarget");
var result = SharedResources.SendString(":CM#"); var result = SharedResources.SendString(":CM#");
//:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates.
//Returns: //Returns:
@@ -1468,6 +1530,7 @@ namespace ASCOM.Meade.net
if (value < -90) if (value < -90)
throw new ASCOM.InvalidValueException("Declination cannot be less than -90."); throw new ASCOM.InvalidValueException("Declination cannot be less than -90.");
CheckConnected("TargetDeclination Set");
var dms = utilities.DegreesToDMS(value, "*", ":", ":", 2); var dms = utilities.DegreesToDMS(value, "*", ":", ":", 2);
var s = value < 0 ? '-' : '+'; var s = value < 0 ? '-' : '+';
@@ -1517,7 +1580,7 @@ namespace ASCOM.Meade.net
if (value >= 24) if (value >= 24)
throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59");
CheckConnected("TargetRightAscension Set");
//todo implement the low precision version //todo implement the low precision version
var hms = utilities.HoursToHMS(value, ":", ":", ":", 2); var hms = utilities.HoursToHMS(value, ":", ":", ":", 2);
@@ -1552,6 +1615,7 @@ namespace ASCOM.Meade.net
} }
private DriveRates _trackingRate = DriveRates.driveSidereal; private DriveRates _trackingRate = DriveRates.driveSidereal;
public DriveRates TrackingRate public DriveRates TrackingRate
{ {
get get
@@ -1574,6 +1638,7 @@ namespace ASCOM.Meade.net
set set
{ {
tl.LogMessage("TrackingRate Set", $"{value}"); tl.LogMessage("TrackingRate Set", $"{value}");
CheckConnected("TrackingRate Set");
switch (value) switch (value)
{ {
@@ -1620,6 +1685,8 @@ namespace ASCOM.Meade.net
private TimeSpan GetUtcCorrection() private TimeSpan GetUtcCorrection()
{ {
CheckConnected("GetUtcCorrection");
string utcOffSet = SharedResources.SendString(":GG#"); string utcOffSet = SharedResources.SendString(":GG#");
//:GG# Get UTC offset time //:GG# Get UTC offset time
//Returns: sHH# or sHH.H# //Returns: sHH# or sHH.H#
@@ -1641,6 +1708,8 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
CheckConnected("UTCDate Get");
tl.LogMessage("UTCDate", "Get started"); tl.LogMessage("UTCDate", "Get started");
TelescopeDateDetails telescopeDateDetails = SharedResources.Lock(() => TelescopeDateDetails telescopeDateDetails = SharedResources.Lock(() =>
@@ -1683,6 +1752,8 @@ namespace ASCOM.Meade.net
{ {
tl.LogMessage("UTCDate", "Set - " + value.ToString("MM/dd/yy HH:mm:ss")); tl.LogMessage("UTCDate", "Set - " + value.ToString("MM/dd/yy HH:mm:ss"));
CheckConnected("UTCDate Set");
SharedResources.Lock(() => SharedResources.Lock(() =>
{ {
var utcCorrection = GetUtcCorrection(); var utcCorrection = GetUtcCorrection();
@@ -1812,7 +1883,7 @@ namespace ASCOM.Meade.net
get get
{ {
// TODO check that the driver hardware connection exists and is connected to the hardware // TODO check that the driver hardware connection exists and is connected to the hardware
return connectedState; return _connectedState;
} }
} }
+7 -1
View File
@@ -109,7 +109,7 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
public Focuser() public Focuser()
{ {
tl = new TraceLogger("", "Meade.net"); tl = new TraceLogger("", "Meade.net.focusser");
ReadProfile(); // Read device configuration from the ASCOM Profile store ReadProfile(); // Read device configuration from the ASCOM Profile store
tl.LogMessage("Focuser", "Starting initialisation"); tl.LogMessage("Focuser", "Starting initialisation");
@@ -136,8 +136,10 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
public void SetupDialog() public void SetupDialog()
{ {
tl.LogMessage("SetupDialog", "Opening setup dialog");
SharedResources.SetupDialog(); SharedResources.SetupDialog();
ReadProfile(); ReadProfile();
tl.LogMessage("SetupDialog", "complete");
} }
public ArrayList SupportedActions public ArrayList SupportedActions
@@ -297,6 +299,9 @@ namespace ASCOM.Meade.net
public void Halt() public void Halt()
{ {
tl.LogMessage("Halt", "Halting"); tl.LogMessage("Halt", "Halting");
CheckConnected("Halt");
SharedResources.SendBlind(":FQ#"); SharedResources.SendBlind(":FQ#");
//:FQ# Halt Focuser Motion //:FQ# Halt Focuser Motion
//Returns: Nothing //Returns: Nothing
@@ -348,6 +353,7 @@ namespace ASCOM.Meade.net
public void Move(int Position) public void Move(int Position)
{ {
tl.LogMessage("Move", Position.ToString()); tl.LogMessage("Move", Position.ToString());
CheckConnected("Move");
//todo implement backlash compensation //todo implement backlash compensation
//todo implement direction reverse //todo implement direction reverse
+27 -29
View File
@@ -42,8 +42,7 @@ namespace ASCOM.Meade.net
private static readonly object lockObject = new object(); private static readonly object lockObject = new object();
// Shared serial port. This will allow multiple drivers to use one single serial port. // Shared serial port. This will allow multiple drivers to use one single serial port.
private static ASCOM.Utilities.Serial s_sharedSerial = new ASCOM.Utilities.Serial(); // Shared serial port private static ASCOM.Utilities.Serial s_sharedSerial; // Shared serial port
private static int s_z = 0; // counter for the number of connections to the serial port
// //
// Public access to shared resources // Public access to shared resources
@@ -68,19 +67,12 @@ namespace ASCOM.Meade.net
/// <summary> /// <summary>
/// Shared serial port /// Shared serial port
/// </summary> /// </summary>
public static ASCOM.Utilities.Serial SharedSerial public static ASCOM.Utilities.Serial SharedSerial => s_sharedSerial ?? (s_sharedSerial = new ASCOM.Utilities.Serial());
{
get { return s_sharedSerial; }
}
/// <summary> /// <summary>
/// number of connections to the shared serial port /// number of connections to the shared serial port
/// </summary> /// </summary>
public static int connections public static int Connections { get; set; } = 0;
{
get { return s_z; }
set { s_z = value; }
}
public static void SendBlind(string message) public static void SendBlind(string message)
{ {
@@ -149,14 +141,14 @@ namespace ASCOM.Meade.net
{ {
if (value) if (value)
{ {
if (s_z == 0) if (Connections == 0)
SharedSerial.Connected = true; SharedSerial.Connected = true;
s_z++; Connections++;
} }
else else
{ {
s_z--; Connections--;
if (s_z <= 0) if (Connections <= 0)
{ {
SharedSerial.Connected = false; SharedSerial.Connected = false;
} }
@@ -178,11 +170,14 @@ namespace ASCOM.Meade.net
public static void WriteProfile(ProfileProperties profileProperties) public static void WriteProfile(ProfileProperties profileProperties)
{ {
using (Profile driverProfile = new Profile()) lock (lockObject)
{ {
driverProfile.DeviceType = "Telescope"; using (Profile driverProfile = new Profile())
driverProfile.WriteValue(driverID, traceStateProfileName, profileProperties.TraceLogger.ToString()); {
driverProfile.WriteValue(driverID, comPortProfileName, profileProperties.ComPort); driverProfile.DeviceType = "Telescope";
driverProfile.WriteValue(driverID, traceStateProfileName, profileProperties.TraceLogger.ToString());
driverProfile.WriteValue(driverID, comPortProfileName, profileProperties.ComPort);
}
} }
} }
@@ -191,17 +186,20 @@ namespace ASCOM.Meade.net
public static ProfileProperties ReadProfile() public static ProfileProperties ReadProfile()
{ {
ProfileProperties profileProperties = new ProfileProperties(); lock (lockObject)
using (Profile driverProfile = new Profile())
{ {
driverProfile.DeviceType = "Telescope"; ProfileProperties profileProperties = new ProfileProperties();
profileProperties.ComPort = using (Profile driverProfile = new Profile())
driverProfile.GetValue(driverID, comPortProfileName, string.Empty, comPortDefault); {
profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(driverID, driverProfile.DeviceType = "Telescope";
traceStateProfileName, string.Empty, traceStateDefault)); profileProperties.ComPort =
} driverProfile.GetValue(driverID, comPortProfileName, string.Empty, comPortDefault);
profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(driverID,
traceStateProfileName, string.Empty, traceStateDefault));
}
return profileProperties; return profileProperties;
}
} }
#endregion #endregion
@@ -212,7 +210,7 @@ namespace ASCOM.Meade.net
{ {
// consider only showing the setup dialog if not connected // consider only showing the setup dialog if not connected
// or call a different dialog if connected // or call a different dialog if connected
if (SharedSerial.Connected) if (Connections > 0)
{ {
System.Windows.Forms.MessageBox.Show("Already connected, please disconnect before altering settings"); System.Windows.Forms.MessageBox.Show("Already connected, please disconnect before altering settings");
return; return;