コード例 #1
0
        private void __UpdatePolledVariablesSerial()
        {

            Trace.Enter("_UpdatePolledVariablesSerial");

            string macro = "";

            //lock (m_SerialPort)
            {
                try
                {
                    DiscardInBuffer(); //clear all received data
                    string cmd = CompleteNativeCommand("<81:");
                    Transmit(cmd);
                    CommandItem command = new CommandItem("<81:", 2000, true);
                    macro = GetCommandResult(command);
                }
                catch
                {
                    return;
                }
            }

            if (macro == null)
            {
                Trace.Error("timeout", "UpdatePolledVariablesSerial");
                return;
            }

            Trace.Info(4, "Serial Macro 0 result", macro);
            _UpdatePolledVariablesFromMacro(macro);
            Trace.Exit("_UpdatePolledVariablesSerial");
        }
コード例 #2
0
        internal override void _UpdatePolledVariables()
        {
            if (GeminiLevel >= 5)
            {
                if (!CanPoll)
                {
                    Thread.Sleep(SharedResources.GEMINI_POLLING_INTERVAL / 2);
                    return; //don't tie up the serial port while pulse guiding -- timing is critical!
                }

                Trace.Enter("_UpdatePolledVariables5");
                try
                {
                    CommandItem command;
                    int timeout = 3000; // polling should not hold up the queue for too long
                    DiscardInBuffer(); //clear all received data
                    Transmit(CompleteNativeCommand("<97:"));
                    command = new CommandItem("<97:", timeout, true);
                    string change = GetCommandResult(command);
                    if (change != null && change.Length == 6)
                    {
                        m_CurrentUpdateState = change;
                    }
                }
                catch { }

                if (m_CurrentUpdateState != m_PreviousUpdateState) ProcessUpdates();

            }
            base._UpdatePolledVariables();
        }
コード例 #3
0
         /// <summary>
 /// Wait for a proper response from Gemini for a given command. Command has already been sent.
 /// 
 /// </summary>
 /// <param name="command">actual command sent to Gemini</param>
 /// <param name="bResyncOnError">true if driver should resync if an error was detected</param>
 /// <returns>result received from Gemini, or null if no result, timeout, or bad result received</returns>
 private string GetCommandResult(CommandItem command, bool bResyncOnError, ref bool bReturn)
 {
     if (m_EthernetPort)
         return GetCommandResultEthernet(command, bResyncOnError, ref bReturn);
     else
         return GetCommandResultSerial(command, bResyncOnError, ref bReturn);
 }
コード例 #4
0
        /// <summary>
        /// Wait for a proper response from Gemini for a given command. Command has already been sent.
        /// 
        /// </summary>
        /// <param name="command">actual command sent to Gemini</param>
        /// <param name="bResyncOnError">true if driver should resync if an error was detected</param>
        /// <returns>result received from Gemini, or null if no result, timeout, or bad result received</returns>
        private string GetCommandResultSerial(CommandItem command, bool bResyncOnError, ref bool bReturn)
        {
            string result = null;

            if (!m_SerialPort.IsOpen) return null;

            Trace.Enter(4, "GetCommandResult", command.m_Command);

            GeminiCommand.ResultType gemini_result = GeminiCommand.ResultType.HashChar;
            int char_count = 0;
            GeminiCommand gmc = FindGeminiCommand(command.m_Command);

            if (gmc != null)
            {
                gemini_result = gmc.Type;
                char_count = gmc.Chars;
                command.m_UpdateRequired = gmc.UpdateStatus;
            }

            // no result expected by this command, just return;
            if (gemini_result == GeminiCommand.ResultType.NoResult)
            {
                bReturn = false;
                return null;
            }
            
            bReturn = true;

            m_SerialTimeoutExpired.Reset();
            m_SerialErrorOccurred.Reset();

            if (command.m_Timeout > 0)
            {
                tmrReadTimeout.Interval = command.m_Timeout;
                tmrReadTimeout.Start();
            }

            try
            {
                Trace.Info(0, "Serial wait for response", command.m_Command);

                switch (gemini_result)
                {
                    // a specific number of characters expected as the return value
                    case GeminiCommand.ResultType.NumberofChars:
                        result = ReadNumber(char_count);
                        break;

                    // value '1' or a string terminated by '#'
                    case GeminiCommand.ResultType.OneOrHash:
                        result = ReadNumber(1); ;  // check if first character is 1, and return if it is, no hash expected
                        if (result != "1")
                        {
                            result += ReadTo('#');
                            if (command.m_Raw) //Raw should return the full string including #
                                result += "#";
                        }
                        break;

                    // value '0' or a string terminated by '#'
                    case GeminiCommand.ResultType.ZeroOrHash:
                        result = ReadNumber(1);
                        if (result != "0")
                        {
                            result += ReadTo('#');
                            if (command.m_Raw) //Raw should return the full string including #
                                result += "#";
                        }
                        break;

                    // string terminated by '#'
                    case GeminiCommand.ResultType.HashChar:
                        result = ReadTo('#');
                        if (command.m_Raw) //Raw should return the full string including #
                            result += "#";
                        break;

                    // '0' or two strings, each terminated with '#' (:SC command)
                    case GeminiCommand.ResultType.ZeroOrTwoHash:
                        result = ReadNumber(1);
                        if (result != "0")
                        {
                            result += ReadTo('#');
                            if (command.m_Raw) result += '#';
                            result += ReadTo('#');
                            if (command.m_Raw) result += '#';
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                if (m_AllowErrorNotify)
                {
                    Trace.Except(ex);
                    GeminiError.LogSerialError(SharedResources.TELESCOPE_DRIVER_NAME, "Timeout error occurred after " + command.m_Timeout + "msec while processing command '" + command.m_Command + "'");
                    if (OnError != null && m_Connected) OnError(SharedResources.TELESCOPE_DRIVER_NAME, Resources.SerialTimeout);
                }

                AddOneMoreError();

                if (bResyncOnError) Resync();


                return null;
            }
            finally
            {
                tmrReadTimeout.Stop();
            }


            if (m_SerialErrorOccurred.WaitOne(0))
            {
                Trace.Error("Communications error", command.m_Command);

                GeminiError.LogSerialError(SharedResources.TELESCOPE_DRIVER_NAME, "Comm error reported while processing command '" + command.m_Command + "'");
                if (OnError != null && m_Connected && m_AllowErrorNotify) OnError(SharedResources.TELESCOPE_DRIVER_NAME, Resources.SerialError);
                AddOneMoreError();
                return null;  // error occurred!
            }

            if (result != null)
                m_LastDataTick = DateTime.Now;      // remember when last successfull data was received.

            // return value for native commands has a checksum appended: validate it and remove it from the return string:
            if (!string.IsNullOrEmpty(result) && (command.m_Command[0] == '<' || command.m_Command[0] == '>') && !command.m_Raw)
            {
                byte chksum = (byte)result[result.Length - 1];

                result = result.Substring(0, result.Length - 1); //remove checksum character

                if ((((int)chksum) & m_ChecksumMask) != (ComputeChecksum(result) & m_ChecksumMask))  // bad checksum -- ignore the return value! 
                {
                    Trace.Error("Bad Checksum", command.m_Command, result);

                    GeminiError.LogSerialError(SharedResources.TELESCOPE_DRIVER_NAME, "Serial comm error (bad checksum) while processing command '" + command.m_Command + "'");
                    if (OnError != null && m_Connected && m_AllowErrorNotify) OnError(SharedResources.TELESCOPE_DRIVER_NAME, Resources.SerialError);
                    AddOneMoreError();
                    result = null;
                }
            }

            Trace.Info(0, "Serial received:", command.m_Command, result);
            Trace.Exit(4, "GetCommandResult", command.m_Command, result);
            return result;
        }
コード例 #5
0
 private string GetCommandResult(CommandItem command, bool bResyncOnError)
 {
     bool bReturn = false;
     return GetCommandResult(command, bResyncOnError, ref bReturn);
 }