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); }
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); }