//XBEE Function

        public static async void sentcommand(XBeeController controller)
        {
            await controller.DiscoverNetwork();
        }
Exemple #2
0
        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);
                //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.DiscoverNetwork();

            //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.");
        }