Bug in 4.2 R2 - EthernetENC28J60
Because of a PCB error we have found a bug in the EthernetENC28J60 class in 4.2 R2.
If there is no communcation with the ENC28J60 chip the class returnes True in:
Checks should never default be True, but always False!
Else they give no meaning at all !!!
Open() should raise a timeout exception or return false if the communication failed.
What do you mean when there is no communication with the chip? Could you also show some code? I tested the ENC28 on the Spider both with no cable connected and the module itself unplugged, in both cases all three of the properties you listed returned false.
Assume a SPI that is connected to nothing - or assume that the ENC28 chip is dead or sick.
Then you create the ENC28 class and calls Open().
The property IsOpen then returns True - it should return False, no connection to ENC28 is opened and no communication was ever successful.
Next all other properties returns True aswell - like IsCableConnected etc. You do not know!
All you initializations of check properties should default be FALSE - always!
Then if you are 100% sure that evething acted as it should - like SPI commnunication OK, Values is received that 100% confirms that a cable is connected, Checksums OK etc. Then you returns a True - in all other cases FALSE.
Very basic programming!
The ENC28 Reset Pin is not exposed in the ENC28 Class as a method.
If things goes wrong one should be able to call END28 HW RESET.
The open call just prepares some things internally so that communication with the ENC28 can take place, which is why the IsOpen call returns true after you call open, regardless of whether or not the ENC28 is actually connected. When you read IsCableConnected, we read a register from the chip. If there is no chip connected, the SPI MISO line is left floating and the IsCableConnected bit could be either 0 or 1, we have no way of verifying if that bit is valid. There is no real way to validate that bit. The IsActivated property just tells you if the ENC28 network interface is the active interface in the system. To test presence of the chip, you should either try to send and receive data with it, or wait for the NetworkAddressChanged event if it is applicable.
That is exactly therefore the return value should be default false and not default true!
False = We do not know, we never asked, No cable, will not work etc.
True = It is confirmed that stuff works!
The value is default false. If the bit we read is true because the line was floating and happened to be high at that moment, the value then becomes true. As I said, if you want to be sure that there is a chip present, try to send and receive data after the open and connected properties return true.
We are comming closer…
You try to do SPI communication t0 the ENC28…
When there is no chip or a chip failure the you SPI communication failes.
Then your result value should be false - due to SPI failure.
Same as no cable!
When I do programming I do something like this:
public bool getMyChipValue(ref bool aValue)
bool myValue = MyChip.Read();
aValue = myValue;
The return value indicates if all went OK - and the aValue is changed if commnunication etc. succeeded and a valid value is read, only.
The return value will in many cases be e.g. and integer to return error codes, also.
In your case the communication fails, then you initial FALSE should not be changed!
Logic is: No cable, no ENC28 chip, no PCB etc. => it will not work!
- so no communication attempts is needed.
Same for the rest…
I am also experiencing the same thing on EMX and 4.2.10.
EthernetBuiltin.IsCableConnected return true while there’s no cable… this is really confusing and has to be solved.
Can you try quickly using the latest firmware and can you show your code? Using an EMX with the latest firmware, IsCableConnected performed as it is supposed to for me, true when there is a cable connected, false otherwise.
The GHI SDK I am using is the 126.96.36.199 and NETMF 188.8.131.52.
The latest EMX version is 184.108.40.206. Can you update a device to that firmware and test?
I don’t know how much time it will take to change all my code on this SDK and how much new bugs this will involve. Seriously, I know that upgrading may solve this particular case but it will certainly break something else… I have no time right now for that.
There should be no or minor changes plus the SDK out now is more stable and highly recommended over any previous version.
This is what I noticed or may be I did something wrong. I explain: I have first uninstalled the previous sdk and then install the new one. I have opened my project without any modification (without reloading any references) and click on run and no errors!!! And the Cable Disconnect error seems to be solved.
The weird thing is that I did not update the GHI FW on the device (it still print 4.2.10), I just uploaded the appplication builded with 4.2.11…
I finally rechecked on 4.2.10 and it is working! I definitely shouldn’t code during two weeks after the new years eve party!