コード例 #1
0
    public void DoConnect2()
    {
        String strPort;
        int    idx;

        idx = m_dropDownPort.value;

        strPort = m_dropDownPort.options[idx].text;

        m_objRFE = new RFECommunicator(true);
        m_objRFE.PortClosedEvent                += new EventHandler(OnRFE_PortClosed);
        m_objRFE.ReportInfoAddedEvent           += new EventHandler(OnRFE_ReportLog);
        m_objRFE.ReceivedConfigurationDataEvent += new EventHandler(OnRFE_ReceivedConfigData);
        m_objRFE.UpdateDataEvent                += new EventHandler(OnRFE_UpdateData);

        m_objRFE.ConnectPort(strPort, 500000);

        if (!m_objRFE.PortConnected)
        {
            return;
        }

        m_panelConnect.SetActive(false);

        m_objRFE.SendCommand_RequestConfigData();

        Thread.Sleep(500);


        // Set calc mode to "average"
        m_objRFE.SendCommand("C+\x02");

        if (DSP_MODE_FAST == m_iDSPMode)
        {
            // Set DSP mode to "fast"
            m_objRFE.SendCommand("Cp\x02");
        }
        else
        {
            // Set DSP mode to "filter"
            m_objRFE.SendCommand("Cp\x01");
        }


        m_iAdvanceCounter = m_iNumStepsToAdvance;

        String sRFEReceivedString;

        m_objRFE.ProcessReceivedString(true, out sRFEReceivedString);
    }
コード例 #2
0
 static bool IsIOT(string[] args)
 {
     if (args.Contains("/IOT", StringComparer.Ordinal))
     {
         //This is a Raspberry Pi with a RF Explorer IoT Hat
         g_bIoTBoard = (RFECommunicator.IsRaspberry());
         Console.WriteLine("Working in IoT - Raspberry Pi mode");
         if (!g_bIoTBoard)
         {
             Console.WriteLine("ERROR: Unrecognized Raspberry Pi platform");
             return(false);
         }
         return(true);
     }
     return(false);
 }
コード例 #3
0
        private void OnNumScreenIndex_ValueChanged(object sender, EventArgs e)
        {
            RFECommunicator objRFE = m_controlRemoteScreen.RFExplorer;

            if (objRFE == null)
            {
                return;
            }

            objRFE.ScreenIndex     = (UInt16)m_numScreenIndex.Value;
            m_numScreenIndex.Value = objRFE.ScreenIndex;
            if (objRFE.ScreenData.Count > 0)
            {
                m_controlRemoteScreen.Invalidate();
            }
        }
コード例 #4
0
        /// <summary>
        /// Get analyzer or generator object deppending which one is connected. Analyzer has preference
        /// </summary>
        /// <returns>Analyzer or Generator object</returns>
        public RFECommunicator GetConnectedDeviceByPrecedence()
        {
            RFECommunicator objRFE = m_objAnalyzer;

            if (m_objGenerator != null && m_objGenerator.PortConnected && m_objAnalyzer != null && !m_objAnalyzer.PortConnected)
            {
                objRFE = m_objGenerator;
            }

            if ((objRFE != null) && (m_controlRemoteScreen.RFExplorer != objRFE))
            {
                objRFE.CleanScreenData();
            }

            return(objRFE);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //start application by displaying some help on screen
            PrintHelp(args.Length == 0);
            if (args.Length == 0)
            {
                return; //no parameters, nothing to do, just finish here
            }
            //Create and initialize a RFECommunicator object to proxy a RF Explorer device (of any kind)
            g_objRFE = new RFECommunicator(true, IsIOT(args)); //Initialize a new Spectrum Analyzer object
            g_objRFE.ReportInfoAddedEvent           += new EventHandler(OnRFE_ReportLog);
            g_objRFE.ReceivedConfigurationDataEvent += new EventHandler(OnRFE_ReceivedConfigData);
            g_objRFE.UpdateDataEvent += new EventHandler(OnRFE_UpdateData);
            g_objRFE.AutoConfigure    = false;

            UpdateBaudrate(args);

            //Connect to specified serial port
            if (!ConnectPort(args))
            {
                ClosePort();
                return; //if cannot connect to serial port, we cannot do anything else
            }

            //g_objRFE.DebugSentTracesEnabled = true;
            //g_objRFE.DebugTracesEnabled = true;

            //Request analyzer to send current configuration and enable sweep data dump
            if (UpdateFrequencyRange(args))
            {
                g_objRFE.SendCommand_RequestConfigData();
                UpdateSweepTime(args);
                WaitAndProcess(2, false);

                //Set working frequency range from command line parameters
                if (SetFrequencyRange(args))
                {
                    UpdateFileNames(args);
                    //If correct, process responses and display output for some seconds
                    WaitAndProcess(g_nTotalSeconds);
                }
            }

            //Close port and finish
            ClosePort();
        }
コード例 #6
0
        /// <summary>
        /// Function that checks if one of the arguments is /IOT
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static bool IsIOT(string[] args)
        {
            bool bIsIoT = false;

            if (args.Contains("/IOT", StringComparer.OrdinalIgnoreCase))
            {
                //This is a Raspberry Pi with a RF Explorer IoT Hat
                g_bIoTBoard = (RFECommunicator.IsRaspberryPlatform());
                Trace.WriteLine("Working in IoT - Raspberry Pi mode");
                if (!g_bIoTBoard)
                {
                    Trace.WriteLine("ERROR IoT: Unrecognized Raspberry Pi platform");
                    bIsIoT = false;
                }
                bIsIoT = true;
            }
            return(bIsIoT);
        }
コード例 #7
0
        /// <summary>
        /// Returns power channel over the full span being captured. The power is instantaneous real time
        /// For average power channel use the collection method GetAverageChannelPower().
        /// </summary>
        /// <returns>channel power in dBm/span</returns>
        public double GetChannelPowerDBM()
        {
            double fChannelPower = RFECommunicator.MIN_AMPLITUDE_DBM;
            double fPowerTemp    = 0.0f;

            for (UInt16 nInd = 0; nInd < m_nTotalSteps; nInd++)
            {
                fPowerTemp += RFECommunicator.Convert_dBm_2_mW(m_arrAmplitude[nInd]);
            }

            if (fPowerTemp > 0.0f)
            {
                //add here actual RBW calculation in the future - currently we are assuming frequency step is the same
                //as RBW which is not 100% accurate.
                fChannelPower = RFECommunicator.Convert_mW_2_dBm(fPowerTemp);
            }

            return(fChannelPower);
        }
コード例 #8
0
        /// <summary>
        /// Returns amplitude in dBm from whatever dAmplitude current value is specified
        /// </summary>
        /// <param name="dAmplitude"></param>
        /// <returns></returns>
        private double ConvertFromCurrentAmplitudeUnit(double dAmplitude)
        {
            double fResult = 0.0f;

            switch (m_objRFEAnalyzer.CurrentAmplitudeUnit)
            {
            case RFECommunicator.eAmplitudeUnit.dBm:
                fResult = dAmplitude;
                break;

            case RFECommunicator.eAmplitudeUnit.dBuV:
                fResult = RFECommunicator.Convert_dBuV_2_dBm(dAmplitude);
                break;

            case RFECommunicator.eAmplitudeUnit.Watt:
                fResult = RFECommunicator.Convert_Watt_2_dBm(dAmplitude);
                break;
            }
            return(fResult);
        }
コード例 #9
0
        private void OnAnalyzerUpdateRemoteScreen(object sender, EventArgs e)
        {
            RFECommunicator objRFE = (RFECommunicator)sender;

            RFEScreenData objData = objRFE.ScreenData.GetData((UInt16)objRFE.ScreenIndex);

            if (objData != null)
            {
                UpdateScreenNumericControls();
                //Update button status but first time only to minimize overhead
                if (objRFE.ScreenIndex == 1)
                {
                    UpdateButtonStatus();
                }

                if (m_MainTab.SelectedTab == m_tabRemoteScreen)
                {
                    m_tabRemoteScreen.Invalidate();
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Update status of all internal buttons based on analyzer object status
        /// </summary>
        /// <param name="menuAutoLCDOffChecked">Whether LCD screen of the device is on(true) or off(false).</param>
        public void UpdateButtonStatus(bool menuAutoLCDOffChecked)
        {
            if (m_controlRemoteScreen != null)
            {
                m_chkDumpLCDGrid.Checked     = m_controlRemoteScreen.LCDGrid;
                m_chkDumpColorScreen.Checked = m_controlRemoteScreen.LCDColor;
                m_chkDumpHeader.Checked      = m_controlRemoteScreen.HeaderText;
            }

            RFECommunicator objRFE = GetConnectedDeviceByPrecedence();

            if (objRFE != null)
            {
                CaptureDumpScreen             = CaptureDumpScreen && !menuAutoLCDOffChecked && (objRFE.PortConnected);
                m_chkDumpScreen.Enabled       = !menuAutoLCDOffChecked && (objRFE.PortConnected);
                m_btnSaveRemoteBitmap.Enabled = objRFE.ScreenData.Count > 1;

                m_chkDumpColorScreen.Enabled = m_chkDumpScreen.Enabled;
                m_chkDumpLCDGrid.Enabled     = m_chkDumpScreen.Enabled;
                m_chkDumpHeader.Enabled      = m_chkDumpScreen.Enabled;
            }
        }
コード例 #11
0
        private void OnDumpScreen_CheckedChanged(object sender, EventArgs e)
        {
            RFECommunicator objRFE = m_controlRemoteScreen.RFExplorer;

            if (objRFE == null)
            {
                return;
            }

            objRFE.CaptureRemoteScreen = CaptureDumpScreen;

            OnChkDumpScreenChangeEvent(new EventArgs());

            if (CaptureDumpScreen)
            {
                objRFE.SendCommand_EnableScreenDump();
            }
            else
            {
                objRFE.SendCommand_DisableScreenDump();
            }
        }
コード例 #12
0
        public bool Connect()
        {
            if (m_dev.GetConnectedPorts())
            {
                m_dev.ConnectPort(m_dev.ValidCP2101Ports[m_port], m_baud, RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOS(), true);
            }

            if (m_dev.PortConnected)
            {
                Console.WriteLine("Connected to port " + m_dev.ValidCP2101Ports[m_port]);

                m_dev.SendCommand_RequestConfigData();

                return(true);
            }
            else
            {
                Console.WriteLine("ERROR: no port available, please review your connection");

                return(false);
            }
        }
コード例 #13
0
ファイル: LimitLine.cs プロジェクト: raviteja9494/rfexplorer
        /// <summary>
        /// Save limit line data to a RFL file, substracting the offset if defined
        /// </summary>
        /// <param name="sFilename"></param>
        public void SaveFile(string sFilename)
        {
            if (Count < 2)
            {
                return;
            }

            using (StreamWriter myFile = new StreamWriter(sFilename, true))
            {
                myFile.WriteLine(FileHeaderVersioned());
                myFile.WriteLine("--RF Explorer Limit Lines data file version 01");
                myFile.WriteLine("--Sample points: " + Count);
                myFile.WriteLine("--Generated " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());

                foreach (PointPair objPoint in this)
                {
                    string sVal = objPoint.X.ToString("f3") + "\t" + RFECommunicator.ConvertAmplitude(m_eUnits, (objPoint.Y - m_dLastOffset), RFECommunicator.eAmplitudeUnit.dBm).ToString("f1");
                    myFile.WriteLine(sVal);
                }

                myFile.WriteLine("--EOF");
            }
        }
コード例 #14
0
        /// <summary>
        /// Connect to specified serial port
        /// It could be a IOTBoard, connect automatically if it is an device connected by USB or select a specified port from command line
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static bool ConnectPort(string[] args)
        {
            //Connect to the right UART port (may be USB in Windows/Unix/Mac or a Raspberry Mainboard)
            if (g_bIoTBoard)
            {
                try
                {
                    //Define pins to control baudrate (GPIO2 on Pin21) and force a HW reset of the MWSUB3G (Pin12)
                    OutputPinConfiguration pinGPIO2 = ConnectorPin.P1Pin21.Output();
                    m_pinConnection = new GpioConnection(pinGPIO2);
                    OutputPinConfiguration pinRESET = ConnectorPin.P1Pin12.Output();
                    m_pinConnection.Add(pinRESET);

                    //Reset sequence
                    m_pinConnection[pinRESET] = false;
                    Thread.Sleep(100);
                    m_pinConnection[pinGPIO2] = g_bHighSpeed; //true for 500Kbps, change to false for 2400bps low speed
                    m_pinConnection[pinRESET] = true;
                    Thread.Sleep(2500);                       //wait for initialization firmware code to finish startup

                    //Open COM port from Raspberry mainboard
                    string sCOMPort = "/dev/ttyAMA0";
                    g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, true);
                    Trace.WriteLine("Connected to port " + sCOMPort);
                    Thread.Sleep(500);
                }
                catch
                {
                    Trace.WriteLine("ERROR: Unable to connect IoT device");
                }
            }
            else if (args.Contains("/p:AUTO", StringComparer.OrdinalIgnoreCase))    //Accept /p:auto or /p:AUTO
            {
                //This is any non-IoT platform with a single device connected to USB
                if (g_objRFE.GetConnectedPorts())
                {
                    if (g_objRFE.ValidCP2101Ports.Length == 1)
                    {
                        bool bForceBaudrate = (RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOSPlatform());
                        g_objRFE.ConnectPort(g_objRFE.ValidCP2101Ports[0], g_nBaudrate, RFECommunicator.IsUnixLike(), bForceBaudrate);
                    }
                }
                if (g_objRFE.PortConnected)
                {
                    Trace.WriteLine("Connected to port " + g_objRFE.ValidCP2101Ports[0]);
                }
                else
                {
                    Trace.WriteLine("ERROR: No port available or several connections detected." + Environment.NewLine + "Please, review your RF Explorer connection");
                    return(false);
                }
            }
            else
            {
                //Use specified port from command line
                int nPos = Array.FindIndex(args, x => x.StartsWith("/p:"));
                if (nPos >= 0)
                {
                    string sCOMPort = args[nPos].Replace("/p:", "");
                    Trace.WriteLine("Trying manual port: " + sCOMPort);
                    g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, RFECommunicator.IsUnixLike(), RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOSPlatform());
                    Trace.WriteLine("Connected to port " + sCOMPort);
                }
                else
                {
                    Trace.WriteLine("ERROR: Please, insert /IOT or /p:PORT parameter");
                }
            }
            return(g_objRFE.PortConnected);
        }
コード例 #15
0
        static bool ConnectPort(string[] args)
        {
            //Connect to the right UART port (may be USB in Windows/Unix/Mac or a Raspberry Mainboard)
            if (g_bIoTBoard)
            {
                //Define pins to control baudrate (GPIO2 on Pin21) and force a HW reset of the MWSUB3G (Pin12)
                OutputPinConfiguration pinGPIO2 = ConnectorPin.P1Pin21.Output();
                m_pinConnection = new GpioConnection(pinGPIO2);
                OutputPinConfiguration pinRESET = ConnectorPin.P1Pin12.Output();
                m_pinConnection.Add(pinRESET);

                //Reset sequence
                m_pinConnection[pinRESET] = false;
                Thread.Sleep(100);
                m_pinConnection[pinGPIO2] = true; //true for 500Kbps, change to false for 2400bps low speed
                m_pinConnection[pinRESET] = true;
                Thread.Sleep(2500);               //wait for initialization firmware code to finish startup

                //Open COM port from Raspberry mainboard
                string sCOMPort = "/dev/ttyAMA0";
                g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, true);
                Console.WriteLine("Connected to port " + sCOMPort);
            }
            else if (args.Contains("/p:AUTO", StringComparer.Ordinal))
            {
                //This is any non-IoT platform with a single device connected to USB
                if (g_objRFE.GetConnectedPorts())
                {
                    if (g_objRFE.ValidCP2101Ports.Length == 1)
                    {
                        g_objRFE.ConnectPort(g_objRFE.ValidCP2101Ports[0], g_nBaudrate);
                    }
                }
                if (g_objRFE.PortConnected)
                {
                    Console.WriteLine("Connected to port " + g_objRFE.ValidCP2101Ports[0]);
                }
                else
                {
                    Console.WriteLine("ERROR: no port available, please review your connection");
                    return(false);
                }
            }
            else if (args.Contains("/p:", StringComparer.Ordinal))
            {
                //Use specified port from command line
                int nPos = Array.FindIndex(args, x => x.StartsWith("/p:"));
                if (nPos >= 0)
                {
                    string sCOMPort = args[nPos];
                    g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOS());
                    Console.WriteLine("Connected to port " + sCOMPort);
                }
            }

            return(g_objRFE.PortConnected);
        }
コード例 #16
0
        /// <summary>
        /// Refresh correct Ports available for device in ComboBox COM Ports
        /// If there is an available COM port already used by m_objRFE.PortNameExternal it will be ignored
        /// </summary>
        public void UpdateComboBox()
        {
            string sPortExternal;

            if (m_objRFE != null && !m_objRFE.PortConnected)
            {
                if (m_objRFE.ValidCP2101Ports != null)
                {
                    string sSelectedPort = "";
                    if (m_comboCOMPort.SelectedItem != null)
                    {
                        sSelectedPort = m_comboCOMPort.SelectedItem.ToString();
                    }
                    sPortExternal = m_objRFE.PortNameExternal;
                    string[] arrPortsAvailable = null;

                    if (!String.IsNullOrEmpty(sPortExternal))
                    {
                        //If exists external port associated to the connection, remove from available port list
                        arrPortsAvailable = m_objRFE.ValidCP2101Ports.Where(str => str != sPortExternal).ToArray();
                    }
                    else
                    {
                        arrPortsAvailable = m_objRFE.ValidCP2101Ports;
                    }
#if UNIX_LIKE
                    if (RFECommunicator.IsUnixLike())
                    {
                        if (RFECommunicator.IsMacOSPlatform())
                        {
                            //Mac replace string for USB port name
                            sSelectedPort = sSelectedPort.Replace(MAC_PORT_PREFIX, USB_PREFIX);
                            if (sSelectedPort.Equals(USB_PREFIX))
                            {
                                sSelectedPort += "0";
                            }
                            for (int nInd = 0; nInd < arrPortsAvailable.Length; nInd++)
                            {
                                arrPortsAvailable[nInd] = arrPortsAvailable[nInd].Replace(MAC_PORT_PREFIX, USB_PREFIX);
                                if (arrPortsAvailable[nInd].Equals(USB_PREFIX))
                                {
                                    arrPortsAvailable[nInd] += "0";
                                }
                            }
                        }
                        else
                        {
                            //Replace COM port names for Linux
                            sSelectedPort = sSelectedPort.Replace(LINUX_PORT_PREFIX, "");
                            for (int nInd = 0; nInd < arrPortsAvailable.Length; nInd++)
                            {
                                arrPortsAvailable[nInd] = arrPortsAvailable[nInd].Replace(LINUX_PORT_PREFIX, "");
                            }
                        }
                    }
#endif
                    m_comboCOMPort.DataSource   = arrPortsAvailable;
                    m_comboCOMPort.SelectedItem = sSelectedPort;
                }
                else
                {
                    m_comboCOMPort.DataSource = null;
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// Connect the selected port
        /// </summary>
        public void ConnectPort()
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                string sCOMPort = "";
                if (m_objRFE.ValidCP2101Ports != null && m_objRFE.ValidCP2101Ports.Length > 0)
                {
                    //there are valid ports available
                    if (m_objRFE.ValidCP2101Ports.Length == 1)
                    {
                        if (m_objRFE.PortNameExternal != m_objRFE.ValidCP2101Ports[0])
                        {
                            //if only one, ignore the selection from any combo and use what is available
                            sCOMPort                    = m_objRFE.ValidCP2101Ports[0];
                            m_sDefaultCOMPort           = sCOMPort;
                            m_comboCOMPort.SelectedItem = m_sDefaultCOMPort;
                        }
                    }
                    else
                    {
                        //if more than one, try to use the one from the combo and otherwise fail
                        if ((m_comboCOMPort != null) && (m_comboCOMPort.Items.Count > 0) && (m_comboCOMPort.SelectedValue != null))
                        {
                            foreach (string sTestCOMPort in m_objRFE.ValidCP2101Ports)
                            {
                                string sTestCOMPortName = "";
#if UNIX_LIKE
                                if (RFECommunicator.IsMacOSPlatform())
                                {
                                    sTestCOMPortName = sTestCOMPort.Replace(MAC_PORT_PREFIX, USB_PREFIX);
                                    if (sTestCOMPortName.Equals(USB_PREFIX)) //In MacOS USB 0 match with SLAB_USBtoUART
                                    {
                                        sTestCOMPortName += "0";
                                    }
                                }
                                else
#endif
                                sTestCOMPortName = sTestCOMPort.Replace(LINUX_PORT_PREFIX, "");      //Linux prefix is removed if exist to compare correctly with selectem item

                                if (sTestCOMPortName == m_comboCOMPort.SelectedValue.ToString())
                                {
                                    sCOMPort = m_comboCOMPort.SelectedValue.ToString();
                                    break;
                                }
                            }
                        }
                    }
                }
#if UNIX_LIKE
                if (!String.IsNullOrEmpty(sCOMPort))
                {
                    if (RFECommunicator.IsUnixLike())
                    {
                        if (RFECommunicator.IsMacOSPlatform())
                        {
                            if (!sCOMPort.StartsWith("/"))
                            {
                                if (sCOMPort.EndsWith(USB_PREFIX + "0"))  //USB0 match with /dev/tty.SLAB_USBtoUART
                                {
                                    sCOMPort = MAC_PORT_PREFIX;
                                }
                                else
                                {
                                    sCOMPort = sCOMPort.Replace(USB_PREFIX, MAC_PORT_PREFIX); //In MacOS USB 0 match with SLAB_USBtoUART
                                }
                            }
                        }
                        else
                        {
                            if (!sCOMPort.StartsWith("/"))
                            {
                                sCOMPort = LINUX_PORT_PREFIX + sCOMPort;
                            }
                        }
                    }
                }
#endif
                m_objRFE.ConnectPort(sCOMPort, Convert.ToInt32(m_ComboBaudRate.SelectedItem.ToString()), RFECommunicator.IsUnixLike(), RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOSPlatform());

                m_objRFE.HoldMode = false;
                UpdateButtonStatus();
                OnPortConnected(new EventArgs());
            }
            catch (Exception obEx)
            {
                Trace.WriteLine(obEx.ToString());
            }

            Cursor.Current = Cursors.Default;
        }