Пример #1
0
        /////////////////////////////////
        // Delegate Functions:
        /////////////////////////////////

        // Temporary functions:
        public void SetCommandWindowText(string strCommand)
        {
            if (!(mpForm.mbIsClosing))
            {
                SetCommandWindowDelegate pDelegate = new SetCommandWindowDelegate(mpForm.SetCommandWindowText);
                mpForm.Invoke(pDelegate, new object[] { strCommand });
            }
        }
Пример #2
0
        public override void ProcessReply(string strReply, eCommandType eType)
        {
            // Temp: Show the replies in the command window box:
            if (!(mpForm.IsClosing))
            {
                SetCommandWindowDelegate pDelegate = new SetCommandWindowDelegate(mpForm.SetCommandWindowText);
                mpForm.Invoke(pDelegate, new object[] { strReply });
            }

            // Handle special (non-supported command) cases first
            if (eType == eCommandType.ScanStart)
            {
                // We are starting a scan.  Make a new entry in the database for the scan and for the settings
                cDatabaseItem dbiCommand = new cDatabaseItem(eDBCommandType.ScanStart);
                mDatabaseQueue.Add(dbiCommand);
                SettingsChanged();

                mbScanning = true;
            }
            else if (eType == eCommandType.ScanStop)
            {
                // The scan has stopped, note so
                cDatabaseItem dbiCommand = new cDatabaseItem(eDBCommandType.ScanStop);
                mDatabaseQueue.Add(dbiCommand);

                mbScanning = false;
                base.ScanComplete();
            }
            else if (eType == eCommandType.Rescan)
            {
                Scan();
            }
            else
            {
                // Init vars
                int iValue;
                char cFirstCharacter = strReply[0];
                strReply = strReply.Remove(0, 1);

                // If we reach this point, we either have a data point, or a setting change.  The majority
                // of times we come in here will be for data points but the majority of the code below is
                // for settings changes.
                bool bSettingsChanged = true;

                // Ready for a long set of if statments?  Go!
                if (cFirstCharacter == 'A')         // IF Gain
                {
                    iValue = HexStringToInt(strReply);
                    mdIFGain = 10 + iValue * 0.25;
                }
                else if (cFirstCharacter == 'B')    // Change of Bandwidth (not all SpectraCyber 1 units support this command.
                {
                    int iIndex = int.Parse(strReply);
                    miBandwidth = marrBandwithValues[iIndex];
                }
                else if (cFirstCharacter == 'D')    // Data point
                {
                    // eCommandType.DataRequests and eCommandType.DataDiscards get us into this block
                    // Neither of which is a settings change
                    bSettingsChanged = false;

                    // Data requests are the only data command that is processed.
                    if(eType == eCommandType.DataRequest)
                    {
                        // A few more vars:
                        int iVoltage = HexStringToInt(strReply);
                        double dVoltage = Math.Round(iVoltage * mdVoltageStepSize, 6);
                        double dFrequency = 0;

                        // Setup the vars for the database item a little more
                        string[] arrFields = new string[] { "fFrequency", "fValue" };
                        string[] arrValues;
                        eDBCommandType eDBType = eDBCommandType.Data;

                        // Now, build the values for the database item, Continuum and Spectrum modes do this differently.
                        if (meMode == enumMode.Continuum)
                            arrValues = new string[] { null, dVoltage.ToString() };
                        else
                        {
                            // Calculate the observation frequency:
                            dFrequency = 1000 * mdPLLFrequency + 1371805;  // In GHz
                            arrValues = new string[] { dFrequency.ToString(), dVoltage.ToString() };
                        }

                        if (!(mpForm.IsClosing))
                        {
                            VoltageTextboxDelegate pDelegate = new VoltageTextboxDelegate(mpForm.SetVoltageTextbox);
                            mpForm.Invoke(pDelegate, new object[] { dVoltage.ToString() });

                            FrequencyTextboxDelegate pFreqDelegate = new FrequencyTextboxDelegate(mpForm.SetFrequencyTextbox);
                            mpForm.Invoke(pFreqDelegate, new object[] { dFrequency.ToString() });
                        }

                        cDatabaseItem dbiCommandItem = new cDatabaseItem(arrFields, arrValues, eDBType);
                        mDatabaseQueue.Add(dbiCommandItem);
                    }
                }
                else if (cFirstCharacter == 'F')    // PLL Frequency Change
                {
                    iValue = HexStringToInt(strReply);
                    mdPLLFrequency = Math.Round(46 + ((iValue - .05) / 200), 3);
                }
                else if (cFirstCharacter == 'G')    // Continuum DC Gain
                {
                    int iIndex = int.Parse(strReply);
                    miContinuumGain = marrGainValues[iIndex];
                }
                else if (cFirstCharacter == 'I')    // Continuum Integration Setting
                {
                    int iIndex = int.Parse(strReply);
                    mdContinuumIntegration = marrContinuumIntegrationValues[iIndex];
                }
                else if (cFirstCharacter == 'J')    // Spectrum DC Voltage Offset
                {
                    iValue = HexStringToInt(strReply);
                    mdDCOffsetSpec = iValue * mdDCOffsetStepSize;
                }
                else if (cFirstCharacter == 'K')    // Spectrometer DC Gain
                {
                    int iIndex = int.Parse(strReply);
                    miSpectrumGain = marrGainValues[iIndex];
                }
                else if (cFirstCharacter == 'L')    // Spectrometer Integration Setting
                {
                    int iIndex = int.Parse(strReply);
                    mdSpectrumIntegration = marrSpectrumIntegrationValues[iIndex];
                }
                else if (cFirstCharacter == 'N')    // Noise Source Status changed
                {
                    bool bNoiseSourceOn = false;

                    if (strReply[2] == 1)   // Look at the last character in the string
                        mbNoiseSourceStatus = true;

                    mbNoiseSourceStatus = bNoiseSourceOn;
                }
                else if (cFirstCharacter == 'O')    // Continuum DC Voltage Offset
                {
                    iValue = HexStringToInt(strReply);
                    mdDCOffsetCont = iValue * mdDCOffsetStepSize;
                }
                else if (cFirstCharacter == 'R')    // SpectraCyber Reset.
                {
                    mcommCommunication.Reset();
                    InitDatamembers();

                    // Even though the settings have been changed we don't invoke the SettingsChanged method
                    // The eCommandType.ScanStart "command" takes care of sending the settings off to the database
                    bSettingsChanged = false;
                }
                else // The command is not implemented.  There is not a settings change associated with this item.
                {
                    // System.Windows.Forms.MessageBox.Show("The specified command is not implemented for this unit.  Please verify the command structure.");
                    bSettingsChanged = false;
                }

                // If some setting on the SpectraCyber has changed, update all of the settings.
                if (bSettingsChanged && mbScanning)
                    SettingsChanged();

            }
        }
 // Temporary functions:
 public void SetCommandWindowText(string strCommand)
 {
     if (!(mpForm.IsClosing))
     {
         SetCommandWindowDelegate pDelegate = new SetCommandWindowDelegate(mpForm.SetCommandWindowText);
         mpForm.Invoke(pDelegate, new object[] { strCommand });
     }
 }