问题描述
我遇到以下问题,无法使用以下代码登录到我的Nucleo-F746ZG:
我看到DHCP分配了一个有效的IP地址,这意味着该板可以看到网络(和路由器),但是当我使用Telnet客户端进行连接时。该代码永远不会离开监听器。相同的代码在.NET Framework下的Windows上运行良好。
private void ConnectionListenerThread()
{
byte [] buff = new byte[ 1024 ];
int received;
//
// Grab a collection of available network interfaces.
//
NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
//
// We need at least one interface to continue.
//
if ( nis.Length > 0 )
{
NetworkInterface ni = nis[0];
ni.EnableDhcp();
//
// Wait to be assigned an IP address.
//
while ( ni.IPv4Address == null || ni.IPv4Address.Length == 0 || ni.IPv4Address.Equals( "0.0.0.0" ) )
{
Thread.Sleep( 100 );
}
Debug.WriteLine( $"DHCP has given us the address {ni.IPv4Address},{ni.IPv4subnetMask},{ni.IPv4GatewayAddress}" );
while ( true )
{
_clientSocket = null;
//
// We Now have an IP address allocated so we can await
// incoming client connections.
//
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any,ListeningPort);
Socket listener = new Socket( localEndPoint.AddressFamily,SocketType.Stream,ProtocolType.Tcp );
try
{
listener.Bind( localEndPoint );
listener.Listen( 100 );
Debug.WriteLine( $"Waiting for an incoming connection on port {ListeningPort}.." );
_clientSocket = listener.Accept();
Debug.WriteLine( "Connected to a client" );
while ( true )
{
received = _clientSocket.Receive( buff );
if ( received > 0 )
{
OnSerialDataReceived?.Invoke( this,new EventArguments.BytesReceivedEventArgs( buff,received ) );
}
}
}
catch ( Exception ex )
{
Debug.WriteLine( $"Got a network exception: {ex.Message}" );
}
}
}
}
ListeningPort通常设置为54321。
以下是显示已安装NanoFramework版本的系统信息。
System @R_966_4045@ion
HAL build info: nanoCLR running @ ST_NUCLEO144_F746ZG
Target: ST_NUCLEO144_F746ZG
Platform: STM32F7
Firmware build Info:
Date: Jul 13 2020
Type: MinSizeRel build with ChibiOS v19.1.4.1
Version: 1.4.590.0
Compiler: GNU ARM GCC v9.3.1
有人对我做错了什么建议吗?
安迪
解决方法
这似乎是个错误……请在我们的GitHub中提出问题。 确保添加一个可以重现该问题的项目。