static void Main(string[] args) { //var controllerTask = XBeeController.FindAndOpenAsync(9600); //controllerTask.Wait(); //var controller = controllerTask.Result; var controller = new XBeeController(); var openTask = controller.OpenAsync("COM4", 115200); openTask.Wait(); if (controller == null) { return; } var s2 = new XBeeSeries2(controller); var s2Task = s2.GetPanIdAsync(); s2Task.Wait(); return; var local = controller.Local as XBeeSeries1; controller.ModemStatusChanged += (sender, eventArgs) => { Console.WriteLine($"Modem status: {eventArgs.Status}"); }; var panIdTask = local.GetPanIdAsync(); panIdTask.Wait(); //var panId = panIdTask.Result; //var pullupTask = local.GetPullUpResistorConfigurationAsync(); //pullupTask.Wait(); //var pullupConfig = pullupTask.Result; //var rssiCycleTask = local.GetRssiPwmTimeAsync(); //rssiCycleTask.Wait(); //var rssiCycle = rssiCycleTask.Result; Console.WriteLine("Found controller."); controller.NodeDiscovered += (sender, eventArgs) => { Console.WriteLine($"{eventArgs.Name} discovered."); eventArgs.Node.TransmitDataAsync(Enumerable.Repeat((byte)5, 400).ToArray()); }; var discoverTask = controller.DiscoverNetworkAsync(); discoverTask.Wait(); Console.WriteLine("Discovery finished."); Console.ReadKey(); }
private async Task FindXBeeAsync() { var controllers = await XBeeController.FindControllersAsync(9600); if (controllers.Count == 0) { StatusText.Text = "No controllers."; return; } StatusText.Text = "Found controller \n"; _controller = controllers.First(); _controller.NodeDiscovered += (sender, args) => { _remoteNode = args.Node; StatusText.Text += $"Discovered remote node: {args.Name}\n"; }; await _controller.DiscoverNetworkAsync(TimeSpan.FromSeconds(5)); }
private static async void Discover() { //await _xbee.OpenAsync("COM5", 9600); Console.WriteLine("Discovering network..."); _xbee.NodeDiscovered += async(sender, args) => { Console.WriteLine("---------------- Discovered '{0}'", args.Name); await args.Node.SetApiModeAsync(ApiMode.Enabled); //Console.WriteLine("Sending data to '{0}'", args.Name); //await args.Node.TransmitDataAsync(Encoding.ASCII.GetBytes("Hello!")); //var node = args.Node as XBeeSeries2; //var receivedData = // node.GetReceivedData().Subscribe(data => Console.WriteLine("recieved {0} bytes", data.Length)); //var stopwatch = new Stopwatch(); //stopwatch.Start(); //var range = Enumerable.Range(0, 10); //await Task.WhenAll(range.Select(i => Toggle(node, i))); //for (int i = 0; i < 100; i++) //{ // await node.SetInputOutputConfiguration(InputOutputChannel.Channel4, InputOutputConfiguration.DigitalLow); // await node.SetInputOutputConfiguration(InputOutputChannel.Channel4, InputOutputConfiguration.Disabled); //} //Console.WriteLine(TimeSpan.FromMilliseconds((double)stopwatch.ElapsedMilliseconds/100)); //var ai = await node.GetAssociation(); //Console.WriteLine("Ack from '{0}'!", args.Name); //var changeDetection = await args.Node.GetChangeDetectionChannels(); //var ee = await args.Node.IsEncryptionEnabled(); // await args.Node.SetNodeIdentifier("BOB"); //for (int i = 0; i < 1; i++) //{ // var id = await args.Node.GetNodeIdentifier(); // Console.WriteLine(id); //} //if (args.Name == "ED1") // return; //await Task.Delay(1000); //await args.Node.SetNodeIdentifier("BOB"); //await args.Node.Reset(); //Console.WriteLine("reset"); //await args.Node.SetInputOutputConfiguration(InputOutputChannel.Channel2, InputOutputConfiguration.DigitalIn); //await args.Node.SetInputOutputConfiguration(InputOutputChannel.Channel3, InputOutputConfiguration.AnalogIn); //await args.Node.SetChangeDetectionChannels(DigitalSampleChannels.Input2); //await args.Node.SetSampleRate(TimeSpan.FromSeconds(5)); //var address = await args.Node.GetDestinationAddress(); //await args.Node.SetDestinationAddress(new ShortAddress(0)); //await args.Node.WriteChanges(); //var samples = args.Node.GetSamples(); //await samples.ForEachAsync(sample => Console.WriteLine("{0} ({1})", sample.ToString(), args.Name)); //await args.Node.ForceSample(); }; await _xbee.DiscoverNetworkAsync(); //await _xbee.ExecuteMultiQueryAsync(new NetworkDiscoveryCommand(), new Action<AtCommandResponseFrame>( // async frame => // { // Console.WriteLine(frame.Data); // var node = frame.Data as NetworkDiscoveryResponseData; // if (node != null && !node.IsCoordinator) // { // Console.WriteLine("Sending data to {0}", node.Name); // await _xbee.TransmitDataAsync(node.LongAddress, Encoding.ASCII.GetBytes("Hello!")); // Console.WriteLine("Received!"); // } // }), TimeSpan.FromSeconds(6)); Console.WriteLine("Done."); }