Main Site Documentation

A personal challenge? - 'This should never happen!'


#1

I love error messages like this

Now of course I’m doing something stupid (my speciality) but really ‘This should never happen!’, sounds more like a personal challenge then an error message and I love challenges.

What I’m looking to do is fudge a basic network reset and based on the error message I’m thinking this isn’t how to do it.



                ethernet_J11D.Interface.Close();
                ethernet_J11D.Interface.Open(); <- blows here
                ethernet_J11D.UseDHCP();


This works better and doesn’t raise an error, but its maybe not as much of a ‘reset’ as I’d like, but for now I’m going with it.


                ethernet_J11D.NetworkSettings.ReleaseDhcpLease();
                ethernet_J11D.UseDHCP();

Never found a bug I couldn’t write :slight_smile:


#2

Looks like one of the guys here owe you a beer for making it happen :slight_smile:


#3

Are you using the Spider? Can you show a more complete example?

The following didn’t give any problems on the Spider:

void ProgramStarted()
        {
            ethernet_J11D.Interface.Open();
            ethernet_J11D.UseDHCP();
            NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_J11D.Interface);

            ethernet_J11D.Interface.Close();
            ethernet_J11D.Interface.Open();
            ethernet_J11D.UseDHCP();
        } 

#4

FYI, the RESET# pin of the ENC28 chip is connected to pin 4 of the module’s socket, as can be seen in the schematic: http://www.ghielectronics.com/downloads/schematic/Ethernet_ENC28_Module_SCH.pdf

I wonder which of the EthernetENC28J60 Class methods: Constructor, Close, Dispose, or Open toggles the RESET pin?

One workaround is to Close the Driver (But of course this might trigger: ‘This should never happen!’), then toggle the GPIO pin connected to the RESET pin, which happens to be Pin.P1_14 for my G120HDR. The same is true for Cobra II.

One final important question:

As customers/owners of GHI Premium product, do we have access to the source code of GHI.Premium Library?

From what I gathered online, the answer is No! But I could be wrong!

As I am always curious to take an inside peek, I’ll soon be checking out this product:
http://www.red-gate.com/products/dotnet-development/reflector/


#5

And you will be disappointed…


#6

I used RedGate Reflector a while ago.
Now I’m using ReSharper, which can do the same for you, and way more.
It’s a little more expensive, but it’s absolutely worth the money.
You could also apply for a free license if you work on a open source project.


#7

The point I was trying to make was this: most of the “interesting” stuff is done in native code. So there is no much use of ReSharper or Reflector. Most of the time you will end up at [em]MethodImplOptions.InternalCall[/em] :wink:


#8

Yes that’s true, time to learn to read byte code fluently :wink:


#9

You both mean that neither one will show the code in C at least?

In the long gone past, I was able to find a few compiler errors by looking at their generated assembly code but I would definitely prefer C at this age of mine!

Cheers!


#10

You will get C# code from both.
But a lot of the C# methods are just representations for the C methods inside the firmware.
Everything inside the firmware is coded in native C (may be C++) and is therefor not decompilable in the same way as C#.
There might be some tolls which give you assembler code, but that’s really hard to read if you not an CPU junky with a lot of experience.


#11

I got the same thing Duke :wink:

The only way I found to reset my network card is


try{NetworkInterfaceExtension.AssignNetworkingStackTo(null);}catch { }
try{ethernet_ENC28.Interface.Close();}catch { }
try{ethernet_ENC28.Interface.Dispose();}catch { }
try{ethernet_ENC28 = new GTM.GHIElectronics.Ethernet_ENC28(1);}catch { }
try{ethernet_ENC28.Interface.Open(); } catch { }
try { ethernet_ENC28.Interface.NetworkInterface.EnableStaticIP("192.168.1.2", "255.255.255.0", "192.168.1.1");}catch { }
try { ethernet_ENC28.Interface.NetworkInterface.EnableStaticDns(new string[1] { "192.168.1.1" }); } catch { }
try { NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface);  } catch { }



#12

@ GMISoft

Would you please explain the advantage of using a try… catch for each line vs. one for all?


#13

With a try catch for each line only that line will fail and fall through to the next line.

If you have a try catch around the complete code then the first failure will skip the rest of the code.


#14

@ Cowboy - This makes sense when closing/disposing the device.
But for initialization it is most likely, that if one call fails, the next one will too.


#15

You ask what the advantage was, I didn’t say that this is the right thing to do.


#16

As Reinhard indicated, I was trying to alert in a question form that it doesn’t make sense to try to do anything after the failure of ‘new’ or ‘.Open()’ statement! This is not really critical since the following statements will also fail but the code looked awkward to me!

The funny thing, as I was testing different fail scenarios with my ENC28 module, all the initialization code shown above did NOT fail when I unplugged the ENC28 module and started the system! However, if it’s plugged in and the cable is not connected or disconnected after start-up, I’m able to detect that!


#17

Hi,
I “Try-Catch” every line because it’s a “reset” code and I remarked that sometimes a line is failing but the others are working.

From my “experience” it’s working 1 or 2 times, no more.

I’d like to Dispose the Ethernet module and recreate it, but I did not find how to do that for now (I didn’t spent much time on that point)


#18

The code is in fact awkward, but the reason to do that is awkward too.

I have IP stack failure, and the only way to restore the network is resetting the network module and without a clean “Reset” method, it was the only way I found.


#19

@ GMISoft

You are right and I apologize for diverging from the main issue at hand.

Have you considered what I mentioned about RESET in my earlier post?

https://www.ghielectronics.com/community/forum/topic?id=14802&page=1#msg152340

Cheers!


#20

Since the title of this thread is for a different subject, maybe we should start an new one entitled: “Resetting ENC28 network module after IP stack failure”.

I am sure not what’s the best way to do this other than creating a new topic with above title and mention that its a continuation to what was started in this thread.

If someone has a better suggestion please take the lead. Otherwise, I’ll go ahead and do it myself after 30 minutes or so.

Thanks