Merged in feature/PortSpeed (pull request #40)
Feature/PortSpeed * Added support for changing the speed of the autostar * Added support for changing the speed of the autostar * Merge remote-tracking branch 'origin/feature/PortSpeed' into feature/PortSpeed * Upgraded unit testing to make sure that speed changes are properly tested
This commit is contained in:
@@ -194,6 +194,10 @@
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
||||
@@ -590,6 +590,349 @@ namespace Meade.net.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Connect_WhenSpeedIsFastAndAutostarSetToFast_ThenConnectsDirectlyAtFastSpeed()
|
||||
{
|
||||
string deviceId = "Serial";
|
||||
|
||||
string DriverId = "ASCOM.MeadeGeneric.Telescope";
|
||||
|
||||
string TraceStateDefault = "false";
|
||||
|
||||
string ComPortDefault = "COM1";
|
||||
string SpeedDefault = "57600";
|
||||
string DataBitsDefault = "8";
|
||||
string StopBitsDefault = "One";
|
||||
string HandshakeDefault = "None";
|
||||
string ParityDefault = "None";
|
||||
string RtsDtrEnabledDefault = "false";
|
||||
|
||||
string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate
|
||||
string PrecisionDefault = "Unchanged";
|
||||
|
||||
string ParkedBehaviourDefault = "No Coordinates";
|
||||
string ParkedAltDefault = "0";
|
||||
string ParkedAzimuthDefault = "180";
|
||||
string FocalLengthDefault = "2000";
|
||||
string ApertureAreaDefault = "32685";
|
||||
string ApertureDiameterDefault = "203";
|
||||
|
||||
Mock<IProfileWrapper> profileWrapperMock = new Mock<IProfileWrapper>();
|
||||
profileWrapperMock.SetupAllProperties();
|
||||
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault))
|
||||
.Returns(TraceStateDefault);
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault))
|
||||
.Returns(ComPortDefault);
|
||||
profileWrapperMock
|
||||
.Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty,
|
||||
GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault);
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault))
|
||||
.Returns(PrecisionDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault))
|
||||
.Returns(() => SpeedDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault))
|
||||
.Returns(() => DataBitsDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault))
|
||||
.Returns(() => StopBitsDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault))
|
||||
.Returns(() => HandshakeDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parity", string.Empty, ParityDefault))
|
||||
.Returns(() => ParityDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault))
|
||||
.Returns(() => RtsDtrEnabledDefault);
|
||||
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault))
|
||||
.Returns(() => ParityDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault))
|
||||
.Returns(() => ParkedAltDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault))
|
||||
.Returns(() => ParkedAzimuthDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault))
|
||||
.Returns(() => FocalLengthDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault))
|
||||
.Returns(() => ApertureAreaDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault))
|
||||
.Returns(() => ApertureDiameterDefault);
|
||||
|
||||
Mock<IProfileFactory> profileFactoryMock = new Mock<IProfileFactory>();
|
||||
profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object);
|
||||
|
||||
SharedResources.ProfileFactory = profileFactoryMock.Object;
|
||||
|
||||
string serialPortReturn = string.Empty;
|
||||
|
||||
_serialMock.Setup(x => x.Transmit("#:GVP#")).Callback(() => { serialPortReturn = TelescopeList.LX200GPS; });
|
||||
_serialMock.Setup(x => x.Transmit("#:GVN#")).Callback(() => { serialPortReturn = TelescopeList.LX200GPS_42G; });
|
||||
_serialMock.Setup(x => x.Transmit("#:GG#")).Callback(() => { serialPortReturn = "0"; });
|
||||
_serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn);
|
||||
|
||||
var connectionResult = SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object);
|
||||
try
|
||||
{
|
||||
Assert.That(connectionResult.SameDevice, Is.EqualTo(1));
|
||||
Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.LX200GPS));
|
||||
Assert.That(SharedResources.FirmwareVersion, Is.EqualTo(TelescopeList.LX200GPS_42G));
|
||||
}
|
||||
finally
|
||||
{
|
||||
SharedResources.Disconnect(deviceId, String.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("57600")]
|
||||
[TestCase("38400")]
|
||||
[TestCase("28800")]
|
||||
[TestCase("19200")]
|
||||
[TestCase("14400")]
|
||||
[TestCase("4800")]
|
||||
[TestCase("2400")]
|
||||
[TestCase("1200")]
|
||||
public void Connect_WhenSpeedIsFastAndAutostarAtDefault_ThenConnectsAutoStarSpeedChanged(string WantedSpeed)
|
||||
{
|
||||
string deviceId = "Serial";
|
||||
|
||||
string DriverId = "ASCOM.MeadeGeneric.Telescope";
|
||||
|
||||
string TraceStateDefault = "false";
|
||||
|
||||
string ComPortDefault = "COM1";
|
||||
string SpeedDefault = "9600";
|
||||
string DataBitsDefault = "8";
|
||||
string StopBitsDefault = "One";
|
||||
string HandshakeDefault = "None";
|
||||
string ParityDefault = "None";
|
||||
string RtsDtrEnabledDefault = "false";
|
||||
|
||||
string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate
|
||||
string PrecisionDefault = "Unchanged";
|
||||
|
||||
string ParkedBehaviourDefault = "No Coordinates";
|
||||
string ParkedAltDefault = "0";
|
||||
string ParkedAzimuthDefault = "180";
|
||||
string FocalLengthDefault = "2000";
|
||||
string ApertureAreaDefault = "32685";
|
||||
string ApertureDiameterDefault = "203";
|
||||
|
||||
Mock<IProfileWrapper> profileWrapperMock = new Mock<IProfileWrapper>();
|
||||
profileWrapperMock.SetupAllProperties();
|
||||
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault))
|
||||
.Returns(TraceStateDefault);
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault))
|
||||
.Returns(ComPortDefault);
|
||||
profileWrapperMock
|
||||
.Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty,
|
||||
GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault);
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault))
|
||||
.Returns(PrecisionDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault))
|
||||
.Returns(() => WantedSpeed);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault))
|
||||
.Returns(() => DataBitsDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault))
|
||||
.Returns(() => StopBitsDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault))
|
||||
.Returns(() => HandshakeDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parity", string.Empty, ParityDefault))
|
||||
.Returns(() => ParityDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault))
|
||||
.Returns(() => RtsDtrEnabledDefault);
|
||||
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault))
|
||||
.Returns(() => ParityDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault))
|
||||
.Returns(() => ParkedAltDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault))
|
||||
.Returns(() => ParkedAzimuthDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault))
|
||||
.Returns(() => FocalLengthDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault))
|
||||
.Returns(() => ApertureAreaDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault))
|
||||
.Returns(() => ApertureDiameterDefault);
|
||||
|
||||
Mock<IProfileFactory> profileFactoryMock = new Mock<IProfileFactory>();
|
||||
profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object);
|
||||
|
||||
SharedResources.ProfileFactory = profileFactoryMock.Object;
|
||||
|
||||
string serialPortReturn = string.Empty;
|
||||
|
||||
_serialMock.Setup(x => x.Transmit("#:GVP#")).Callback(() => { serialPortReturn = TelescopeList.LX200GPS; });
|
||||
_serialMock.Setup(x => x.Transmit("#:GVN#")).Callback(() => { serialPortReturn = TelescopeList.LX200GPS_42G; });
|
||||
_serialMock.Setup(x => x.Transmit("#:SB1#")).Callback(() => { serialPortReturn = "1"; });
|
||||
|
||||
var ggCall = 0;
|
||||
|
||||
_serialMock.Setup(x => x.Transmit("#:GG#")).Callback(() => {
|
||||
ggCall++;
|
||||
if (ggCall == 1)
|
||||
throw new Exception("Fake Timeout");
|
||||
else
|
||||
serialPortReturn = "0"; });
|
||||
_serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn);
|
||||
_serialMock.Setup(x => x.ReceiveCounted(1)).Returns(() => "1");
|
||||
|
||||
var connectionResult = SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object);
|
||||
try
|
||||
{
|
||||
Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.LX200GPS));
|
||||
Assert.That(SharedResources.FirmwareVersion, Is.EqualTo(TelescopeList.LX200GPS_42G));
|
||||
|
||||
_traceLoggerMock.Verify(x => x.LogIssue("Connect", $"Telescope serial port speed change, connecting at ps{WantedSpeed}."), Times.Once);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SharedResources.Disconnect(deviceId, String.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("57600")]
|
||||
[TestCase("38400")]
|
||||
[TestCase("28800")]
|
||||
[TestCase("19200")]
|
||||
[TestCase("14400")]
|
||||
[TestCase("4800")]
|
||||
[TestCase("2400")]
|
||||
[TestCase("1200")]
|
||||
public void Connect_WhenAutostarReportsFailedToChangeSpeec_ThenConnectsAutoStarAtDefaultSpeed(string WantedSpeed)
|
||||
{
|
||||
string deviceId = "Serial";
|
||||
|
||||
string DriverId = "ASCOM.MeadeGeneric.Telescope";
|
||||
|
||||
string TraceStateDefault = "false";
|
||||
|
||||
string ComPortDefault = "COM1";
|
||||
string SpeedDefault = "9600";
|
||||
string DataBitsDefault = "8";
|
||||
string StopBitsDefault = "One";
|
||||
string HandshakeDefault = "None";
|
||||
string ParityDefault = "None";
|
||||
string RtsDtrEnabledDefault = "false";
|
||||
|
||||
string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate
|
||||
string PrecisionDefault = "Unchanged";
|
||||
|
||||
string ParkedBehaviourDefault = "No Coordinates";
|
||||
string ParkedAltDefault = "0";
|
||||
string ParkedAzimuthDefault = "180";
|
||||
string FocalLengthDefault = "2000";
|
||||
string ApertureAreaDefault = "32685";
|
||||
string ApertureDiameterDefault = "203";
|
||||
|
||||
Mock<IProfileWrapper> profileWrapperMock = new Mock<IProfileWrapper>();
|
||||
profileWrapperMock.SetupAllProperties();
|
||||
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault))
|
||||
.Returns(TraceStateDefault);
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault))
|
||||
.Returns(ComPortDefault);
|
||||
profileWrapperMock
|
||||
.Setup(x => x.GetValue(DriverId, "Guide Rate Arc Seconds Per Second", string.Empty,
|
||||
GuideRateProfileNameDefault)).Returns(GuideRateProfileNameDefault);
|
||||
profileWrapperMock.Setup(x => x.GetValue(DriverId, "Precision", string.Empty, PrecisionDefault))
|
||||
.Returns(PrecisionDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Speed", string.Empty, SpeedDefault))
|
||||
.Returns(() => WantedSpeed);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Data Bits", string.Empty, DataBitsDefault))
|
||||
.Returns(() => DataBitsDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Stop Bits", string.Empty, StopBitsDefault))
|
||||
.Returns(() => StopBitsDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Hand Shake", string.Empty, HandshakeDefault))
|
||||
.Returns(() => HandshakeDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parity", string.Empty, ParityDefault))
|
||||
.Returns(() => ParityDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Rts / Dtr", string.Empty, RtsDtrEnabledDefault))
|
||||
.Returns(() => RtsDtrEnabledDefault);
|
||||
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Behaviour", string.Empty, ParkedBehaviourDefault))
|
||||
.Returns(() => ParityDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Altitude", string.Empty, ParkedAltDefault))
|
||||
.Returns(() => ParkedAltDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Parked Azimuth", string.Empty, ParkedAzimuthDefault))
|
||||
.Returns(() => ParkedAzimuthDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Focal Length (mm)", string.Empty, FocalLengthDefault))
|
||||
.Returns(() => FocalLengthDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Aperture Area (mm²)", string.Empty, ApertureAreaDefault))
|
||||
.Returns(() => ApertureAreaDefault);
|
||||
profileWrapperMock.Setup(x =>
|
||||
x.GetValue(DriverId, "Aperture Diameter (mm)", string.Empty, ApertureDiameterDefault))
|
||||
.Returns(() => ApertureDiameterDefault);
|
||||
|
||||
Mock<IProfileFactory> profileFactoryMock = new Mock<IProfileFactory>();
|
||||
profileFactoryMock.Setup(x => x.Create()).Returns(profileWrapperMock.Object);
|
||||
|
||||
SharedResources.ProfileFactory = profileFactoryMock.Object;
|
||||
|
||||
string serialPortReturn = string.Empty;
|
||||
|
||||
_serialMock.Setup(x => x.Transmit("#:GVP#")).Callback(() => { serialPortReturn = TelescopeList.LX200GPS; });
|
||||
_serialMock.Setup(x => x.Transmit("#:GVN#")).Callback(() => { serialPortReturn = TelescopeList.LX200GPS_42G; });
|
||||
_serialMock.Setup(x => x.Transmit("#:SB1#")).Callback(() => { serialPortReturn = "1"; });
|
||||
|
||||
var ggCall = 0;
|
||||
|
||||
_serialMock.Setup(x => x.Transmit("#:GG#")).Callback(() => {
|
||||
ggCall++;
|
||||
if (ggCall == 1)
|
||||
throw new Exception("Fake Timeout");
|
||||
else
|
||||
serialPortReturn = "0";
|
||||
});
|
||||
_serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(() => serialPortReturn);
|
||||
_serialMock.Setup(x => x.ReceiveCounted(1)).Returns(() => "0");
|
||||
|
||||
var connectionResult = SharedResources.Connect(deviceId, string.Empty, _traceLoggerMock.Object);
|
||||
try
|
||||
{
|
||||
Assert.That(SharedResources.ProductName, Is.EqualTo(TelescopeList.LX200GPS));
|
||||
Assert.That(SharedResources.FirmwareVersion, Is.EqualTo(TelescopeList.LX200GPS_42G));
|
||||
|
||||
_traceLoggerMock.Verify(x => x.LogIssue("Connect", $"Telescope not responding to speed change, connecting at ps{SpeedDefault}."), Times.Once);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SharedResources.Disconnect(deviceId, String.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Connect_WhenSerialPortIsNotRespondingCorrectly_ThenExceptionThrown()
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
SetItemsFromEnum(cboStopBits.Items, typeof(SerialStopBits));
|
||||
SetItemsFromEnum(cboParity.Items, typeof(SerialParity));
|
||||
SetItemsFromEnumValues(cboSpeed.Items, typeof(SerialSpeed));
|
||||
SetItemFromEnumValues(cboSpeed.Items, SerialSpeed.ps1200, SerialSpeed.ps57600);
|
||||
SetItemsFromEnum(cboHandShake.Items, typeof(SerialHandshake));
|
||||
SetItemsFromEnum(cboParkedBehaviour.Items, typeof(ParkedBehaviour));
|
||||
}
|
||||
@@ -41,13 +41,30 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
|
||||
private void SetItemsFromEnumValues(IList items, Type enumItems)
|
||||
//private void SetItemsFromEnumValues(IList items, Type enumItems)
|
||||
//{
|
||||
// items.Clear();
|
||||
|
||||
// foreach (int item in Enum.GetValues(enumItems))
|
||||
// {
|
||||
// items.Add(item);
|
||||
// }
|
||||
//}
|
||||
|
||||
private void SetItemFromEnumValues<T>(IList items, T minValue, T maxValue)
|
||||
{
|
||||
items.Clear();
|
||||
|
||||
foreach (int item in Enum.GetValues(enumItems))
|
||||
var type = typeof(T);
|
||||
|
||||
var intMinValue = (int)Convert.ChangeType(minValue, typeof(int));
|
||||
|
||||
var intMaxValue = (int)Convert.ChangeType(maxValue, typeof(int));
|
||||
|
||||
foreach (int item in Enum.GetValues(type))
|
||||
{
|
||||
items.Add(item);
|
||||
if ((item >= intMinValue) && (item <= intMaxValue))
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using ASCOM.DeviceInterface;
|
||||
@@ -389,8 +389,70 @@ namespace ASCOM.Meade.net
|
||||
SharedSerial.DataBits = profileProperties.DataBits;
|
||||
SharedSerial.StopBits = (SerialStopBits)Enum.Parse(typeof(SerialStopBits), profileProperties.StopBits);
|
||||
SharedSerial.Parity = (SerialParity)Enum.Parse(typeof(SerialParity), profileProperties.Parity);
|
||||
SharedSerial.Speed = (SerialSpeed)profileProperties.Speed;
|
||||
SharedSerial.Handshake = (SerialHandshake)Enum.Parse(typeof(SerialHandshake), profileProperties.Handshake);
|
||||
SharedSerial.Speed = SerialSpeed.ps9600;
|
||||
|
||||
var wantedSpeed = (SerialSpeed)profileProperties.Speed;
|
||||
if (wantedSpeed != SerialSpeed.ps9600)
|
||||
{
|
||||
SharedSerial.Speed = wantedSpeed;
|
||||
SharedSerial.Connected = true;
|
||||
|
||||
var speedRampNeeded = false;
|
||||
|
||||
//Test if communication is working.
|
||||
try
|
||||
{
|
||||
string utcOffSet = SendString("GG");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
speedRampNeeded = true;
|
||||
}
|
||||
|
||||
if (speedRampNeeded)
|
||||
{
|
||||
SharedSerial.Connected = false;
|
||||
SharedSerial.Speed = SerialSpeed.ps9600;
|
||||
SharedSerial.Connected = true;
|
||||
|
||||
int newSpeedIndex = GetSpeedIndex(wantedSpeed);
|
||||
//:SBn# Set Baud Rate n, where n is an ASCII digit (1..9) with the following interpertation
|
||||
// 1 56.7K
|
||||
// 2 38.4K
|
||||
// 3 28.8K
|
||||
// 4 19.2K
|
||||
// 5 14.4K
|
||||
// 6 9600
|
||||
// 7 4800
|
||||
// 8 2400
|
||||
// 9 1200
|
||||
//Returns:
|
||||
// 1 At the current baud rate and then changes to the new rate for further communication
|
||||
//SendBlind($"SB{newSpeedIndex}");
|
||||
try
|
||||
{
|
||||
var speedChanged = SendChar($"SB{newSpeedIndex}");
|
||||
if (speedChanged == "1")
|
||||
{
|
||||
SharedSerial.Connected = false;
|
||||
SharedSerial.Speed = wantedSpeed;
|
||||
traceLogger.LogIssue("Connect",
|
||||
$"Telescope serial port speed change, connecting at {SharedSerial.Speed}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Autostar not signalled speed change.");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
SharedSerial.Connected = false;
|
||||
SharedSerial.Speed = SerialSpeed.ps9600;
|
||||
traceLogger.LogIssue("Connect", $"Telescope not responding to speed change, connecting at {SharedSerial.Speed}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
SharedSerial.Connected = true;
|
||||
|
||||
try
|
||||
@@ -451,6 +513,23 @@ namespace ASCOM.Meade.net
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetSpeedIndex(SerialSpeed speed)
|
||||
{
|
||||
switch (speed)
|
||||
{
|
||||
case SerialSpeed.ps57600: return 1;
|
||||
case SerialSpeed.ps38400: return 2;
|
||||
case SerialSpeed.ps28800: return 3;
|
||||
case SerialSpeed.ps19200: return 4;
|
||||
case SerialSpeed.ps14400: return 5;
|
||||
case SerialSpeed.ps9600: return 6;
|
||||
case SerialSpeed.ps4800: return 7;
|
||||
case SerialSpeed.ps2400: return 8;
|
||||
case SerialSpeed.ps1200: return 9;
|
||||
default: throw new NotSupportedException($"{SpeedDefault} not supported");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Disconnect(string deviceId, string driverId)
|
||||
{
|
||||
lock (LockObject)
|
||||
|
||||
Reference in New Issue
Block a user