Exemplo n.º 1
0
        private void btnFocusPlus_Click(object sender, EventArgs e)
        {
            // 正向调焦
            string value = txtInFocus.Text; // 容错: 须判断数据格式是整数

            if (value == "")
            {
                return;
            }

            int position = Convert.ToInt32(value);

            if (chkAbsFocus.Checked == true) // 需要绝对定位, 不论加\减, 都是相同操作
            {
                lblFocusTarget.Text = Convert.ToString(position);
                if (focuser_.Absolute == false) // 不支持绝对定位
                {
                    position = position - focuser_.Position;
                }
            }
            else // 需要相对定位, 与加\减符号有关
            {
                if (focuser_.Absolute == true) // 不支持相对定位
                {
                    position = focuser_.Position + position;
                }
                lblFocusTarget.Text = Convert.ToString(position);
            }
            focuser_.Move(position);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                var progId = Focuser.Choose(string.Empty);
                var driver = new Focuser(progId);
                var thing = driver.IsMoving;				// Just to give a place to set a breakpoint.
                driver.SetupDialog();
                while (Console.ReadLine() != "e")
                {
                    driver.Link = true;
                    driver.TempComp = true;
                    Console.WriteLine("In temp comp mode");

                    Console.WriteLine("IsMoving = " + driver.IsMoving.ToString());
                    Console.WriteLine("Moving to 3500...");
                    try{
                    driver.Move((int)3500);
                    }
                    catch{
                        Console.WriteLine("Exception thrown as expected!");
                    }
                    driver.TempComp = false;

                    Console.WriteLine("Moving to 3500...");
                    driver.Move((int)3500);
                    Console.WriteLine("IsMoving = " + driver.IsMoving.ToString());
                    Console.WriteLine("Current Position = " + driver.Position.ToString());
                    Console.WriteLine("Moving to 1000...");
                    driver.Move((int)1000);
                    Console.WriteLine("IsMoving = " + driver.IsMoving.ToString());
                    Console.WriteLine("Current Position = " + driver.Position.ToString());
                    Console.WriteLine("Moving to 3000...");
                    driver.Move((int)3000);
                    Console.WriteLine("IsMoving = " + driver.IsMoving.ToString());
                    Console.WriteLine("Current Position = " + driver.Position.ToString());
                    while (driver.IsMoving) { }
                    driver.Link = false;
                    Console.WriteLine("Current Position = " + driver.Position.ToString());
                    Console.WriteLine("IsMoving = " + driver.IsMoving.ToString());
                    Console.WriteLine("Press ESC key to exit");
                }

                //Console.ReadLine();
            }
            catch (Exception ex)
            {
                EventLogger.LogMessage(ex);
                Debug.Print(ex.Message);
            }
        }
Exemplo n.º 3
0
 //指定位置移动
 public void FocuserMoveToPos(double targetPos)
 {
     try
     {
         targetPos *= 1000;
         targetPos  = System.Math.Round(targetPos);
         if (m_focuser != null && m_focuser.Connected == true)
         {
             m_focuser.Move((int)targetPos);
         }
     }
     catch (System.Exception ex)
     {
         m_focuser          = null;
         m_focParams.errMsg = ex.Message;
     }
 }
Exemplo n.º 4
0
 private void bSetPosition_Click(object sender, EventArgs e)
 {
     bSetPosition.Text = "Position=" + focus.Position;
     focus.Move(Int32.Parse(tbPosition.Text));
     while (focus.IsMoving)
     {
         System.Threading.Thread.Sleep(200);
     }
     bSetPosition.Text = "Position=" + focus.Position;
 }
Exemplo n.º 5
0
        public async Task <int> MoveFocuser(int position, CancellationToken ct)
        {
            int pos = -1;

            await Task.Run(async() => {
                try {
                    using (ct.Register(() => HaltFocuser())) {
                        var tempComp = false;
                        if (Focuser.TempCompAvailable && Focuser.TempComp)
                        {
                            tempComp = true;
                            ToggleTempComp(false);
                        }

                        Logger.Info($"Moving Focuser to position {position}");
                        progress.Report(new ApplicationStatus()
                        {
                            Status = string.Format(Locale.Loc.Instance["LblFocuserMoveToPosition"], position)
                        });

                        while (Focuser.Position != position)
                        {
                            FocuserInfo.IsMoving = true;
                            ct.ThrowIfCancellationRequested();
                            await Focuser.Move(position, ct);
                        }

                        FocuserInfo.Position = this.Position;
                        pos = this.Position;
                        ToggleTempComp(tempComp);
                        BroadcastFocuserInfo();

                        //Wait for focuser to settle
                        if (profileService.ActiveProfile.FocuserSettings.FocuserSettleTime > 0)
                        {
                            FocuserInfo.IsSettling = true;
                            await Utility.Utility.Wait(TimeSpan.FromSeconds(profileService.ActiveProfile.FocuserSettings.FocuserSettleTime), ct, progress, Locale.Loc.Instance["LblSettle"]);
                        }
                    }
                } catch (OperationCanceledException) {
                } finally {
                    FocuserInfo.IsSettling = false;
                    FocuserInfo.IsMoving   = false;
                    progress.Report(new ApplicationStatus()
                    {
                        Status = string.Empty
                    });
                }
            });

            return(pos);
        }
        public void Move_SendValidRequest()
        {
            //Arrange
            string       commandName            = "move";
            string       positionParameterName  = "Position";
            int          positionParameterValue = 2;
            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 focuser = new Focuser(_deviceConfiguration, commandSenderMock.Object);

            //Act
            focuser.Move(positionParameterValue);

            //Assert
            Assert.Equal(Method.PUT, sentRequest.Method);
            AssertCommonParameters(sentRequest.Parameters, _deviceConfiguration, commandName);
            AssertParameter(sentRequest.Parameters, positionParameterName, positionParameterValue);
        }
Exemplo n.º 7
0
        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();
        }