Before becoming crazy to find out why, please is there a known UDP problem on Premium Library in GHI SDK R3?
Socket ntpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
EndPoint remoteEP = new IPEndPoint(new IPAddress(serverAddress) , 123);
// init request
byte[] ntpData = new byte[48];
Array.Clear(ntpData, 0, 48);
ntpData[0] = 0x1B; // set protocol version
// send request
ntpSocket.SendTo(ntpData, remoteEP); //<<--- EXCEPTION here!!
// wait, if no response, timeout
if (ntpSocket.Poll(timeout * 1000 * 1000, SelectMode.SelectRead))
{
// get response
ntpSocket.ReceiveFrom(ntpData, ref remoteEP);
ntpSocket.Close();
This code idea come from FixedTimeService useful routine by eolson.
It works on my STM32F4 firmware, compiled by myself, but can’t get it working on G120 and G400 …
I missed something ?
.....
Eth1 = eth;
Eth1.Open();
NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1); // <<--- move
Eth1.CableConnectivityChanged += new EthernetENC28J60.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
//Eth1.CableConnectivityChanged += new EthernetBuiltIn.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);
Eth1.NetworkInterface.EnableStaticIP(_boardIp, _boardNetmask, _boardGw); // class C net
string[] DnsAddresses = new string[] { "8.8.8.8", "192.168.20.1" }; //Test so hardwired in code
Eth1.NetworkInterface.EnableStaticDns(DnsAddresses);
Eth1.NetworkInterface.PhysicalAddress = new byte[] { 0x00, 0x21, 0x03, 0x00, 0x00, 0x0B }; // test MAC
if (!Eth1.IsCableConnected)
To this:
Eth1 = eth;
Eth1.Open();
Eth1.CableConnectivityChanged += new EthernetENC28J60.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
//Eth1.CableConnectivityChanged += new EthernetBuiltIn.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);
Eth1.NetworkInterface.EnableStaticIP(_boardIp, _boardNetmask, _boardGw); // class C net
string[] DnsAddresses = new string[] { "8.8.8.8", "192.168.20.1" };
Eth1.NetworkInterface.EnableStaticDns(DnsAddresses);
Eth1.NetworkInterface.PhysicalAddress = new byte[] { 0x00, 0x21, 0x03, 0x00, 0x00, 0x0B };
NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);
if (!Eth1.IsCableConnected)
.....
So I used a wrong place for [em]NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);[/em] !!!
This didn’t create problem on older SDK.
Sorry @ dobova I don’t mean to hijack this thread, but this is a good example of network stack initialization “best practice” that keeps coming up over and over again on this forum. It would be extremely useful for both novices and experienced NETMF developers to have this information organized in such a way that it can be browsed and searched by category, device, NETMF version, etc.
@ LuisCpro : This is the first ethernet setup point when program loaded into the board (after other setup job).
@ jasdev : This code I’d hijack from some sample coming from Gus for EMX boards, then revised for other specific boards. I don’t think it’s the “best” practice, but it can work. For example I completely miss the “no cable connected” problem retry in this case.
But there’s one point: we haven’t a satisfactory document consisting of tables about:
[ul]
Best practice to Ethernet init on various board for ENC28 or Builtin, here included SPI and other pins related to each board. EMX Spider, G120 Cobra II, G400 HDR and Raptor and so on. I couldn’t find nothing about raptor, which socket and various INT,CS, RESET pin related, although using it as a gadgeteer socket you avoid this knowledge[/ul]
[ul]2. Best practice to (micro)SD init and use on various board. Card Detecting, StorageDev or PersistentStorage support and so on.[/ul]
[ul]3. Best practice to LCD init. For example all GHI display parameters needed to start from code an LCD.[/ul]
@ danibjor - Hi, I can’t share the entire project, it’s too big and is made of many modules/classes. Please which part of the code are you interested in ? I can simplify code for the porpouse.