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)
                    {
                        bool bForceBaudrate = (RFECommunicator.IsRaspberry() && g_nBaudrate > 115200);
                        g_objRFE.ConnectPort(g_objRFE.ValidCP2101Ports[0], g_nBaudrate, RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOS(), bForceBaudrate);
                    }
                }
                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
            {
                //Use specified port from command line
                int nPos = Array.FindIndex(args, x => x.StartsWith("/p:"));
                if (nPos >= 0)
                {
                    string sCOMPort = args[nPos].Replace("/p:", "");
                    Console.WriteLine("Trying manual port: " + sCOMPort);
                    g_objRFE.ConnectPort(sCOMPort, g_nBaudrate, RFECommunicator.IsUnixLike() && !RFECommunicator.IsMacOS());
                    Console.WriteLine("Connected to port " + sCOMPort);
                }
            }

            return(g_objRFE.PortConnected);
        }
Esempio n. 2
0
        public void ConnectPort()
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                string csCOMPort = "";
                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
                            csCOMPort                   = m_objRFE.ValidCP2101Ports[0];
                            m_sDefaultCOMPort           = csCOMPort;
                            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)
                            {
                                if (sTestCOMPort == m_comboCOMPort.SelectedValue.ToString())
                                {
                                    csCOMPort = m_comboCOMPort.SelectedValue.ToString();
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!String.IsNullOrEmpty(csCOMPort))
                {
                    m_objRFE.ConnectPort(csCOMPort, Convert.ToInt32(m_ComboBaudRate.SelectedItem.ToString()));

                    m_objRFE.HoldMode = false;
                    //m_groupControl_Connection.m_CollGroupBox.Collapsed = true;
                    UpdateButtonStatus();
                    OnPortConnected(new EventArgs());
                }
            }
            catch (Exception obEx)
            {
                Console.WriteLine(obEx.ToString());
            }

            Cursor.Current = Cursors.Default;
        }
Esempio n. 3
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);
    }
Esempio n. 4
0
 private void btnConnectRFExplorer_Click(object sender, EventArgs e)
 {
     Cursor.Current = Cursors.WaitCursor;
     if (comboBoxPortsRFExplorer.Items.Count > 0)
     {
         m_objRFE.ConnectPort(comboBoxPortsRFExplorer.SelectedValue.ToString(), Convert.ToInt32(comboBoxBaudrateRFExplorer.SelectedItem.ToString()));
         if (m_objRFE.PortConnected)
         {
             m_objRFE.SendCommand_RequestConfigData();
         }
         Thread.Sleep(2000);
         m_objRFE.ProcessReceivedString(true, out m_sRFEReceivedString);
     }
     UpdateButtonStatus();
     Cursor.Current = Cursors.Default;
 }
        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);
            }
        }
Esempio n. 6
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;
        }