public async Task InvokeActionAsync_SendValidRequest() { //Arrange string commandName = "action"; string actionNameParameterName = "Action"; string actionNameParameterValue = "actionNameParameterValue"; string actionParametersParameterName = "Parameters"; string actionParametersParameterValue = "actionParametersParameterValue"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequestAsync <StringResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(Task.FromResult(new StringResponse("test"))); var device = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act await device.InvokeActionAsync(actionNameParameterValue, actionParametersParameterValue); //Assert Assert.Equal(Method.PUT, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); AssertParameter(sentRequest.Parameters, actionNameParameterName, actionNameParameterValue); AssertParameter(sentRequest.Parameters, actionParametersParameterName, actionParametersParameterValue); }
public void Disconnect() { Connected = false; Filters.Clear(); _filterwheel?.Dispose(); _filterwheel = null; }
public void SendCommandBlind_SendValidRequest() { //Arrange string commandName = "commandblind"; string commandParameterName = "Command"; string commandParameterValue = "commandParameterValue"; string rawParameterName = "Raw"; bool rawParameterValue = true; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequest <CommandResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(new CommandResponse()); var device = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act device.SendCommandBlind(commandParameterValue, rawParameterValue); //Assert Assert.Equal(Method.PUT, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); AssertParameter(sentRequest.Parameters, commandParameterName, commandParameterValue); AssertParameter(sentRequest.Parameters, rawParameterName, rawParameterValue); }
private void CallDeviceMethods(FilterWheel filterWheel) { Logger.LogInformation("START CallDeviceMethods"); Logger.LogInformation("Connect Filter wheel"); filterWheel.SetConnected(true); var isConnected = filterWheel.IsConnected(); Logger.LogInformation("is Connected : {Connected}", isConnected); var name = filterWheel.GetName(); Logger.LogInformation("Name : {Name}", name); var description = filterWheel.GetDescription(); Logger.LogInformation("Description : {Description}", description); var driverInfo = filterWheel.GetDriverInfo(); Logger.LogInformation("DriverInfo : {DriverInfo}", driverInfo); var driverVersion = filterWheel.GetDriverVersion(); Logger.LogInformation("DriverVersion : {DriverVersion}", driverVersion); var names = filterWheel.GetNames(); Logger.LogInformation("Filter names : {Names}", names); var offsets = filterWheel.GetFocusOffsets(); Logger.LogInformation("Filter offsets : {Offsets}", offsets); var position = filterWheel.GetPosition(); Logger.LogInformation("Current position : {Position}", position); Logger.LogInformation("Set filter position"); filterWheel.SetPosition(2); position = filterWheel.GetPosition(); Logger.LogInformation("Current position : {Position}", position); try { filterWheel.SetPosition(1000); } catch (Exception e) { Logger.LogError(e, e.Message); } Logger.LogInformation("END CallDeviceMethods"); }
public T CreateDeviceInstance <T>(DeviceConfiguration configuration) where T : IDevice { Type deviceType = typeof(T); switch (deviceType.Name) { case nameof(FilterWheel): IDevice device = new FilterWheel(configuration, _clientTransactionIdGenerator); return((T)device); case nameof(SafetyMonitor): IDevice safetyMonitor = new SafetyMonitor(configuration, _clientTransactionIdGenerator); return((T)safetyMonitor); case nameof(Dome): IDevice dome = new Dome(configuration, _clientTransactionIdGenerator); return((T)dome); case nameof(Camera): IDevice camera = new Camera(configuration, _clientTransactionIdGenerator); return((T)camera); case nameof(Focuser): IDevice focuser = new Focuser(configuration, _clientTransactionIdGenerator); return((T)focuser); case nameof(ObservingConditions): IDevice observingConditions = new ObservingConditions(configuration, _clientTransactionIdGenerator); return((T)observingConditions); case nameof(Rotator): IDevice rotator = new Rotator(configuration, _clientTransactionIdGenerator); return((T)rotator); case nameof(Switch): IDevice @switch = new Switch(configuration, _clientTransactionIdGenerator); return((T)@switch); case nameof(Telescope): IDevice telescope = new Telescope(configuration, _clientTransactionIdGenerator); return((T)telescope); default: throw new InvalidOperationException($"Type {deviceType.Name} is not supported"); } }
public async Task IsConnectedAsync_SendValidRequest() { //Arrange string commandName = "connected"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequestAsync <BoolResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(Task.FromResult(new BoolResponse(false))); var device = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act await device.IsConnectedAsync(); //Assert Assert.Equal(Method.GET, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); }
public void GetName_SendValidRequest() { //Arrange string commandName = "name"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequest <StringResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(new StringResponse("test")); var device = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act device.GetName(); //Assert Assert.Equal(Method.GET, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); }
public async Task GetNamesAsync_SendValidRequest() { //Arrange string commandName = "names"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequestAsync <StringListResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(Task.FromResult(new StringListResponse(new List <string> { "test" }))); var filterWheel = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act await filterWheel.GetNamesAsync(); //Assert Assert.Equal(Method.GET, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); }
public void GetFocusOffsets_SendValidRequest() { //Arrange string commandName = "focusoffsets"; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequest <IntListResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(new IntListResponse(new List <int> { 1 })); var filterWheel = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act filterWheel.GetFocusOffsets(); //Assert Assert.Equal(Method.GET, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); }
public async Task <bool> Connect(CancellationToken token) { return(await Task <bool> .Run(() => { try { _filterwheel = new FilterWheel(Id); Connected = true; if (Connected) { init(); RaiseAllPropertiesChanged(); } } catch (ASCOM.DriverAccessCOMException ex) { Utility.Utility.HandleAscomCOMException(ex); } catch (System.Runtime.InteropServices.COMException ex) { Utility.Utility.HandleAscomCOMException(ex); } catch (Exception ex) { Logger.Error(ex); Notification.ShowError("Unable to connect to filter wheel " + ex.Message); } return Connected; })); }
public async Task SetPositionAsync_SendValidRequest() { //Arrange string commandName = "position"; string positionParameterName = "Position"; int positionParameterValue = 2; IRestRequest sentRequest = null; var commandSenderMock = new Mock <ICommandSender>(); commandSenderMock .Setup(x => x.ExecuteRequestAsync <CommandResponse>(It.IsAny <string>(), It.IsAny <RestRequest>())) .Callback((string baseUrl, IRestRequest request) => sentRequest = request) .Returns(Task.FromResult(new CommandResponse())); var filterWheel = new FilterWheel(_deviceConfiguration, commandSenderMock.Object); //Act await filterWheel.SetPositionAsync(positionParameterValue); //Assert Assert.Equal(Method.PUT, sentRequest.Method); AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName); AssertParameter(sentRequest.Parameters, positionParameterName, positionParameterValue); }
public void SetupDialog() { if (HasSetupDialog) { try { bool dispose = false; if (_filterwheel == null) { _filterwheel = new FilterWheel(Id); dispose = true; } _filterwheel.SetupDialog(); if (dispose) { _filterwheel.Dispose(); _filterwheel = null; } } catch (Exception ex) { Logger.Error(ex); Notification.ShowError(ex.Message); } } }
static void Main(string[] args) { string progID; Util U = new Util(); #region Focuser Console.WriteLine("\r\nFocuser:"******"ASCOM.Simulator.Focuser"); // Pre-select simulator (typ.) if (progID != "") { Focuser F = new Focuser(progID); F.Link = true; Console.WriteLine(" Connected to " + progID); Console.WriteLine(" Current position is " + F.Position); int nfp = (int)(0.7 * F.Position); Console.Write(" Moving to " + nfp); F.Move(nfp); while (F.IsMoving) { Console.Write("."); U.WaitForMilliseconds(333); } Console.WriteLine("\r\n Move complete. New position is " + F.Position.ToString()); F.Link = false; F.Dispose(); // Release this now, not at exit (typ.) } #endregion #region FilterWheel Console.WriteLine("\r\nFilterWheel:"); progID = FilterWheel.Choose("ASCOM.Simulator.FilterWheel"); if (progID != "") { FilterWheel fw = new FilterWheel(progID); fw.Connected = true; Console.WriteLine(" Position = " + fw.Position); string[] names = fw.Names; Console.WriteLine(" There are " + names.Length + " filters:\r\n "); for (int i = 0; i < names.Length; i++) { Console.Write(names[i] + " "); } Console.WriteLine(""); fw.Connected = false; fw.Dispose(); } #endregion #region Rotator Console.WriteLine("\r\nRotator:"); progID = Rotator.Choose("ASCOM.Simulator.Rotator"); if (progID != "") { Rotator R = new Rotator(progID); R.Connected = true; Console.WriteLine(" Position = " + R.Position); float np = R.Position + 60; if (np >= 360) { np -= 360; } Console.Write(" Rotating to " + np.ToString("0")); R.MoveAbsolute(np); while (R.IsMoving) { Console.Write("."); U.WaitForMilliseconds(300); } Console.WriteLine("\r\n Rotation complete."); R.Connected = false; R.Dispose(); } #endregion #region Dome /* * Console.WriteLine("\r\nDome:"); * progID = Dome.Choose("ASCOM.Simulator.Dome"); * if (progID != "") * { * Dome D = new Dome(progID); * D.Connected = true; * Console.WriteLine(" Description = " + D.Description); * Console.WriteLine(" Name = " + D.Name); * if (D.CanSetAzimuth) * { * Console.WriteLine(" This is a rotatable dome"); * Console.WriteLine(" Current slit azimuth = " + D.Azimuth.ToString("0.0")); * double z = D.Azimuth + 60; * if (z >= 360) z -= 360; * D.SlewToAzimuth(z); * Console.Write(" Rotating to azimuth " + z.ToString("0")); * while (D.Slewing) * { * Console.Write("."); * U.WaitForMilliseconds(300); * } * Console.WriteLine("\r\n Rotation complete."); * } * if (D.CanSetShutter) * { * if (D.CanSetAzimuth) * Console.WriteLine(" This dome has a controllable shutter"); * else * Console.WriteLine(" This is a roll-off roof"); * Console.WriteLine(" It is currently " + D.ShutterStatus.ToString()); * switch (D.ShutterStatus) * { * case ShutterState.shutterClosed: * Console.Write(" Opening"); * D.OpenShutter(); * while (D.ShutterStatus != ShutterState.shutterOpen && * D.ShutterStatus != ShutterState.shutterError) * { * Console.Write("."); * U.WaitForMilliseconds(300); * } * Console.WriteLine("\r\n It is now " + D.ShutterStatus.ToString()); * break; * case ShutterState.shutterOpen: * Console.Write(" Closing"); * D.CloseShutter(); * while (D.ShutterStatus != ShutterState.shutterClosed && * D.ShutterStatus != ShutterState.shutterError) * { * Console.Write("."); * U.WaitForMilliseconds(300); * } * Console.WriteLine("\r\n It is now " + D.ShutterStatus.ToString()); * break; * case ShutterState.shutterError: * Console.WriteLine(" ** cannot do anything right now **"); * break; * default: * Console.WriteLine(" ** it's moving so can't do anythjing else now **"); * break; * } * } * D.Connected = false; * D.Dispose(); * } */ #endregion #region Telescope /* * Console.WriteLine("\r\nTelescope:"); * progID = Telescope.Choose("ASCOM.Simulator.Telescope"); * if (progID != "") * { * Telescope T = new Telescope(progID); * T.Connected = true; * Console.WriteLine(" Connected to " + progID); * Console.WriteLine(" Current LST = " + U.HoursToHMS(T.SiderealTime)); * Console.WriteLine(" Current RA = " + U.HoursToHMS(T.RightAscension)); * Console.WriteLine(" Current DEC = " + U.DegreesToDMS(T.Declination)); * Console.WriteLine(" CanSetTracking = " + T.CanSetTracking); * if (T.CanSetTracking) * { * Console.WriteLine(" Turning Tracking off..."); * T.Tracking = false; * Console.WriteLine(" Tracking is now " + (T.Tracking ? "on" : "off") + "."); * Console.WriteLine(" Wait 5 seconds..."); * U.WaitForMilliseconds(5000); * Console.WriteLine(" Turning Tracking back on..."); * T.Tracking = true; * } * Console.WriteLine(" Latitude = " + U.DegreesToDMS(T.SiteLatitude)); * Console.WriteLine(" Longitude = " + U.DegreesToDMS(T.SiteLongitude)); * Console.Write(" Slewing to point 1"); * T.SlewToCoordinatesAsync(T.SiderealTime - 2, (T.SiteLatitude > 0 ? +55 : -55)); * while (T.Slewing) * { * Console.Write("."); * U.WaitForMilliseconds(300); * } * Console.WriteLine("\r\n Slew complete."); * Console.Write(" Slewing to point 2"); * T.SlewToCoordinatesAsync(T.SiderealTime + 2, (T.SiteLatitude > 0 ? +35 : -35)); * while (T.Slewing) * { * Console.Write("."); * U.WaitForMilliseconds(300); * } * Console.WriteLine("\r\n Slew complete."); * IAxisRates AxR = T.AxisRates(TelescopeAxes.axisPrimary); * Console.WriteLine(" " + AxR.Count + " rates"); * if (AxR.Count == 0) * Console.WriteLine(" Empty AxisRates"); * else * foreach (IRate r in AxR) * Console.WriteLine(" Max=" + r.Maximum + " Min=" + r.Minimum); * ITrackingRates TrR = T.TrackingRates; * if (TrR.Count == 0) * Console.WriteLine(" Empty TrackingRates!"); * else * foreach (DriveRates dr in TrR) * Console.WriteLine(" DriveRate=" + dr); * T.Connected = false; * T.Dispose(); * } */ #endregion #region Camera /* * Console.WriteLine("\r\nCamera:"); * progID = Camera.Choose("ASCOM.Simulator.Camera"); * if (progID != "") * { * Camera C = new Camera(progID); * C.Connected = true; * Console.WriteLine(" Connected to " + progID); * Console.WriteLine(" Description = " + C.Description); * Console.WriteLine(" Pixel size = " + C.PixelSizeX + " * " + C.PixelSizeY); * Console.WriteLine(" Camera size = " + C.CameraXSize + " * " + C.CameraYSize); * Console.WriteLine(" Max Bin = " + C.MaxBinX + " * " + C.MaxBinY); * Console.WriteLine(" Bin = " + C.BinX + " * " + C.BinY); * Console.WriteLine(" MaxADU = " + C.MaxADU); * Console.WriteLine(" CameraState = " + C.CameraState.ToString()); * Console.WriteLine(" CanAbortExposure = " + C.CanAbortExposure); * Console.WriteLine(" CanAsymmetricBin = " + C.CanAsymmetricBin); * Console.WriteLine(" CanGetCoolerPower = " + C.CanGetCoolerPower); * Console.WriteLine(" CanPulseGuide = " + C.CanPulseGuide); * Console.WriteLine(" CanSetCCDTemperature = " + C.CanSetCCDTemperature); * Console.WriteLine(" CanStopExposure = " + C.CanStopExposure); * Console.WriteLine(" CCDTemperature = " + C.CCDTemperature); * if (C.CanGetCoolerPower) * Console.WriteLine(" CoolerPower = " + C.CoolerPower); * Console.WriteLine(" ElectronsPerADU = " + C.ElectronsPerADU); * Console.WriteLine(" FullWellCapacity = " + C.FullWellCapacity); * Console.WriteLine(" HasShutter = " + C.HasShutter); * Console.WriteLine(" HeatSinkTemperature = " + C.HeatSinkTemperature); * if (C.CanPulseGuide) * Console.WriteLine(" IsPulseGuiding = " + C.IsPulseGuiding); * Console.Write(" Take 15 second image"); * C.StartExposure(15.0, true); * while (!C.ImageReady) * { * Console.Write("."); * U.WaitForMilliseconds(300); * } * Console.WriteLine("\r\n Exposure complete, ready for download."); * Console.WriteLine(" CameraState = " + C.CameraState.ToString()); * Console.WriteLine(" LastExposureDuration = " + C.LastExposureDuration); * Console.WriteLine(" LastExposureStartTime = " + C.LastExposureStartTime); * int[,] imgArray = (int[,])C.ImageArray; * Console.WriteLine(" Array is " + (imgArray.GetUpperBound(0) + 1) + " by " + (imgArray.GetUpperBound(1) + 1)); * C.Connected = false; * C.Dispose(); * } */ #endregion Console.Write("\r\nPress enter to quit..."); Console.ReadLine(); }
protected override void ProcessRecord() { m_filterWheel = new FilterWheel(m_driverId); WriteObject(m_filterWheel); }
public void FilterWheelChooser() { ASCOM.Utilities.Chooser chooser = new ASCOM.Utilities.Chooser(); chooser.DeviceType = "FilterWheel"; devId3 = chooser.Choose(); // ASCOM.DriverAccess.Focuser focuser = new ASCOM.DriverAccess.Focuser(devId2); if (devId3 != "") filterWheel = new FilterWheel(devId3); else return; filterWheel.Connected = true; Log("filterwheel connected " + devId3); FileLog2("filterwheel connected " + devId3); buttonFilterConnect.BackColor = System.Drawing.Color.Lime; if (!checkBox31.Checked) filterWheel.Position = 0; DisplayCurrentFilter(); if (!checkBox31.Checked) { foreach (string filter in filterWheel.Names) comboBox6.Items.Add(filter); comboBox6.SelectedItem = filterWheel.Position; ComboBoxFill(); } }
public FilterWheelSpecificMethodsApiTests() { instance = new FilterWheel("http://localhost:5000/api/v1/"); }
private async Task CallDeviceMethodsAsync(FilterWheel filterWheel) { Logger.LogInformation("START CallDeviceMethodsAsync"); Logger.LogInformation("Connect Filter wheel"); var setConnectedAsyncTask = filterWheel.SetConnectedAsync(true); ContinueTask(setConnectedAsyncTask); var isConnectedAsyncTask = filterWheel.IsConnectedAsync(); ContinueTask(isConnectedAsyncTask); Logger.LogInformation("Call GetNameAsync"); var getNameAsyncTask = filterWheel.GetNameAsync(); ContinueTask(getNameAsyncTask); Logger.LogInformation("Call GetDescriptionAsync"); var getDescriptionAsyncTask = filterWheel.GetDescriptionAsync(); ContinueTask(getDescriptionAsyncTask); Logger.LogInformation("Call GetDriverInfoAsync"); var getDriverInfoAsyncTask = filterWheel.GetDriverInfoAsync(); ContinueTask(getDriverInfoAsyncTask); Logger.LogInformation("Call GetDriverVersionAsync"); var getDriverVersionAsyncTask = filterWheel.GetDriverVersionAsync(); ContinueTask(getDriverVersionAsyncTask); Logger.LogInformation("Call GetNamesAsync"); var getNamesAsyncTask = filterWheel.GetNamesAsync(); ContinueTask(getNamesAsyncTask); Logger.LogInformation("Call GetFocusOffsetsAsync"); var getFocusOffsetsAsyncTask = filterWheel.GetFocusOffsetsAsync(); ContinueTask(getFocusOffsetsAsyncTask); Logger.LogInformation("Call SetPositionAsync(2)"); var setPositionAsync2Task = filterWheel.SetPositionAsync(2); ContinueTask(setPositionAsync2Task); Logger.LogInformation("Call GetPositionAsync"); var getPositionAsyncTask = filterWheel.GetPositionAsync(); ContinueTask(getPositionAsyncTask); Logger.LogInformation("Call SetPositionAsync(1000)"); var setPositionAsync1000Task = filterWheel.SetPositionAsync(1000); ContinueTask(setPositionAsync1000Task); await Task.WhenAll(setConnectedAsyncTask, isConnectedAsyncTask, getNameAsyncTask, getDescriptionAsyncTask, getDriverInfoAsyncTask, getDriverVersionAsyncTask, getNamesAsyncTask, getFocusOffsetsAsyncTask, setPositionAsync2Task, getPositionAsyncTask, setPositionAsync1000Task); Logger.LogInformation("END CallDeviceMethodsAsync"); }