private static void disconnect()
 {
     try
     {
         // already logged in?
         if (m_ID.Length > 0)
         {
             // logout from MTB
             m_MTBConnection.Logout(m_ID);
         }
     }
     catch (Exception exc)
     {
         // message box showing exception text
         Console.WriteLine(exc.Message);
     }
     finally
     {
         m_MTBRoot = null;
         device = null;
         m_MTBComponent = null;
     }
 }
        private static void connect()
        {
            try
            {
                // login to MTB
                m_MTBConnection.Login("de", out m_ID);//get a user ID from the server

                // get m_MTBRoot object
                m_MTBRoot = m_MTBConnection.GetRoot(m_ID);//get device id of root component, i.e microscope

                m_MTBRoot.StartMonitoring(m_ID);

                // list devices
                Console.WriteLine("List of connected components: ");
                int count = m_MTBRoot.GetDeviceCount();
                for (int i = 0; i < count; i++)
                {
                    IMTBDevice device = m_MTBRoot.GetDevice(i);
                    string name = device.Name;
                    Console.WriteLine(name);//print device name to conosle
                }
                m_MTBShutter = (IMTBShutter)m_MTBRoot.GetComponent("MTBShutter");
                m_MTBFocus = (IMTBFocus)m_MTBRoot.GetComponent("MTBFocus"); //get component id of focus mechanism
                m_MTBPassiveFocus = (IMTBAutoFocus)m_MTBRoot.GetComponent("MTBAutoFocus"); //get component id of auto focus mechan //-------this requires zeiss autofocus software
                m_MTBStage = (IMTBStage)m_MTBRoot.GetComponent("MTBStage"); //get component id of microscope stage
                microMetersPerSec = m_MTBFocus.GetSpeedUnit(1);
                microMeters = m_MTBFocus.GetPositionUnit(0);
                Console.WriteLine("MTB component ID's acquired");
            }
            catch (Exception exc)
            {
                disconnect();
                Console.WriteLine(exc.Message);
            }
        }