/// <summary> /// Try to find and open a local node. /// </summary> /// <param name="ports">Ports to scan</param> /// <param name="baudRate">Baud rate, typically 9600 or 115200</param> /// <returns>The controller or null if no controller was found</returns> public static async Task <XBeeController> FindAndOpen(IEnumerable <string> ports, int baudRate) { var controller = new XBeeController(); foreach (var port in ports) { try { await controller.OpenAsync(port, baudRate); return(controller); } catch (InvalidOperationException) { } catch (UnauthorizedAccessException) { } catch (ArgumentOutOfRangeException) { } catch (ArgumentException) { } catch (TimeoutException) { } catch (IOException) { } } return(null); }
/// <summary> /// Try to find and open a local node. /// </summary> /// <returns>The controller or null if no controller was found</returns> public static async Task <XBeeController> FindAndOpen() { var controller = new XBeeController(); string aqs = SerialDevice.GetDeviceSelector(); var devices = await DeviceInformation.FindAllAsync(aqs); foreach (var device in devices) { try { var serialDevice = await SerialDevice.FromIdAsync(device.Id); await controller.OpenAsync(serialDevice); return(controller); } catch (InvalidOperationException) { } catch (UnauthorizedAccessException) { } catch (ArgumentOutOfRangeException) { } catch (ArgumentException) { } catch (TimeoutException) { } catch (IOException) { } } return(null); }