private async Task Discover() { var ports = SerialPort.GetPortNames(); var discoverMessage = string.Format("Checking serial ports: {0}", string.Join(", ", ports)); AddLog(discoverMessage); var controller = new XBeeController(); foreach (var port in ports) { try { await controller.OpenAsync(port, 9600); AddLog(string.Format("Opened {0}", port)); } catch (Exception e) { AddLog(string.Format("Failed to open {0} with {1}", port, e.Message)); } finally { controller.Close(); } } AddLog("Done."); }
public static async void getInfoNodeNow(XBeeController x, NodeData node, ListBox list) { var localNode = x.Local; var serialNumber = await localNode.GetSerialNumber(); var name = "-1"; name = await localNode.GetNodeIdentifier(); if (name != "-1") { x.Close(); node.pushNodeData(name, serialNumber.ToString()); list.Items.Add(name); } }
private void reScanPortbtn_Click(object sender, EventArgs e) { controller.Close(); portstatus.Text = "-"; String[] stpPortNames = SerialPort.GetPortNames(); comboBox1.Items.Clear(); foreach (string x in stpPortNames) { comboBox1.Items.Add(x); } if (comboBox1.Items.Count == 0) { MessageBox.Show("Please plug in Xbee"); Application.Exit(); } else { comboBox1.SelectedIndex = 0; } }
public static async void connect(XBeeController controller, string port) { controller.Close(); await controller.OpenAsync(port, 9600); }