Main Site Documentation

Using EthernetBuiltin and spider how to Detect if the ethenet is connected (differentiate between gadgeteer and emulator modes)


#1

hi.
I’m using spider and ethernet module. I wrote in addition an emulator project. so I can run my project either on spider or with the emulator.
the problem is with the following code:


       _ethernet= new EthernetBuiltIn();
         try
                {
                    _ethernet.Open();
                    if (!_ethernet.IsOpen || !_ethernet.IsActivated)
                    {
                        throw new NetworkException("Problems with the initialize of the ethernet module");
                    }
                }
                catch (NotSupportedException  e)
                {
                    Debug.Print(e.Message );
                    _mode = Mode.Emulator;
                }

the _ethernet.Open will throw a not supported exception if this is running on the emulator (no ethernet there)
is there any better way to differentiate if the network module is connected or not?
thanks!


#2

thanks great this is what I was looking for
there is also a field

Microsoft.SPOT.Hardware.SystemInfo.IsEmulator