//
        // Constructor - Must be public for COM registration!
        //
        public Telescope()
        {
            m_AxisRates     = new AxisRates[3];
            m_AxisRates[0]  = new AxisRates(TelescopeAxes.axisPrimary);
            m_AxisRates[1]  = new AxisRates(TelescopeAxes.axisSecondary);
            m_AxisRates[2]  = new AxisRates(TelescopeAxes.axisTertiary);
            m_TrackingRates = new TrackingRates();


            profile.DeviceType = "Telescope";

            try
            {
                this.comPort = profile.GetValue(ASCOM.Arduino.Telescope.s_csDriverID, "ComPort");
            }
            catch
            {
                this.comPort = null;
            }


            SerialConnection          = new ASCOM.Utilities.Serial();
            SerialConnection.PortName = this.comPort;
            SerialConnection.StopBits = SerialStopBits.One;
            SerialConnection.Parity   = SerialParity.None;
            SerialConnection.Speed    = SerialSpeed.ps9600;
        }
예제 #2
0
        private void checkbtn_Click(object sender, EventArgs e)
        {
            port          = new ASCOM.Utilities.Serial();
            port.PortName = comboBoxComPort.SelectedItem.ToString();
            port.Speed    = (SerialSpeed)9600;
            port.StopBits = SerialStopBits.One;
            port.DataBits = 8;
            port.Parity   = SerialParity.None;

            try
            {
                port.Connected = true;
                byte[] request = new byte[6] {
                    0xA5, 0x3, 0x2, 0x0, 0x0, 0xAA
                };
                port.TransmitBinary(request);
                port.ReceiveTimeoutMs = 100;
                byte[] receive = port.ReceiveCountedBinary(6);
                txtConnect.AppendText("Connected");
                cmdOK.Enabled  = true;
                port.Connected = false;
            }
            catch
            {
                MessageBox.Show("No SBIG CFW-10 filter wheel found on current COM port!", "ASCOM Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        static uint getSetPos(ASCOM.Utilities.Serial sp)
        {
            sp.TransmitBinary(LinShengStepMotor.cmd_query_setpos);
            byte[] resp = sp.ReceiveCountedBinary(7);
            uint   pos  = LinShengStepMotor.extrace_query_response_value_0_3(resp);

            return(pos);
        }
예제 #4
0
        public static void moveAndWaitStep(bool add, uint nstep, ASCOM.Utilities.Serial port)
        {
            byte[] cmd = add ? LinShengStepMotor.cmd_acc_add_relative_position(nstep) :
                         LinShengStepMotor.cmd_acc_sub_relative_position(nstep);

            port.TransmitBinary(cmd);

            waitForFinish(port);
        }
예제 #5
0
 public void Dispose()
 {
     // Clean up the tracelogger and util objects
     tl.Enabled = false;
     tl.Dispose();
     tl = null;
     utilities.Dispose();
     utilities = null;
     astroUtilities.Dispose();
     astroUtilities = null;
     objSerial.Dispose();
     objSerial = null;
 }
예제 #6
0
        private ASCOM.Utilities.Serial OpenPort(string portName)
        {
            ASCOM.Utilities.Serial port = new ASCOM.Utilities.Serial();
            port.PortName       = portName;
            port.DTREnable      = false;
            port.RTSEnable      = false;
            port.ReceiveTimeout = 10000;

            port.Speed     = SerialSpeed.ps19200;
            port.Connected = true;
            port.ClearBuffers();

            return(port);
        }
예제 #7
0
 private void buttonConnect_Click(object sender, EventArgs e)
 {
     if (IsConnected)
     {
         driver.Connected = false;
     }
     else
     {
         driver                 = new ASCOM.DriverAccess.FilterWheel(Properties.Settings.Default.DriverId);
         driver.Connected       = true;
         serPort                = new ASCOM.Utilities.Serial();
         serPort.ReceiveTimeout = 15;
         serPort.Port           = 2;
         serPort.Speed          = (SerialSpeed)9600;
         serPort.StopBits       = SerialStopBits.One;
         serPort.DataBits       = 8;
         serPort.Parity         = SerialParity.None;
         serPort.Connected      = true;
         serPort.ClearBuffers();
     }
     SetUIState();
 }
예제 #8
0
        // The following helper methods make the code more readable and eliminate redundant statements.
        // Notice that I also added a try/catch around the port connection to fail cleanly and log the failure.
        // I also added code to dispose and null each of the ports when they are closed.

        private bool Connect()
        {
            tl.LogMessage("Connected Set", "Connecting to port " + StepperComPort);
            //set the stepper motor connection
            try
            {
                pkstepper = OpenPort(StepperComPort);

                //the stepper needs to be initialised on connection to avoid failure linked to a previous goto when a system wide
                //restart of equipment is required.

                initialise_stepper();

                // set the compass (now encoder) connection
                pkcompass = OpenPort(CompassComPort);
                pkShutter = OpenPort(ShutterComPort);

                return(true);    //pk added cos of build error not all code paths return a value
            }
            catch (Exception ex)
            {
                tl.LogMessage("Connected Set", "Unable to connect to COM ports " + ex.ToString());

                if (pkstepper != null)
                {
                    DisconnectPort(pkstepper);
                }

                if (pkcompass != null)
                {
                    DisconnectPort(pkcompass);
                }
                if (pkShutter != null)
                {
                    DisconnectPort(pkShutter);
                }
                return(false);   //pk added cos of build error not all code paths return a value
            }
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DrFocuser"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public Focuser()
        {
            tl = new TraceLogger("", "DrFocuser");
            ReadProfile(); // Read device configuration from the ASCOM Profile store

            tl.LogMessage("Focuser", "Starting initialisation");

            connectedState = false;            // Initialise connected to false
            utilities      = new Util();       //Initialise util object
            astroUtilities = new AstroUtils(); // Initialise astro utilities object

            //TODO: Implement your additional construction here
            SerialConnection           = new ASCOM.Utilities.Serial();
            SerialConnection.PortName  = comPort;
            SerialConnection.StopBits  = SerialStopBits.One;
            SerialConnection.Parity    = SerialParity.None;
            SerialConnection.Speed     = SerialSpeed.ps115200;
            SerialConnection.DataBits  = 8;
            SerialConnection.Connected = true;

            SerialConnection.Transmit("P#");

            tl.LogMessage("Focuser", "Completed initialisation on " + comPort);
        }
예제 #10
0
        static void waitForFinish(ASCOM.Utilities.Serial myPort)
        {
            uint      curpos = 0;
            uint      setpos = 0;
            SpeedInfo spd    = getCurrentSpeed(myPort);

            for (int i = 0; i < 10000000; i++)
            {
                curpos = getCurPos(myPort);
                setpos = getSetPos(myPort);
                //spd = getCurrentSpeed(myPort);

                // Console.WriteLine("即时运行位置:" + curpos + " 设定运行位置:" + setpos + " 速度倍数:" + spd.level + " 速度单位毫秒:" + spd.speed);

                if (curpos == setpos)
                {
                    //  Console.WriteLine("到达目标位置");
                    break;
                }

                uint wt = (setpos > curpos ? (setpos - curpos) : (curpos - setpos)) * spd.speed / 1000 + 2000;
                Thread.Sleep((int)wt);
            }
        }
        //
        // Constructor - Must be public for COM registration!
        //
        public Telescope()
        {
            m_AxisRates = new AxisRates[3];
            m_AxisRates[0] = new AxisRates(TelescopeAxes.axisPrimary);
            m_AxisRates[1] = new AxisRates(TelescopeAxes.axisSecondary);
            m_AxisRates[2] = new AxisRates(TelescopeAxes.axisTertiary);
            m_TrackingRates = new TrackingRates();

            profile.DeviceType = "Telescope";

            try
            {
                this.comPort = profile.GetValue(ASCOM.Arduino.Telescope.s_csDriverID, "ComPort");
            }
            catch
            {
                this.comPort = null;
            }

            SerialConnection = new ASCOM.Utilities.Serial();
            SerialConnection.PortName = this.comPort;
            SerialConnection.StopBits = SerialStopBits.One;
            SerialConnection.Parity = SerialParity.None;
            SerialConnection.Speed = SerialSpeed.ps9600;
        }
 public void Dispose()
 {
     // Clean up the tracelogger and util objects
     tl.Enabled = false;
     tl.Dispose();
     tl = null;
     utilities.Dispose();
     utilities = null;
     astroUtilities.Dispose();
     astroUtilities = null;
     objSerial.Dispose();
     objSerial = null;
 }
 public BusInterface()
 {
     asport = new ASCOM.Utilities.Serial();
 }
예제 #14
0
 private void DisconnectPort(ASCOM.Utilities.Serial port)
 {
     port.Connected = false;
     port.Dispose();
     port = null;
 }
예제 #15
0
 static SpeedInfo getCurrentSpeed(ASCOM.Utilities.Serial sp)
 {
     sp.TransmitBinary(LinShengStepMotor.cmd_query_cur_speed);
     byte[] resp = sp.ReceiveCountedBinary(6);
     return(LinShengStepMotor.extrace_query_response_speed(resp));
 }
예제 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StellarFocus"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public Focuser()
        {
            ReadProfile(); // Read device configuration from the ASCOM Profile store

            tl = new TraceLogger("", "StellarFocus");
            tl.Enabled = traceState;
            tl.LogMessage("Focuser", "Starting initialisation");

            connectedState = false; // Initialise connected to false
            utilities = new Util(); //Initialise util object
            astroUtilities = new AstroUtils(); // Initialise astro utilities object
            serialPort = new ASCOM.Utilities.Serial();

            ConnectStatus = 0;
            Homing = false;

            tl.LogMessage("Focuser", "Completed initialisation");
        }