private static Device <Sensors> ConfigureSerialDevice() { Console.Clear(); Console.WriteLine("Enter the COM port of the device"); Device <Sensors> device; while (true) { string number = Console.ReadLine(); int portNum; if (int.TryParse(number, out portNum)) { try { device = new SerialPortDevice <Sensors>(portNum, "ArduinoBoxProp"); device.Connect(); Console.WriteLine("Connected"); return(device); } catch { Console.WriteLine("Could not connect to device, please select another COM port"); } } } }
public static Device <TData> ConnectToPropUsingSerial <TData>(int port, string name = "ArduinoProp") where : TData { Console.Clear(); Console.WriteLine("Enter the COM port of the device"); Device <TData> device; while (true) { string number = Console.ReadLine(); int portNum; if (int.TryParse(number, out portNum)) { try { device = new SerialPortDevice <TData>(portNum, "ArduinoBoxProp"); device.Connect(); Console.WriteLine("Connected"); return(device); } catch { Console.WriteLine("Could not connect to device, please select another COM port"); } } } }
private static Device <Sensors> ConfigureTcpNetworkDeviceAP() { //first connect over serial to the device Console.Clear(); Console.WriteLine("Setting up prop over usb..."); Console.WriteLine("Enter the WiFi network SSID: "); string ssid = Console.ReadLine(); Console.WriteLine("Enter the Wifi network Password: "******"ArduinoConfig"); string ipAddress = ""; bool isDoneConfig = false; MessageRecievedHandler <Config> messageHandler = (device, message) => { if (message.Status == "Done") { ipAddress = message.DeviceIp; isDoneConfig = true; } }; serialConfig.Recieved += messageHandler; serialConfig.Connect(); serialConfig.Send(new Config() { WifiCredentials = new WifiCredentials() { SSID = ssid, Password = pass } }); while (!isDoneConfig) { //just keep running... } serialConfig.Recieved -= messageHandler; serialConfig.Disconnect(); serialConfig.Dispose(); ConfigurationManager.AppSettings["DeviceIp"] = ipAddress; Console.WriteLine("Now recieving data, you may now disconnect the device"); return(new TCPNetworkDevice <Sensors>(ipAddress, 53005, "ArduinoProp"));; }