FEZ cobra and MAC address

I know this is a very trivial question, but how do I find the IP and MAC address of my FEZ cobra when connected through ethernet? Thanks.

Do you mean in code, or from a PC?

From a PC

MAC addresses and the mapping to IP addresses can be found using “ARP -a” command from a command prompt, but that only shows you what your PC has communicated to.

What’s the reason you’re asking; what problem are you trying to solve? If you tell us what you’re hoping to achieve, we might be able to help guide to you solve this rather than give you correct information (but unlikely to be helpful in the long term)

Sorry i’m not trying to solve a problem, Just getting some information :D. So far I’ve connected the Cobra to my PC, and issued ‘ARP -a’, and I have got a list of Internet Addresses and Physical Addresses as such :

Interface : 10.234.185.129 ---- 0x10003

Internet Address Physical Address Type
10.234.190.20 00-22-64-07-01-96 Dynamic

Oh, found it, thanks. Outof curiosity how do I find it in code?

Sorry, my question has changed! I do have a problem to do with my question! I wish to have a program that grabs the IP and MAC address and then displays this in a window. I think it will be fairly simple no?

OK, so finding it in code: do you mean on a PC program, or on your Fez? On the Fez it’s relatively trivial, but on a PC it’s somewhat more challenging (and to be honest, you probably don’t need the MAC address?) Anyway, the core issue then will be about establishing the communication between the Fez and PC in the first place; if you’re only doing this for your home network where you can control things, again it’s relatively simple, but it gets extremely complex when you need to be able to plug your Fez into any network and then your PC app needs to find the fez; that’s doable (look up NetBIOS name server on codeshare) but far from simple.

Yeah, I want to display it on my Fez. With a written code in Visual Studio. Yep, for now just need it for one network, which is why I thought it would be simple. A wa of grabbing the IP and MAC from the fez and then displaying it on the Fez when I run the code.

I;ve been looking at this example for creating a web server.

Im guessing that I will need the code up to the point of assigning an IP address, and then somehow display that as a string xml to show on the cobra?

Kind of.

Today your application starts and gets an IP address from DHCP, or uses a fixed address. To do that you have a network interface object. In the code you can see the following debug.print statement (plus more that I’ve trimmed)

[quote]Debug.Print("DCHP - IP Address = " + NI.IPAddress + " … Net Mask = " +
[/quote]

Live debug your device and inspect the properties of the NI object and see what you can see.

Then create another project that displays text on your device, and make sure you understand that.

Then merge the two.

Ah yes I see. Well I have this so far

using System.Threading;
using System.Net;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;

namespace Test
{
    public class Program
    {
        // This will hold the windows. 
        static Window[] windows = new Window[3];

        // Indicates the current window index. 
        static int index = 0;

        public static void Main()
        {
            // Makes sure that there is a functional interface on the board 
            if (Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces().Length < 1)
            {
                Debug.Print("No Active network interfaces.");
                //Thread.CurrentThread.Abort();
            }

            // OK, retrieve the network interface
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

            //If network has a DHCP server on it, it should be used. This bit of code enabled DHCP on the network interface. Chooses IP address so there will be no clashes
            if (NI.IsDhcpEnabled == false)
            {
                Debug.Print("Enabling DHCP.");
                NI.EnableDhcp();
                Debug.Print("DCHP - IP Address = " + NI.IPAddress + NI.PhysicalAddress + " ... Net Mask = " + NI.SubnetMask + " ... Gateway = " + NI.GatewayAddress);
            }
                /*}
            else
            {
                Debug.Print("Renewing DHCP lease.");
                NI.RenewDhcpLease();
                Debug.Print("DCHP - IP Address = " + NI.IPAddress + NI.PhysicalAddress + " ... Net Mask = " + NI.SubnetMask + " ... Gateway = " + NI.GatewayAddress);
            }*/

        

            
            
    // Load the windows 
    string xml;
    xml = "<Glide Version=\"" + Glide.Version + "\">";
    xml += "<Window Name=\"window1\" Width=\"480\" Height=\"272\" BackColor=\"F2F2F2\">"; 
    xml += "<Button Name=\"nextBtn\" X=\"260\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Next\" Font=\"2\" FontColor=\"000000\"/>"; 
    xml += "<Button Name=\"backBtn\" X=\"10\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Back\" Font=\"2\" FontColor=\"000000\"/>"; 
    xml += "<TextBlock Name=\"label\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Window #1\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0\"/>";
    xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"green\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
    xml += "</Window>";
    xml += "</Glide>";

    // Resize any loaded Window to the LCD's size.
    Glide.FitToScreen = true;

    // Load the Window XML string.
    windows[0] = GlideLoader.LoadWindow(xml);
            


    xml = "<Glide Version=\"" + Glide.Version + "\">";
    xml += "<Window Name=\"window2\" Width=\"480\" Height=\"272\" BackColor=\"E6E6E6\">"; 
    xml += "<Button Name=\"nextBtn\" X=\"260\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Next\" Font=\"2\" FontColor=\"000000\"/>"; 
    xml += "<Button Name=\"backBtn\" X=\"10\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Back\" Font=\"2\" FontColor=\"000000\"/>"; 
    xml += "<TextBlock Name=\"label\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Window #2\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0\"/>";
    xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"red\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
    xml += "</Window>";
    xml += "</Glide>";

    // Resize any loaded Window to the LCD's size.
    Glide.FitToScreen = true;

    // Load the Window XML string.
    windows[1] = GlideLoader.LoadWindow(xml);


    xml = "<Glide Version=\"" + Glide.Version + "\">";
    xml += "<Window Name=\"window3\" Width=\"480\" Height=\"272\" BackColor=\"DADADA\">"; 
    xml += "<Button Name=\"nextBtn\" X=\"260\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Next\" Font=\"2\" FontColor=\"000000\"/>"; 
    xml += "<Button Name=\"backBtn\" X=\"10\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Back\" Font=\"2\" FontColor=\"000000\"/>"; 
    xml += "<TextBlock Name=\"label\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Window #3\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0\"/>";
    xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"blue\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
    xml += "</Window>";
    xml += "</Glide>";

    // Resize any loaded Window to the LCD's size.
    Glide.FitToScreen = true;

    // Load the Window XML string.
    windows[2] = GlideLoader.LoadWindow(xml);
            
            // Activate touch 
            GlideTouch.Initialize();

            // Initialize the windows. 
            // Since all windows are identical we can reuse the same function. 
            InitWin(windows[0]);
            InitWin(windows[1]);
            InitWin(windows[2]);

            updateButtons();

            // Assigning a window to MainWindow flushes it to the screen. 
            // This also starts event handling on the window. 
            Glide.MainWindow = windows[index];

            Thread.Sleep(-1);
        }

        // Initializes the back and next buttons. 
        static void InitWin(Window window)
        {
            // Find the back button within the window. 
            Button backBtn = (Button)window.GetChildByName("backBtn");
            // Attach a tap event handler. 
            backBtn.TapEvent += new OnTap(backBtn_TapEvent);

            Button nextBtn = (Button)window.GetChildByName("nextBtn");
            nextBtn.TapEvent += new OnTap(nextBtn_TapEvent);
        }

        // Enables/disables navigation buttons appropriately. 
        static void updateButtons()
        {
            Window window = windows[index];

            // First window 
            if (index == 0)
            {
                Button backBtn = (Button)window.GetChildByName("backBtn");
                backBtn.Enabled = false;

                // Disabling a button reduces it's alpha to 1/3 it's current value. 
                // Simply invalidating a button won't show the alpha change because 
                // it's redrawing over the current bitmap. To show this change we need 
                // to clear the region it occupies (fill it with background color). 
                window.FillRect(backBtn.Rect);
                backBtn.Invalidate();
            }

            // Last window 
            if (index == windows.Length - 1)
            {
                Button nextBtn = (Button)window.GetChildByName("nextBtn");
                nextBtn.Enabled = false;

                window.FillRect(nextBtn.Rect);
                nextBtn.Invalidate();
            }
        }

        // Handles the next button tap event. 
        static void nextBtn_TapEvent(object sender)
        {
            if (index < windows.Length - 1)
            {
                int lastIndex = index;
                index++;

                // Update before we slide so the button state(s) are 
                // visually correct while we slide. 
                updateButtons();

                Tween.SlideWindow(windows[lastIndex], windows[index], Direction.Up);
            }
        }

        // Handles the back button tap event. 
        static void backBtn_TapEvent(object sender)
        {
            if (index > 0)
            {
                int lastIndex = index;
                index--;

                updateButtons();
                Tween.SlideWindow(windows[lastIndex], windows[index], Direction.Down);
            }
        }
    }
}

There are three windows that are navigated with buttons in this code. As you can see I have code at the start referencing the IP. My, hopefully, last question is that I’m unsure of how to reference the newly created IP in one of my ‘string xmls’ . For example to create a textblock there is

xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"Adam\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";

However I do not know how to call up somethng that is not text (Adam in the case above).

If you look at the Glide examples, say the Keyboard example, you can see how it uses the textbox.

TextBox textBox = (TextBox)window.GetChildByName("textBox");             
Debug.Print(textBox.Text); 

Take a bigger look at the Glide documentation; http://www.ghielectronics.com/downloads/Glide/Library/html/1ef24de6-c32c-eb27-d70d-3fa6ec9f9358.htm is the TextBlock doco, and there’s an example there how you update the text value.

Okay perfect. Managedto get the code working with this :

using System.Threading;
using System.Net;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;

namespace Test
{
    public class Program
    {
        // This will hold the windows. 
        static Window[] windows = new Window[3];

        // Indicates the current window index. 
        static int index = 0;

        public static void Main()
        {
            // Makes sure that there is a functional interface on the board 
            if (Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces().Length < 1)
            {
                Debug.Print("No Active network interfaces.");
                //Thread.CurrentThread.Abort();
            }

            // OK, retrieve the network interface
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];

            //If network has a DHCP server on it, it should be used. This bit of code enabled DHCP on the network interface. Chooses IP address so there will be no clashes
            if (NI.IsDhcpEnabled == false)
            {

                Debug.Print("Enabling DHCP.");

                NI.EnableDhcp();

                Debug.Print("DCHP - IP Address = " + NI.IPAddress + ", MAC Address = " + NI.PhysicalAddress[0].ToString() + "-" + NI.PhysicalAddress[1].ToString() + "-" + NI.PhysicalAddress[2].ToString() + "-"

                + NI.PhysicalAddress[3].ToString() + "-" + NI.PhysicalAddress[4].ToString() + "-" + NI.PhysicalAddress[5].ToString());

            }



            else
            {

                Debug.Print("Renewing DHCP lease.");

                NI.RenewDhcpLease();

                Debug.Print("DCHP - IP Address = " + NI.IPAddress + ", MAC Address = " + NI.PhysicalAddress[0].ToString() + "-" + NI.PhysicalAddress[1].ToString() + "-" + NI.PhysicalAddress[2].ToString() + "-"

                + NI.PhysicalAddress[3].ToString() + "-" + NI.PhysicalAddress[4].ToString() + "-" + NI.PhysicalAddress[5].ToString());

            }

           

            // Load the windows 
            string xml;
            xml = "<Glide Version=\"" + Glide.Version + "\">";
            xml += "<Window Name=\"window1\" Width=\"480\" Height=\"272\" BackColor=\"F2F2F2\">";
            xml += "<Button Name=\"nextBtn\" X=\"260\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Next\" Font=\"2\" FontColor=\"000000\"/>";
            xml += "<Button Name=\"backBtn\" X=\"10\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Back\" Font=\"2\" FontColor=\"000000\"/>";
            xml += "<TextBlock Name=\"label\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Window #1\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0\"/>";
            xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"Adam\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
            xml += "<TextBlock Name=\"ipTextBlock\" X=\"10\" Y=\"104\" Width=\"470\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
            xml += "<TextBlock Name=\"macTextBlock\" X=\"10\" Y=\"124\" Width=\"470\" Height=\"32\" Alpha=\"255\" Text=\"\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
            xml += "</Window>";
            xml += "</Glide>";



            // Resize any loaded Window to the LCD's size.
            Glide.FitToScreen = true;

            // Load the Window XML string.
            windows[0] = GlideLoader.LoadWindow(xml);



            xml = "<Glide Version=\"" + Glide.Version + "\">";
            xml += "<Window Name=\"window2\" Width=\"480\" Height=\"272\" BackColor=\"E6E6E6\">";
            xml += "<Button Name=\"nextBtn\" X=\"260\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Next\" Font=\"2\" FontColor=\"000000\"/>";
            xml += "<Button Name=\"backBtn\" X=\"10\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Back\" Font=\"2\" FontColor=\"000000\"/>";
            xml += "<TextBlock Name=\"label\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Window #2\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0\"/>";
            xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"is\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
            xml += "</Window>";
            xml += "</Glide>";

            // Resize any loaded Window to the LCD's size.
            Glide.FitToScreen = true;

            // Load the Window XML string.
            windows[1] = GlideLoader.LoadWindow(xml);


            xml = "<Glide Version=\"" + Glide.Version + "\">";
            xml += "<Window Name=\"window3\" Width=\"480\" Height=\"272\" BackColor=\"DADADA\">";
            xml += "<Button Name=\"nextBtn\" X=\"260\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Next\" Font=\"2\" FontColor=\"000000\"/>";
            xml += "<Button Name=\"backBtn\" X=\"10\" Y=\"198\" Width=\"50\" Height=\"32\" Alpha=\"255\" Text=\"Back\" Font=\"2\" FontColor=\"000000\"/>";
            xml += "<TextBlock Name=\"label\" X=\"0\" Y=\"0\" Width=\"320\" Height=\"32\" Alpha=\"255\" Text=\"Window #3\" TextAlign=\"Center\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"0\"/>";
            xml += "<TextBlock Name=\"textBlock\" X=\"300\" Y=\"104\" Width=\"120\" Height=\"32\" Alpha=\"255\" Text=\"GAY\" TextAlign=\"Left\" TextVerticalAlign=\"Middle\" Font=\"4\" FontColor=\"000000\"/>";
            xml += "</Window>";
            xml += "</Glide>";

            // Resize any loaded Window to the LCD's size.
            Glide.FitToScreen = true;

            // Load the Window XML string.
            windows[2] = GlideLoader.LoadWindow(xml);

            // Activate touch 
            GlideTouch.Initialize();

            // Initialize the windows. 
            // Since all windows are identical we can reuse the same function. 
            InitWin(windows[0], NI);
            InitWin(windows[1], NI);
            InitWin(windows[2], NI);

            updateButtons();

            // Assigning a window to MainWindow flushes it to the screen. 
            // This also starts event handling on the window. 
            Glide.MainWindow = windows[index];

            Thread.Sleep(-1);
        }

        // Initializes the back and next buttons. 
        static void InitWin(Window window, Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI)
        {
            // Find the back button within the window. 
            Button backBtn = (Button)window.GetChildByName("backBtn");
            // Attach a tap event handler. 
            backBtn.TapEvent += new OnTap(backBtn_TapEvent);

            Button nextBtn = (Button)window.GetChildByName("nextBtn");
            nextBtn.TapEvent += new OnTap(nextBtn_TapEvent);
            //Handler for IP address

            // dynamcially update the screen with ip & mac addr -- MM

            // Get the TextBox

            TextBlock ipTextBlock = (TextBlock)windows[0].GetChildByName("ipTextBlock");

            TextBlock macTextBlock = (TextBlock)windows[0].GetChildByName("macTextBlock");

            ipTextBlock.Text = "IP Address: = " + NI.IPAddress.ToString();

            macTextBlock.Text = "MAC Address = " + NI.PhysicalAddress[0].ToString() + "-" + NI.PhysicalAddress[1].ToString() + "-" + NI.PhysicalAddress[2].ToString() + "-"

            + NI.PhysicalAddress[3].ToString() + "-" + NI.PhysicalAddress[4].ToString() + "-" + NI.PhysicalAddress[5].ToString();




        }

        // Enables/disables navigation buttons appropriately. 
        static void updateButtons()
        {
            Window window = windows[index];

            // First window 
            if (index == 0)
            {
                Button backBtn = (Button)window.GetChildByName("backBtn");
                backBtn.Enabled = false;

                // Disabling a button reduces it's alpha to 1/3 it's current value. 
                // Simply invalidating a button won't show the alpha change because 
                // it's redrawing over the current bitmap. To show this change we need 
                // to clear the region it occupies (fill it with background color). 
                window.FillRect(backBtn.Rect);
                backBtn.Invalidate();
            }

            // Last window 
            if (index == windows.Length - 1)
            {
                Button nextBtn = (Button)window.GetChildByName("nextBtn");
                nextBtn.Enabled = false;

                window.FillRect(nextBtn.Rect);
                nextBtn.Invalidate();
            }
        }

        // Handles the next button tap event. 
        static void nextBtn_TapEvent(object sender)
        {
            if (index < windows.Length - 1)
            {
                int lastIndex = index;
                index++;

                // Update before we slide so the button state(s) are 
                // visually correct while we slide. 
                updateButtons();

                Tween.SlideWindow(windows[lastIndex], windows[index], Direction.Up);
            }
        }

        // Handles the back button tap event. 
        static void backBtn_TapEvent(object sender)
        {
            if (index > 0)
            {
                int lastIndex = index;
                index--;

                updateButtons();
                Tween.SlideWindow(windows[lastIndex], windows[index], Direction.Down);
            }
        }
    }
}

Only issue I have now is that I have an exception error that occurs at the folloiwng bit of code when the ethernet is not connected :

  Debug.Print("Renewing DHCP lease.");

                NI.RenewDhcpLease();

                Debug.Print("DCHP - IP Address = " + NI.IPAddress + ", MAC Address = " + NI.PhysicalAddress[0].ToString() + "-" + NI.PhysicalAddress[1].ToString() + "-" + NI.PhysicalAddress[2].ToString() + "-"

                + NI.PhysicalAddress[3].ToString() + "-" + NI.PhysicalAddress[4].ToString() + "-" + NI.PhysicalAddress[5].ToString());

Would like to add some error handling that debug prints ‘No connection available’ if the DHCP cannot be renewed. Would be great if anyone had any tips!

So you’re forcing DHCP - if it’s not enabled, enable it.

And if it is enabled, try to renew the lease - but that renewal won’t happen if you’ve just enabled it, right?

Can you tell us what throws the exception - the debug.print, or the renew? I wonder if the debug.print is doing it, which means all you have to do is check if the NI object and see if a valid address is there; if it’s the renew that’s failing then you could wrap it with Try/Catch and handle it, although progressing past that isn’t likely to be something that will get you anywhere.

Yep thats right. rwenewal wont happen. The exception occurs at NI.RenewDhcpLease();. Yeah I thikn I will need to use a Try/Catch but unsure of how to implement.

Ahh solved with this

  Debug.Print("Renewing DHCP lease.");

                try
                {
                    NI.RenewDhcpLease();

                }

                catch
                {
                    Debug.Print("IP address cannot be found");
                }
                Debug.Print("DCHP - IP Address = " + NI.IPAddress + ", MAC Address = " + NI.PhysicalAddress[0].ToString() + "-" + NI.PhysicalAddress[1].ToString() + "-" + NI.PhysicalAddress[2].ToString() + "-"

               + NI.PhysicalAddress[3].ToString() + "-" + NI.PhysicalAddress[4].ToString() + "-" + NI.PhysicalAddress[5].ToString());



Thanks for the help!

great news.

Try Catch is pretty simple really. Try this, and if that fails the catch bit gets executed. Syntax just like the pseudocode :slight_smile:

I would worry about debug.printing the IP address when it fails though, that also might lead you to problems - it’s certainly not needed, right? Just put it after the renew.

IIRC, there are also an iscableconnected() method that will tell you whether this comes about; dig into the API reference and see what it says.