Closed PaulNoto closed 6 years ago
Ha, damn. Ok I'll get back on it. Thanks
From: PaulNoto notifications@github.com Sent: Sunday, September 17, 2017 9:37:59 PM To: jefffhaynes/XBee Cc: Subscribed Subject: [jefffhaynes/XBee] Node_SampleReceived still not being called (#37)
Hi Jeff,
I just tried 1.5.4 and it works for your proactive DiscoverNetworkAsync() to call Node_SampleReceived() on a Router. However, naturally , it will not find sleeping nodes.
I tried it on my reactive code that does find all nodes even if they are sleeping. However, it will not call Node_SampleReceived() on the same router that works above. I'm including the code that works, the code that doesn't work, and the packages that NuGet added for the code that doesn't work.
I can't thank you enough for all the effort your putting into this.
This code works and calls Node_SampleReceived() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System; using System.Windows; using XBee;
namespace WpfApp2 { ///
/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { private XBeeController controller = null;
public MainWindow() {
InitializeComponent();
controller = new XBeeController();
controller.NodeDiscovered += NodeDiscovered;
Await_DiscoverController();
}
//----------------------------------------------------------
private async void Await_DiscoverController() {
try {
await controller.OpenAsync( "COM3", 115200 );
// NOTE: DiscoverNetworkAsync does not discover Sleeping Nodes < < < < < < < < < < < <
await controller.DiscoverNetworkAsync();
}
catch ( Exception e ) {
string s = e.Message;
}
}
//----------------------------------------------------------
private void NodeDiscovered( object sender, NodeDiscoveredEventArgs args ) {
string s = args.Name;
if ( args.Node.Address.LongAddress.Value == 0x0013A20040F4F731 ) {
args.Node.SampleReceived += Node_SampleReceived;
}
}
//---------------------------------------------------------------------------
private int _sampleReceived_Cntr = 0;
private void Node_SampleReceived( object sender, SampleReceivedEventArgs e ) {
_sampleReceived_Cntr++;
}
}
}
This code DOES NOT CALL Node_SampleReceived() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System; using System.IO.Ports; using System.Threading.Tasks; using System.Windows; using XBee;
namespace WpfApp3 { ///
/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { private XBeeController controller = null; private XBeeNode _xBeeNode = null;
public MainWindow() {
InitializeComponent();
Await_DiscoverController();
}
private async void Await_DiscoverController() {
await DiscoverController();
}
//---------------------------------------------------------------------------
private async Task DiscoverController() {
// NOTE: Sometimes the controller will take several tries before it is discovered
var ports = SerialPort.GetPortNames();
if ( ports.Length == 0 ) {
//historyLog.Add( new HistoryLog_Item( false, "Can't find XBee Controller on any USB Serial Port", HistoryLog_Item_Types.error ) );
return;
}
//historyLog.Add( new HistoryLog_Item( false, "Initializing XBee Controller", HistoryLog_Item_Types.info ) );
//historyLog.Add( new HistoryLog_Item( false, string.Format( "Checking serial ports: {0}", string.Join( ", ", ports ) ), HistoryLog_Item_Types.info ) );
int pass = 1;
do {
foreach ( var port in ports ) {
try {
controller = new XBeeController();
await controller.OpenAsync( port, 115200 );
//historyLog.Add( new HistoryLog_Item( false, string.Format( "Opened {0}", port ), HistoryLog_Item_Types.info ) );
controller.SampleReceived += Controller_SampleReceived;
pass = 0; // Finished initializing controller
}
catch ( Exception e ) {
controller?.Dispose();
controller = null;
//historyLog.Add( new HistoryLog_Item( false, string.Format( "Pass {0}: Failed to open {1} with {2}", pass, port, e.Message ), HistoryLog_Item_Types.error ) );
pass++;
}
if ( pass >= 30 ) {
//historyLog.Add( new HistoryLog_Item( false, string.Format( "Can't initialize XBee Controller on USB Serial Port {0}", port ), HistoryLog_Item_Types.error ) );
return;
}
}
} while ( pass != 0 );
//historyLog.Add( new HistoryLog_Item( false, "Finished Initializing XBee Controller", HistoryLog_Item_Types.info ) );
}
//---------------------------------------------------------------------------
public async void GetXBeeAsync( string hexAddressString ) {
try {
// I think somehow this is the problem.
_xBeeNode = await controller.GetNodeAsync( new NodeAddress( new LongAddress( ulong.Parse( hexAddressString, System.Globalization.NumberStyles.HexNumber ) ) ) );
}
catch {
return;
}
}
//---------------------------------------------------------------------------
ulong _test_XBeeNodeAddress_ULong = 5526146530998065;
string _test_XBeeNodeAddress_HexString = "13A20040F4F731";
bool _sampleHandlerSet = false;
/// <summary>
/// This is the incomming Method of the Controller XBee, every incomming communication hits this before the data is sent to the actual XBee Node object (if one exists).
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Controller_SampleReceived( object sender, SourcedSampleReceivedEventArgs e ) {
ulong nodeAddressULong = e.Address.LongAddress.Value;
if ( nodeAddressULong == _test_XBeeNodeAddress_ULong ) {
// Pass #1 Create Node
if ( _xBeeNode == null ) {
GetXBeeAsync( _test_XBeeNodeAddress_HexString );
return;
}
// Pass #2 Set Handler
if ( !_sampleHandlerSet ) {
_xBeeNode.SampleReceived += Node_SampleReceived;
_sampleHandlerSet = true;
return;
} else {
// Pass #3 For some reason the debugger won't show me the method, the Node's SampleReceived handler is set to, when I inspect the node on the third pass
// Pass #4 or more will let me inspect what method the Node's SampleReceived handler is set to. WEIRD!
XBeeNode node = _xBeeNode;
return; // Set Break Point Here to inspect fully initialized Node
}
}
}// END Controller_SampleReceived()
//---------------------------------------------------------------------------
private int _sampleReceived_Cntr = 0;
private void Node_SampleReceived( object sender, SampleReceivedEventArgs e ) {
_sampleReceived_Cntr++; // This Break Point never happens
}
}
}
These are the packages that NuGet added <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
package id="BinarySerializer" version="7.5.7" targetFramework="net47" /> package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="net47" /> package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net47" /> package id="NETStandard.Library" version="2.0.0" targetFramework="net47" /> package id="System.AppContext" version="4.3.0" targetFramework="net47" /> package id="System.Collections" version="4.3.0" targetFramework="net47" /> package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net47" /> package id="System.Console" version="4.3.0" targetFramework="net47" /> package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net47" /> package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net47" /> package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net47" /> package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net47" /> package id="System.Globalization" version="4.3.0" targetFramework="net47" /> package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net47" /> package id="System.IO" version="4.3.0" targetFramework="net47" /> package id="System.IO.Compression" version="4.3.0" targetFramework="net47" /> package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net47" /> package id="System.IO.FileSystem" version="4.3.0" targetFramework="net47" /> package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Linq" version="4.3.0" targetFramework="net47" /> package id="System.Linq.Expressions" version="4.3.0" targetFramework="net47" /> package id="System.Net.Http" version="4.3.2" targetFramework="net47" /> package id="System.Net.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Net.Sockets" version="4.3.0" targetFramework="net47" /> package id="System.ObjectModel" version="4.3.0" targetFramework="net47" /> package id="System.Reflection" version="4.3.0" targetFramework="net47" /> package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net47" /> package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Reflection.TypeExtensions" version="4.4.0" targetFramework="net47" /> package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net47" /> package id="System.Runtime" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.Handles" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net47" /> package id="System.Text.Encoding" version="4.3.0" targetFramework="net47" /> package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net47" /> package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net47" /> package id="System.Threading" version="4.3.0" targetFramework="net47" /> package id="System.Threading.Tasks" version="4.3.0" targetFramework="net47" /> package id="System.Threading.Timer" version="4.3.0" targetFramework="net47" /> package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net47" /> package id="System.Xml.XDocument" version="4.3.0" targetFramework="net47" /> package id="XBee" version="5.3.3" targetFramework="net47" /> package id="XBee.Core" version="1.5.4" targetFramework="net47" />
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/XBee/issues/37, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJSKR3W28vU-yUgi51L2engeZ2vQ7o7qks5sjcl3gaJpZM4PaWzM.
So there was a minor bug in discovery although I don't think that was the issue. I noticed that sometimes this series of device doesn't respond very quickly after discovery so I increased the guard time after discover. Your code is working for me now but give it a try.
Hi Jeff,
I just tried 1.5.4 and it works for your proactive DiscoverNetworkAsync() to call Node_SampleReceived() on a Router. However, naturally , it will not find sleeping nodes.
I tried it on my reactive code that does find all nodes even if they are sleeping. However, it will not call Node_SampleReceived() on the same router that works above. I'm including the code that works, the code that doesn't work, and the packages that NuGet added for the code that doesn't work.
I can't thank you enough for all the effort your putting into this.
This code works and calls Node_SampleReceived() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System; using System.Windows; using XBee;
namespace WpfApp2 { ///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window {
private XBeeController controller = null;
}
This code DOES NOT CALL Node_SampleReceived() <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System; using System.IO.Ports; using System.Threading.Tasks; using System.Windows; using XBee;
namespace WpfApp3 { ///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window {
private XBeeController controller = null;
private XBeeNode _xBeeNode = null;
}
These are the packages that NuGet added <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
package id="BinarySerializer" version="7.5.7" targetFramework="net47" /> package id="Microsoft.NETCore.Platforms" version="2.0.0" targetFramework="net47" /> package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net47" /> package id="NETStandard.Library" version="2.0.0" targetFramework="net47" /> package id="System.AppContext" version="4.3.0" targetFramework="net47" /> package id="System.Collections" version="4.3.0" targetFramework="net47" /> package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net47" /> package id="System.Console" version="4.3.0" targetFramework="net47" /> package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net47" /> package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net47" /> package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net47" /> package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net47" /> package id="System.Globalization" version="4.3.0" targetFramework="net47" /> package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net47" /> package id="System.IO" version="4.3.0" targetFramework="net47" /> package id="System.IO.Compression" version="4.3.0" targetFramework="net47" /> package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net47" /> package id="System.IO.FileSystem" version="4.3.0" targetFramework="net47" /> package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Linq" version="4.3.0" targetFramework="net47" /> package id="System.Linq.Expressions" version="4.3.0" targetFramework="net47" /> package id="System.Net.Http" version="4.3.2" targetFramework="net47" /> package id="System.Net.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Net.Sockets" version="4.3.0" targetFramework="net47" /> package id="System.ObjectModel" version="4.3.0" targetFramework="net47" /> package id="System.Reflection" version="4.3.0" targetFramework="net47" /> package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net47" /> package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Reflection.TypeExtensions" version="4.4.0" targetFramework="net47" /> package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net47" /> package id="System.Runtime" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.Handles" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net47" /> package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net47" /> package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net47" /> package id="System.Text.Encoding" version="4.3.0" targetFramework="net47" /> package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net47" /> package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net47" /> package id="System.Threading" version="4.3.0" targetFramework="net47" /> package id="System.Threading.Tasks" version="4.3.0" targetFramework="net47" /> package id="System.Threading.Timer" version="4.3.0" targetFramework="net47" /> package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net47" /> package id="System.Xml.XDocument" version="4.3.0" targetFramework="net47" /> package id="XBee" version="5.3.3" targetFramework="net47" /> package id="XBee.Core" version="1.5.4" targetFramework="net47" />