Started working on getting the basic communications with the scope working.

Working on routines to get and set the date and time in the handbox.
This commit is contained in:
2019-04-29 00:06:56 +01:00
parent f2f4b05911
commit da6b7ec55f
19 changed files with 746 additions and 79 deletions
@@ -0,0 +1,36 @@
<#
This script initializes a bare minimum set of registry entries required for ASCOM.Utilities.Profile to work
without throwing any exceptions. When building on a build server, or on a computer without the ASCOM Platform installed,
it may be useful to execute this script as a build step prior to running any unit tests, or calling any code that relies on
ASCOM.Utilities.Profile. The alternative is to install the ASCOM Platform on the build agent.
NOTE: This script equires elevated permissions because it creates registry keys in the LocalMachine hive.
#>
$wow = Test-Path HKLM:\SOFTWARE\Wow6432Node
if ($wow)
{
$root = "HKLM:\SOFTWARE\Wow6432Node"
}
else
{
$root = "HKLM:\SOFTWARE"
}
$ascomRoot = $root + "\ASCOM"
if (Test-Path $ascomRoot)
{
<# Don't upset an already-existing ASCOM registry #>
exit
}
<# Create the ASCOM root key and set it's ACL to allow all users read/write access #>
New-Item -Path $root -Name ASCOM Force
$ascomAcl = Get-Acl $ascomRoot
$aclRule = New-Object System.Security.AccessControl.RegistryAccessRule ("Users","FullControl","Allow")
$ascomAcl.SetAccessRule($aclRule)
$ascomAcl | Set-Acl -Path $ascomRoot
<# Now create the bare minimum keys required so that ASCOM.Utilities.Profile doesn't crash and burn #>
New-ItemProperty -Path $ascomRoot -Name PlatformVersion -Value "6.1" -PropertyType String Force
New-ItemProperty -Path $ascomRoot -Name SerTraceFile -Value "C:\SerialTraceAuto.txt" -PropertyType String Force
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9638DA27-77C7-4B30-A730-6E7159A4A09F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MeadeAutostar497.UnitTests</RootNamespace>
<AssemblyName>MeadeAutostar497.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ASCOM.Astrometry, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Astrometry.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Attributes, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Attributes.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Cache, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Cache.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Controls, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Controls.dll</HintPath>
</Reference>
<Reference Include="ASCOM.DeviceInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.DeviceInterfaces.dll</HintPath>
</Reference>
<Reference Include="ASCOM.DriverAccess, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.DriverAccess.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Exceptions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Exceptions.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Internal.Extensions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Internal.Extensions.dll</HintPath>
</Reference>
<Reference Include="ASCOM.SettingsProvider, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.SettingsProvider.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Utilities, Version=6.0.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Utilities.dll</HintPath>
</Reference>
<Reference Include="ASCOM.Utilities.Video, Version=6.1.0.0, Culture=neutral, PublicKeyToken=565de7938946fba7, processorArchitecture=MSIL">
<HintPath>..\packages\ASCOM.Platform.6.4.2\lib\net40\ASCOM.Utilities.Video.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.10.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.10.1\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="TelescopeControllerUnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MeadeAutostar497\MeadeAutostar497.csproj">
<Project>{64308775-bd4a-469c-bcab-3ed830b811af}</Project>
<Name>MeadeAutostar497</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="BootstrapAscomProfileStore.ps1" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
</Target>
</Project>
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MeadeAutostar497.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MeadeAutostar497.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9638da27-77c7-4b30-a730-6e7159a4a09f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,151 @@
using System.Collections.Generic;
using ASCOM;
using ASCOM.MeadeAutostar497.Controller;
using ASCOM.Utilities;
using ASCOM.Utilities.Interfaces;
using Moq;
using NUnit.Framework;
namespace MeadeAutostar497.UnitTests
{
[TestFixture]
public class TelescopeControllerUnitTests
{
private Mock<ISerial> serialMock;
private readonly List<string> _availableComPorts = new List<string> { "COM1", "COM2", "COM3" };
private TelescopeController _telescopeController;
private string transmittedString;
private string stringToRecieve;
[SetUp]
public void Setup()
{
transmittedString = string.Empty;
stringToRecieve = string.Empty;
serialMock = new Mock<ISerial>();
serialMock.SetupAllProperties();
serialMock.Setup(x => x.AvailableComPorts).Returns( () => _availableComPorts.ToArray());
serialMock.Setup(X => X.Transmit(It.IsAny<string>())).Callback<string>(str => { transmittedString = str; });
serialMock.Setup(X => X.Receive()).Returns(() => stringToRecieve);
_telescopeController = TelescopeController.Instance;
_telescopeController.SerialPort = serialMock.Object;
}
[TearDown]
public void TearDown()
{
_telescopeController.Connected = false;
_telescopeController.Port = "COM1";
}
[Test]
public void ImplementsExpectedInterfaces()
{
Assert.That(_telescopeController, Is.Not.Null);
Assert.That(_telescopeController, Is.AssignableTo<ITelescopeController>());
}
[Test]
public void NotConnectedByDefault()
{
Assert.That(_telescopeController.Connected, Is.False);
}
[Test]
public void ConnectedCanBeSetTrue()
{
stringToRecieve = "test#";
_telescopeController.Connected = true;
Assert.That(_telescopeController.Connected, Is.True);
}
[Test]
public void EnsureThatTheSerialCommunicationsAreSetCorrectly()
{
Assert.That(serialMock.Object.Connected, Is.False);
stringToRecieve = "test#";
_telescopeController.Connected = true;
Assert.That(_telescopeController.Connected, Is.True);
Assert.That(serialMock.Object.DTREnable, Is.False);
Assert.That(serialMock.Object.RTSEnable, Is.False);
Assert.That(serialMock.Object.Speed, Is.EqualTo(SerialSpeed.ps9600));
Assert.That(serialMock.Object.DataBits, Is.EqualTo(8));
Assert.That(serialMock.Object.StopBits, Is.EqualTo(SerialStopBits.One));
Assert.That(serialMock.Object.Parity, Is.EqualTo(SerialParity.None));
Assert.That(serialMock.Object.PortName, Is.EqualTo(_telescopeController.Port));
Assert.That(serialMock.Object.Connected, Is.True);
}
[Test]
public void WhenOpensComPortToNonAutostarThrowException()
{
Assert.That(serialMock.Object.Connected, Is.False);
var exception = Assert.Throws<InvalidOperationException>(() => { _telescopeController.Connected = true; });
Assert.That(exception.Message, Is.EqualTo("Failed to communicate with telescope."));
Assert.That(_telescopeController.Connected, Is.False);
}
[Test]
public void CannotChangeSerialPortObjectWhenConnected()
{
stringToRecieve = "test#";
_telescopeController.Connected = true;
Mock<ISerial> newSerialMock = new Mock<ISerial>();
var exception = Assert.Throws<InvalidOperationException>( () => { _telescopeController.SerialPort = newSerialMock.Object; });
Assert.That(exception, Is.Not.Null);
Assert.That(exception.Message, Is.EqualTo("Please disconnect before changing the serial engine."));
}
[Test]
public void PortIsSetToCom1ByDefault()
{
Assert.That(_telescopeController.Port, Is.EqualTo("COM1"));
}
[Test]
public void SettingPortToValidPortAllowed()
{
_telescopeController.Port = "COM2";
Assert.That(_telescopeController.Port, Is.EqualTo("COM2"));
}
[Test]
public void SettingPortToValidPortWhenConnectedFails()
{
stringToRecieve = "test#";
_telescopeController.Connected = true;
var exception = Assert.Throws<InvalidOperationException>( () => _telescopeController.Port = "COM2");
Assert.That(exception.Message, Is.EqualTo("Please disconnect from the scope before changing port."));
Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
}
[Test]
public void SettingPortToInavalidPortFails()
{
var exception = Assert.Throws<InvalidOperationException>(() => _telescopeController.Port = "COM5");
Assert.That(exception.Message, Is.EqualTo("Unable to select port COM5 as it does not exist."));
Assert.That(_telescopeController.Port, Is.EqualTo("COM1")); //port hasn't changed
}
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ASCOM.Platform" version="6.4.2" targetFramework="net45" />
<package id="Castle.Core" version="4.3.1" targetFramework="net45" />
<package id="Moq" version="4.10.1" targetFramework="net45" />
<package id="NUnit" version="3.11.0" targetFramework="net45" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net45" requireReinstallation="true" />
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net45" requireReinstallation="true" />
</packages>